import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature
import org.opendaylight.yangtools.sal.binding.model.api.Restrictions
import org.opendaylight.yangtools.sal.binding.model.api.Type
-import org.opendaylight.yangtools.yang.common.QName
abstract class BaseTemplate {
protected val GeneratedType type;
def protected CharSequence asJavadoc(String comment) {
if(comment == null) return ''
var txt = comment
- if (txt.contains("*/")) {
- txt = txt.replace("*/", "*/")
- }
+
txt = comment.trim
txt = formatToParagraph(txt)
}
def protected String formatDataForJavaDoc(GeneratedType type) {
- val typeDescription = type.description
- val typeReference = type.reference
- val typeModuleName = type.moduleName
- val typeSchemaPath = type.schemaPath
+ val typeDescription = type.getDescription().encodeJavadocSymbols;
return '''
- «IF !type.isDocumentationParametersNullOrEmtpy»
- «IF typeDescription != null && !typeDescription.empty»
- «formatToParagraph(typeDescription)»
- «ENDIF»
- «IF typeReference != null && !typeReference.empty»
- Reference:
- «formatReference(typeReference)»
- «ENDIF»
- «IF typeModuleName != null && !typeModuleName.empty»
- Module name:
- «typeModuleName»
- «ENDIF»
- «IF typeSchemaPath != null && !typeSchemaPath.empty»
- Schema path:
- «formatPath(typeSchemaPath)»
- «ENDIF»
+ «IF !typeDescription.nullOrEmpty»
+ «typeDescription»
«ENDIF»
'''.toString
}
- def formatPath(Iterable<QName> schemaPath) {
- var currentElement = schemaPath.head
- val StringBuilder sb = new StringBuilder()
- sb.append('[')
- sb.append(currentElement)
-
- for(pathElement : schemaPath) {
- if(!currentElement.namespace.equals(pathElement.namespace)) {
- currentElement = pathElement
- sb.append('/')
- sb.append(pathElement)
- }
- else {
- sb.append('/')
- sb.append(pathElement.localName)
- }
- }
- sb.append(']')
- return sb.toString
- }
-
- def formatReference(String reference) {
- if(reference == null || reference.isEmpty)
- return reference
-
- val StringTokenizer tokenizer = new StringTokenizer(reference, " ", true)
- val StringBuilder sb = new StringBuilder();
-
- while(tokenizer.hasMoreTokens) {
- var String oneElement = tokenizer.nextToken
- if (oneElement.contains("http://")) {
- oneElement = asLink(oneElement)
- }
- sb.append(oneElement)
+ def encodeJavadocSymbols(String description) {
+ if (!description.nullOrEmpty) {
+ return description.replace("*/", "*/")
}
- return sb.toString
+ return description;
}
def asLink(String text) {
var StringBuilder lineBuilder = new StringBuilder();
var boolean isFirstElementOnNewLineEmptyChar = false;
- formattedText = formattedText.replace("*/", "*/")
+ formattedText = formattedText.encodeJavadocSymbols
formattedText = formattedText.replace(NEW_LINE, "")
formattedText = formattedText.replace("\t", "")
formattedText = formattedText.replaceAll(" +", " ");
lineBuilder.setLength(0)
sb.append(NEW_LINE)
- if(nextElement.toString == ' ')
+ if(nextElement.toString == ' ') {
isFirstElementOnNewLineEmptyChar = !isFirstElementOnNewLineEmptyChar;
+ }
}
if(isFirstElementOnNewLineEmptyChar) {
}
def isDocumentationParametersNullOrEmtpy(GeneratedType type) {
- var boolean isNullOrEmpty = true
- val String typeDescription = type.description
- val String typeReference = type.reference
- val String typeModuleName = type.moduleName
- val Iterable<QName> typeSchemaPath = type.schemaPath
-
- if(typeDescription != null && !typeDescription.empty) {
- isNullOrEmpty = false
- return isNullOrEmpty
- }
- if(typeReference != null && !typeReference.empty) {
- isNullOrEmpty = false
- return isNullOrEmpty
- }
- if(typeModuleName != null && !typeModuleName.empty) {
- isNullOrEmpty = false
- return isNullOrEmpty
- }
- if(typeSchemaPath != null && !typeSchemaPath.empty) {
- isNullOrEmpty = false
- return isNullOrEmpty
+ val boolean isTypeDescriptionNullOrEmpty = type.description.nullOrEmpty
+ val boolean isTypeReferenceNullOrEmpty = type.reference.nullOrEmpty
+ val boolean isTypeModuleNameNullOrEmpty = type.moduleName.nullOrEmpty
+ val boolean isTypeSchemaPathNullOrEmpty = type.schemaPath.nullOrEmpty
+
+ if (isTypeDescriptionNullOrEmpty && isTypeReferenceNullOrEmpty && isTypeModuleNameNullOrEmpty
+ && isTypeSchemaPathNullOrEmpty) {
+ return true
}
- return isNullOrEmpty
+ return false
}
def generateRestrictions(Type type, String paramName, Type returnType) '''
«IF !properties.empty»
@Override
public «String.importedName» toString() {
- «StringBuilder.importedName» builder = new «StringBuilder.importedName»("«type.name» [");
+ «StringBuilder.importedName» builder = new «StringBuilder.importedName»(«type.importedName».class.getSimpleName()).append(" [");
boolean first = true;
«FOR property : properties»