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>
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();
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;
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));
+ }
+
}
--- /dev/null
+module "extdef" {
+ yang-version 1;
+ namespace "urn:test:bug:extdef";
+ prefix "extdef";
+
+ revision 2012-04-16 {
+ }
+
+ extension "help" {
+ argument "text";
+ }
+
+}
--- /dev/null
+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";
+ }
+ }
+ }
+
+}