Binding generator v2 - uses statement - uses inner type
[mdsal.git] / binding2 / mdsal-binding2-generator-impl / src / main / java / org / opendaylight / mdsal / binding / javav2 / generator / impl / AugmentToGenType.java
index 2c2f77027704aec7b3df83fe03965876e313a02b..339ad82c79ffac30a3f872351db08964274ca9cd 100644 (file)
@@ -8,6 +8,8 @@
 
 package org.opendaylight.mdsal.binding.javav2.generator.impl;
 
+import static org.opendaylight.mdsal.binding.javav2.generator.impl.GenHelperUtil.processUsesImplements;
+
 import com.google.common.annotations.Beta;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
@@ -20,6 +22,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 import java.util.stream.Collectors;
+import org.opendaylight.mdsal.binding.javav2.generator.context.ModuleContext;
 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;
@@ -138,7 +141,7 @@ final class AugmentToGenType {
                     verboseClassComments, resultCtx, genTypeBuilders, typeProvider);
 
             for (AugmentationSchema augSchema : schemaPathAugmentListEntry.getValue()) {
-                GenHelperUtil.processUsesImplements(augSchema, module, schemaContext, genCtx, BindingNamespaceType.Data);
+                processUsesImplements(augSchema, module, schemaContext, genCtx, BindingNamespaceType.Data);
             }
 
         }
@@ -166,15 +169,19 @@ final class AugmentToGenType {
 
         final Set<AugmentationSchema> augmentations = module.getAugmentations();
         final List<AugmentationSchema> sortedAugmentations = new ArrayList<>(augmentations).stream()
-                .filter(aug -> !module.equals(schemaContext.findModuleByNamespaceAndRevision(
-                        aug.getTargetPath().getLastComponent().getNamespace(),
-                        aug.getTargetPath().getLastComponent().getRevision())))
+                .filter(aug -> !module.equals(findAugmentTargetModule(schemaContext, aug)))
                 .collect(Collectors.toList());
         Collections.sort(sortedAugmentations, AUGMENT_COMP);
 
         return sortedAugmentations;
     }
 
+    public static Module findAugmentTargetModule(final SchemaContext schemaContext , final AugmentationSchema aug) {
+        Preconditions.checkNotNull(aug, "Augmentation schema can not be null.");
+        final QName first = aug.getTargetPath().getPathFromRoot().iterator().next();
+        return schemaContext.findModuleByNamespaceAndRevision(first.getNamespace(), first.getRevision());
+    }
+
     /**
      * Converts <code>augSchema</code> to list of <code>Type</code> which
      * contains generated type for augmentation. In addition there are also
@@ -468,6 +475,7 @@ final class AugmentToGenType {
                         GenHelperUtil.resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType,
                                 childNodes, genCtx, schemaContext, verboseClassComments, genTypeBuilders, typeProvider,
                                 namespaceType);
+                        processUsesImplements(node, module, schemaContext, genCtx, namespaceType);
                     }
                     genCtx.get(module).addCaseType(caseNode.getPath(), caseTypeBuilder);
                     genCtx.get(module).addChoiceToCaseMapping(targetType, caseTypeBuilder, node);