public class PropertyRegistrarClassGenerator extends Object
| Modifier and Type | Field and Description |
|---|---|
protected static String |
ANNOTATION_TEMPLATE_PATH |
protected static String |
CLASS_TEMPLATE_PATH |
protected static String |
COMMENTED_ANNOTATION_TEMPLATE_PATH |
| Constructor and Description |
|---|
PropertyRegistrarClassGenerator(CompileUnit compUnit,
Class<?> generatingClass,
Calendar runDate,
int srcMajorVersion,
int jdkMajorVersion)
Create a new instance w all info needed to generateSource a PropertyRegistrar file.
|
| Modifier and Type | Method and Description |
|---|---|
protected String |
buildGeneratedClassFullName()
The complete canonical name of the generated class, including the package.
|
protected String |
buildGeneratedClassSimpleName()
The simple class name of the generated class.
|
protected String |
buildPackageString()
The package declaration of the generated class.
|
protected String |
buildRegistrationAddsString()
Builds the source code for the content of the addPropertyRegistrations method.
|
protected String |
buildRunDateString()
A formatted date appropriate for the `Generated` annotation.
|
String |
generateAnnotationSource()
Generates the source for the 'Generated' annotation to place on the generated class.
|
String |
generateSource()
Generates the complete source for the AndHow proxy class as a String.
|
String |
getTemplate(String path)
Loads a text file as a String from a classpath path.
|
protected static final String CLASS_TEMPLATE_PATH
protected static final String ANNOTATION_TEMPLATE_PATH
protected static final String COMMENTED_ANNOTATION_TEMPLATE_PATH
public PropertyRegistrarClassGenerator(CompileUnit compUnit, Class<?> generatingClass, Calendar runDate, int srcMajorVersion, int jdkMajorVersion)
Annotation Processor generated classes should have an @Generated annotation, however, the package of that class changed between JDK8 and JDK9. The srcMajorVersion is used to distinguish which annotation to use. JDK 1.8 = version 8, and so on.
compUnit - CompileUnit instance w/ all needed class and property infogeneratingClass - The class of our AnnotationProcessor to be listed as the generator in the
Generated annotation.runDate - The Calendar date-time of the run, used for annotation.
Passed in so all generated files can have the same timestamp.srcMajorVersion - The major java lang version the output needs to be compatible with.jdkMajorVersion - The major version of the JDK currently running.public String getTemplate(String path) throws Exception
path - A path on the classpath, beginning with a slash.Exception - IF the file cannot be read.public String generateAnnotationSource() throws Exception
Exception - If the template file for the annotation cannot be found.public String generateSource() throws Exception
Exception - If any of the template files used for creating the class cannot be read.protected String buildPackageString()
This should match the class its proxying, including an empty string for classes in the default package.
protected String buildGeneratedClassSimpleName()
As per Java conventions, a generated class starts with a '$'. The rest of the class name matches the class it proxies followed by "_AndHowProps".
protected String buildGeneratedClassFullName()
The package portion matches the package of the class being proxied. The class name
as described in buildGeneratedClassSimpleName().
protected String buildRunDateString()
protected String buildRegistrationAddsString()
Copyright © 2022. All rights reserved.