Class SmithyAnnotationProcessor<A extends java.lang.annotation.Annotation>
- java.lang.Object
-
- javax.annotation.processing.AbstractProcessor
-
- software.amazon.smithy.build.processor.SmithyAnnotationProcessor<A>
-
- Type Parameters:
A- Annotation to execute the processor for. This annotation should target thePACKAGEElementTypeand should be applied in thepackage-info.javafile of a package.
- All Implemented Interfaces:
javax.annotation.processing.Processor
public abstract class SmithyAnnotationProcessor<A extends java.lang.annotation.Annotation> extends javax.annotation.processing.AbstractProcessorBase implementation of a Smithy annotation processor.This implementation can be extended to create an Annotation processor for a Smithy build plugin that generates Java code. The processor will execute a single build plugin and write any generated Java code created by the plugin to the correct output path.
Smithy models on the classpath of extending annotation processors are automatically discovered and any java artifacts generated by this plugin are written to standard locations. Generated resource files are written to the class output while all other generated Java classes are written to the source output. Plugin artifacts that are not java files or resource files under
META-INF/are ignored.Extending classes must specify the name of the build plugin they will execute using
getPluginName(). This plugin must be discoverable on the annotation processor classpath. The plugin is then executed using the data from the annotation as the plugin configuration.For example, if your plugin has the following configuration node in a `smithy-build.json` file:
"myPlugin" : { "packageName" = "myPackage.namespace", "listOfTags" = ["a", "b", "c"] }Then you would define an annotation like the following:{@code
-
-
Constructor Summary
Constructors Constructor Description SmithyAnnotationProcessor()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract ObjectNodecreatePluginNode(A annotation, java.lang.String packageName)Maps annotation data to a plugin configuration node.protected abstract java.lang.Class<A>getAnnotationClass()Annotation class for the processor.protected abstract java.lang.StringgetPluginName()Name of the Smithy build plugin to execute with this annotation processor.voidinit(javax.annotation.processing.ProcessingEnvironment processingEnv)booleanprocess(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations, javax.annotation.processing.RoundEnvironment roundEnv)
-
-
-
Method Detail
-
init
public void init(javax.annotation.processing.ProcessingEnvironment processingEnv)
- Specified by:
initin interfacejavax.annotation.processing.Processor- Overrides:
initin classjavax.annotation.processing.AbstractProcessor
-
process
public boolean process(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations, javax.annotation.processing.RoundEnvironment roundEnv)- Specified by:
processin interfacejavax.annotation.processing.Processor- Specified by:
processin classjavax.annotation.processing.AbstractProcessor
-
getPluginName
protected abstract java.lang.String getPluginName()
Name of the Smithy build plugin to execute with this annotation processor.- Returns:
- name of plugin to run.
-
getAnnotationClass
protected abstract java.lang.Class<A> getAnnotationClass()
Annotation class for the processor.Each implementation of
SmithyProcessorshould have a specific package-scoped annotation used for configuration.createPluginNode(Annotation, String)maps this annotation to the configuration node for the plugin specified bygetPluginName().- Returns:
- class of the annotation used by this processor
-
createPluginNode
protected abstract ObjectNode createPluginNode(A annotation, java.lang.String packageName)
Maps annotation data to a plugin configuration node.- Parameters:
annotation- instance of generator annotation to use to create the build config.- Returns:
- ObjectNode to use as plugin configuration node.
-
-