Class AbstractAnnotationProcessor

java.lang.Object
javax.annotation.processing.AbstractProcessor
com.github.tadukoo.util.annotation.process.AbstractAnnotationProcessor
All Implemented Interfaces:
javax.annotation.processing.Processor
Direct Known Subclasses:
AnnotationProcessorProcessor, ShouldBeFinalProcessor

public abstract class AbstractAnnotationProcessor
extends javax.annotation.processing.AbstractProcessor
An Abstract Annotation Process to be used in creating new annotation processors in a simpler way than having them extend AbstractProcessor themselves.
Also includes AnnotationUtil to make it easier to perform common operations in processors.
Version:
Pre-Alpha
Author:
Logan Ferree (Tadukoo)
  • Field Summary

    Fields
    Modifier and Type Field Description
    private java.lang.Class<? extends java.lang.annotation.Annotation> annotation
    The Annotation class this processor is used for
    protected AnnotationUtil annotationUtil
    AnnotationUtil to use for common annotation processing operations

    Fields inherited from class javax.annotation.processing.AbstractProcessor

    processingEnv
  • Constructor Summary

    Constructors
    Constructor Description
    AbstractAnnotationProcessor​(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
    Calls the AbstractProcessor constructor and sets the Annotation class this processor is used for.
  • Method Summary

    Modifier and Type Method Description
    java.util.Set<java.lang.String> getSupportedAnnotationTypes()
    Returns the Annotation type this is for, by grabbing the name off the stored Annotation class.
    void init​(javax.annotation.processing.ProcessingEnvironment processingEnvironment)
    Calls the AbstractProcessor init method and then uses the given ProcessingEnvironment to initialize the AnnotationUtil.
    boolean process​(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations, javax.annotation.processing.RoundEnvironment roundEnv)
    Processes the annotation on the elements it's attached to.
    protected abstract void processElements​(java.util.Set<? extends javax.lang.model.element.Element> elements)
    Actually handle processing the given elements for the annotation this handles.

    Methods inherited from class javax.annotation.processing.AbstractProcessor

    getCompletions, getSupportedOptions, getSupportedSourceVersion, isInitialized

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • annotationUtil

      protected AnnotationUtil annotationUtil
      AnnotationUtil to use for common annotation processing operations
    • annotation

      private final java.lang.Class<? extends java.lang.annotation.Annotation> annotation
      The Annotation class this processor is used for
  • Constructor Details

    • AbstractAnnotationProcessor

      public AbstractAnnotationProcessor​(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
      Calls the AbstractProcessor constructor and sets the Annotation class this processor is used for.
      Parameters:
      annotation - The Annotation class this is for
  • Method Details

    • init

      public final void init​(javax.annotation.processing.ProcessingEnvironment processingEnvironment)
      Calls the AbstractProcessor init method and then uses the given ProcessingEnvironment to initialize the AnnotationUtil.
      Specified by:
      init in interface javax.annotation.processing.Processor
      Overrides:
      init in class javax.annotation.processing.AbstractProcessor
      Parameters:
      processingEnvironment - The ProcessingEnvironment this is happening in
    • getSupportedAnnotationTypes

      public final java.util.Set<java.lang.String> getSupportedAnnotationTypes()
      Returns the Annotation type this is for, by grabbing the name off the stored Annotation class.
      Specified by:
      getSupportedAnnotationTypes in interface javax.annotation.processing.Processor
      Overrides:
      getSupportedAnnotationTypes in class javax.annotation.processing.AbstractProcessor
      Returns:
      The Annotation type this processor is for
    • process

      public final boolean process​(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations, javax.annotation.processing.RoundEnvironment roundEnv)
      Processes the annotation on the elements it's attached to. Ultimately calls processElements(java.util.Set<? extends javax.lang.model.element.Element>) to do the actual processing. If processElements(java.util.Set<? extends javax.lang.model.element.Element>) throws anything, it throws a compile error on the relevant annotation with the stack trace.
      Specified by:
      process in interface javax.annotation.processing.Processor
      Specified by:
      process in class javax.annotation.processing.AbstractProcessor
      Parameters:
      annotations - The annotations to process (should just be the one this processor is for)
      roundEnv - The RoundEnvironment used for grabbing the elements
      Returns:
      True
    • processElements

      protected abstract void processElements​(java.util.Set<? extends javax.lang.model.element.Element> elements) throws java.lang.Throwable
      Actually handle processing the given elements for the annotation this handles.
      Parameters:
      elements - The Set of elements to process for the annotation
      Throws:
      java.lang.Throwable - If anything goes wrong, subclasses may throw something