Bug 1512 - generated builder java file for a leaf containing a union 52/9952/6
authorLadislav Borak <lborak@cisco.com>
Fri, 15 Aug 2014 07:41:59 +0000 (09:41 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Mon, 15 Sep 2014 09:44:05 +0000 (09:44 +0000)
- added clarification for location of builder class for union types
  into javadoc
- remove redundant check in YangTempla.writeRpcInput() and
  YangTemplate.writeRpcOutput() methods
- added return type for GeneratorImpl.printAugmentedNode() method
  (problem to infer return type in recursivecalled method)
- added local set of typedefinitions into
  GeneratorImpl.printSchemaNodeInfo() to to remove error in geterated java
  file

Change-Id: If4ad960a998254868a0347bb836c79aac7dd19d8
Signed-off-by: Ladislav Borak <lborak@cisco.com>
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/YangTemplate.xtend
code-generator/binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/BaseTemplate.xtend
code-generator/binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/UnionBuilderTemplate.xtend
code-generator/binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/TypedefCompilationTest.java
code-generator/binding-java-api-generator/src/test/resources/compilation/typedef/foo.yang
code-generator/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/yangtools/yang/unified/doc/generator/GeneratorImpl.xtend

index d0ad08c36b950c07a0945204b5bd37cb71f60406..a9759d885fd73804172f86fb8000e1e98bbdac25 100644 (file)
@@ -239,7 +239,7 @@ class YangTemplate {
 
         '''
             input {
-                «IF input instanceof DataSchemaNode && !input.childNodes.nullOrEmpty»
+                «IF !input.childNodes.nullOrEmpty»
                 «writeDataSchemaNodes(input.childNodes)»
                 «ENDIF»
             }
@@ -253,7 +253,7 @@ class YangTemplate {
 
         '''
             output {
-                «IF output instanceof DataSchemaNode && !output.childNodes.nullOrEmpty»
+                «IF !output.childNodes.nullOrEmpty»
                 «writeDataSchemaNodes(output.childNodes)»
                 «ENDIF»
             }
index 26c95d2fa3236738d775797a41816f4c458adaf8..2c303b9fb917a4d6714be0005a035774859aff4e 100644 (file)
@@ -203,6 +203,23 @@ abstract class BaseTemplate {
         return description;
     }
 
+    def protected String formatDataForJavaDoc(GeneratedType type, String additionalComment) {
+        val StringBuilder typeDescription = new StringBuilder();
+        if (!type.description.nullOrEmpty) {
+            typeDescription.append(type.description)
+            typeDescription.append(NEW_LINE)
+            typeDescription.append(NEW_LINE)
+            typeDescription.append(NEW_LINE)
+            typeDescription.append(additionalComment)
+        } else {
+            typeDescription.append(additionalComment)
+        }
+
+        return '''
+            «typeDescription.toString»
+        '''.toString
+    }
+
     def asLink(String text) {
         val StringBuilder sb = new StringBuilder()
         var tempText = text
index dbed6c75153613df5fdb0701f947934120841101..13c9fc309bb4c73027881fe4dc4c7c13962956fd 100644 (file)
@@ -25,7 +25,7 @@ class UnionBuilderTemplate extends ClassTemplate {
     }
 
     def override body() '''
-        «wrapToDocumentation(formatDataForJavaDoc(type))»
+        «wrapToDocumentation(formatDataForJavaDoc(type, getClarification()))»
         public class «type.name» {
 
             «generateMethods»
@@ -51,4 +51,16 @@ class UnionBuilderTemplate extends ClassTemplate {
         }
     }
 
+    def private String getClarification() {
+        return
+        '''
+        The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation.
+        In some cases it is very difficult to automate it since there can be unions such as (uint32 - uint16), or (string - uint32).
+
+        The reason behind putting it under src/main/java is:
+        This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
+        loss of user code.
+        '''
+    }
+
 }
index ab8fe5c9c4c5987c9db927292e78f427deb03986..124fadb6cdc2305615ebb1cf402f828c338a44ad 100644 (file)
@@ -91,7 +91,7 @@ public class TypedefCompilationTest extends BaseCompilationTest {
         assertTrue(unionExt2.exists());
         assertTrue(unionExt3.exists());
         assertTrue(unionExt4.exists());
-        assertFilesCount(parent, 31);
+        assertFilesCount(parent, 33);
 
         // Test if sources are compilable
         testCompilation(sourcesOutputDir, compiledOutputDir);
index 911096606efee2258902f48d7947ec4b56677297..855279f3fc3e5f0e04e5fbcd50b4b995da9b88f8 100644 (file)
@@ -186,5 +186,10 @@ module foo {
     typedef h {
         type uint64;
     }
+    container cont1 {
+        leaf leaf1 {
+            type union-ext1;
+        }
+    }
 
 }
index f40cbcaa3dff249ad6cc8443028d380853fa8485..185299d190f35dca2e35424b3e40e577e195e526 100644 (file)
@@ -400,7 +400,7 @@ class GeneratorImpl {
         '''
     }
     
-    private def printAugmentedNode(DataSchemaNode child) {
+    private def CharSequence printAugmentedNode(DataSchemaNode child) {
         
         if(child instanceof ChoiceCaseNode)
             return ''
@@ -810,7 +810,8 @@ class GeneratorImpl {
                 «ENDFOR»
                 </ul>
                 <ul>
-                «FOR typeDef : dataNode.typeDefinitions»
+                «val Set<TypeDefinition<?>> typeDefinitions = dataNode.typeDefinitions»
+                «FOR typeDef : typeDefinitions»
                     «typeDef.restrictions»
                 «ENDFOR»
                 </ul>