Package dagger.hilt.processor.internal
Class BaseProcessor
- java.lang.Object
-
- javax.annotation.processing.AbstractProcessor
-
- dagger.hilt.processor.internal.BaseProcessor
-
- All Implemented Interfaces:
javax.annotation.processing.Processor
- Direct Known Subclasses:
AggregatedDepsProcessor,AliasOfProcessor,AndroidEntryPointProcessor,BindValueProcessor,ComponentTreeDepsProcessor,CustomTestApplicationProcessor,DefineComponentProcessor,DisableInstallInCheckProcessor,GeneratesRootInputProcessor,OriginatingElementProcessor,RootProcessor,UninstallModulesProcessor
public abstract class BaseProcessor extends javax.annotation.processing.AbstractProcessorImplements default configurations for Processors, and provides structure for exception handling.By default #process() will do the following:
- #preRoundProcess()
- foreach element:
- #processEach()
- #postRoundProcess()
- #claimAnnotation()
#processEach() allows each element to be processed, even if exceptions are thrown. Due to the non-deterministic ordering of the processed elements, this is needed to ensure a consistent set of exceptions are thrown with each build.
-
-
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 booleanclaimAnnotations()protected booleandelayErrors()javax.lang.model.util.ElementsgetElementUtils()protected dagger.hilt.processor.internal.ProcessorErrorHandlergetErrorHandler()javax.annotation.processing.MessagergetMessager()javax.annotation.processing.ProcessingEnvironmentgetProcessingEnv()java.util.Set<java.lang.String>getSupportedOptions()javax.lang.model.SourceVersiongetSupportedSourceVersion()javax.lang.model.util.TypesgetTypeUtils()voidinit(javax.annotation.processing.ProcessingEnvironment processingEnvironment)protected voidpostRoundProcess(javax.annotation.processing.RoundEnvironment roundEnv)Used to perform post processing at the end of a round.protected voidpreRoundProcess(javax.annotation.processing.RoundEnvironment roundEnv)Used to perform initialization before each round of processing.booleanprocess(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 voidprocessEach(javax.lang.model.element.TypeElement annotation, javax.lang.model.element.Element element)Called for each element in a round that uses a supported annotation.
-
-
-
Method Detail
-
getSupportedOptions
public final java.util.Set<java.lang.String> getSupportedOptions()
- Specified by:
getSupportedOptionsin interfacejavax.annotation.processing.Processor- Overrides:
getSupportedOptionsin classjavax.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.ExceptionCalled 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.ExceptionUsed 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:
initin interfacejavax.annotation.processing.Processor- Overrides:
initin classjavax.annotation.processing.AbstractProcessor
-
getSupportedSourceVersion
public javax.lang.model.SourceVersion getSupportedSourceVersion()
- Specified by:
getSupportedSourceVersionin interfacejavax.annotation.processing.Processor- Overrides:
getSupportedSourceVersionin classjavax.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:
processin interfacejavax.annotation.processing.Processor- Specified by:
processin classjavax.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()
-
-