Merge "Bug 1372 - toString methods in generated classes"
[yangtools.git] / code-generator / binding-java-api-generator / src / main / java / org / opendaylight / yangtools / sal / java / api / generator / BaseTemplate.xtend
index 97e570d46d2f32da2971b5236adb743061e7e53e..eb8682f03ee73e3778d1b86dc44f1002ba994a4e 100644 (file)
@@ -190,70 +190,15 @@ 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();
 
         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)
-        }
-        return sb.toString
-    }
-
     def asLink(String text) {
         val StringBuilder sb = new StringBuilder()
         var tempText = text
@@ -329,29 +274,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) '''
@@ -498,15 +430,15 @@ abstract class BaseTemplate {
             «val numberClass = restrictions.lengthConstraints.iterator.next.min.class»
             public static «List.importedName»<«Range.importedName»<«numberClass.importedNumber»>> «methodName»() {
                 «IF numberClass.equals(typeof(BigDecimal))»
-                    «lengthMethodBody(restrictions, numberClass, className, varName)»
+                    «lengthBody(restrictions, numberClass, className, varName)»
                 «ELSE»
-                    «lengthMethodBody(restrictions, typeof(BigInteger), className, varName)»
+                    «lengthBody(restrictions, typeof(BigInteger), className, varName)»
                 «ENDIF»
             }
         «ENDIF»
     '''
 
-    def private lengthMethodBody(Restrictions restrictions, Class<? extends Number> numberClass, String className, String varName) '''
+    def private lengthBody(Restrictions restrictions, Class<? extends Number> numberClass, String className, String varName) '''
         if («varName» == null) {
             synchronized («className».class) {
                 if («varName» == null) {
@@ -526,9 +458,9 @@ abstract class BaseTemplate {
             «val number = returnType.importedNumber»
             public static «List.importedName»<«Range.importedName»<«number»>> «methodName»() {
                 «IF returnType.fullyQualifiedName.equals(BigDecimal.canonicalName)»
-                    «rangeMethodBody(restrictions, BigDecimal, className, varName)»
+                    «rangeBody(restrictions, BigDecimal, className, varName)»
                 «ELSE»
-                    «rangeMethodBody(restrictions, BigInteger, className, varName)»
+                    «rangeBody(restrictions, BigInteger, className, varName)»
                 «ENDIF»
             }
         «ENDIF»
@@ -539,15 +471,15 @@ abstract class BaseTemplate {
             «val returnType = properties.iterator.next.returnType»
             public static «List.importedName»<«Range.importedName»<«returnType.importedNumber»>> «methodName»() {
                 «IF returnType.fullyQualifiedName.equals(BigDecimal.canonicalName)»
-                    «rangeMethodBody(restrictions, BigDecimal, className, varName)»
+                    «rangeBody(restrictions, BigDecimal, className, varName)»
                 «ELSE»
-                    «rangeMethodBody(restrictions, BigInteger, className, varName)»
+                    «rangeBody(restrictions, BigInteger, className, varName)»
                 «ENDIF»
             }
         «ENDIF»
     '''
 
-    def private rangeMethodBody(Restrictions restrictions, Class<? extends Number> numberClass, String className, String varName) '''
+    def private rangeBody(Restrictions restrictions, Class<? extends Number> numberClass, String className, String varName) '''
         if («varName» == null) {
             synchronized («className».class) {
                 if («varName» == null) {
@@ -576,7 +508,7 @@ abstract class BaseTemplate {
         return BigInteger.importedName
     }
 
-    def private String numericValue(Class<? extends Number> clazz, Object numberValue) {
+    def protected String numericValue(Class<? extends Number> clazz, Object numberValue) {
         val number = clazz.importedName;
         val value = numberValue.toString
         if (clazz.equals(typeof(BigInteger)) || clazz.equals(typeof(BigDecimal))) {