Skip to main content

Feature Anchor Options

In some cases the behaviour of the feature anchorsAnchorA marker within generated source code reserved for adding custom logic during re-expansion. needs to be modified to generate the correct artifactArtifactA build or deployment result, such as a Docker container image or Java archive, produced by a software project. content. Both @anchor and @hook statements in the templates allow you to define options in the start anchorAnchorA marker within generated source code reserved for adding custom logic during re-expansion..

@anchor(options...)​

optiondescriptionexample
prefixAdds the prefix at the start of the content, but only if at least 1 feature injects content.@anchor:interfaces(prefix: 'implements ')
suffixAdds the suffix at the end of the content, but only if at least 1 feature injects content.@anchor:items(suffix: ', ')
separatorAdds the separator between each feature. For inline anchorsAnchorA marker within generated source code reserved for adding custom logic during re-expansion., if the injected content has multiple lines, the separator is placed between the lines as well.@anchor:items(separator: ', ')
commentLineFormatProvides a format for the start and end anchorAnchorA marker within generated source code reserved for adding custom logic during re-expansion. comments. Useful if the default comment format is not correct for the generated file.@anchor:vars(commentLineFormat: '# %s')
noCommentsRemoves the start and end anchorAnchorA marker within generated source code reserved for adding custom logic during re-expansion. comments. This reduces traceability, but some file formats do not support comments.@anchor:vars(noComments: true)
sortDefine a java class that implements Comparator<FeatureSegmentComposite>, which will be used to sort the injected features.@anchor:vars(sort: org.example.SortAlphabetically)
inline feature anchors

Inline feature anchorsAnchorA marker within generated source code reserved for adding custom logic during re-expansion. are a special variant of the feature anchorAnchorA marker within generated source code reserved for adding custom logic during re-expansion.. They combine the feature injections into a single line, usually using a separator.

base() ::= <<
class <className> @anchor:interfaces(prefix: 'implements ', separator: ', ')@{
}
>>

Results in:

class MyClass /*@anchor:interfaces:start*/implements Serializable, MyInterface/*@anchor:interfaces:end*/ {
}

@hook(options....)​

For feature templates, options need to be defined in the start hook.

base() ::= <<
@hook:variables(first: true):start
private String myVariable; // Always placed first.
@hook:variables:end
>>
optiondescriptionexample
firstPlace the content of this feature segment at the start of the anchorAnchorA marker within generated source code reserved for adding custom logic during re-expansion..@hook:vars(first: true):start
lastPlace the content of this feature segment at the end of the anchorAnchorA marker within generated source code reserved for adding custom logic during re-expansion..@hook:vars(last: true):start
groupOnly works in a @hook:methods anchorAnchorA marker within generated source code reserved for adding custom logic during re-expansion.. Features defining the same group are placed together and preceded by a comment with the group name.@hook:methods(group: 'Getters'):start