Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Load common.vm as velocimacro library
Browse files Browse the repository at this point in the history
And use Types in templates

Signed-off-by: Daniel Bluhm <bluhmdj@ornl.gov>
  • Loading branch information
dbluhm committed Aug 6, 2020
1 parent 9ca3eb3 commit a2d2882
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 54 deletions.
Expand Up @@ -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",
Expand Down
@@ -1,4 +1,3 @@
#parse("templates/common.vm")
#if($package)
package $package;
#end
Expand All @@ -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
Expand Down
@@ -1,9 +1,9 @@
#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
Expand Down
Expand Up @@ -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
Expand Down
@@ -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

0 comments on commit a2d2882

Please sign in to comment.