Bug 1672 - Generated javadoc contains symbols of javadoc comment tags
[mdsal.git] / code-generator / binding-java-api-generator / src / main / java / org / opendaylight / yangtools / sal / java / api / generator / BaseTemplate.xtend
index eb7b948c545283c6e7e3d162a202574365eb0723..26c95d2fa3236738d775797a41816f4c458adaf8 100644 (file)
@@ -25,7 +25,6 @@ import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType
 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;
@@ -158,9 +157,7 @@ abstract class BaseTemplate {
     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)
 
@@ -190,68 +187,20 @@ abstract class BaseTemplate {
     }
 
     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("*/", "&#42;&#47;")
         }
-        return sb.toString
+        return description;
     }
 
     def asLink(String text) {
@@ -286,7 +235,7 @@ abstract class BaseTemplate {
         var StringBuilder lineBuilder = new StringBuilder();
         var boolean isFirstElementOnNewLineEmptyChar = false;
 
-        formattedText = formattedText.replace("*/", "&#42;&#47;")
+        formattedText = formattedText.encodeJavadocSymbols
         formattedText = formattedText.replace(NEW_LINE, "")
         formattedText = formattedText.replace("\t", "")
         formattedText = formattedText.replaceAll(" +", " ");
@@ -310,8 +259,9 @@ abstract class BaseTemplate {
                 lineBuilder.setLength(0)
                 sb.append(NEW_LINE)
 
-                if(nextElement.toString == ' ')
+                if(nextElement.toString == ' ') {
                     isFirstElementOnNewLineEmptyChar = !isFirstElementOnNewLineEmptyChar;
+                }
             }
 
             if(isFirstElementOnNewLineEmptyChar) {
@@ -329,29 +279,16 @@ abstract class BaseTemplate {
     }
 
     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) '''
@@ -431,7 +368,7 @@ abstract class BaseTemplate {
         «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»