field
*
* @param field
* generated property with data about field which is generated as the getter method
* @return string with the getter method source code in JAVA format
*/
protected def getterMethod(GeneratedProperty field) {
'''
public «field.returnType.importedName» «field.getterMethodName»() {
«val fieldName = field.fieldName»
«IF field.returnType.name.endsWith("[]")»
return «fieldName» == null ? null : «fieldName».clone();
«ELSE»
return «fieldName»;
«ENDIF»
}
'''
}
final protected def getterMethodName(GeneratedProperty field) {
val prefix = if(field.returnType.equals(Types.BOOLEAN)) "is" else "get"
return '''«prefix»«field.name.toFirstUpper»'''
}
/**
* Template method which generates the setter method for field
*
* @param field
* generated property with data about field which is generated as the setter method
* @return string with the setter method source code in JAVA format
*/
final protected def setterMethod(GeneratedProperty field) '''
«val returnType = field.returnType.importedName»
public «type.name» set«field.name.toFirstUpper»(«returnType» value) {
this.«field.fieldName» = value;
return this;
}
'''
/**
* Template method which generates method parameters with their types from parameters
.
*
* @param parameters
* group of generated property instances which are transformed to the method parameters
* @return string with the list of the method parameters with their types in JAVA format
*/
def final protected asArgumentsDeclaration(Iterableparameters
.
*
* @param parameters
* group of generated property instances which are transformed to the sequence of parameter names
* @return string with the list of the parameter names of the parameters
*/
def final protected asArguments(Collection\n") .append("This class represents the following YANG schema fragment defined in module ") .append(def.module.argument).append("\n") .append("
\n") appendYangSnippet(sb, def.module, (node as EffectiveStatement, ?>).declared) sb.append("") if (node instanceof SchemaNode) { sb.append("The schema path to identify an instance is\n") .append("") .append(formatSchemaPath(def.module.argument, node.path.pathFromRoot)) .append("\n") if (hasBuilderClass(node)) { val builderName = type.name + "Builder"; sb.append("\n
To create instances of this class use {@link ").append(builderName) .append("}.\n") .append("@see ").append(builderName).append('\n') if (node instanceof ListSchemaNode) { val keyDef = node.keyDefinition if (keyDef !== null && !keyDef.empty) { sb.append("@see ").append(type.name).append("Key") } sb.append('\n'); } } } } else if (def instanceof Multiple) { sb.append("
\n") for (SchemaNode node : def.nodes) { appendYangSnippet(sb, def.module, (node as EffectiveStatement, ?>).declared) } sb.append("\n") } } } def private static void appendYangSnippet(StringBuilder sb, ModuleEffectiveStatement module, DeclaredStatement> stmt) { for (String str : YANG_FORMATTER.toYangTextSnippet(module, stmt)) { sb.append(encodeAngleBrackets(encodeJavadocSymbols(str))) } } def private static boolean hasBuilderClass(SchemaNode schemaNode) { return schemaNode instanceof ContainerSchemaNode || schemaNode instanceof ListSchemaNode || schemaNode instanceof RpcDefinition || schemaNode instanceof NotificationDefinition; } def private static String formatSchemaPath(String moduleName, Iterable
" + text + "
"
}
def asLink(String text) {
val StringBuilder sb = new StringBuilder()
var tempText = text
var char lastChar = SPACE
var boolean badEnding = false
if (text.endsWith('.') || text.endsWith(':') || text.endsWith(',')) {
tempText = text.substring(0, text.length - 1)
lastChar = text.charAt(text.length - 1)
badEnding = true
}
sb.append("")
sb.append(tempText)
sb.append("")
if(badEnding)
sb.append(lastChar)
return sb.toString
}
protected static def formatToParagraph(String text) {
if(text === null || text.isEmpty)
return text
var formattedText = text
val StringBuilder sb = new StringBuilder();
var StringBuilder lineBuilder = new StringBuilder();
var boolean isFirstElementOnNewLineEmptyChar = false;
formattedText = encodeJavadocSymbols(formattedText)
formattedText = WS_MATCHER.replaceFrom(formattedText, SPACE)
formattedText = SPACES_PATTERN.matcher(formattedText).replaceAll(" ")
val StringTokenizer tokenizer = new StringTokenizer(formattedText, " ", true);
while (tokenizer.hasMoreTokens) {
val nextElement = tokenizer.nextToken
if (lineBuilder.length != 0 && lineBuilder.length + nextElement.length > 80) {
if (lineBuilder.charAt(lineBuilder.length - 1) == SPACE) {
lineBuilder.setLength(lineBuilder.length - 1)
}
if (lineBuilder.length != 0 && lineBuilder.charAt(0) == SPACE) {
lineBuilder.deleteCharAt(0)
}
sb.append(lineBuilder).append(NEW_LINE)
lineBuilder.setLength(0)
if (nextElement == " ") {
isFirstElementOnNewLineEmptyChar = !isFirstElementOnNewLineEmptyChar;
}
}
if (isFirstElementOnNewLineEmptyChar) {
isFirstElementOnNewLineEmptyChar = !isFirstElementOnNewLineEmptyChar
} else {
lineBuilder.append(nextElement)
}
}
return sb.append(lineBuilder).append(NEW_LINE).toString
}
def protected generateToString(Collectionparameters
.
*
* @param parameters
* list of parameter instances which are transformed to the method parameters
* @return string with the list of the method parameters with their types in JAVA format
*/
def protected generateParameters(List