@Retention(value=SOURCE) @Target(value={TYPE,PACKAGE}) public @interface VALJOConfigure
VALJOGenerate
annotation. If specified on both a package and an interface then the package specification is ignored. Has no effect
unless affected interfaces also has a VALJOGenerate
annotation. All options may be overruled by setting identically named qualified key/values
in the annotation processor using the -Acom.fortyoneconcepts.valjogen.optionName=value option to javac. Indeed some details like logLevel
are usally better specified as a runtime option instead of hardcoding in the source using this annotation.
Usage example (package-info.java):
@VALJOConfigure(outputPackage="test.impl", baseClazzName="test.CommonBaseClass")
package test;
The above code will instruct the VALJOGen annotation processor to have generated value object classes from interfaces in this package belong to
the "test.impl" package and to inherit from a common base class with qualified name "test.CommonBaseClass". Note that generation requires
a seperate VALJOGenerate
annotation. This other annotation is also used to specify what name the generated class should have.
For advanced customization do refer to the customJavaTemplateFileName option. This is the ultimate swiss army knife that lets you change and extend everything you want. It is a bit more difficult to use then other features though so look at the other options first.
* All string properties expand system properties as macros when enclosed in $() as well as the following macros:
$(This)
which resolves to the fully qualified name of the generated class. The macro can be especially useful when implementing the Comparable interface using the extraInterfaceNames option.
$(IThis)
which resolves to the the fully qualified name of the interface that is used for generation.
$(ExecutionDate)
which resolves to the the time the annotation processes ran.
$(N/A)
which signifies the value is unspecified (internally represented as a 'null').
Modifier and Type | Optional Element and Description |
---|---|
String[] |
baseClazzConstructors
Specifies the base class constructors to delegate to in generated constructors and factory methods.
|
String |
baseClazzName
Specifies the base class of the generated class.
|
String[] |
clazzAnnotations
Specifies annotation strings with arguments that should be added to the generated class.
|
String |
clazzJavaDoc
Javadoc text string (without leading/ending comment characters) that should be added to generated class.
|
String[] |
clazzModifiers
Explicitly defined modifiers such as PUBLIC, PROTECTED, PRIVATE, FINAL or ABSTRACT to set in generated class.
|
String |
comment
An optional user supplied comment.
|
String[] |
comparableMembers
For classes that implement the
Comparable interface this is the ordered names of members to use in a compareTo implementation. |
String |
customJavaTemplateFileName
This is the ultimate customization power feature as it allows all aspects of the generated class to be changed or extended.
|
DataConversion |
dataConversion
Specifies if generated object should be easily convertable to/from xml or json.
|
boolean |
debugStringTemplates
Experimental debugging feature that specifies if the annotation processor should open the STViz GUI Inspector for debugging the internal stringtemplates.
|
boolean |
ensureNotNullEnabled
Specifies assignments to local variables should guard against null.
|
boolean |
equalsEnabled
Specifies if equals method should be generated for the class.
|
String[] |
extraInterfaceNames
Specifies if additional interfaces should be implemented to the generated class.
|
boolean |
finalMembersAndParametersEnabled
Specifies if generated members and method parameters should be final if possible.
|
boolean |
finalMethodsEnabled
Specifies if generated methods (incl.
|
boolean |
forceThisAsImmutableSetterReturnType
Specifies if return type of immutable setters should be fixed to be the class itself (covariannce) instead of what interfaces declare.
|
String[] |
getterPrefixes
Specifies the prefixes of javaBean-style getter methods.
|
boolean |
hashEnabled
Specifies if hash method should be generated for the class.
|
String |
headerFileName
UTF-8 formatted file that contains a header that should be added at the top of the generated output.
|
boolean |
ignoreMalformedProperties
Specifies if errors should be issued for malformed getter and setter methods.
|
String[] |
importClasses
Fully qualified extra classes to import into the generated code (in addition to implemented interfaces
and baseclass which is imported as needed).
|
boolean |
insertInheritDocOnMethodsEnabled
Specifies if inheritDoc javaDoc comments should be added to the generated class for methods.
|
int |
lineWidth
Linewidth for generated code.
|
String |
localeTag
Experimental IETF BCP 47 language tag string descripting internal locale to use for annotation processor.
|
String |
logLevel
Specifies the
Level log level to use inside the annotation processor. |
String[] |
memberAnnotations
Specifies individual annotations for member fields as key-value entries.
|
String[] |
methodAnnotations
Specifies individual annotations for individual methods as key-value entries.
|
Mutability |
mutability
Specifies if generated object should be immutable or mutable.
|
String |
outputPackage
Package name of generated class.
|
long |
serialVersionUID
Specifies the serialization ID to use for generated classes or ZERO if not set.
|
String[] |
setterPrefixes
Specifies the prefixes of javaBean-style getter methods.
|
boolean |
staticFactoryMethodEnabled
Specifie if a static factory method should be generated instead of having the constructor being public.
|
String |
suggestedVariablesPrefix
Specifies prefix to use by temporary variables in method in order to avoid clashing with members.
|
boolean |
synchronizedAccessEnabled
Specifies if generated properties/methods for mutable members should be synchronized.
|
boolean |
toStringEnabled
Specifies if a toString method should be generated the class.
|
boolean |
warnAboutSynthesisedNames
Specifies if the annotation processor should warn about parameter names that are synthesised because -parameter option is missing.
|
public abstract String outputPackage
public abstract String[] clazzModifiers
public abstract int lineWidth
public abstract Mutability mutability
public abstract DataConversion dataConversion
public abstract boolean finalMembersAndParametersEnabled
public abstract boolean finalMethodsEnabled
public abstract boolean ensureNotNullEnabled
public abstract boolean staticFactoryMethodEnabled
public abstract boolean synchronizedAccessEnabled
public abstract String suggestedVariablesPrefix
public abstract long serialVersionUID
Serializable
interface.
May be overruled by equivalent annotation processor key.public abstract boolean equalsEnabled
hashEnabled()
public abstract boolean hashEnabled
equalsEnabled()
public abstract String[] comparableMembers
Comparable
interface this is the ordered names of members to use in a compareTo implementation. This may include accessible members of a base class.
If left unspecified it defaults to all members of the generated class in declaration order. May be overruled by equivalent annotation processor key.public abstract boolean toStringEnabled
public abstract boolean insertInheritDocOnMethodsEnabled
public abstract boolean ignoreMalformedProperties
public abstract String[] importClasses
public abstract String[] getterPrefixes
public abstract String[] setterPrefixes
public abstract boolean forceThisAsImmutableSetterReturnType
public abstract String[] extraInterfaceNames
"$(This)"
for the generic qualifier is useful to refer to the name of the generated class. F.x.
to implement Comparable write "java.lang.Comparable<(This)>
".public abstract String baseClazzName
public abstract String[] baseClazzConstructors
"(" <unqualifed parameter type name> { "," <unqualifed parameter type name> } ")"
. For example to specify a constructor taking an integer and a String
as arguments write (int,String)
. Note that all type names are unqualified.
In addition the wildcard '*' may be used to match a single type name and the wildcard '**' may used to match all set of typenames (i.e. each and every base constructor).public abstract String[] clazzAnnotations
public abstract String[] methodAnnotations
<method name> "(" <unqualifed parameter type name> { "," <unqualifed parameter type name> } ")" "=" <annotation string>
. For example to annotate a method "f" taking an integer and a String
as arguments write f(int,String)=@MyAnnotation(...)
. Note that all type names are unqualified. To specify a constructor set <method_name> to an empty string. To specify a factory method set method name to "valueOf".
In addition the wildcard '*' may be used to match a single type name and the wildcard '**' may used to match all combinations of type name arguments.public abstract String[] memberAnnotations
<member name> "=" <annotation string>
. For example to annotate a member named "x" write x=@MyAnnotation(...)
.public abstract String clazzJavaDoc
public abstract String headerFileName
public abstract String customJavaTemplateFileName
See ST 4 documentation and the cheat sheet in particular for details about how to write templates. The custom group file that can be added using this option will inherit from the existing templates allowing you to add new templates or override the build-in templates.
Note that ST maintains strict Model-View separation so templates can not contain logic or compare values other then booleans. Note also that templates can call into model getters but with the get/is prefix omitted.
Refer to the existing source (*.stg files) for this processor for how to work with the models available from a template. For details about the model see refer to javadoc or source for the com.fortyoneconcepts.valjogen.model.* classes in the annotation processor tool.
Preferably consider overriding declared ST regions like for example <@preamble>
to change output rather then overriding existing templates in your ST file. This
should reduce maintaince problems for future updates. ST requires regions to be prefixed with the template method they are declared in, so to add code in beginning of the equals method, add a
ST file with a template rule like this:
@method_equals.preamble() ::= << // initial method code here. >>
When you need to generate code for new java methods implementations, first make sure the method signature is declared, then add a template named method_specifier
with the template arguments clazz
and method
in your ST group file. The specifier is the java method name followed by underscore seperated, unqualified type arguments with a leading underscore
before first argument (if present). For example to generate the method "void f()" create a template named method_f
" and to generate the method "double f(String arg, int value)"
create a template named method_f_String_int
". The require custom method arguments are of type Clazz and Method in the com.fortyoneconcepts.valjogen.model package. Refer to the JavaDoc for these for details.
Declared methods that the implementation can override include methods in the interfaces and base class and their ancestors. In addition, if the generated class is serializable
the magic serialization methods readResolve, readObjectNoData, writeObject and writeReplace are also recognized as methods.
In you instead need to implement non-declared methods, add nested types or do something special then do override one of the ST regions in the main class
template like f.x. @class.before_class_methods,
@class.after_class_methods, @class.before_instance_methods or @class.after_instance_methods. When you override regions you have complete freedom to add
any kind of code but without help like method signatures etc.
The example shown below shows how the main part of the equals method might be defined. Refer to the ST source file for the equals method
for the complete and present source code. In any case it is a good idea to study the template sources and example templates for tips about how to write custom templates. Note how getters in the model
is accessed (with getter prefixes stripped) to facilitate the generation of the method according of the actal class members, method arguments etc.
method_equals(clazz, method) ::= <<
<declare_method(clazz, method)>
{
<if(clazz.anyMembers)>
<clazz.prototypicalName> <uniqueVariableName(clazz,"other")> = (<clazz.prototypicalName>) <first(method.parameters).name>;
return (<clazz.members:{m | <(equalsTemplateNamesByTypeCategory.(m.type.typeCategory))(clazz, m.name, m.type)>}; wrap, anchor, separator=" && ">);
<else>
return true;
<endif>
}
>>
This file name may be overruled by equivalent annotation processor key.
public abstract boolean warnAboutSynthesisedNames
public abstract String logLevel
Level
log level to use inside the annotation processor. Set this to INFO or FINE to inspect model instances,
inspect output or to help track errors inside the processor. Set to WARNING otherwise.
Note that normally java.util.logging.ConsoleHandler.level needs to be set as well for log levels below INFO to be shown.public abstract boolean debugStringTemplates
public abstract String localeTag
Locale.forLanguageTag(java.lang.String)
public abstract String comment
Version 2.0.0 generated on 2014-11-22 at 09:45 - (C) 41concepts Aps. Refer to project homepage valjogen.41concepts.com for more information.