Binding generator v2 - augments fix #3 32/59232/1
authorJie Han <han.jie@zte.com.cn>
Tue, 20 Jun 2017 07:11:24 +0000 (15:11 +0800)
committerMartin Ciglan <martin.ciglan@pantheon.tech>
Tue, 20 Jun 2017 13:03:24 +0000 (13:03 +0000)
- handle Choice Cases augmentation
- add test yangs
- delete deprecated methods and fix tests
Change-Id: I78724808fcf4d5451cf2e0df29edf829abadb8dc
Signed-off-by: Jie Han <han.jie@zte.com.cn>
(cherry picked from commit 671ad01291ff0007de9fadd677c442ff0bf7ae14)

binding2/mdsal-binding2-generator-impl/src/main/java/org/opendaylight/mdsal/binding/javav2/generator/impl/AugmentToGenType.java
binding2/mdsal-binding2-generator-impl/src/main/java/org/opendaylight/mdsal/binding/javav2/generator/impl/GenHelperUtil.java
binding2/mdsal-binding2-generator-impl/src/test/java/org/opendaylight/mdsal/binding/javav2/generator/impl/AugmentToGenTypeTest.java
binding2/mdsal-binding2-generator-impl/src/test/java/org/opendaylight/mdsal/binding/javav2/generator/impl/Bug8542Test.java
binding2/mdsal-binding2-generator-impl/src/test/resources/augment-group/test-augment-choice-case.yang [new file with mode: 0644]
binding2/mdsal-binding2-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/javav2/java/api/generator/renderers/BuilderRenderer.java
binding2/mdsal-binding2-spec/src/main/java/org/opendaylight/mdsal/binding/javav2/spec/base/Instantiable.java

index 2be4fd43a7aa608d98efb4f5ab46e1de8d5fa3c4..2dc6ccdfdb66ed439da3bf2f5ebcc7e093e0c12d 100644 (file)
@@ -24,6 +24,7 @@ import org.opendaylight.mdsal.binding.javav2.generator.spi.TypeProvider;
 import org.opendaylight.mdsal.binding.javav2.generator.util.BindingGeneratorUtil;
 import org.opendaylight.mdsal.binding.javav2.model.api.Type;
 import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.GeneratedTypeBuilder;
+import org.opendaylight.mdsal.binding.javav2.spec.runtime.BindingNamespaceType;
 import org.opendaylight.mdsal.binding.javav2.util.BindingMapping;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
@@ -65,6 +66,27 @@ final class AugmentToGenType {
         return otherIt.hasNext() ? -1 : 0;
     };
 
+    /**
+     * Comparator based on augment target path.
+     */
+    private static final Comparator<Map.Entry<SchemaPath, List<AugmentationSchema>>> AUGMENTS_COMP = (o1, o2) -> {
+        final Iterator<QName> thisIt = o1.getKey().getPathFromRoot().iterator();
+        final Iterator<QName> otherIt = o2.getKey().getPathFromRoot().iterator();
+
+        while (thisIt.hasNext()) {
+            if (!otherIt.hasNext()) {
+                return 1;
+            }
+
+            final int comp = thisIt.next().compareTo(otherIt.next());
+            if (comp != 0) {
+                return comp;
+            }
+        }
+
+        return otherIt.hasNext() ? -1 : 0;
+    };
+
     private AugmentToGenType() {
         throw new UnsupportedOperationException("Utility class");
     }
