From da346999b22f65c47c22e5ed12b370aea34a7da3 Mon Sep 17 00:00:00 2001 From: Martin Vitez Date: Fri, 1 Aug 2014 09:06:41 +0200 Subject: [PATCH] BUG-576: fixed bug in parsing of union types. 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 --- .../yang/parser/impl/ParserListenerUtils.java | 10 +++--- .../yang/parser/impl/TypesResolutionTest.java | 10 ++++++ .../types/union-with-ext/extdef.yang | 13 ++++++++ .../types/union-with-ext/unionbug.yang | 31 +++++++++++++++++++ 4 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 yang/yang-parser-impl/src/test/resources/types/union-with-ext/extdef.yang create mode 100644 yang/yang-parser-impl/src/test/resources/types/union-with-ext/unionbug.yang diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/ParserListenerUtils.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/ParserListenerUtils.java index 2757c10e1e..542506045d 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/ParserListenerUtils.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/ParserListenerUtils.java @@ -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(); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TypesResolutionTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TypesResolutionTest.java index 050f620928..022cda45a5 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TypesResolutionTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TypesResolutionTest.java @@ -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 index 0000000000..68a568bfb9 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/types/union-with-ext/extdef.yang @@ -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 index 0000000000..a8821683d9 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/types/union-with-ext/unionbug.yang @@ -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"; + } + } + } + +} -- 2.36.6