Fix augmented action code generation 90/82890/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 2 Jul 2019 11:49:06 +0000 (13:49 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 2 Jul 2019 13:21:54 +0000 (15:21 +0200)
When an action is introduced as part of an augment statement, we
attempt to generate it in the augmented module, which refuses to
generate its input/output statements, leading to a NPE.

This patch updates codegen to ignore augmenting actions in the
augmented module and process them as part of augmentation.

JIRA: MDSAL-459
Change-Id: Ibd7d7abc5ec1eec6d32ee1885da00a0de69b2445
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit dee452d009946a175273ac2a21dca4174b2142af)

binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/impl/AbstractTypeGenerator.java
binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal459Test.java [new file with mode: 0644]
binding/mdsal-binding-generator-impl/src/test/resources/mdsal-459/aug.yang [new file with mode: 0644]
binding/mdsal-binding-generator-impl/src/test/resources/mdsal-459/base.yang [new file with mode: 0644]

index 27d9cf9355844629c837b122a89a5f9b2d7186c7..9942b680bddeced9ad606275b5e043d0a10516d1 100644 (file)
@@ -416,6 +416,10 @@ abstract class AbstractTypeGenerator {
     private <T extends DataNodeContainer & ActionNodeContainer> void actionsToGenType(final ModuleContext context,
             final Type parent, final T parentSchema, final Type keyType, final boolean inGrouping) {
         for (final ActionDefinition action : parentSchema.getActions()) {
+            if (action.isAugmenting()) {
+                continue;
+            }
+
             final GeneratedType input;
             final GeneratedType output;
             if (action.isAddedByUses()) {
@@ -920,12 +924,13 @@ abstract class AbstractTypeGenerator {
         addImplementedInterfaceFromUses(augSchema, augTypeBuilder);
 
         augSchemaNodeToMethods(context, augTypeBuilder, augSchema.getChildNodes(), inGrouping);
+        actionsToGenType(context, augTypeBuilder, augSchema, null, inGrouping);
         augmentBuilders.put(augTypeName, augTypeBuilder);
 
         if (!augSchema.getChildNodes().isEmpty()) {
             context.addTypeToAugmentation(augTypeBuilder, augSchema);
-
         }
+
         context.addAugmentType(augTypeBuilder);
         return augTypeBuilder;
     }
diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal459Test.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal459Test.java
new file mode 100644 (file)
index 0000000..fdbe9a3
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.generator.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import com.google.common.collect.ImmutableSet;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.junit.Test;
+import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
+import org.opendaylight.mdsal.binding.model.api.Type;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
+
+public class Mdsal459Test {
+
+    @Test
+    public void testAugmentedAction() {
+        final List<Type> types = new BindingGeneratorImpl().generateTypes(
+            YangParserTestUtils.parseYangResourceDirectory("/mdsal-459/"));
+        assertNotNull(types);
+        assertEquals(6, types.size());
+
+        final Set<JavaTypeName> typeNames = types.stream().map(Type::getIdentifier).collect(Collectors.toSet());
+        assertEquals(ImmutableSet.of(
+            JavaTypeName.create("org.opendaylight.yang.gen.v1.base.norev", "Foo"),
+            JavaTypeName.create("org.opendaylight.yang.gen.v1.base.norev", "BaseData"),
+            JavaTypeName.create("org.opendaylight.yang.gen.v1.aug.norev", "Foo1"),
+            JavaTypeName.create("org.opendaylight.yang.gen.v1.aug.norev.foo", "Bar"),
+            JavaTypeName.create("org.opendaylight.yang.gen.v1.aug.norev.foo.bar", "Output"),
+            JavaTypeName.create("org.opendaylight.yang.gen.v1.aug.norev.foo.bar", "Input")), typeNames);
+    }
+}
diff --git a/binding/mdsal-binding-generator-impl/src/test/resources/mdsal-459/aug.yang b/binding/mdsal-binding-generator-impl/src/test/resources/mdsal-459/aug.yang
new file mode 100644 (file)
index 0000000..72504ea
--- /dev/null
@@ -0,0 +1,16 @@
+module aug {
+    yang-version 1.1;
+    namespace "aug";
+    prefix "aug";
+
+    import base {
+        prefix base;
+    }
+
+    augment /base:foo {
+        action bar {
+
+        }
+    }
+}
+
diff --git a/binding/mdsal-binding-generator-impl/src/test/resources/mdsal-459/base.yang b/binding/mdsal-binding-generator-impl/src/test/resources/mdsal-459/base.yang
new file mode 100644 (file)
index 0000000..e880134
--- /dev/null
@@ -0,0 +1,10 @@
+module base {
+    yang-version 1.1;
+    namespace "base";
+    prefix "base";
+
+    container foo {
+
+    }
+}
+