This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load common.vm as velocimacro library
And use Types in templates Signed-off-by: Daniel Bluhm <bluhmdj@ornl.gov>
- Loading branch information
Showing
5 changed files
with
58 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
....ice.dev/org.eclipse.ice.dev.annotations/src/main/resources/templates/ElementInterface.vm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 53 additions & 51 deletions
104
org.eclipse.ice.dev/org.eclipse.ice.dev.annotations/src/main/resources/templates/common.vm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,74 @@ | ||
## | ||
## Macros and values useful across all templates and other readability helpers. | ||
## | ||
## Help make this file more readable. | ||
#macro(definitions) | ||
#evaluate($bodyContent.toString().replaceAll("\n\p{Space}*\n", "").replaceAll("\p{Space}*##.*", "")) | ||
#end | ||
#@definitions | ||
|
||
## Whitespace helpers ## | ||
## Whitespace helpers ## | ||
|
||
## Prepend a directive with this value if you don't want the directive to | ||
## Gobble whitespace | ||
#set($blank = "") | ||
## Gobbles whitespace | ||
#macro(noop)#end | ||
|
||
## Literal newline | ||
## Use as a block macro to set the tab index of all lines in body. | ||
#macro(settab $num) | ||
#set($tab = " ") | ||
#set($newline = " | ||
") | ||
|
||
## Literal tab | ||
#set($tab = " ") | ||
|
||
## Gobbles whitespace | ||
#macro(noop)#end | ||
|
||
## Use as a block macro to set the tab index of all lines in body. | ||
#macro(settab $num) | ||
#if($num == 0) | ||
#set($shift = "") | ||
#else | ||
#set($shift = "#foreach($i in [1..$num])$tab#end") | ||
#noop$shift$bodyContent.toString().replace("$tab", "").replace("$newline", "$newline$shift").trim() | ||
#end | ||
#noop$shift$bodyContent.toString().replace("$tab", "").replace("$newline", "$newline$shift").trim() | ||
#end | ||
|
||
## Use as a block macro to remove the first newline in the body. | ||
## Useful when having foreach and output on the same line is unreadable but | ||
## output is intended to be all on one line. | ||
#macro(nonewline)$bodyContent.toString().replaceFirst("\n", "")#end | ||
## Use as a block macro to remove the first newline in the body. | ||
## Useful when having foreach and output on the same line is unreadable but | ||
## output is intended to be all on one line. | ||
#macro(nonewline)$bodyContent.toString().replaceFirst("\n", "")#end | ||
|
||
## Join a list | ||
#macro(join $sep $list) | ||
#foreach($element in $list)#@nonewline | ||
#noop$element$sep | ||
#end#end | ||
#end | ||
## Join a list | ||
#macro(join $sep $list) | ||
#foreach($element in $list)#@nonewline | ||
#noop$element$sep | ||
#end#end | ||
#end | ||
|
||
## Field helpers ## | ||
## Field helpers ## | ||
|
||
## Get evaluated field type | ||
#macro(fieldtype)#evaluate(${field.Type})#end | ||
## Imports | ||
#macro(imports) | ||
#foreach($import in $types.getImports()) | ||
#@settab(0) | ||
import $import; | ||
#end | ||
#end | ||
#end | ||
|
||
## Get the type of this field for use in parameter list (includes nonnull) | ||
#macro(fieldparametertype)#nonnull("", " ")#fieldtype#end | ||
## Get evaluated field type | ||
#macro(fieldtype)$types.resolve(${field.Type})#end | ||
|
||
## Get field declaration | ||
#macro(fielddecl) | ||
#@settab(1) | ||
#join(" ", ${field.Annotations})#join(" ", ${field.Modifiers})#fieldtype() ${field.VarName}#if(${field.DefaultValue}) = #evaluate(${field.DefaultValue})#end; | ||
#end | ||
## Get the type of this field for use in parameter list (includes nonnull) | ||
#macro(fieldparametertype)#nonnull("", " ")#fieldtype#end | ||
|
||
## Get field declaration | ||
#macro(fielddecl) | ||
#@settab(1) | ||
#join(" ", ${field.Annotations})#join(" ", ${field.Modifiers})#fieldtype() ${field.VarName}#if(${field.DefaultValue}) = #evaluate(${field.DefaultValue})#end; | ||
#end | ||
#end | ||
|
||
## Return @NonNull if field should have it, otherwise return empty string | ||
#macro(nonnull $before $after)#if(!${field.Nullable} && !${field.Primitive})$!before@NonNull$!after#end#end | ||
## Return @NonNull if field should have it, otherwise return empty string | ||
#macro(nonnull $before $after)#if(!${field.Nullable} && !${field.Primitive})$!before@NonNull$!after#end#end | ||
|
||
## Get field doc comment | ||
#macro(fielddoc) | ||
#if(${field.DocString}) | ||
#@settab(1) | ||
/** | ||
* $field.DocString.trim().replace("$newline", "$newline$tab *") | ||
*/ | ||
#end | ||
#end | ||
## Get field doc comment | ||
#macro(fielddoc) | ||
#set($tab = " ") | ||
#set($newline = " | ||
") | ||
#if(${field.DocString}) | ||
#@settab(1) | ||
/** | ||
* $field.DocString.trim().replace("$newline", "$newline$tab *") | ||
*/ | ||
#end | ||
#end | ||
#end |