Binding generator v2 - Augments fix 24/59424/2
authorMartin Ciglan <martin.ciglan@pantheon.tech>
Tue, 20 Jun 2017 19:05:26 +0000 (21:05 +0200)
committerMartin Ciglan <martin.ciglan@pantheon.tech>
Mon, 26 Jun 2017 14:05:07 +0000 (14:05 +0000)
- if YANG file uses augment identifier extension,
we need to normalize this identifier, otherwise
we end up with non-compilable generated Java code

- code clean up

Change-Id: I05ce4290b9587578944ef64428cff3e96d33dcf8
Signed-off-by: Martin Ciglan <martin.ciglan@pantheon.tech>
binding2/mdsal-binding2-generator-impl/src/main/java/org/opendaylight/mdsal/binding/javav2/generator/impl/GenHelperUtil.java
binding2/mdsal-binding2-generator-impl/src/main/twirl/org/opendaylight/mdsal/binding/javav2/generator/impl/yangTemplateWriteUnknownSchemaNode.scala.txt
binding2/mdsal-binding2-generator-impl/src/test/resources/augment-group/test-augment-identifier.yang [new file with mode: 0644]

index bd75b2195c21f9fe0c6836a4bd9ce5e7ed004d97..d3570d4a997b1f9a2c2f697f7728f4bfde3f3a38 100644 (file)
@@ -23,7 +23,6 @@ import static org.opendaylight.mdsal.binding.javav2.generator.impl.AuxiliaryGenU
 import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingGeneratorUtil.computeDefaultSUID;
 import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingGeneratorUtil.encodeAngleBrackets;
 import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingGeneratorUtil.packageNameForGeneratedType;
-import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingTypes.INSTANTIABLE;
 import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingTypes.NOTIFICATION;
 import static org.opendaylight.mdsal.binding.javav2.generator.util.Types.parameterizedTypeFor;
 import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findDataSchemaNode;
@@ -38,7 +37,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.stream.Collectors;
-
 import org.opendaylight.mdsal.binding.javav2.generator.spi.TypeProvider;
 import org.opendaylight.mdsal.binding.javav2.generator.util.BindingGeneratorUtil;
 import org.opendaylight.mdsal.binding.javav2.generator.util.BindingTypes;
@@ -310,12 +308,14 @@ final class GenHelperUtil {
             break;
         }
 
+        boolean isTypeNormalized = false;
         if (augIdentifier == null) {
             augIdentifier = augGenTypeName(augmentBuilders, targetTypeRef.getName());
+            isTypeNormalized = true;
         }
 
         GeneratedTypeBuilder augTypeBuilder = new GeneratedTypeBuilderImpl(augmentPackageName, augIdentifier,
-                false, true);
+                false, isTypeNormalized);
 
         augTypeBuilder.addImplementsType(BindingTypes.TREE_NODE);
         augTypeBuilder.addImplementsType(parameterizedTypeFor(BindingTypes.INSTANTIABLE, augTypeBuilder));
@@ -340,62 +340,6 @@ final class GenHelperUtil {
         return genCtx;
     }
 
