Feature Anchor Options
In some cases the behaviour of the feature anchors needs to be modified to generate the correct artifact content.
Both @anchor
and @hook
statements in the templates allow you to define options in the start anchor.
@anchor(options...)
option | description | example |
---|---|---|
prefix | Adds the prefix at the start of the content, but only if at least 1 feature injects content. | @anchor:interfaces(prefix: 'implements ') |
suffix | Adds the suffix at the end of the content, but only if at least 1 feature injects content. | @anchor:items(suffix: ', ') |
separator | Adds the separator between each feature. For inline anchors, if the injected content has multiple lines, the separator is placed between the lines as well. | @anchor:items(separator: ', ') |
commentLineFormat | Provides a format for the start and end anchor comments. Useful if the default comment format is not correct for the generated file. | @anchor:vars(commentLineFormat: '# %s') |
noComments | Removes the start and end anchor comments. This reduces traceability, but some file formats do not support comments. | @anchor:vars(noComments: true) |
sort | Define 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 anchors are a special variant of the feature anchor. 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
>>
option | description | example |
---|---|---|
first | Place the content of this feature segment at the start of the anchor. | @hook:vars(first: true):start |
last | Place the content of this feature segment at the end of the anchor. | @hook:vars(last: true):start |
group | Only works in a @hook:methods anchor. Features defining the same group are placed together and preceded by a comment with the group name. | @hook:methods(group: 'Getters'):start |