Class SourceTemplate
java.lang.Object
de.japkit.test.members.common.source.SourceTemplate
@Clazz(commentExpr="The generated class for the example.")
@RuntimeMetadata
public class SourceTemplate
extends java.lang.Object
When generating members, the src (source) variable can be set by evaluating
an expression (src) or calling a function (srcFun). If the src variable is
set to a collection value, a member for each field in that collection is
generated.
The template mainly generates fields, but the same applies also to methods, constructors and inner classes.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
SourceTemplate.FieldAndMethod
If multiple elements shall be generated for the same src, they can be grouped by a template.(package private) class
SourceTemplate.fields
A function to get the fields of aTypeElement
.(package private) class
SourceTemplate.isField
A function to determine whether anElement
is a field. -
Field Summary
Fields Modifier and Type Field Description (package private) java.lang.String
originalSourceIsTheAnnotatedClass
If no src is set, the src variable is the same as the one of the surrounding template.(package private) de.japkit.functions.SrcType
srcIsSetToTheListOfFields
Here, the src is set to the list of fields of theTypeElement
for the annotated classSourceExample
.(package private) de.japkit.functions.SrcType
srcIsSetToTheListOfFieldsFilter
Since filtering is quite common for a src collection, the filter condition can also be provided as srcFilter.(package private) de.japkit.functions.SrcType
srcIsSetToTheListOfFieldsFilterSrcIsImplicit
The src variable is always implicit in expressions, so it can be omitted.(package private) de.japkit.functions.SrcType
srcIsSetToTheListOfFieldsWithFilterFunction
Also, a function can be called to filter the source.(package private) de.japkit.functions.SrcType
srcIsSetToTheListOfFieldsWithFunction
Also, a function can be called to determine the source. -
Constructor Summary
Constructors Constructor Description SourceTemplate()
-
Method Summary
-
Field Details
-
originalSourceIsTheAnnotatedClass
@Field(nameExpr="#{src.simpleName.toFirstLower}") java.lang.String originalSourceIsTheAnnotatedClassIf no src is set, the src variable is the same as the one of the surrounding template. Since this is theClazz
template here, the src is theTypeElement
for the class annotated with the trigger annotation.So, the resulting field name is "sourceExample", since the src is the
TypeElement
for the annotated classSourceExample
, and itsTypeElement.getSimpleName()
is "SourceExample". -
srcIsSetToTheListOfFields
@Field(src="#{src.enclosedElements.stream().filter(e -> e.kind == \'FIELD\').toList()}", nameExpr="#{src.simpleName}Copy1") de.japkit.functions.SrcType srcIsSetToTheListOfFieldsHere, the src is set to the list of fields of theTypeElement
for the annotated classSourceExample
. For a src of a collection type, the member template is applied for every element. Thus, there is a field generated for every field in this list. The resulting fields are "srcField1Copy" and "srcField2Copy".The new src hides the original one, which was the
TypeElement
for the annotated classSourceExample
. If generating the member is done, the original src is restored again. In other words, each member is generated within a new scope with its own value for src and potentially other variables. -
srcIsSetToTheListOfFieldsFilter
@Field(src="#{src.enclosedElements}", srcFilter="#{src.kind == \'FIELD\'}", nameExpr="#{src.simpleName}Copy2") de.japkit.functions.SrcType srcIsSetToTheListOfFieldsFilterSince filtering is quite common for a src collection, the filter condition can also be provided as srcFilter. -
srcIsSetToTheListOfFieldsFilterSrcIsImplicit
@Field(src="#{enclosedElements}", srcFilter="#{kind == \'FIELD\'}", nameExpr="#{simpleName}Copy3") de.japkit.functions.SrcType srcIsSetToTheListOfFieldsFilterSrcIsImplicitThe src variable is always implicit in expressions, so it can be omitted. -
srcIsSetToTheListOfFieldsWithFunction
@Field(srcFun=fields.class, nameExpr="#{simpleName}Copy4") de.japkit.functions.SrcType srcIsSetToTheListOfFieldsWithFunctionAlso, a function can be called to determine the source. -
srcIsSetToTheListOfFieldsWithFilterFunction
@Field(src="#{enclosedElements}", srcFilterFun=isField.class, nameExpr="#{simpleName}Copy5") de.japkit.functions.SrcType srcIsSetToTheListOfFieldsWithFilterFunctionAlso, a function can be called to filter the source.
-
-
Constructor Details
-
SourceTemplate
public SourceTemplate()
-