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»() {
«IF field.returnType.importedName.contains("[]")»
return «field.fieldName» == null ? null : «field.fieldName».clone();
«ELSE»
return «field.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(Iterable\n") .append("This class represents the following YANG schema fragment defined in module ") .append(def.module.name).append("\n") .append("
\n") .append(encodeAngleBrackets(encodeJavadocSymbols(YangTemplate.generateYangSnippet(node)))) .append("") if (node instanceof SchemaNode) { sb.append("The schema path to identify an instance is\n") .append("") .append(formatSchemaPath(def.module.name, 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 (DocumentedNode schemaNode : def.nodes) { sb.append(encodeAngleBrackets(encodeJavadocSymbols(YangTemplate.generateYangSnippet(schemaNode)))) } sb.append("\n") } } } 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 = ' '
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 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 = NL_MATCHER.removeFrom(formattedText)
formattedText = TAB_MATCHER.removeFrom(formattedText)
formattedText = SPACES_PATTERN.matcher(formattedText).replaceAll(" ")
val StringTokenizer tokenizer = new StringTokenizer(formattedText, " ", true);
while (tokenizer.hasMoreElements) {
val nextElement = tokenizer.nextElement.toString
if (lineBuilder.length != 0 && lineBuilder.length + nextElement.length > 80) {
if (lineBuilder.charAt(lineBuilder.length - 1) == ' ') {
lineBuilder.setLength(0)
lineBuilder.append(lineBuilder.substring(0, lineBuilder.length - 1))
}
if (lineBuilder.charAt(0) == ' ') {
lineBuilder.setLength(0)
lineBuilder.append(lineBuilder.substring(1))
}
sb.append(lineBuilder);
lineBuilder.setLength(0)
sb.append(NEW_LINE)
if(nextElement.toString == ' ') {
isFirstElementOnNewLineEmptyChar = !isFirstElementOnNewLineEmptyChar;
}
}
if (isFirstElementOnNewLineEmptyChar) {
isFirstElementOnNewLineEmptyChar = !isFirstElementOnNewLineEmptyChar
}
else {
lineBuilder.append(nextElement)
}
}
sb.append(lineBuilder)
sb.append(NEW_LINE)
return sb.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