Class BaseProcessor

    • Field Summary

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

        processingEnv
    • Constructor Summary

      Constructors 
      Constructor Description
      BaseProcessor()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.util.Set<java.lang.String> additionalProcessingOptions()
      Returns additional processing options that should only be applied for a single processor.
      protected boolean claimAnnotations()  
      protected boolean delayErrors()  
      javax.lang.model.util.Elements getElementUtils()  
      protected dagger.hilt.processor.internal.ProcessorErrorHandler getErrorHandler()  
      javax.annotation.processing.Messager getMessager()  
      javax.annotation.processing.ProcessingEnvironment getProcessingEnv()  
      java.util.Set<java.lang.String> getSupportedOptions()  
      javax.lang.model.SourceVersion getSupportedSourceVersion()  
      javax.lang.model.util.Types getTypeUtils()  
      void init​(javax.annotation.processing.ProcessingEnvironment processingEnvironment)  
      protected void postRoundProcess​(javax.annotation.processing.RoundEnvironment roundEnv)
      Used to perform post processing at the end of a round.
      protected void preRoundProcess​(javax.annotation.processing.RoundEnvironment roundEnv)
      Used to perform initialization before each round of processing.
      boolean process​(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations, javax.annotation.processing.RoundEnvironment roundEnv)
      This should not be overridden, as it defines the order of the processing.
      protected void processEach​(javax.lang.model.element.TypeElement annotation, javax.lang.model.element.Element element)
      Called for each element in a round that uses a supported annotation.
      • Methods inherited from class javax.annotation.processing.AbstractProcessor

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

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

      • BaseProcessor

        public BaseProcessor()
    • Method Detail

      • getSupportedOptions

        public final java.util.Set<java.lang.String> getSupportedOptions()
        Specified by:
        getSupportedOptions in interface javax.annotation.processing.Processor
        Overrides:
        getSupportedOptions in class javax.annotation.processing.AbstractProcessor
      • additionalProcessingOptions

        protected java.util.Set<java.lang.String> additionalProcessingOptions()
        Returns additional processing options that should only be applied for a single processor.
      • preRoundProcess

        protected void preRoundProcess​(javax.annotation.processing.RoundEnvironment roundEnv)
        Used to perform initialization before each round of processing.
      • processEach

        protected void processEach​(javax.lang.model.element.TypeElement annotation,
                                   javax.lang.model.element.Element element)
                            throws java.lang.Exception
        Called for each element in a round that uses a supported annotation. Note that an exception can be thrown for each element in the round. This is usually preferred over throwing only the first exception in a round. Only throwing the first exception in the round can lead to flaky errors that are dependent on the non-deterministic ordering that the elements are processed in.
        Throws:
        java.lang.Exception
      • postRoundProcess

        protected void postRoundProcess​(javax.annotation.processing.RoundEnvironment roundEnv)
                                 throws java.lang.Exception
        Used to perform post processing at the end of a round. This is especially useful for handling additional processing that depends on aggregate data, that cannot be handled in #processEach().

        Note: this will not be called if an exception is thrown during #processEach() -- if we have already detected errors on an annotated element, performing post processing on an aggregate will just produce more (perhaps non-deterministic) errors.

        Throws:
        java.lang.Exception
      • claimAnnotations

        protected boolean claimAnnotations()
        Returns:
        true if you want to claim annotations after processing each round. Default false.
      • delayErrors

        protected boolean delayErrors()
        Returns:
        true if you want to delay errors to the last round. Useful if the processor generates code for symbols used a lot in the user code. Delaying allows as much code to compile as possible for correctly configured types and reduces error spam.
      • init

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

        public javax.lang.model.SourceVersion getSupportedSourceVersion()
        Specified by:
        getSupportedSourceVersion in interface javax.annotation.processing.Processor
        Overrides:
        getSupportedSourceVersion in class javax.annotation.processing.AbstractProcessor
      • process

        public final boolean process​(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations,
                                     javax.annotation.processing.RoundEnvironment roundEnv)
        This should not be overridden, as it defines the order of the processing.
        Specified by:
        process in interface javax.annotation.processing.Processor
        Specified by:
        process in class javax.annotation.processing.AbstractProcessor
      • getErrorHandler

        protected final dagger.hilt.processor.internal.ProcessorErrorHandler getErrorHandler()
        Returns:
        the error handle for the processor.
      • getProcessingEnv

        public final javax.annotation.processing.ProcessingEnvironment getProcessingEnv()
      • getElementUtils

        public final javax.lang.model.util.Elements getElementUtils()
      • getTypeUtils

        public final javax.lang.model.util.Types getTypeUtils()
      • getMessager

        public final javax.annotation.processing.Messager getMessager()