Class SmithyAnnotationProcessor<A extends java.lang.annotation.Annotation>

  • Type Parameters:
    A - Annotation to execute the processor for. This annotation should target the PACKAGE ElementType and should be applied in the package-info.java file of a package.
    All Implemented Interfaces:
    javax.annotation.processing.Processor

    public abstract class SmithyAnnotationProcessor<A extends java.lang.annotation.Annotation>
    extends javax.annotation.processing.AbstractProcessor
    Base 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
    • Field Summary

      • Fields inherited from class javax.annotation.processing.AbstractProcessor

        processingEnv
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract ObjectNode createPluginNode​(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.String getPluginName()
      Name of the Smithy build plugin to execute with this annotation processor.
      void init​(javax.annotation.processing.ProcessingEnvironment processingEnv)  
      boolean process​(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations, javax.annotation.processing.RoundEnvironment roundEnv)  
      • Methods inherited from class javax.annotation.processing.AbstractProcessor

        getCompletions, getSupportedAnnotationTypes, getSupportedOptions, getSupportedSourceVersion, isInitialized
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SmithyAnnotationProcessor

        public SmithyAnnotationProcessor()
    • Method Detail

      • init

        public void init​(javax.annotation.processing.ProcessingEnvironment processingEnv)
        Specified by:
        init in interface javax.annotation.processing.Processor
        Overrides:
        init in class javax.annotation.processing.AbstractProcessor
      • process

        public boolean process​(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations,
                               javax.annotation.processing.RoundEnvironment roundEnv)
        Specified by:
        process in interface javax.annotation.processing.Processor
        Specified by:
        process in class javax.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 SmithyProcessor should have a specific package-scoped annotation used for configuration. createPluginNode(Annotation, String) maps this annotation to the configuration node for the plugin specified by getPluginName().

        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.