import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findDataSchemaNode;
import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findNodeInSchemaContext;
import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findParentModule;
+
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
Type returnType = null;
final TypeDefinition<?> typeDef = CompatUtils.compatLeafType(leaf);
- if (isInnerType(leaf, typeDef)) {
- if (typeDef instanceof EnumTypeDefinition) {
- returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf);
- final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) typeDef;
- final EnumBuilder enumBuilder = resolveInnerEnumFromTypeDefinition(enumTypeDef, leaf.getQName(),
- typeBuilder, module);
-
- if (enumBuilder != null) {
- returnType = enumBuilder.toInstance(typeBuilder);
- }
- ((TypeProviderImpl) typeProvider).putReferencedType(leaf.getPath(), returnType);
- } else if (typeDef instanceof UnionTypeDefinition) {
+ if (typeDef instanceof EnumTypeDefinition) {
+ final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) typeDef;
+ final EnumBuilder enumBuilder = resolveInnerEnumFromTypeDefinition(enumTypeDef, leaf.getQName(), typeBuilder, module);
+ returnType = enumBuilder != null ? enumBuilder.toInstance(typeBuilder) :
+ typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf);
+ ((TypeProviderImpl) typeProvider).putReferencedType(leaf.getPath(), returnType);
+ } else if (isInnerType(leaf, typeDef)) {
+ if (typeDef instanceof UnionTypeDefinition) {
GeneratedTOBuilder genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leaf, parentModule);
if (genTOBuilder != null) {
returnType = createReturnTypeForUnion(genTOBuilder, typeDef, typeBuilder, parentModule);
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. 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.yangtools.sal.binding.generator.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.List;
+import org.junit.Test;
+import org.opendaylight.yangtools.sal.binding.model.api.Enumeration;
+import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType;
+import org.opendaylight.yangtools.sal.binding.model.api.Type;
+import org.opendaylight.yangtools.yang.model.util.type.EnumerationTypeBuilder;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
+
+public class Bug6135Test {
+
+ @Test
+ public void bug6135Test() throws ReactorException {
+ final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ reactor.addSource(new YangStatementSourceImpl("/bug-6135/foo.yang", false));
+
+ final EffectiveSchemaContext context = reactor.buildEffective();
+ assertNotNull(context);
+
+ final List<Type> generateTypes = new BindingGeneratorImpl(false).generateTypes(context);
+ assertFalse(generateTypes.isEmpty());
+
+ GeneratedType genInterface = null;
+ for (final Type type : generateTypes) {
+ if (!(type instanceof Enumeration)) {
+ genInterface = (GeneratedType) type;
+ }
+ }
+ assertNotNull(genInterface);
+ final List<Enumeration> enums = genInterface.getEnumerations();
+ assertEquals(3, enums.size());
+ }
+}
\ No newline at end of file
Enumeration operStatus = null;
final List<Enumeration> enums = genInterface.getEnumerations();
assertNotNull("Generated Type Interface cannot contain NULL reference to Enumeration types!", enums);
- assertEquals("Generated Type Interface MUST contain 2 Enumeration Types", 2, enums.size());
+ assertEquals("Generated Type Interface MUST contain 3 Enumeration Types", 3, enums.size());
for (final Enumeration e : enums) {
if (e.getName().equals("LinkUpDownTrapEnable")) {
linkUpDownTrapEnable = e;
--- /dev/null
+module test-leafref {
+
+ namespace "odl:test:leafref";
+ prefix "tl";
+ revision 2015-04-09;
+
+ typedef my-enum {
+ type enumeration {
+ enum one {
+ value 1;
+ }
+ }
+ }
+
+ leaf my-inner-leaf {
+ type my-enum;
+ }
+
+ leaf my-leafref-inner {
+ type leafref {
+ path "/tl:my-inner-leaf";
+ }
+ }
+
+ leaf my-leaf {
+ type enumeration {
+ enum one {
+ value 1;
+ }
+ }
+ }
+
+ leaf my-leafref {
+ type leafref {
+ path "/tl:my-leaf";
+ }
+ }
+
+ leaf-list list-of-enums-inner {
+ type enumeration {
+ enum x;
+ enum y;
+ enum z;
+ }
+ }
+
+ leaf-list enums {
+ type leafref {
+ path "/tl:list-of-enums";
+ }
+ }
+
+ leaf-list list-of-enums {
+ type leafref {
+ path "/tl:my-leaf";
+ }
+ }
+}
\ No newline at end of file