Binding generator v2 - Instantiable compilability fix 81/58781/14
authorJie Han <han.jie@zte.com.cn>
Tue, 13 Jun 2017 03:07:07 +0000 (11:07 +0800)
committerMartin Ciglan <martin.ciglan@pantheon.tech>
Thu, 15 Jun 2017 07:52:46 +0000 (07:52 +0000)
Change-Id: I43f784d724f8d29bda669a043015944d78ed3597
Signed-off-by: Jie Han <han.jie@zte.com.cn>
binding2/mdsal-binding2-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/javav2/java/api/generator/renderers/BuilderRenderer.java
binding2/mdsal-binding2-java-api-generator/src/main/twirl/org/opendaylight/mdsal/binding/javav2/java/api/generator/builderTemplate.scala.txt

index 5355a4054d7bca08ea8b9410f66af9ab6147fbf6..6b80e6993682ecc89a31b3542b6ef3ddfc491014 100644 (file)
@@ -179,6 +179,8 @@ public class BuilderRenderer extends BaseRenderer {
                             importedNames.put("augmentFieldReturnType", importedName(augmentField.getReturnType()));
                         }
                     }
+                } else if (Instantiable.class.getName().equals(implementedIfc.getFullyQualifiedName())) {
+                    importedNames.put("class", importedName(Class.class));
                 }
             }
         }
@@ -265,6 +267,11 @@ public class BuilderRenderer extends BaseRenderer {
             childTreeNode = true;
         }
 
+        boolean instantiable = false;
+        if (getType().getImplements().contains(BindingTypes.INSTANTIABLE)) {
+            instantiable = true;
+        }
+
         importedNames.put("augmentation", importedName(Augmentation.class));
         importedNames.put("classInstMap", importedName(ClassToInstanceMap.class));
 
@@ -273,7 +280,7 @@ public class BuilderRenderer extends BaseRenderer {
         List<String> getterMethods = new ArrayList<>(Collections2.transform(properties, this::getterMethod));
 
         return builderTemplate.render(getType(), properties, importedNames, importedNamesForProperties, augmentField,
-            copyConstructorHelper, getterMethods, parentTypeForBuilderName, childTreeNode)
+            copyConstructorHelper, getterMethods, parentTypeForBuilderName, childTreeNode, instantiable)
                 .body();
     }
 
index 2f7485c088c5d2c9ad1b4f1b79a77a5a29f94c40..25af90df30edc67832ffac05f4bfa10c67898c94 100644 (file)
@@ -29,7 +29,7 @@
 
 @(genType: GeneratedType, properties: Set[GeneratedProperty], importedNames: Map[String, String],
 ImportedNamesWithProperties: Map[GeneratedProperty, String], augmentField: GeneratedProperty, copyConstructorHelper: String,
-getterMethods: List[String], parentTypeForBuilderName: String, childTreeNode: Boolean)
+getterMethods: List[String], parentTypeForBuilderName: String, childTreeNode: Boolean, instantiable: Boolean)
 @if(genType != null) {
 @{wrapToDocumentation(formatDataForJavaDocBuilder(importedNames.get("genType")))}
 public class @{genType.getName}Builder implements @{getSimpleNameForBuilder} <@{importedNames.get("genType")}> {
@@ -54,9 +54,10 @@ public class @{genType.getName}Builder implements @{getSimpleNameForBuilder} <@{
     }
 
     private static final class @{genType.getName}Impl implements @{genType.getName} {
-    @if(parentTypeForBuilderName != null) {
+    @if(instantiable) {
         @implementedInterfaceGetter()
     }
+
         @generateFields(true)
 
         @generateAugmentField(true)