codegen.templates.Command Maven / Gradle / Ivy
<@pp.dropOutputFile />
<#list commandDefs as def>
<#global cmd=def.command>
<#global commandName=def.commandName>
<#global optionName=cmd.simpleName+"Option">
<#global optionsName=cmd.simpleName+"Options">
<#global factoryName=cmd.simpleName+"Factory">
<#global optionSetsName=cmd.simpleName+"OptionSets">
<@pp.changeOutputFile name=pp.pathTo("/"+cmd.pkg.path+"/"+cmd.simpleName+".java")/>
package ${cmd.pkg.name};
import org.unix4j.command.CommandInterface;
import ${def.pkg.name}.${factoryName};
<#if def.options?size != 0>
import ${def.pkg.name}.${optionName};
import ${def.pkg.name}.${optionsName};
import ${def.pkg.name}.${optionSetsName};
#if>
<#function isOptionsArg def arg>
<#return def.operands[arg].type == optionsName>
#function>
<#macro synopsisArg def arg><#if
isOptionsArg(def, arg)>[-<#foreach opt in def.options?values>${opt.acronym}#foreach>]<#else
><${arg}>#if
>#macro>
/**
* Non-instantiable module with inner types making up the ${commandName} command.
*
* NAME
*
* ${def.name}
*
* SYNOPSIS
*
*
<#foreach method in def.methods>
* {@code ${method.name}<#foreach arg in method.args> <@synopsisArg def arg/>#foreach>}
#foreach>
*
*
* See {@link Interface} for the corresponding command signature methods.
*
* DESCRIPTION
*
* ${def.description}
* <#if def.notes?size != 0>
*
* NOTES
*
*
<#foreach note in def.notes>
* - ${note}
* #foreach>
* #if>
*
* Options
*
<#if def.options?size != 0>
* The following options are supported:
*
<#include "/include/options-javadoc.java">
<#else>
* The command supports no options.
#if>
*
* OPERANDS
*
* The following operands are supported:
*
*
<#foreach opd in def.operands?values>
* {@code <${opd.name}>} : {@code ${opd.type}} ${opd.desc}
#foreach>
*
*/
public final class ${cmd.simpleName} {
/**
* The "${commandName}" command name.
*/
public static final String NAME = "${commandName}";
/**
* Interface defining all method signatures for the "${commandName}" command.
*
<#include "/include/returntype-class-javadoc.java">
*/
public static interface Interface extends CommandInterface {
<#foreach method in def.methods>
/**
* ${method.desc}
*
<#foreach arg in method.args>
* @param ${arg} ${def.operands[arg].desc}
#foreach>
<#include "/include/returntype-method-javadoc.java">
*/
R ${method.name}(<#foreach arg in method.args>${def.operands[arg].type} ${arg}<#if arg_has_next>, #if>#foreach>);
#foreach>
}
<#if def.options?size != 0>
/**
* Options for the "${commandName}" command: <#foreach opt in def.options?values>{@link ${optionName}#${opt.name} ${opt.acronym}}<#if opt_has_next>, #if>#foreach>.
*
<#include "/include/options-javadoc.java">
*/
public static final ${optionSetsName} Options = ${optionSetsName}.INSTANCE;
#if>
/**
* Singleton {@link ${factoryName} factory} instance for the "${commandName}" command.
*/
public static final ${factoryName} Factory = ${factoryName}.INSTANCE;
// no instances
private ${cmd.simpleName}() {
super();
}
}
#list>