@SupportedAnnotationTypes(value="*") public class AndHowCompileProcessor extends AbstractProcessor
SupportedAnnotationTypes("*"), allowing it to
'see' all classes as they are compiled. This class then delegates to a
'scanner' class that does deep inspection on compiled code, looking for
AndHow Properties.
PropertyRegistrar
class is created, which contains the list of Properties in that class.
There is a one-to-one correspondence between user classes that contain
AndHow Properties and auto-created PropertyRegistrar classes.
ServiceLoader to discover all instances
of PropertyRegistrar on the classpath, thus finding all AndHow
Property containing classes.| Modifier and Type | Class and Description |
|---|---|
protected static class |
AndHowCompileProcessor.CauseEffect
Match up a causal Element (Basically the compiler representation of a
class to be compiled) w/ the Class name that will be registered in
a service registry.
|
processingEnv| Constructor and Description |
|---|
AndHowCompileProcessor()
A no-arg constructor is required.
|
| Modifier and Type | Method and Description |
|---|---|
SourceVersion |
getSupportedSourceVersion() |
void |
init(ProcessingEnvironment processingEnv) |
boolean |
process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) |
void |
writeClassFile(Filer filer,
PropertyRegistrarClassGenerator generator,
Element causingElement)
Writes a new class implementing the
PropertyRegistrar interface. |
protected void |
writeServiceFile(Filer filer,
String fullyQualifiedServiceInterfaceName,
List<AndHowCompileProcessor.CauseEffect> implementingClasses) |
getCompletions, getSupportedAnnotationTypes, getSupportedOptions, isInitializedpublic AndHowCompileProcessor()
public void init(ProcessingEnvironment processingEnv)
init in interface Processorinit in class AbstractProcessorpublic SourceVersion getSupportedSourceVersion()
getSupportedSourceVersion in interface ProcessorgetSupportedSourceVersion in class AbstractProcessorpublic boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv)
process in interface Processorprocess in class AbstractProcessorpublic void writeClassFile(Filer filer, PropertyRegistrarClassGenerator generator, Element causingElement) throws Exception
PropertyRegistrar interface.
The new class directly corresponds to a user classes containing AndHow
Properties and will contain meta data about the properties.filer - The javac file system representation for writing files.generator - AndHow class capable of generating source code for this
PropertyRegistrar class.causingElement - A javac Element, which generically refers to any
piece of source code such as a keyword, class name, etc.. When a file
is written to the filer, a causingElement is recorded as metadata
so there is an association between the file and the reason it was written.
Likely this is normally used to associate source code line numbers with
generated code.Exception - If unable to write (out of disc space?)protected void writeServiceFile(Filer filer, String fullyQualifiedServiceInterfaceName, List<AndHowCompileProcessor.CauseEffect> implementingClasses) throws IOException
IOExceptionCopyright © 2021. All rights reserved.