-    //TODO: delete this method eventually when uses-augments & augmented choice cases are implemented
-    /**
-     * Returns a generated type builder for an augmentation.
-     *
-     * The name of the type builder is equal to the name of augmented node with
-     * serial number as suffix.
-     *
-     * @param module
-     *            current module
-     * @param augmentPackageName
-     *            string with contains the package name to which the augment
-     *            belongs
-     * @param basePackageName
-     *            string with the package name to which the augmented node
-     *            belongs
-     * @param targetTypeRef
-     *            target type
-     * @param augSchema
-     *            augmentation schema which contains data about the child nodes
-     *            and uses of augment
-     * @return generated type builder for augment in genCtx
-     */
-    @Deprecated
-    static Map<Module, ModuleContext> addRawAugmentGenTypeDefinition(final Module module, final String augmentPackageName,
-                final String basePackageName, final Type targetTypeRef, final AugmentationSchema augSchema,
-                final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders, final Map<Module,
-                ModuleContext> genCtx, final SchemaContext schemaContext, final boolean verboseClassComments, final
-                TypeProvider typeProvider) {
-
-        Map<String, GeneratedTypeBuilder> augmentBuilders = genTypeBuilders.computeIfAbsent(augmentPackageName, k -> new HashMap<>());
-        String augIdentifier = getAugmentIdentifier(augSchema.getUnknownSchemaNodes());
-
-        if (augIdentifier == null) {
-            augIdentifier = augGenTypeName(augmentBuilders, targetTypeRef.getName());
-        }
-
-        GeneratedTypeBuilder augTypeBuilder = new GeneratedTypeBuilderImpl(augmentPackageName, augIdentifier);
-
-        augTypeBuilder.addImplementsType(BindingTypes.TREE_NODE);
-        augTypeBuilder.addImplementsType(parameterizedTypeFor(BindingTypes.INSTANTIABLE, augTypeBuilder));
-        augTypeBuilder.addImplementsType(Types.augmentationTypeFor(targetTypeRef));
-        annotateDeprecatedIfNecessary(augSchema.getStatus(), augTypeBuilder);
-        augTypeBuilder = addImplementedInterfaceFromUses(augSchema, augTypeBuilder, genCtx);
-
-        augTypeBuilder = augSchemaNodeToMethods(module, basePackageName, augTypeBuilder, augTypeBuilder, augSchema
-                .getChildNodes(), genCtx, schemaContext, verboseClassComments, typeProvider, genTypeBuilders);
-        augmentBuilders.put(augTypeBuilder.getName(), augTypeBuilder);
-
-        if(!augSchema.getChildNodes().isEmpty()) {
-            genCtx.get(module).addTypeToAugmentation(augTypeBuilder, augSchema);
-
-        }
-        genCtx.get(module).addAugmentType(augTypeBuilder);
-        return genCtx;
-    }
-
     /**
      * Adds the methods to <code>typeBuilder</code> what represents subnodes of
      * node for which <code>typeBuilder</code> was created.
index 7c69dffe235989e63d7c7cbded9925f99822dc5b..a5798a4019b5f96097dc6a7f7e2a551854672eb9 100644 (file)
@@ -18,9 +18,9 @@
 
 @(unknownSchemaNode: UnknownSchemaNode, module: Module)
 @if(unknownSchemaNode != null) {
-    @if(unknownSchemaNode.getExtensionDefinition().getArgument() == null || unknownSchemaNode.getExtensionDefinition().getArgument().isEmpty()){
-        @{module.getPrefix}:@{unknownSchemaNode.getNodeType().getLocalName()};
-    } else {
+    @if(unknownSchemaNode.getExtensionDefinition().getArgument() != null && !unknownSchemaNode.getExtensionDefinition().getArgument().isEmpty()){
         @{module.getPrefix}:@{unknownSchemaNode.getNodeType().getLocalName()} "@{unknownSchemaNode.getNodeParameter()}";
+    } else {
+        @{module.getPrefix}:@{unknownSchemaNode.getNodeType().getLocalName()};
     }
 }
\ No newline at end of file
diff --git a/binding2/mdsal-binding2-generator-impl/src/test/resources/augment-group/test-augment-identifier.yang b/binding2/mdsal-binding2-generator-impl/src/test/resources/augment-group/test-augment-identifier.yang
new file mode 100644 (file)
index 0000000..f3a34d6
--- /dev/null
@@ -0,0 +1,39 @@
+module augment-identifier-test {
+    prefix "foo";
+    namespace "org.test.augment.identifier";
+
+    import yang-ext {
+      prefix ext;
+    }
+
+    container foo1 {
+        leaf my-leaf {
+            type string;
+        }
+    }
+
+    augment /foo:foo1 {
+        leaf bar {
+            type string;
+        }
+    }
+
+    augment /foo:foo1 {
+        leaf baz {
+            type string;
+        }
+    }
+    container foo2 {
+      leaf foo2-leaf {
+          type string;
+      }
+    }
+
+    augment /foo:foo2 {
+      ext:augment-identifier i-am-new-identifier;
+
+      leaf aug-foo2-leaf {
+          type string;
+      }
+    }
+}
\ No newline at end of file