Binding generator v2 - augment statement #4
[mdsal.git] / binding2 / mdsal-binding2-generator-impl / src / main / java / org / opendaylight / mdsal / binding / javav2 / generator / impl / AugmentToGenType.java
index 2c2f77027704aec7b3df83fe03965876e313a02b..641b71232c5cac92d30cff32516452df569cddd1 100644 (file)
@@ -166,15 +166,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