Commit a2d28822 authored by Daniel Bluhm's avatar Daniel Bluhm

Load common.vm as velocimacro library

And use Types in templates
Signed-off-by: Daniel Bluhm's avatarDaniel Bluhm <bluhmdj@ornl.gov>
parent 9ca3eb31
......@@ -20,6 +20,7 @@ enum VelocityProperties {
// Set up Velocity using the Singleton approach; ClasspathResourceLoader allows
// us to load templates from src/main/resources
LIBRARY_PATH("velocimacro.library.path", "templates/common.vm"),
RESOURCE_LOADER("resource.loader", "class"),
CLASS_RESOURCE_LOADER(
"class.resource.loader.class",
......
#parse("templates/common.vm")
#if($package)
package $package;
#end
......@@ -23,7 +22,7 @@ import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import org.eclipse.ice.data.JavascriptValidator;
#imports
/**
* This is an implementation of $interface that satisfies the dependencies of
......
#parse("templates/common.vm")
#if($package)
package $package;
#end
import org.eclipse.ice.data.IDataElement;
#imports
/**
* This interface satisfies the dependencies of the @DataElement Annotation and
......
......@@ -10,6 +10,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
#imports
/**
* This is an implementation of $interface<$elementInterface>
* that satisfies the dependencies of the {@code @Persisted} Annotation and was
......
##
## 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
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment