Binding generator v2 - augment statement #1 58/60458/2
authorJie Han <han.jie@zte.com.cn>
Mon, 10 Jul 2017 06:57:41 +0000 (14:57 +0800)
committerRobert Varga <nite@hq.sk>
Mon, 17 Jul 2017 09:09:31 +0000 (09:09 +0000)
- Only resolve augmentation that it's target in same module

Change-Id: Ifb135570871e37a697238919ec6b6ef08cb8d048
Signed-off-by: Jie Han <han.jie@zte.com.cn>
(cherry picked from commit fb0cecb23bc02de2e243ce6f7a2b4df59a7334ff)

binding2/mdsal-binding2-generator-impl/src/main/java/org/opendaylight/mdsal/binding/javav2/generator/impl/AugmentToGenType.java
binding2/mdsal-binding2-generator-impl/src/test/java/org/opendaylight/mdsal/binding/javav2/generator/impl/AugmentToGenTypeTest.java

index 740cd5ddebe00155487add9decd80f25cf4f45f1..3b8dd41eee2b3896c53d0c7b9948d026c23f18ca 100644 (file)
@@ -121,7 +121,7 @@ final class AugmentToGenType {
         Preconditions.checkState(module.getAugmentations() != null, "Augmentations Set cannot be NULL.");
 
         final String basePackageName = BindingMapping.getRootPackageName(module);
-        final List<AugmentationSchema> augmentations = resolveAugmentations(module);
+        final List<AugmentationSchema> augmentations = resolveAugmentations(module, schemaContext);
         Map<Module, ModuleContext> resultCtx = genCtx;
 
         //let's group augments by target path
@@ -161,12 +161,16 @@ final class AugmentToGenType {
      * @throws IllegalStateException
      *             if set of module augmentations is null
      */
-    private static List<AugmentationSchema> resolveAugmentations(final Module module) {
+    private static List<AugmentationSchema> resolveAugmentations(final Module module, final SchemaContext schemaContext) {
         Preconditions.checkArgument(module != null, "Module reference cannot be NULL.");
         Preconditions.checkState(module.getAugmentations() != null, "Augmentations Set cannot be NULL.");
 
         final Set<AugmentationSchema> augmentations = module.getAugmentations();
-        final List<AugmentationSchema> sortedAugmentations = new ArrayList<>(augmentations);
+        final List<AugmentationSchema> sortedAugmentations = new ArrayList<>(augmentations).stream()
+                .filter(aug -> !module.equals(schemaContext.findModuleByNamespaceAndRevision(
+                        aug.getTargetPath().getLastComponent().getNamespace(),
+                        aug.getTargetPath().getLastComponent().getRevision())))
+                .collect(Collectors.toList());
         Collections.sort(sortedAugmentations, AUGMENT_COMP);
 
         return sortedAugmentations;
@@ -252,6 +256,7 @@ final class AugmentToGenType {
         return genCtx;
     }
 
+    @Deprecated
     static Map<Module, ModuleContext> usesAugmentationToGenTypes(final SchemaContext schemaContext,
            final String augmentPackageName, final List<AugmentationSchema> schemaPathAugmentListEntry, final Module module,
            final UsesNode usesNode, final DataNodeContainer usesNodeParent, Map<Module, ModuleContext> genCtx,
index 63d24bd898d3b8c3952101e67522dbc335aac250..30d5fc64dcaaf491d5e5835ddd5529af3972117f 100644 (file)
@@ -209,14 +209,15 @@ public class AugmentToGenTypeTest {
     @SuppressWarnings("rawtypes")
     @Test
     public void resolveAugmentationsNullModuleTest() throws Exception {
-        final Class[] parameterTypes = { Module.class };
+        final Class[] parameterTypes = { Module.class, SchemaContext.class };
         final Method generate = AugmentToGenType.class.getDeclaredMethod("resolveAugmentations", parameterTypes);
         assertNotNull(generate);
         generate.setAccessible(true);
 
         final Module m = null;
+        final SchemaContext schemaContext = null;
 
-        final Object[] args = { m };
+        final Object[] args = { m, schemaContext };
         try {
             generate.invoke(AugmentToGenType.class, args);
             fail();
@@ -233,15 +234,16 @@ public class AugmentToGenTypeTest {
     @SuppressWarnings("rawtypes")
     @Test
     public void resolveAugmentationsNullAugmentationsTest() throws Exception {
-        final Class[] parameterTypes = { Module.class };
+        final Class[] parameterTypes = { Module.class, SchemaContext.class };
         final Method generate = AugmentToGenType.class.getDeclaredMethod("resolveAugmentations", parameterTypes);
         assertNotNull(generate);
         generate.setAccessible(true);
 
         final Module m = mock(Module.class);
         when(m.getAugmentations()).thenReturn(null);
+        final SchemaContext schemaContext = mock(SchemaContext.class);
 
-        final Object[] args = { m };
+        final Object[] args = { m, schemaContext };
         try {
             generate.invoke(AugmentToGenType.class, args);
             fail();
@@ -258,12 +260,14 @@ public class AugmentToGenTypeTest {
     @SuppressWarnings({ "rawtypes", "unchecked" })
     @Test
     public void resolveAugmentationsTest() throws Exception {
-        final Class[] parameterTypes = { Module.class };
+        final Class[] parameterTypes = { Module.class, SchemaContext.class };
         final Method generate = AugmentToGenType.class.getDeclaredMethod("resolveAugmentations", parameterTypes);
         assertNotNull(generate);
         generate.setAccessible(true);
 
         final Module m = mock(Module.class);
+        final Module m2 = mock(Module.class);
+        final SchemaContext schemaContext = mock(SchemaContext.class);
 
         final Set<AugmentationSchema> augmentations = new HashSet<>();
 
@@ -281,8 +285,10 @@ public class AugmentToGenTypeTest {
         augmentations.add(augmentationSchema2);
 
         when(m.getAugmentations()).thenReturn(augmentations);
+        when(schemaContext.findModuleByNamespaceAndRevision(q2.getNamespace(), q2.getRevision())).thenReturn(m2);
+        when(schemaContext.findModuleByNamespaceAndRevision(q5.getNamespace(), q5.getRevision())).thenReturn(m2);
 
-        final Object[] args = { m };
+        final Object[] args = { m, schemaContext };
 
         final List<AugmentationSchema> result =
                 (List<AugmentationSchema>) generate.invoke(AugmentToGenType.class, args);
@@ -722,6 +728,7 @@ public class AugmentToGenTypeTest {
         assertEquals("pckg.name", moduleContext.getChildNode(path).getPackageName());
     }
 
+    @Deprecated
     @Test
     public void usesAugmentationToGenTypesNullPckgNameTest() throws Exception {
         try {
@@ -733,6 +740,7 @@ public class AugmentToGenTypeTest {
         }
     }
 
+    @Deprecated
     @Test
     public void usesAugmentationToGenTypesNullAugSchemaListEntryTest() throws Exception {
         try {
@@ -744,6 +752,7 @@ public class AugmentToGenTypeTest {
         }
     }
 
+    @Deprecated
     @Test
     public void usesAugmentationToGenTypesEmptyAugSchemaListTest() throws Exception {
         final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
@@ -757,6 +766,7 @@ public class AugmentToGenTypeTest {
         }
     }
 
+    @Deprecated
     @Test
     public void usesAugmentationToGenTypesNullAugSchemaNodeTargetPathTest() throws Exception {
         final AugmentationSchema augmentationSchema = mock(AugmentationSchema.class);
@@ -773,6 +783,7 @@ public class AugmentToGenTypeTest {
         }
     }
 
+    @Deprecated
     @Test
     public void usesAugmentationToGenTypesNullAugmentTargetTest() throws Exception {
         final QName qnamePath = QName.create("test", "2017-04-04", "aug");
@@ -818,6 +829,7 @@ public class AugmentToGenTypeTest {
         }
     }
 
+    @Deprecated
     @Test
     public void usesAugmentationToGenTypesNullTargetGTBTest() throws Exception {
         final QName qnamePath = QName.create("test", "2017-04-04", "aug");
@@ -864,6 +876,7 @@ public class AugmentToGenTypeTest {
         }
     }
 
+    @Deprecated
     @Test
     public void usesAugmentationToGenTypesTest() throws Exception {
         final QName qnamePath = QName.create("test", "2017-04-04", "aug");
@@ -912,6 +925,7 @@ public class AugmentToGenTypeTest {
         assertNotNull(result);
     }
 
+    @Deprecated
     @Test
     public void usesAugmentationToGenTypesChoiceTest() throws Exception {
         final QName qnamePath = QName.create("test", "2017-04-04", "aug");