Bug 5788: enum used as a key does not work 06/38106/4
authorFilip Gregor <fgregor@cisco.com>
Tue, 26 Apr 2016 08:54:54 +0000 (10:54 +0200)
committerFilip Gregor <fgregor@cisco.com>
Fri, 13 May 2016 09:38:08 +0000 (11:38 +0200)
fixed Qname check for enum as key from grouping in
bindingGeneratorImpl

Change-Id: Id6521d28a4b9aebcd1dfca2d33e8dfed68e9a269
Signed-off-by: Filip Gregor <fgregor@cisco.com>
binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java
binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/CompilationTest.java
binding/mdsal-binding-java-api-generator/src/test/resources/compilation/bug5788/foo.yang [new file with mode: 0644]

index 1447b61543551b80ff103c3a1a5315dafd844934..ac2d728032ba8243fe383cca62c7aeceece5fd2c 100644 (file)
@@ -1545,7 +1545,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
                         qname.getRevision());
                 final ModuleContext mc = genCtx.get(unionModule);
                 returnType = mc.getTypedefs().get(typeDef.getPath());
-            } else if (typeDef instanceof EnumTypeDefinition && BaseTypes.ENUMERATION_QNAME.equals(typeDef.getQName())) {
+            } else if (typeDef instanceof EnumTypeDefinition && typeDef.getBaseType() == null) {
                 // Annonymous enumeration (already generated, since it is inherited via uses).
                 LeafSchemaNode originalLeaf = (LeafSchemaNode) SchemaNodeUtils.getRootOriginalIfPossible(leaf);
                 QName qname = originalLeaf.getQName();
index 8c45d2894710a58548b4ab2ce51cb5b047efa45a..c12718b1cb56be9e027b8bae40c9c2f3dce4d7f6 100644 (file)
@@ -589,6 +589,21 @@ public class CompilationTest extends BaseCompilationTest {
         cleanUp(sourcesOutputDir, compiledOutputDir);
     }
 
+    @Test
+    public void testBug5788() throws Exception {
+        final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "bug5788");
+        assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
+        final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "bug5788");
+        assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
+
+        generateTestSources("/compilation/bug5788", sourcesOutputDir);
+
+        // Test if sources are compilable
+        testCompilation(sourcesOutputDir, compiledOutputDir);
+
+        cleanUp(sourcesOutputDir, compiledOutputDir);
+    }
+
     /**
      * Test if class generated for node from grouping implements ChildOf.
      *
diff --git a/binding/mdsal-binding-java-api-generator/src/test/resources/compilation/bug5788/foo.yang b/binding/mdsal-binding-java-api-generator/src/test/resources/compilation/bug5788/foo.yang
new file mode 100644 (file)
index 0000000..d62125e
--- /dev/null
@@ -0,0 +1,23 @@
+module foo {
+    namespace "urn:yang.foo";
+    prefix "foo";
+
+    revision "2016-01-02" {
+    }
+
+    grouping A {
+        leaf B {
+            type enumeration {
+                enum X {}
+                enum Y {}
+            }
+        }
+    }
+
+    container C {
+        list D {
+            key "B";
+            uses A;
+        }
+    }
+}
\ No newline at end of file