Type returnType = null;
final TypeDefinition<?> typeDef = leaf.getType();
- if (isInnerType(leaf, typeDef)) {
+
+ if (leaf.isAddedByUses()) {
+ Preconditions.checkState(leaf instanceof DerivableSchemaNode);
+ LeafSchemaNode originalLeaf = (LeafSchemaNode)((DerivableSchemaNode) leaf).getOriginal().orNull();
+ Preconditions.checkNotNull(originalLeaf);
+ if (isInnerType(originalLeaf, typeDef)) {
+ returnType = genCtx.get(findParentModule(schemaContext, originalLeaf)).getInnerType(typeDef.getPath());
+ } else {
+ final Restrictions restrictions = BindingGeneratorUtil.getRestrictions(typeDef);
+ returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf, restrictions, genCtx.get(module));
+ }
+ } else if (isInnerType(leaf, typeDef)) {
if (typeDef instanceof EnumTypeDefinition) {
returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf, genCtx.get(module));
final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) typeDef;
returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf, restrictions, genCtx.get(module));
}
+
if (returnType == null) {
return null;
}
case "binary":
return restrictions == null ? Types.BYTE_ARRAY : Types.primitiveType("byte[]", restrictions);
case "decimal64":
- return Types.typeForClass(BigDecimal.class, restrictions);
+ return Types.typeForClass(BigDecimal.class, restrictions, context);
case "enumeration":
- return Types.typeForClass(Enum.class, restrictions);
+ return Types.typeForClass(Enum.class, restrictions, context);
case "int8":
- return Types.typeForClass(Byte.class, restrictions);
+ return Types.typeForClass(Byte.class, restrictions, context);
case "int16":
- return Types.typeForClass(Short.class, restrictions);
+ return Types.typeForClass(Short.class, restrictions, context);
case "int32":
- return Types.typeForClass(Integer.class, restrictions);
+ return Types.typeForClass(Integer.class, restrictions, context);
case "int64":
- return Types.typeForClass(Long.class, restrictions);
+ return Types.typeForClass(Long.class, restrictions, context);
case "string":
- return Types.typeForClass(String.class, restrictions);
+ return Types.typeForClass(String.class, restrictions, context);
case "uint8":
- return Types.typeForClass(Short.class, restrictions);
+ return Types.typeForClass(Short.class, restrictions, context);
case "uint16":
- return Types.typeForClass(Integer.class, restrictions);
+ return Types.typeForClass(Integer.class, restrictions, context);
case "uint32":
- return Types.typeForClass(Long.class, restrictions);
+ return Types.typeForClass(Long.class, restrictions, context);
case "uint64":
- return Types.typeForClass(BigInteger.class, restrictions);
+ return Types.typeForClass(BigInteger.class, restrictions, context);
case "union" :
return UNION_TYPE;
default:
}
if (returnType == null) {
returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(
- baseTypeDef, typeDefinition, r, null);
+ baseTypeDef, typeDefinition, r, context);
}
}
}
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.opendaylight.mdsal.binding.javav2.generator.api.BindingGenerator;
}
}
+ @Test
+ public void generatedTypesUsesEnumLeafTest() throws Exception {
+ final BindingGenerator bg = new BindingGeneratorImpl(false);
+ final List<String> sources = new ArrayList<>();
+ sources.add("/uses-statement/test-uses-leaf-innertype-base.yang");
+ sources.add("/uses-statement/test-uses-leaf-innertype.yang");
+ final SchemaContext context = YangParserTestUtils.parseYangSources(sources);
+ final List<Type> generateTypes = bg.generateTypes(context);
+ assertNotNull(generateTypes);
+ assertTrue(!generateTypes.isEmpty());
+ for (final Type type : generateTypes) {
+ if (type.getName().equals("MyCont") && type.getPackageName()
+ .equals("org.opendaylight.mdsal.gen.javav2.urn.test.uses.leaf.innertype.base.rev170809.data")) {
+ final GeneratedType gt = (GeneratedType) type;
+ final MethodSignature methodSignature = gt.getMethodDefinitions().get(0);
+ assertEquals("ErrorType", methodSignature.getReturnType().getName());
+ }
+
+ if (type.getName().equals("MyCont") && type.getPackageName()
+ .equals("org.opendaylight.mdsal.gen.javav2.urn.test.uses.leaf.innertype.rev170809.data")) {
+ final GeneratedType gt = (GeneratedType) type;
+ final MethodSignature methodSignature = gt.getMethodDefinitions().get(0);
+ assertEquals("ErrorType", methodSignature.getReturnType().getName());
+ }
+ }
+ }
+
@Test
public void generatedTypesTest() throws Exception {
final BindingGenerator bg = new BindingGeneratorImpl(false);
--- /dev/null
+module test-uses-leaf-innertype-base {
+ namespace "urn:test:uses:leaf:innertype:base";
+ prefix uses-leaf;
+ revision 2017-08-09;
+
+ grouping errors {
+ leaf error-type {
+ type enumeration {
+ enum transport {
+ description "The transport layer";
+ }
+ enum rpc {
+ description "The rpc or notification layer";
+ }
+ enum protocol {
+ description "The protocol operation layer";
+ }
+ enum application {
+ description "The server application layer";
+ }
+ }
+ mandatory true;
+ description
+ "The protocol layer where the error occurred.";
+ }
+ }
+
+ container my-cont {
+ uses errors;
+ }
+}
\ No newline at end of file
--- /dev/null
+module test-uses-leaf-innertype {
+ namespace "urn:test:uses:leaf:innertype";
+ prefix uses-leaf;
+ revision 2017-08-09;
+ import test-uses-leaf-innertype-base {
+ prefix "base";
+ }
+
+ container my-cont {
+ uses base:errors;
+ }
+}
\ No newline at end of file
}
}
+ public static ConcreteType typeForClass(final Class<?> cls, final Restrictions restrictions,
+ final ModuleContext moduleContext) {
+ if (restrictions != null) {
+ if (restrictions instanceof DefaultRestrictions) {
+ return new ConcreteTypeImpl(cls.getPackage().getName(), cls.getSimpleName(), restrictions);
+ } else {
+ return new BaseTypeWithRestrictionsImpl(cls.getPackage().getName(), cls.getSimpleName(), restrictions,
+ moduleContext);
+ }
+ } else {
+ return typeForClass(cls);
+ }
+ }
+
/**
* Returns an instance of {@link ParameterizedType} describing the typed
* {@link Map}<K,V>
this.restrictions = Preconditions.checkNotNull(restrictions);
}
+ private BaseTypeWithRestrictionsImpl(final String pkName, final String name, final Restrictions restrictions,
+ final ModuleContext moduleContext) {
+ super(pkName, name, moduleContext);
+ this.restrictions = Preconditions.checkNotNull(restrictions);
+ }
+
@Override
public Restrictions getRestrictions() {
return this.restrictions;