@@ -106,8 +128,12 @@ final class AugmentToGenType {
         Map<SchemaPath, List<AugmentationSchema>> augmentationsGrouped =
                 augmentations.stream().collect(Collectors.groupingBy(AugmentationSchema::getTargetPath));
 
+        List<Map.Entry<SchemaPath, List<AugmentationSchema>>> sortedAugmentationsGrouped =
+                new ArrayList<>(augmentationsGrouped.entrySet());
+        Collections.sort(sortedAugmentationsGrouped, AUGMENTS_COMP);
+
         //process child nodes of grouped augment entries
-        for (Entry<SchemaPath, List<AugmentationSchema>> schemaPathAugmentListEntry : augmentationsGrouped.entrySet()) {
+        for (Map.Entry<SchemaPath, List<AugmentationSchema>> schemaPathAugmentListEntry : sortedAugmentationsGrouped) {
             resultCtx = augmentationToGenTypes(basePackageName, schemaPathAugmentListEntry, module, schemaContext,
                     verboseClassComments, resultCtx, genTypeBuilders, typeProvider);
 
@@ -153,7 +179,7 @@ final class AugmentToGenType {
      * <code>augSchema</code> node or a generated types for cases are added if
      * augmented node is choice.
      *
-     * @param augmentPackageName
+     * @param basePackageName
      *            string with the name of the package to which the augmentation
      *            belongs
      * @param schemaPathAugmentListEntry
@@ -175,15 +201,17 @@ final class AugmentToGenType {
             final SchemaContext schemaContext, final boolean verboseClassComments,
             Map<Module, ModuleContext> genCtx, Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders,
             final TypeProvider typeProvider) {
-
-        final SchemaPath targetPath = schemaPathAugmentListEntry.getKey();
         Preconditions.checkArgument(basePackageName != null, "Package Name cannot be NULL.");
+        Preconditions.checkArgument(schemaPathAugmentListEntry != null, "Augmentation List Entry cannot be NULL.");
+        final SchemaPath targetPath = schemaPathAugmentListEntry.getKey();
         Preconditions.checkState(targetPath != null,
-                "Augmentation Schema does not contain Target Path (Target Path is NULL).");
+                "Augmentation List Entry does not contain Target Path (Target Path is NULL).");
 
-        SchemaNode targetSchemaNode;
+        final List<AugmentationSchema> augmentationSchemaList = schemaPathAugmentListEntry.getValue();
+        Preconditions.checkState(augmentationSchemaList.size() > 0,
+                "Augmentation List cannot be empty.");
 
-        targetSchemaNode = SchemaContextUtil.findDataSchemaNode(schemaContext, targetPath);
+        SchemaNode targetSchemaNode = SchemaContextUtil.findDataSchemaNode(schemaContext, targetPath);
         if (targetSchemaNode instanceof DataSchemaNode && ((DataSchemaNode) targetSchemaNode).isAddedByUses()) {
             if (targetSchemaNode instanceof DerivableSchemaNode) {
                 targetSchemaNode = ((DerivableSchemaNode) targetSchemaNode).getOriginal().orNull();
@@ -198,13 +226,10 @@ final class AugmentToGenType {
             throw new IllegalArgumentException("augment target not found: " + targetPath);
         }
 
-        //TODO: loose this assignment afterwards #2 done
-        Map<Module, ModuleContext> generatedCtx = genCtx;
-
         GeneratedTypeBuilder targetTypeBuilder = GenHelperUtil.findChildNodeByPath(targetSchemaNode.getPath(),
-                generatedCtx);
+                genCtx);
         if (targetTypeBuilder == null) {
-            targetTypeBuilder = GenHelperUtil.findCaseByPath(targetSchemaNode.getPath(), generatedCtx);
+            targetTypeBuilder = GenHelperUtil.findCaseByPath(targetSchemaNode.getPath(), genCtx);
         }
         if (targetTypeBuilder == null) {
             throw new NullPointerException("Target type not yet generated: " + targetSchemaNode);
@@ -214,13 +239,16 @@ final class AugmentToGenType {
                 BindingGeneratorUtil.packageNameForAugmentedGeneratedType(basePackageName, targetPath);
 
         if (!(targetSchemaNode instanceof ChoiceSchemaNode)) {
-            generatedCtx = GenHelperUtil.addRawAugmentGenTypeDefinition(module, augmentNamespacePackageName,
-                    targetTypeBuilder.toInstance(), schemaPathAugmentListEntry.getValue(), genTypeBuilders, generatedCtx,
+            genCtx = GenHelperUtil.addRawAugmentGenTypeDefinition(module, augmentNamespacePackageName,
+                    targetTypeBuilder.toInstance(), schemaPathAugmentListEntry.getValue(), genTypeBuilders, genCtx,
                     schemaContext, verboseClassComments, typeProvider);
         } else {
-            //TODO: #3 implement augmented choice cases scenario
+            genCtx = generateTypesFromAugmentedChoiceCases(schemaContext, module, basePackageName,
+                    targetTypeBuilder.toInstance(), (ChoiceSchemaNode) targetSchemaNode,
+                    schemaPathAugmentListEntry.getValue(),
+                    null, genCtx, verboseClassComments, genTypeBuilders, typeProvider);
         }
-        return generatedCtx;
+        return genCtx;
     }
 
     static Map<Module, ModuleContext> usesAugmentationToGenTypes(final SchemaContext schemaContext,
@@ -230,8 +258,15 @@ final class AugmentToGenType {
            final TypeProvider typeProvider) {
 
         Preconditions.checkArgument(augmentPackageName != null, "Package Name cannot be NULL.");
+        Preconditions.checkArgument(schemaPathAugmentListEntry != null,
+                "Augmentation Schema List Entry cannot be NULL.");
+        Preconditions.checkState(schemaPathAugmentListEntry.size() > 0,
+                "Augmentation Schema List cannot be empty");
 
         final SchemaPath targetPath = schemaPathAugmentListEntry.get(0).getTargetPath();
+        Preconditions.checkState(targetPath != null,
+                "Augmentation Schema does not contain Target Path (Target Path is NULL).");
+
         final SchemaNode targetSchemaNode = findOriginalTargetFromGrouping(schemaContext, targetPath, usesNode);
         if (targetSchemaNode == null) {
             throw new IllegalArgumentException("augment target not found: " + targetPath);
@@ -254,7 +289,8 @@ final class AugmentToGenType {
             } else if (usesNodeParent instanceof AugmentationSchema) {
                 Type parentTypeBuilder = genCtx.get(module).getTargetToAugmentation()
                         .get(((AugmentationSchema) usesNodeParent).getTargetPath());
-                packageName = parentTypeBuilder.getFullyQualifiedName();
+                packageName = BindingGeneratorUtil.packageNameForAugmentedGeneratedType(parentTypeBuilder.getPackageName(),
+                        (AugmentationSchema)usesNodeParent);
             }
             genCtx = GenHelperUtil.addRawAugmentGenTypeDefinition(module, packageName,
                     targetTypeBuilder.toInstance(), schemaPathAugmentListEntry, genTypeBuilders, genCtx,
@@ -263,57 +299,7 @@ final class AugmentToGenType {
         } else {
             genCtx = generateTypesFromAugmentedChoiceCases(schemaContext, module, augmentPackageName,
                     targetTypeBuilder.toInstance(), (ChoiceSchemaNode) targetSchemaNode,
-                    schemaPathAugmentListEntry.get(0).getChildNodes(),
-                    usesNodeParent, genCtx, verboseClassComments, genTypeBuilders, typeProvider);
-            return genCtx;
-        }
-    }
-
-    //TODO: delete this method eventually when uses-augments & augmented choice cases are implemented
-    @Deprecated
-    public static Map<Module, ModuleContext> usesAugmentationToGenTypes(final SchemaContext schemaContext, final String
-            augmentPackageName, final AugmentationSchema augSchema, final Module module, final UsesNode usesNode, final DataNodeContainer
-                                                                                usesNodeParent, Map<Module, ModuleContext> genCtx,
-                                                                        Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders,
-                                                                        final boolean verboseClassComments, final TypeProvider typeProvider) {
-
-        Preconditions.checkArgument(augmentPackageName != null, "Package Name cannot be NULL.");
-        Preconditions.checkArgument(augSchema != null, "Augmentation Schema cannot be NULL.");
-        Preconditions.checkState(augSchema.getTargetPath() != null,
-                "Augmentation Schema does not contain Target Path (Target Path is NULL).");
-
-        final SchemaPath targetPath = augSchema.getTargetPath();
-        final SchemaNode targetSchemaNode = findOriginalTargetFromGrouping(schemaContext, targetPath, usesNode);
-        if (targetSchemaNode == null) {
-            throw new IllegalArgumentException("augment target not found: " + targetPath);
-        }
-
-        GeneratedTypeBuilder targetTypeBuilder = GenHelperUtil.findChildNodeByPath(targetSchemaNode.getPath(),
-                genCtx);
-        if (targetTypeBuilder == null) {
-            targetTypeBuilder = GenHelperUtil.findCaseByPath(targetSchemaNode.getPath(), genCtx);
-        }
-        if (targetTypeBuilder == null) {
-            throw new NullPointerException("Target type not yet generated: " + targetSchemaNode);
-        }
-
-        if (!(targetSchemaNode instanceof ChoiceSchemaNode)) {
-            String packageName = augmentPackageName;
-            if (usesNodeParent instanceof SchemaNode) {
-                packageName = BindingGeneratorUtil.packageNameForAugmentedGeneratedType(augmentPackageName,
-                        ((SchemaNode) usesNodeParent).getPath());
-            } else if (usesNodeParent instanceof AugmentationSchema) {
-                Type parentTypeBuilder = genCtx.get(module).getTypeToAugmentation().inverse().get(usesNodeParent);
-                packageName = BindingGeneratorUtil.packageNameForAugmentedGeneratedType(
-                        parentTypeBuilder.getPackageName(), (AugmentationSchema)usesNodeParent);
-            }
-            genCtx = GenHelperUtil.addRawAugmentGenTypeDefinition(module, packageName, augmentPackageName,
-                    targetTypeBuilder.toInstance(), augSchema, genTypeBuilders, genCtx, schemaContext,
-                    verboseClassComments, typeProvider);
-            return genCtx;
-        } else {
-            genCtx = generateTypesFromAugmentedChoiceCases(schemaContext, module, augmentPackageName,
-                    targetTypeBuilder.toInstance(), (ChoiceSchemaNode) targetSchemaNode, augSchema.getChildNodes(),
+                    schemaPathAugmentListEntry,
                     usesNodeParent, genCtx, verboseClassComments, genTypeBuilders, typeProvider);
             return genCtx;
         }
@@ -348,8 +334,7 @@ final class AugmentToGenType {
             throw new IllegalArgumentException("Failed to generate code for augment in " + parentUsesNode);
         }
 
-        final GroupingDefinition grouping = (GroupingDefinition) targetGrouping;
-        SchemaNode result = grouping;
+        SchemaNode result = targetGrouping;
         for (final QName node : targetPath.getPathFromRoot()) {
             if (result instanceof DataNodeContainer) {
                 final QName resultNode = QName.create(result.getQName().getModule(), node.getLocalName());
@@ -406,9 +391,8 @@ final class AugmentToGenType {
      *            Type which represents target choice
      * @param targetNode
      *            node which represents target choice
-     * @param augmentedNodes
-     *            set of choice case nodes for which is checked if are/aren't
-     *            added to choice through augmentation
+     * @param schemaPathAugmentListEntry
+     *            list of AugmentationSchema nodes grouped by target path
      * @return list of generated types which represents augmented cases of
      *         choice <code>refChoiceType</code>
      * @throws IllegalArgumentException
@@ -418,65 +402,70 @@ final class AugmentToGenType {
      *             <li>if <code>augmentedNodes</code> is null</li>
      *             </ul>
      */
-    private static Map<Module, ModuleContext> generateTypesFromAugmentedChoiceCases(final SchemaContext schemaContext, final Module module,
-                          final String basePackageName, final Type targetType, final ChoiceSchemaNode targetNode,
-                          final Iterable<DataSchemaNode> augmentedNodes, final DataNodeContainer usesNodeParent,
-                          Map<Module, ModuleContext> genCtx, final boolean verboseClassComments,
-                          Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders, final TypeProvider typeProvider) {
+    private static Map<Module, ModuleContext> generateTypesFromAugmentedChoiceCases(
+            final SchemaContext schemaContext, final Module module,
+            final String basePackageName, final Type targetType, final ChoiceSchemaNode targetNode,
+            final List<AugmentationSchema> schemaPathAugmentListEntry,
+            final DataNodeContainer usesNodeParent,
+            Map<Module, ModuleContext> genCtx, final boolean verboseClassComments,
+            Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders, final TypeProvider typeProvider) {
         Preconditions.checkArgument(basePackageName != null, "Base Package Name cannot be NULL.");
         Preconditions.checkArgument(targetType != null, "Referenced Choice Type cannot be NULL.");
-        Preconditions.checkArgument(augmentedNodes != null, "Set of Choice Case Nodes cannot be NULL.");
-
-        for (final DataSchemaNode caseNode : augmentedNodes) {
-            if (caseNode != null) {
-                final String packageName = BindingGeneratorUtil.packageNameForGeneratedType(basePackageName,
-                        caseNode.getPath(), null);
-                final GeneratedTypeBuilder caseTypeBuilder = GenHelperUtil.addDefaultInterfaceDefinition(packageName,
-                        caseNode, module, genCtx, schemaContext, verboseClassComments, genTypeBuilders, typeProvider);
-                caseTypeBuilder.addImplementsType(targetType);
-
-                SchemaNode parent;
-                final SchemaPath nodeSp = targetNode.getPath();
-                parent = SchemaContextUtil.findDataSchemaNode(schemaContext, nodeSp.getParent());
-
-                GeneratedTypeBuilder childOfType = null;
-                if (parent instanceof Module) {
-                    childOfType = genCtx.get(parent).getModuleNode();
-                } else if (parent instanceof ChoiceCaseNode) {
-                    childOfType = GenHelperUtil.findCaseByPath(parent.getPath(), genCtx);
-                } else if (parent instanceof DataSchemaNode || parent instanceof NotificationDefinition) {
-                    childOfType = GenHelperUtil.findChildNodeByPath(parent.getPath(), genCtx);
-                } else if (parent instanceof GroupingDefinition) {
-                    childOfType = GenHelperUtil.findGroupingByPath(parent.getPath(), genCtx);
-                }
+        Preconditions.checkArgument(schemaPathAugmentListEntry != null, "Set of Choice Case Nodes cannot be NULL.");
+
+
+        for (final AugmentationSchema augmentationSchema : schemaPathAugmentListEntry) {
+            for (final DataSchemaNode caseNode : augmentationSchema.getChildNodes()) {
+                if (caseNode != null) {
+                    final String packageName = BindingGeneratorUtil.packageNameForGeneratedType(basePackageName,
+                            caseNode.getPath(), BindingNamespaceType.Data);
+                    final GeneratedTypeBuilder caseTypeBuilder = GenHelperUtil.addDefaultInterfaceDefinition(packageName,
+                            caseNode, module, genCtx, schemaContext, verboseClassComments, genTypeBuilders, typeProvider);
+                    caseTypeBuilder.addImplementsType(targetType);
+
+                    SchemaNode parent;
+                    final SchemaPath nodeSp = targetNode.getPath();
+                    parent = SchemaContextUtil.findDataSchemaNode(schemaContext, nodeSp.getParent());
+
+                    GeneratedTypeBuilder childOfType = null;
+                    if (parent instanceof Module) {
+                        childOfType = genCtx.get(parent).getModuleNode();
+                    } else if (parent instanceof ChoiceCaseNode) {
+                        childOfType = GenHelperUtil.findCaseByPath(parent.getPath(), genCtx);
+                    } else if (parent instanceof DataSchemaNode || parent instanceof NotificationDefinition) {
+                        childOfType = GenHelperUtil.findChildNodeByPath(parent.getPath(), genCtx);
+                    } else if (parent instanceof GroupingDefinition) {
+                        childOfType = GenHelperUtil.findGroupingByPath(parent.getPath(), genCtx);
+                    }
 
-                if (childOfType == null) {
-                    throw new IllegalArgumentException("Failed to find parent type of choice " + targetNode);
-                }
+                    if (childOfType == null) {
+                        throw new IllegalArgumentException("Failed to find parent type of choice " + targetNode);
+                    }
 
-                ChoiceCaseNode node = null;
-                final String caseLocalName = caseNode.getQName().getLocalName();
-                if (caseNode instanceof ChoiceCaseNode) {
-                    node = (ChoiceCaseNode) caseNode;
-                } else if (targetNode.getCaseNodeByName(caseLocalName) == null) {
-                    final String targetNodeLocalName = targetNode.getQName().getLocalName();
-                    for (DataSchemaNode dataSchemaNode : usesNodeParent.getChildNodes()) {
-                        if (dataSchemaNode instanceof ChoiceSchemaNode && targetNodeLocalName.equals(dataSchemaNode.getQName
-                                ().getLocalName())) {
-                            node = ((ChoiceSchemaNode) dataSchemaNode).getCaseNodeByName(caseLocalName);
-                            break;
+                    ChoiceCaseNode node = null;
+                    final String caseLocalName = caseNode.getQName().getLocalName();
+                    if (caseNode instanceof ChoiceCaseNode) {
+                        node = (ChoiceCaseNode) caseNode;
+                    } else if (targetNode.getCaseNodeByName(caseLocalName) == null) {
+                        final String targetNodeLocalName = targetNode.getQName().getLocalName();
+                        for (DataSchemaNode dataSchemaNode : usesNodeParent.getChildNodes()) {
+                            if (dataSchemaNode instanceof ChoiceSchemaNode && targetNodeLocalName.equals(dataSchemaNode.getQName
+                                    ().getLocalName())) {
+                                node = ((ChoiceSchemaNode) dataSchemaNode).getCaseNodeByName(caseLocalName);
+                                break;
+                            }
                         }
+                    } else {
+                        node = targetNode.getCaseNodeByName(caseLocalName);
                     }
-                } else {
-                    node = targetNode.getCaseNodeByName(caseLocalName);
-                }
-                final Iterable<DataSchemaNode> childNodes = node.getChildNodes();
-                if (childNodes != null) {
-                    GenHelperUtil.resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType,
-                            childNodes, genCtx, schemaContext, verboseClassComments, genTypeBuilders, typeProvider);
+                    final Iterable<DataSchemaNode> childNodes = node.getChildNodes();
+                    if (childNodes != null) {
+                        GenHelperUtil.resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType,
+                                childNodes, genCtx, schemaContext, verboseClassComments, genTypeBuilders, typeProvider);
+                    }
+                    genCtx.get(module).addCaseType(caseNode.getPath(), caseTypeBuilder);
+                    genCtx.get(module).addChoiceToCaseMapping(targetType, caseTypeBuilder, node);
                 }
-                genCtx.get(module).addCaseType(caseNode.getPath(), caseTypeBuilder);
-                genCtx.get(module).addChoiceToCaseMapping(targetType, caseTypeBuilder, node);
             }
         }
         return genCtx;
index db1ea3c422c15efadc64ba875dfa09d2414fa428..bd75b2195c21f9fe0c6836a4bd9ce5e7ed004d97 100644 (file)
@@ -326,7 +326,7 @@ final class GenHelperUtil {
         for (AugmentationSchema aug : schemaPathAugmentListEntry) {
             //apply all uses
             addImplementedInterfaceFromUses(aug, augTypeBuilder, genCtx);
-            augSchemaNodeToMethods(module, augmentPackageName, augTypeBuilder, augTypeBuilder, aug.getChildNodes(),
+            augSchemaNodeToMethods(module, BindingMapping.getRootPackageName(module), augTypeBuilder, augTypeBuilder, aug.getChildNodes(),
                genCtx, schemaContext, verboseClassComments, typeProvider, genTypeBuilders);
         }
 
@@ -651,7 +651,7 @@ final class GenHelperUtil {
                     schemaContext, "", verboseClasssComments, genTypeBuilders);
             constructGetter(parent, choiceNode.getQName().getLocalName(),
                     choiceNode.getDescription(), choiceTypeBuilder, choiceNode.getStatus());
-            choiceTypeBuilder.addImplementsType(INSTANTIABLE);
+            choiceTypeBuilder.addImplementsType(parameterizedTypeFor(BindingTypes.INSTANTIABLE, choiceTypeBuilder));
             annotateDeprecatedIfNecessary(choiceNode.getStatus(), choiceTypeBuilder);
             genCtx.get(module).addChildNodeType(choiceNode, choiceTypeBuilder);
             generateTypesFromChoiceCases(module, schemaContext, genCtx, basePackageName, choiceTypeBuilder.toInstance(),
index 77f5e298df2fcd143a5cb1a25cbe68026feaef0e..a91da673cf2d87df15e03415a687b18537373b02 100644 (file)
@@ -32,6 +32,7 @@ import org.opendaylight.mdsal.binding.javav2.generator.util.generated.type.build
 import org.opendaylight.mdsal.binding.javav2.generator.yang.types.TypeProviderImpl;
 import org.opendaylight.mdsal.binding.javav2.model.api.Type;
 import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.GeneratedTypeBuilder;
+import org.opendaylight.mdsal.binding.javav2.spec.structural.Augmentation;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
@@ -289,25 +290,24 @@ public class AugmentToGenTypeTest {
         assertEquals(result.get(1), augmentationSchema2);
     }
 
-    @Ignore
     @SuppressWarnings({ "rawtypes" })
     @Test
     public void augmentationToGenTypesNullPckgNameTest() throws Exception {
-        final Class[] parameterTypes = { String.class, AugmentationSchema.class, Module.class, SchemaContext.class,
+        final Class[] parameterTypes = { String.class, Map.Entry.class, Module.class, SchemaContext.class,
                 boolean.class, Map.class, Map.class, TypeProvider.class };
         final Method generate = AugmentToGenType.class.getDeclaredMethod("augmentationToGenTypes", parameterTypes);
         assertNotNull(generate);
         generate.setAccessible(true);
 
         final String augmPackName = null;
-        final AugmentationSchema augmSchema = null;
+        final Map.Entry<SchemaPath, List<AugmentationSchema>> schemaPathAugmentListEntry = null;
         final SchemaContext context = null;
         final TypeProvider typeProvider = null;
         final Map<Module, ModuleContext> genCtx = new HashMap<>();
         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
         final Module m = null;
 
-        final Object[] args = { augmPackName, augmSchema, m, context, false, genCtx, genTypeBuilders, typeProvider };
+        final Object[] args = { augmPackName, schemaPathAugmentListEntry, m, context, false, genCtx, genTypeBuilders, typeProvider };
         try {
             generate.invoke(AugmentToGenType.class, args);
             fail();
@@ -321,25 +321,24 @@ public class AugmentToGenTypeTest {
         }
     }
 
-    @Ignore
     @SuppressWarnings({ "rawtypes" })
     @Test
     public void augmentationToGenTypesNullAugSchemaTest() throws Exception {
-        final Class[] parameterTypes = { String.class, AugmentationSchema.class, Module.class, SchemaContext.class,
+        final Class[] parameterTypes = { String.class, Map.Entry.class, Module.class, SchemaContext.class,
                 boolean.class, Map.class, Map.class, TypeProvider.class };
         final Method generate = AugmentToGenType.class.getDeclaredMethod("augmentationToGenTypes", parameterTypes);
         assertNotNull(generate);
         generate.setAccessible(true);
 
         final String augmPackName = "pckg.name";
-        final AugmentationSchema augmSchema = null;
+        final Map.Entry<SchemaPath, List<AugmentationSchema>> schemaPathAugmentListEntry = null;
         final SchemaContext context = null;
         final TypeProvider typeProvider = null;
         final Map<Module, ModuleContext> genCtx = new HashMap<>();
         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
         final Module m = null;
 
-        final Object[] args = { augmPackName, augmSchema, m, context, false, genCtx, genTypeBuilders, typeProvider };
+        final Object[] args = { augmPackName, schemaPathAugmentListEntry, m, context, false, genCtx, genTypeBuilders, typeProvider };
         try {
             generate.invoke(AugmentToGenType.class, args);
             fail();
@@ -349,15 +348,14 @@ public class AugmentToGenTypeTest {
             final Throwable cause = e.getCause();
             assertNotNull(cause);
             assertTrue(cause instanceof IllegalArgumentException);
-            assertEquals("Augmentation Schema cannot be NULL.", cause.getMessage());
+            assertEquals("Augmentation List Entry cannot be NULL.", cause.getMessage());
         }
     }
 
-    @Ignore
     @SuppressWarnings({ "rawtypes" })
     @Test
     public void augmentationToGenTypesNullAugSchemaTargetPathTest() throws Exception {
-        final Class[] parameterTypes = { String.class, AugmentationSchema.class, Module.class, SchemaContext.class,
+        final Class[] parameterTypes = { String.class, Map.Entry.class, Module.class, SchemaContext.class,
                 boolean.class, Map.class, Map.class, TypeProvider.class };
         final Method generate = AugmentToGenType.class.getDeclaredMethod("augmentationToGenTypes", parameterTypes);
         assertNotNull(generate);
@@ -367,13 +365,58 @@ public class AugmentToGenTypeTest {
         final AugmentationSchema augmSchema = mock(AugmentationSchema.class);
         when(augmSchema.getTargetPath()).thenReturn(null);
 
+        final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
+        final Map.Entry<SchemaPath, List<AugmentationSchema>> schemaPathAugmentListEntry = mock(Map.Entry.class);
+        when(schemaPathAugmentListEntry.getKey()).thenReturn(null);
+        when(schemaPathAugmentListEntry.getValue()).thenReturn(augmentationSchemaList);
+
+        final SchemaContext context = null;
+        final TypeProvider typeProvider = null;
+        final Map<Module, ModuleContext> genCtx = new HashMap<>();
+        final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
+        final Module m = null;
+
+        final Object[] args = { augmPackName, schemaPathAugmentListEntry, m, context, false, genCtx, genTypeBuilders, typeProvider };
+        try {
+            generate.invoke(AugmentToGenType.class, args);
+            fail();
+        } catch (final Exception e) {
+            assertNotNull(e);
+            assertTrue(e instanceof InvocationTargetException);
+            final Throwable cause = e.getCause();
+            assertNotNull(cause);
+            assertTrue(cause instanceof IllegalStateException);
+            assertEquals("Augmentation List Entry does not contain Target Path (Target Path is NULL).", cause.getMessage());
+        }
+    }
+
+    @SuppressWarnings({ "rawtypes" })
+    @Test
+    public void augmentationToGenTypesNullAugSchemaListTest() throws Exception {
+        final Class[] parameterTypes = { String.class, Map.Entry.class, Module.class, SchemaContext.class,
+                boolean.class, Map.class, Map.class, TypeProvider.class };
+        final Method generate = AugmentToGenType.class.getDeclaredMethod("augmentationToGenTypes", parameterTypes);
+        assertNotNull(generate);
+        generate.setAccessible(true);
+
+        final String augmPackName = "pckg.name";
+        final AugmentationSchema augmSchema = mock(AugmentationSchema.class);
+        final QName qnamePath = QName.create("test", "2017-04-04", "aug");
+        final SchemaPath path = SchemaPath.create(true, qnamePath);
+        when(augmSchema.getTargetPath()).thenReturn(path);
+
+        final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
+        final Map.Entry<SchemaPath, List<AugmentationSchema>> schemaPathAugmentListEntry = mock(Map.Entry.class);
+        when(schemaPathAugmentListEntry.getKey()).thenReturn(path);
+        when(schemaPathAugmentListEntry.getValue()).thenReturn(augmentationSchemaList);
+
         final SchemaContext context = null;
         final TypeProvider typeProvider = null;
         final Map<Module, ModuleContext> genCtx = new HashMap<>();
         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
         final Module m = null;
 
-        final Object[] args = { augmPackName, augmSchema, m, context, false, genCtx, genTypeBuilders, typeProvider };
+        final Object[] args = { augmPackName, schemaPathAugmentListEntry, m, context, false, genCtx, genTypeBuilders, typeProvider };
         try {
             generate.invoke(AugmentToGenType.class, args);
             fail();
@@ -383,15 +426,14 @@ public class AugmentToGenTypeTest {
             final Throwable cause = e.getCause();
             assertNotNull(cause);
             assertTrue(cause instanceof IllegalStateException);
-            assertEquals("Augmentation Schema does not contain Target Path (Target Path is NULL).", cause.getMessage());
+            assertEquals("Augmentation List cannot be empty.", cause.getMessage());
         }
     }
 
-    @Ignore
     @SuppressWarnings({ "rawtypes" })
     @Test
     public void augmentationToGenTypesNullAugSchemaTargetNodeTest() throws Exception {
-        final Class[] parameterTypes = { String.class, AugmentationSchema.class, Module.class, SchemaContext.class,
+        final Class[] parameterTypes = { String.class, Map.Entry.class, Module.class, SchemaContext.class,
                 boolean.class, Map.class, Map.class, TypeProvider.class };
         final Method generate = AugmentToGenType.class.getDeclaredMethod("augmentationToGenTypes", parameterTypes);
         assertNotNull(generate);
@@ -406,6 +448,12 @@ public class AugmentToGenTypeTest {
         final Set<UsesNode> uses = new HashSet<>();
         when(augmSchema.getUses()).thenReturn(uses);
 
+        final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
+        augmentationSchemaList.add(augmSchema);
+        final Map.Entry<SchemaPath, List<AugmentationSchema>> schemaPathAugmentListEntry = mock(Map.Entry.class);
+        when(schemaPathAugmentListEntry.getKey()).thenReturn(path);
+        when(schemaPathAugmentListEntry.getValue()).thenReturn(augmentationSchemaList);
+
         final SchemaContext context = mock(SchemaContext.class);
         final Module moduleAug = mock(Module.class);
         final DataSchemaNode schNode = null;
@@ -422,7 +470,7 @@ public class AugmentToGenTypeTest {
         when(m.getNamespace()).thenReturn(qnamePath.getNamespace());
         when(m.getRevision()).thenReturn(qnamePath.getRevision());
 
-        final Object[] args = { augmPackName, augmSchema, m, context, false, genCtx, genTypeBuilders, typeProvider };
+        final Object[] args = { augmPackName, schemaPathAugmentListEntry, m, context, false, genCtx, genTypeBuilders, typeProvider };
         try {
             generate.invoke(AugmentToGenType.class, args);
             fail();
@@ -436,11 +484,10 @@ public class AugmentToGenTypeTest {
         }
     }
 
-    @Ignore
     @SuppressWarnings({ "rawtypes" })
     @Test
     public void augmentationToGenTypesNullAugTargetGTBTest() throws Exception {
-        final Class[] parameterTypes = { String.class, AugmentationSchema.class, Module.class, SchemaContext.class,
+        final Class[] parameterTypes = { String.class, Map.Entry.class, Module.class, SchemaContext.class,
                 boolean.class, Map.class, Map.class, TypeProvider.class };
         final Method generate = AugmentToGenType.class.getDeclaredMethod("augmentationToGenTypes", parameterTypes);
         assertNotNull(generate);
@@ -455,6 +502,12 @@ public class AugmentToGenTypeTest {
         final Set<UsesNode> uses = new HashSet<>();
         when(augmSchema.getUses()).thenReturn(uses);
 
+        final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
+        augmentationSchemaList.add(augmSchema);
+        final Map.Entry<SchemaPath, List<AugmentationSchema>> schemaPathAugmentListEntry = mock(Map.Entry.class);
+        when(schemaPathAugmentListEntry.getKey()).thenReturn(path);
+        when(schemaPathAugmentListEntry.getValue()).thenReturn(augmentationSchemaList);
+
         final SchemaContext context = mock(SchemaContext.class);
         final Module moduleAug = mock(Module.class);
         final DataSchemaNode schNode = mock(DataSchemaNode.class);
@@ -471,7 +524,7 @@ public class AugmentToGenTypeTest {
         when(m.getNamespace()).thenReturn(qnamePath.getNamespace());
         when(m.getRevision()).thenReturn(qnamePath.getRevision());
 
-        final Object[] args = { augmPackName, augmSchema, m, context, false, genCtx, genTypeBuilders, typeProvider };
+        final Object[] args = { augmPackName, schemaPathAugmentListEntry, m, context, false, genCtx, genTypeBuilders, typeProvider };
         try {
             generate.invoke(AugmentToGenType.class, args);
             fail();
@@ -485,11 +538,10 @@ public class AugmentToGenTypeTest {
         }
     }
 
-    @Ignore
     @SuppressWarnings({ "rawtypes", "unchecked" })
     @Test
     public void augmentationToGenTypesAugUsesNullOrigTargetTest() throws Exception {
-        final Class[] parameterTypes = { String.class, AugmentationSchema.class, Module.class, SchemaContext.class,
+        final Class[] parameterTypes = { String.class, Map.Entry.class, Module.class, SchemaContext.class,
                 boolean.class, Map.class, Map.class, TypeProvider.class };
         final Method generate = AugmentToGenType.class.getDeclaredMethod("augmentationToGenTypes", parameterTypes);
         assertNotNull(generate);
@@ -504,6 +556,12 @@ public class AugmentToGenTypeTest {
         final Set<UsesNode> uses = new HashSet<>();
         when(augmSchema.getUses()).thenReturn(uses);
 
+        final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
+        augmentationSchemaList.add(augmSchema);
+        final Map.Entry<SchemaPath, List<AugmentationSchema>> schemaPathAugmentListEntry = mock(Map.Entry.class);
+        when(schemaPathAugmentListEntry.getKey()).thenReturn(path);
+        when(schemaPathAugmentListEntry.getValue()).thenReturn(augmentationSchemaList);
+
         final SchemaContext context = mock(SchemaContext.class);
         final Module moduleAug = mock(Module.class);
         final DerivableSchemaNode targetSchNode = mock(DerivableSchemaNode.class);
@@ -524,7 +582,7 @@ public class AugmentToGenTypeTest {
         when(m.getNamespace()).thenReturn(qnamePath.getNamespace());
         when(m.getRevision()).thenReturn(qnamePath.getRevision());
 
-        final Object[] args = { augmPackName, augmSchema, m, context, false, genCtx, genTypeBuilders, typeProvider };
+        final Object[] args = { augmPackName, schemaPathAugmentListEntry, m, context, false, genCtx, genTypeBuilders, typeProvider };
         try {
             generate.invoke(AugmentToGenType.class, args);
             fail();
@@ -539,11 +597,10 @@ public class AugmentToGenTypeTest {
         }
     }
 
-    @Ignore
     @SuppressWarnings({ "rawtypes" })
     @Test
     public void augmentationToGenTypesTargetChoicSchemaNodeTest() throws Exception {
-        final Class[] parameterTypes = { String.class, AugmentationSchema.class, Module.class, SchemaContext.class,
+        final Class[] parameterTypes = { String.class, Map.Entry.class, Module.class, SchemaContext.class,
                 boolean.class, Map.class, Map.class, TypeProvider.class };
         final Method generate = AugmentToGenType.class.getDeclaredMethod("augmentationToGenTypes", parameterTypes);
         assertNotNull(generate);
@@ -558,6 +615,12 @@ public class AugmentToGenTypeTest {
         final Set<UsesNode> uses = new HashSet<>();
         when(augmSchema.getUses()).thenReturn(uses);
 
+        final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
+        augmentationSchemaList.add(augmSchema);
+        final Map.Entry<SchemaPath, List<AugmentationSchema>> schemaPathAugmentListEntry = mock(Map.Entry.class);
+        when(schemaPathAugmentListEntry.getKey()).thenReturn(path);
+        when(schemaPathAugmentListEntry.getValue()).thenReturn(augmentationSchemaList);
+
         final SchemaContext context = mock(SchemaContext.class);
         final Module moduleAug = mock(Module.class);
         final ChoiceSchemaNode targetSchNode = mock(ChoiceSchemaNode.class);
@@ -583,16 +646,15 @@ public class AugmentToGenTypeTest {
         when(m.getNamespace()).thenReturn(qnamePath.getNamespace());
         when(m.getRevision()).thenReturn(qnamePath.getRevision());
 
-        final Object[] args = { augmPackName, augmSchema, m, context, false, genCtx, genTypeBuilders, typeProvider };
+        final Object[] args = { augmPackName, schemaPathAugmentListEntry, m, context, false, genCtx, genTypeBuilders, typeProvider };
         final Map result = (Map) generate.invoke(AugmentToGenType.class, args);
         assertNotNull(result);
     }
 
-    @Ignore
     @SuppressWarnings({ "rawtypes", "unchecked" })
     @Test
     public void augmentationToGenTypesTest() throws Exception {
-        final Class[] parameterTypes = { String.class, AugmentationSchema.class, Module.class, SchemaContext.class,
+        final Class[] parameterTypes = { String.class, Map.Entry.class, Module.class, SchemaContext.class,
                 boolean.class, Map.class, Map.class, TypeProvider.class };
         final Method generate = AugmentToGenType.class.getDeclaredMethod("augmentationToGenTypes", parameterTypes);
         assertNotNull(generate);
@@ -609,6 +671,12 @@ public class AugmentToGenTypeTest {
         final List<UnknownSchemaNode> unknownSchemaNodes = new ArrayList<>();
         when(augmSchema.getUnknownSchemaNodes()).thenReturn(unknownSchemaNodes);
 
+        final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
+        augmentationSchemaList.add(augmSchema);
+        final Map.Entry<SchemaPath, List<AugmentationSchema>> schemaPathAugmentListEntry = mock(Map.Entry.class);
+        when(schemaPathAugmentListEntry.getKey()).thenReturn(path);
+        when(schemaPathAugmentListEntry.getValue()).thenReturn(augmentationSchemaList);
+
         final SchemaContext context = mock(SchemaContext.class);
         final Module moduleAug = mock(Module.class);
         final DerivableSchemaNode targetSchNode = mock(DerivableSchemaNode.class);
@@ -641,13 +709,13 @@ public class AugmentToGenTypeTest {
         when(moduleAug.getRevision()).thenReturn(qnamePath.getRevision());
 
         final Object[] args =
-                { augmPackName, augmSchema, moduleAug, context, false, genCtx, genTypeBuilders, typeProvider };
+                { augmPackName, schemaPathAugmentListEntry, moduleAug, context, false, genCtx, genTypeBuilders, typeProvider };
         final Map<Module, ModuleContext> result =
                 (Map<Module, ModuleContext>) generate.invoke(AugmentToGenType.class, args);
         assertNotNull(result);
         final ModuleContext moduleContext = result.get(moduleAug);
         assertTrue(moduleContext.getAugmentations().get(0).getName().contains("Augm"));
-        assertEquals("pckg.name", moduleContext.getAugmentations().get(0).getPackageName());
+        assertEquals("pckg.name.data.aug", moduleContext.getAugmentations().get(0).getPackageName());
         assertTrue(moduleContext.getChildNode(path).getName().contains("Augm"));
         assertEquals("pckg.name", moduleContext.getChildNode(path).getPackageName());
     }
@@ -655,7 +723,7 @@ public class AugmentToGenTypeTest {
     @Test
     public void usesAugmentationToGenTypesNullPckgNameTest() throws Exception {
         try {
-            AugmentToGenType.usesAugmentationToGenTypes(null, null, (AugmentationSchema) null, null, null, null, null, null, false, null);
+            AugmentToGenType.usesAugmentationToGenTypes(null, null, null, null, null, null, null, null, false, null);
         } catch (final Exception e) {
             assertNotNull(e);
             assertTrue(e instanceof IllegalArgumentException);
@@ -664,13 +732,26 @@ public class AugmentToGenTypeTest {
     }
 
     @Test
-    public void usesAugmentationToGenTypesNullAugSchemaNodeTest() throws Exception {
+    public void usesAugmentationToGenTypesNullAugSchemaListEntryTest() throws Exception {
         try {
-            AugmentToGenType.usesAugmentationToGenTypes(null, "", (AugmentationSchema) null, null, null, null, null, null, false, null);
+            AugmentToGenType.usesAugmentationToGenTypes(null, "", null, null, null, null, null, null, false, null);
         } catch (final Exception e) {
             assertNotNull(e);
             assertTrue(e instanceof IllegalArgumentException);
-            assertEquals(e.getMessage(), "Augmentation Schema cannot be NULL.");
+            assertEquals(e.getMessage(), "Augmentation Schema List Entry cannot be NULL.");
+        }
+    }
+
+    @Test
+    public void usesAugmentationToGenTypesEmptyAugSchemaListTest() throws Exception {
+        final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
+        try {
+            AugmentToGenType.usesAugmentationToGenTypes(null, "", augmentationSchemaList, null, null, null, null, null,
+                    false, null);
+        } catch (final Exception e) {
+            assertNotNull(e);
+            assertTrue(e instanceof IllegalStateException);
+            assertEquals(e.getMessage(), "Augmentation Schema List cannot be empty");
         }
     }
 
@@ -678,8 +759,10 @@ public class AugmentToGenTypeTest {
     public void usesAugmentationToGenTypesNullAugSchemaNodeTargetPathTest() throws Exception {
         final AugmentationSchema augmentationSchema = mock(AugmentationSchema.class);
         when(augmentationSchema.getTargetPath()).thenReturn(null);
+        final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
+        augmentationSchemaList.add(augmentationSchema);
         try {
-            AugmentToGenType.usesAugmentationToGenTypes(null, "", augmentationSchema, null, null, null, null, null,
+            AugmentToGenType.usesAugmentationToGenTypes(null, "", augmentationSchemaList, null, null, null, null, null,
                     false, null);
         } catch (final Exception e) {
             assertNotNull(e);
@@ -697,6 +780,9 @@ public class AugmentToGenTypeTest {
         final Set<UsesNode> uses = new HashSet<>();
         when(augmentationSchema.getUses()).thenReturn(uses);
 
+        final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
+        augmentationSchemaList.add(augmentationSchema);
+
         final SchemaContext context = mock(SchemaContext.class);
         final Module moduleAug = mock(Module.class);
         when(moduleAug.getName()).thenReturn("augm-module");
@@ -721,7 +807,7 @@ public class AugmentToGenTypeTest {
         when(usesNode.getGroupingPath()).thenReturn(path);
 
         try {
-            AugmentToGenType.usesAugmentationToGenTypes(context, "pckg.test.augm", augmentationSchema, moduleAug,
+            AugmentToGenType.usesAugmentationToGenTypes(context, "pckg.test.augm", augmentationSchemaList, moduleAug,
                     usesNode, usesNodeParent, genCtx, genTypeBuilders, false, null);
         } catch (final Exception e) {
             assertNotNull(e);
@@ -739,6 +825,9 @@ public class AugmentToGenTypeTest {
         final Set<UsesNode> uses = new HashSet<>();
         when(augmentationSchema.getUses()).thenReturn(uses);
 
+        final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
+        augmentationSchemaList.add(augmentationSchema);
+
         final SchemaContext context = mock(SchemaContext.class);
         final Module moduleAug = mock(Module.class);
         when(moduleAug.getName()).thenReturn("augm-module");
@@ -764,7 +853,7 @@ public class AugmentToGenTypeTest {
         when(usesNode.getGroupingPath()).thenReturn(path);
 
         try {
-            AugmentToGenType.usesAugmentationToGenTypes(context, "pckg.test.augm", augmentationSchema, moduleAug,
+            AugmentToGenType.usesAugmentationToGenTypes(context, "pckg.test.augm", augmentationSchemaList, moduleAug,
                     usesNode, usesNodeParent, genCtx, genTypeBuilders, false, null);
         } catch (final Exception e) {
             assertNotNull(e);
@@ -782,6 +871,9 @@ public class AugmentToGenTypeTest {
         final Set<UsesNode> uses = new HashSet<>();
         when(augmentationSchema.getUses()).thenReturn(uses);
 
+        final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
+        augmentationSchemaList.add(augmentationSchema);
+
         final SchemaContext context = mock(SchemaContext.class);
         final Module moduleAug = mock(Module.class);
         when(moduleAug.getName()).thenReturn("augm-module");
@@ -813,7 +905,7 @@ public class AugmentToGenTypeTest {
         when(usesNode.getGroupingPath()).thenReturn(path);
 
         final Map<Module, ModuleContext> result = AugmentToGenType.usesAugmentationToGenTypes(context, "pckg.test.augm",
-                augmentationSchema, moduleAug, usesNode, usesNodeParent, genCtx, genTypeBuilders, false, null);
+                augmentationSchemaList, moduleAug, usesNode, usesNodeParent, genCtx, genTypeBuilders, false, null);
         assertNotNull(result);
     }
 
@@ -826,6 +918,9 @@ public class AugmentToGenTypeTest {
         final Set<UsesNode> uses = new HashSet<>();
         when(augmentationSchema.getUses()).thenReturn(uses);
 
+        final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
+        augmentationSchemaList.add(augmentationSchema);
+
         final SchemaContext context = mock(SchemaContext.class);
         final Module moduleAug = mock(Module.class);
         when(moduleAug.getName()).thenReturn("augm-module");
@@ -857,7 +952,7 @@ public class AugmentToGenTypeTest {
         when(usesNode.getGroupingPath()).thenReturn(path);
 
         final Map<Module, ModuleContext> result = AugmentToGenType.usesAugmentationToGenTypes(context, "pckg.test.augm",
-                augmentationSchema, moduleAug, usesNode, usesNodeParent, genCtx, genTypeBuilders, false, null);
+                augmentationSchemaList, moduleAug, usesNode, usesNodeParent, genCtx, genTypeBuilders, false, null);
         assertNotNull(result);
     }
 
@@ -1042,7 +1137,7 @@ public class AugmentToGenTypeTest {
     @Test
     public void generateTypesFromAugmentedChoiceCasesNullPckgNameTest() throws Exception {
         final Class[] parameterTypes =
-                { SchemaContext.class, Module.class, String.class, Type.class, ChoiceSchemaNode.class, Iterable.class,
+                { SchemaContext.class, Module.class, String.class, Type.class, ChoiceSchemaNode.class, List.class,
                         DataNodeContainer.class, Map.class, boolean.class, Map.class, TypeProvider.class };
         final Method generate =
                 AugmentToGenType.class.getDeclaredMethod("generateTypesFromAugmentedChoiceCases", parameterTypes);
@@ -1054,13 +1149,13 @@ public class AugmentToGenTypeTest {
         final String pckgName = null;
         final Type targetType = null;
         final ChoiceSchemaNode targetNode = null;
-        final Iterable augmentNodes = null;
+        final List<AugmentationSchema> schemaPathAugmentListEntry = null;
         final DataNodeContainer usesNodeParent = null;
         final Map<Module, ModuleContext> genCtx = new HashMap<>();
         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilder = new HashMap<>();
 
-        final Object[] args = { schemaContext, module, pckgName, targetType, targetNode, augmentNodes, usesNodeParent,
-                genCtx, false, genTypeBuilder, null };
+        final Object[] args = { schemaContext, module, pckgName, targetType, targetNode, schemaPathAugmentListEntry,
+                usesNodeParent, genCtx, false, genTypeBuilder, null };
         try {
             generate.invoke(AugmentToGenType.class, args);
             fail();
@@ -1078,7 +1173,7 @@ public class AugmentToGenTypeTest {
     @Test
     public void generateTypesFromAugmentedChoiceCasesNullTargetType() throws Exception {
         final Class[] parameterTypes =
-                { SchemaContext.class, Module.class, String.class, Type.class, ChoiceSchemaNode.class, Iterable.class,
+                { SchemaContext.class, Module.class, String.class, Type.class, ChoiceSchemaNode.class, List.class,
                         DataNodeContainer.class, Map.class, boolean.class, Map.class, TypeProvider.class };
         final Method generate =
                 AugmentToGenType.class.getDeclaredMethod("generateTypesFromAugmentedChoiceCases", parameterTypes);
@@ -1090,13 +1185,13 @@ public class AugmentToGenTypeTest {
         final String pckgName = "";
         final Type targetType = null;
         final ChoiceSchemaNode targetNode = null;
-        final Iterable augmentNodes = null;
+        final List<AugmentationSchema> schemaPathAugmentListEntry = null;
         final DataNodeContainer usesNodeParent = null;
         final Map<Module, ModuleContext> genCtx = new HashMap<>();
         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilder = new HashMap<>();
 
-        final Object[] args = { schemaContext, module, pckgName, targetType, targetNode, augmentNodes, usesNodeParent,
-                genCtx, false, genTypeBuilder, null };
+        final Object[] args = { schemaContext, module, pckgName, targetType, targetNode, schemaPathAugmentListEntry,
+                usesNodeParent, genCtx, false, genTypeBuilder, null };
         try {
             generate.invoke(AugmentToGenType.class, args);
             fail();
@@ -1114,7 +1209,7 @@ public class AugmentToGenTypeTest {
     @Test
     public void generateTypesFromAugmentedChoiceCasesNullAugmentNodes() throws Exception {
         final Class[] parameterTypes =
-                { SchemaContext.class, Module.class, String.class, Type.class, ChoiceSchemaNode.class, Iterable.class,
+                { SchemaContext.class, Module.class, String.class, Type.class, ChoiceSchemaNode.class, List.class,
                         DataNodeContainer.class, Map.class, boolean.class, Map.class, TypeProvider.class };
         final Method generate =
                 AugmentToGenType.class.getDeclaredMethod("generateTypesFromAugmentedChoiceCases", parameterTypes);
@@ -1126,12 +1221,12 @@ public class AugmentToGenTypeTest {
         final String pckgName = "";
         final Type targetType = mock(Type.class);
         final ChoiceSchemaNode targetNode = null;
-        final Iterable augmentNodes = null;
+        final List<AugmentationSchema> schemaPathAugmentListEntry = null;
         final DataNodeContainer usesNodeParent = null;
         final Map<Module, ModuleContext> genCtx = new HashMap<>();
         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilder = new HashMap<>();
 
-        final Object[] args = { schemaContext, module, pckgName, targetType, targetNode, augmentNodes, usesNodeParent,
+        final Object[] args = { schemaContext, module, pckgName, targetType, targetNode, schemaPathAugmentListEntry, usesNodeParent,
                 genCtx, false, genTypeBuilder, null };
         try {
             generate.invoke(AugmentToGenType.class, args);
@@ -1150,7 +1245,7 @@ public class AugmentToGenTypeTest {
     @Test
     public void generateTypesFromAugmentedChoiceCasesNullCaseNodeTest() throws Exception {
         final Class[] parameterTypes =
-                { SchemaContext.class, Module.class, String.class, Type.class, ChoiceSchemaNode.class, Iterable.class,
+                { SchemaContext.class, Module.class, String.class, Type.class, ChoiceSchemaNode.class, List.class,
                         DataNodeContainer.class, Map.class, boolean.class, Map.class, TypeProvider.class };
         final Method generate =
                 AugmentToGenType.class.getDeclaredMethod("generateTypesFromAugmentedChoiceCases", parameterTypes);
@@ -1165,11 +1260,17 @@ public class AugmentToGenTypeTest {
         final Set<DataSchemaNode> augmentNodes = new HashSet<>();
         final DataSchemaNode caseNode = null;
         augmentNodes.add(caseNode);
+
+        final AugmentationSchema augmentationSchema = mock(AugmentationSchema.class);
+        when(augmentationSchema.getChildNodes()).thenReturn(augmentNodes);
+        final List<AugmentationSchema> schemaPathAugmentListEntry = new ArrayList<>();
+        schemaPathAugmentListEntry.add(augmentationSchema);
+
         final DataNodeContainer usesNodeParent = null;
         final Map<Module, ModuleContext> genCtx = new HashMap<>();
         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilder = new HashMap<>();
 
-        final Object[] args = { schemaContext, module, pckgName, targetType, targetNode, augmentNodes, usesNodeParent,
+        final Object[] args = { schemaContext, module, pckgName, targetType, targetNode, schemaPathAugmentListEntry, usesNodeParent,
                 genCtx, false, genTypeBuilder, null };
         final Map<Module, ModuleContext> result =
                 (Map<Module, ModuleContext>) generate.invoke(AugmentToGenType.class, args);
@@ -1180,7 +1281,7 @@ public class AugmentToGenTypeTest {
     @Test
     public void generateTypesFromAugmentedChoiceCasesNullChildTest() throws Exception {
         final Class[] parameterTypes =
-                { SchemaContext.class, Module.class, String.class, Type.class, ChoiceSchemaNode.class, Iterable.class,
+                { SchemaContext.class, Module.class, String.class, Type.class, ChoiceSchemaNode.class, List.class,
                         DataNodeContainer.class, Map.class, boolean.class, Map.class, TypeProvider.class };
         final Method generate =
                 AugmentToGenType.class.getDeclaredMethod("generateTypesFromAugmentedChoiceCases", parameterTypes);
@@ -1205,6 +1306,12 @@ public class AugmentToGenTypeTest {
         when(caseNode.getPath()).thenReturn(path);
         when(caseNode.getQName()).thenReturn(qnamePath);
         augmentNodes.add(caseNode);
+
+        final AugmentationSchema augmentationSchema = mock(AugmentationSchema.class);
+        when(augmentationSchema.getChildNodes()).thenReturn(augmentNodes);
+        final List<AugmentationSchema> schemaPathAugmentListEntry = new ArrayList<>();
+        schemaPathAugmentListEntry.add(augmentationSchema);
+
         final DataNodeContainer usesNodeParent = null;
         final ChoiceSchemaNode targetNode = mock(ChoiceSchemaNode.class);
         when(targetNode.getPath()).thenReturn(path);
@@ -1217,7 +1324,7 @@ public class AugmentToGenTypeTest {
         when(schemaContext.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
                 .thenReturn(module);
 
-        final Object[] args = { schemaContext, module, pckgName, targetType, targetNode, augmentNodes, usesNodeParent,
+        final Object[] args = { schemaContext, module, pckgName, targetType, targetNode, schemaPathAugmentListEntry, usesNodeParent,
                 genCtx, false, genTypeBuilder, null };
         try {
             generate.invoke(AugmentToGenType.class, args);
@@ -1236,7 +1343,7 @@ public class AugmentToGenTypeTest {
     @Test
     public void generateTypesFromAugmentedChoiceCasesTest() throws Exception {
         final Class[] parameterTypes =
-                { SchemaContext.class, Module.class, String.class, Type.class, ChoiceSchemaNode.class, Iterable.class,
+                { SchemaContext.class, Module.class, String.class, Type.class, ChoiceSchemaNode.class, List.class,
                         DataNodeContainer.class, Map.class, boolean.class, Map.class, TypeProvider.class };
         final Method generate =
                 AugmentToGenType.class.getDeclaredMethod("generateTypesFromAugmentedChoiceCases", parameterTypes);
@@ -1262,6 +1369,12 @@ public class AugmentToGenTypeTest {
         when(caseNode.getPath()).thenReturn(path);
         when(caseNode.getQName()).thenReturn(qnamePath);
         augmentNodes.add(caseNode);
+
+        final AugmentationSchema augmentationSchema = mock(AugmentationSchema.class);
+        when(augmentationSchema.getChildNodes()).thenReturn(augmentNodes);
+        final List<AugmentationSchema> schemaPathAugmentListEntry = new ArrayList<>();
+        schemaPathAugmentListEntry.add(augmentationSchema);
+
         final DataNodeContainer usesNodeParent = null;
         final ChoiceSchemaNode targetNode = mock(ChoiceSchemaNode.class);
         when(targetNode.getPath()).thenReturn(path);
@@ -1275,7 +1388,7 @@ public class AugmentToGenTypeTest {
         when(schemaContext.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
                 .thenReturn(module);
 
-        final Object[] args = { schemaContext, module, pckgName, targetType, targetNode, augmentNodes, usesNodeParent,
+        final Object[] args = { schemaContext, module, pckgName, targetType, targetNode, schemaPathAugmentListEntry, usesNodeParent,
                 genCtx, false, genTypeBuilder, null };
         final Map<Module, ModuleContext> result =
                 (Map<Module, ModuleContext>) generate.invoke(AugmentToGenType.class, args);
index 66b04e6f8650242fb87294bdd27a846abd6ac23b..a8c7c095b5cc366e5981fcfb300f1ac5f4f368df 100644 (file)
@@ -31,10 +31,10 @@ public class Bug8542Test {
                 assertEquals("org.opendaylight.mdsal.gen.javav2.yang.test.uses.augment.recursive.rev170519.data.d",
                         type.getPackageName());
             } else if (type.getName().equals("B11")) {
-                assertEquals("org.opendaylight.mdsal.gen.javav2.yang.test.uses.augment.recursive.rev170519.data.d.a11",
+                assertEquals("org.opendaylight.mdsal.gen.javav2.yang.test.uses.augment.recursive.rev170519.data.d.a1",
                         type.getPackageName());
             } else if (type.getName().equals("C11")) {
-                assertEquals("org.opendaylight.mdsal.gen.javav2.yang.test.uses.augment.recursive.rev170519.data.d.a11.b11",
+                assertEquals("org.opendaylight.mdsal.gen.javav2.yang.test.uses.augment.recursive.rev170519.data.d.a1.b1",
                         type.getPackageName());
             }
         }
diff --git a/binding2/mdsal-binding2-generator-impl/src/test/resources/augment-group/test-augment-choice-case.yang b/binding2/mdsal-binding2-generator-impl/src/test/resources/augment-group/test-augment-choice-case.yang
new file mode 100644 (file)
index 0000000..c167d79
--- /dev/null
@@ -0,0 +1,140 @@
+module test-augment-choice-case {\r
+    yang-version 1;\r
+    namespace "urn:test:augment:choice:case";\r
+    prefix "augtestchoice";\r
+\r
+    revision "2014-3-13" {\r
+        description\r
+            "Initial revision";\r
+    }\r
+\r
+\r
+    container container {\r
+        choice ch2{}\r
+        choice ch3{\r
+            case c3 {\r
+                leaf c3Leaf {\r
+                    type string;\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+    augment "/container/" {\r
+        leaf augLeaf {\r
+            type string;\r
+        }\r
+    }\r
+\r
+    augment "/container/" {\r
+        choice ch{}\r
+    }\r
+\r
+    augment "/container/ch/" {\r
+        case c1 {\r
+            leaf c1Leaf {\r
+                type string;\r
+            }\r
+        }\r
+\r
+        leaf c12 {\r
+            type string;\r
+        }\r
+    }\r
+    augment "/container/ch/c1/" {\r
+        leaf c1Leaf_AnotherAugment {\r
+            type string;\r
+        }\r
+\r
+        choice deepChoice{}\r
+    }\r
+\r
+    augment "/container/ch3/" {\r
+        case c32 {\r
+            leaf c32Leaf {\r
+                type string;\r
+            }\r
+        }\r
+\r
+        leaf c34LeafS {\r
+            type string;\r
+        }\r
+    }\r
+\r
+\r
+    augment "/container/ch/c1/deepChoice/" {\r
+        case deepCase1 {\r
+            leaf deepLeafc1 {\r
+                type string;\r
+            }\r
+        }\r
+        case deepCase2 {\r
+            leaf deepLeafc2 {\r
+                type string;\r
+            }\r
+        }\r
+    }\r
+\r
+    augment "/container/ch2/" {\r
+        case c2 {\r
+            leaf c2Leaf {\r
+                type string;\r
+            }\r
+\r
+            choice c2DeepChoice {\r
+                case c2DeepChoiceCase1 {\r
+                    leaf c2DeepChoiceCase1Leaf1 {\r
+                        type string;\r
+                    }\r
+                }\r
+                case c2DeepChoiceCase2 {\r
+                    leaf c2DeepChoiceCase1Leaf2 {\r
+                        type string;\r
+                    }\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+    augment "/container/ch2/" {\r
+        leaf c22Leaf {\r
+            type string;\r
+        }\r
+    }\r
+\r
+    augment "/container" {\r
+        /*ext:augment-identifier top-choice-augment1;*/\r
+        choice augment-choice1 {\r
+            case case1 {\r
+                container case1-container {\r
+                    leaf case1-leaf {\r
+                        type string;\r
+                    }\r
+                }\r
+            }\r
+\r
+            case case2 {\r
+                container case2-container {\r
+                    leaf case2-leaf {\r
+                        type string;\r
+                    }\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+    augment "/container/augment-choice1/case1" {\r
+        /*ext:augment-identifier top-choice-augment2;*/\r
+        choice augment-choice2 {\r
+            case case11 {\r
+                container case11-choice-case-container {\r
+                    leaf case11-choice-case-leaf {\r
+                        type string;\r
+                    }\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+\r
+}
\ No newline at end of file
index 6b80e6993682ecc89a31b3542b6ef3ddfc491014..5345f2b44feeb38571f9d10b6206b3a9d43d6848 100644 (file)
@@ -73,6 +73,8 @@ public class BuilderRenderer extends BaseRenderer {
      */
     private GeneratedProperty augmentField;
 
+    boolean instantiable = false;
+
     public BuilderRenderer(final GeneratedType type) {
         super(type);
         this.properties = propertiesFromMethods(createMethods());
@@ -181,6 +183,7 @@ public class BuilderRenderer extends BaseRenderer {
                     }
                 } else if (Instantiable.class.getName().equals(implementedIfc.getFullyQualifiedName())) {
                     importedNames.put("class", importedName(Class.class));
+                    instantiable = true;
                 }
             }
         }
@@ -267,11 +270,6 @@ 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));
 
index 04c0b83169b37458de91ebe8e14ef13d247a09a3..93ae7a5e4cebcf19ba1d975863d4c907e40ec17f 100644 (file)
@@ -20,6 +20,6 @@ import com.google.common.annotations.Beta;
 public interface Instantiable<T extends Instantiable<T>> {
 
     // REPLACES: DataObject#getImplementedInterface()
-    Class<T> implementedInterface();
+    Class<? extends T> implementedInterface();
 
 }