BUG-576: fixed bug in parsing of union types. 65/9565/1
authorMartin Vitez <mvitez@cisco.com>
Fri, 1 Aug 2014 07:06:41 +0000 (09:06 +0200)
committerMartin Vitez <mvitez@cisco.com>
Fri, 1 Aug 2014 07:22:11 +0000 (09:22 +0200)
Parser creates an empty collection of restrictions and tries to set them to union builder, but union cannot be restricted.
This patch avoid adding restrictions to union builder.
Added test.

Change-Id: Ie0822f21380f8e5f9cd42960e7248927710053cd
Signed-off-by: Martin Vitez <mvitez@cisco.com>
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/ParserListenerUtils.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TypesResolutionTest.java
yang/yang-parser-impl/src/test/resources/types/union-with-ext/extdef.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/types/union-with-ext/unionbug.yang [new file with mode: 0644]

index 2757c10e1e755162440c1102b5d0ee37108e75b3..542506045d031de4381010e849d29f9aef56b614 100644 (file)
@@ -1069,10 +1069,12 @@ public final class ParserListenerUtils {
 
             if (parent instanceof TypeDefinitionBuilder) {
                 TypeDefinitionBuilder typedef = (TypeDefinitionBuilder) parent;
-                typedef.setRanges(rangeStatements);
-                typedef.setLengths(lengthStatements);
-                typedef.setPatterns(patternStatements);
-                typedef.setFractionDigits(fractionDigits);
+                if (!(typedef instanceof UnionTypeBuilder)) {
+                    typedef.setRanges(rangeStatements);
+                    typedef.setLengths(lengthStatements);
+                    typedef.setPatterns(patternStatements);
+                    typedef.setFractionDigits(fractionDigits);
+                }
                 return unknownType.build();
             } else {
                 TypeDefinition<?> baseType = unknownType.build();
index 050f62092877a093f389eb8b12dca545749c1bc6..022cda45a59eae835f5989e2597f6e492bcbc2ad 100644 (file)
@@ -16,6 +16,7 @@ import static org.junit.Assert.assertTrue;
 import java.io.File;
 import java.math.BigInteger;
 import java.net.URI;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Set;
 import org.junit.Before;
@@ -333,4 +334,13 @@ public class TypesResolutionTest {
         assertNotNull(type);
     }
 
+    @Test
+    public void testUnionWithExt() throws Exception {
+        File extdef = new File(getClass().getResource("/types/union-with-ext/extdef.yang").toURI());
+        File unionbug = new File(getClass().getResource("/types/union-with-ext/unionbug.yang").toURI());
+        File inet = new File(getClass().getResource("/ietf/ietf-inet-types@2010-09-24.yang").toURI());
+        YangContextParser parser = new YangParserImpl();
+        parser.parseFiles(Arrays.asList(extdef, unionbug, inet));
+    }
+
 }
diff --git a/yang/yang-parser-impl/src/test/resources/types/union-with-ext/extdef.yang b/yang/yang-parser-impl/src/test/resources/types/union-with-ext/extdef.yang
new file mode 100644 (file)
index 0000000..68a568b
--- /dev/null
@@ -0,0 +1,13 @@
+module "extdef" {
+    yang-version 1;
+    namespace "urn:test:bug:extdef";
+    prefix "extdef";
+
+    revision 2012-04-16 {
+    }
+
+    extension "help" {
+        argument "text";
+    }
+
+}
diff --git a/yang/yang-parser-impl/src/test/resources/types/union-with-ext/unionbug.yang b/yang/yang-parser-impl/src/test/resources/types/union-with-ext/unionbug.yang
new file mode 100644 (file)
index 0000000..a882168
--- /dev/null
@@ -0,0 +1,31 @@
+module unionbug {
+    yang-version 1;
+    namespace "urn:test:bug:unionbug";
+    prefix "unionbug";
+
+    import extdef {
+        prefix extdef;
+    }
+
+    import ietf-inet-types {
+        prefix "inet";
+    }
+
+    revision 2012-04-16 {
+    }
+
+    typedef address {
+        type union {
+            type inet:ip-address {
+                extdef:help "IP address";
+            }
+            type inet:ip-prefix {
+                extdef:help "Subnet";
+            }
+            type string {
+                extdef:help "Address name";
+            }
+        }
+    }
+
+}