use of org.opendaylight.mdsal.binding.model.api.ConcreteType in project mdsal by opendaylight.
the class BaseYangTypesTest method test.
@Test
public void test() {
Type stringType = BaseYangTypes.javaTypeForYangType("string");
assertEquals("java.lang", stringType.getPackageName());
assertEquals("String", stringType.getName());
assertTrue(stringType instanceof ConcreteType);
ParameterizedType stringBooleanMap = Types.mapTypeFor(BaseYangTypes.javaTypeForYangType("string"), BaseYangTypes.javaTypeForYangType("boolean"));
assertTrue(!(stringBooleanMap instanceof ConcreteType));
assertEquals("java.util", stringBooleanMap.getPackageName());
assertEquals("Map", stringBooleanMap.getName());
assertEquals(2, stringBooleanMap.getActualTypeArguments().length);
}
use of org.opendaylight.mdsal.binding.model.api.ConcreteType in project mdsal by opendaylight.
the class AbstractTypeObjectGenerator method createSimple.
@NonNull
private static GeneratedType createSimple(final TypeBuilderFactory builderFactory, final JavaTypeName typeName, final ModuleGenerator module, final Type javaType, final TypeDefinition<?> typedef) {
final String moduleName = module.statement().argument().getLocalName();
final GeneratedTOBuilder builder = builderFactory.newGeneratedTOBuilder(typeName);
builder.setTypedef(true);
builder.addImplementsType(BindingTypes.scalarTypeObject(javaType));
final GeneratedPropertyBuilder genPropBuilder = builder.addProperty(TypeConstants.VALUE_PROP);
genPropBuilder.setReturnType(javaType);
builder.addEqualsIdentity(genPropBuilder);
builder.addHashIdentity(genPropBuilder);
builder.addToStringProperty(genPropBuilder);
builder.setRestrictions(BindingGeneratorUtil.getRestrictions(typedef));
// builder.setSchemaPath(typedef.getPath());
builder.setModuleName(moduleName);
builderFactory.addCodegenInformation(typedef, builder);
annotateDeprecatedIfNecessary(typedef, builder);
if (javaType instanceof ConcreteType && // FIXME: This looks very suspicious: we should by checking for Types.STRING
"String".equals(javaType.getName()) && typedef.getBaseType() != null) {
addStringRegExAsConstant(builder, resolveRegExpressions(typedef));
}
addUnits(builder, typedef);
makeSerializable(builder);
return builder.build();
}
use of org.opendaylight.mdsal.binding.model.api.ConcreteType in project mdsal by opendaylight.
the class TypeUtils method getBaseYangType.
/**
* Given a {@link Type} object lookup the base Java type which sits at the top
* of its type hierarchy.
*
* @param type Input Type object
* @return Resolved {@link ConcreteType} instance.
*/
static ConcreteType getBaseYangType(@NonNull final Type type) {
// Already the correct type
if (type instanceof ConcreteType) {
return (ConcreteType) type;
}
checkArgument(type instanceof GeneratedTransferObject, "Unsupported type %s", type);
// Need to walk up the GTO chain to the root
GeneratedTransferObject rootGto = (GeneratedTransferObject) type;
while (rootGto.getSuperType() != null) {
rootGto = rootGto.getSuperType();
}
// Look for the 'value' property and return its type
for (GeneratedProperty s : rootGto.getProperties()) {
if (TypeConstants.VALUE_PROP.equals(s.getName())) {
return (ConcreteType) s.getReturnType();
}
}
// Should never happen
throw new IllegalArgumentException(String.format("Type %s root %s properties %s do not include \"%s\"", type, rootGto, rootGto.getProperties(), TypeConstants.VALUE_PROP));
}
use of org.opendaylight.mdsal.binding.model.api.ConcreteType in project mdsal by opendaylight.
the class TypesTest method testVoidType.
@Test
public void testVoidType() {
final ConcreteType voidType = Types.voidType();
assertEquals("Void", voidType.getName());
assertNotNull(voidType);
}
Aggregations