Search in sources :

Example 1 with ConcreteType

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);
}
Also used : ParameterizedType(org.opendaylight.mdsal.binding.model.api.ParameterizedType) Type(org.opendaylight.mdsal.binding.model.api.Type) ConcreteType(org.opendaylight.mdsal.binding.model.api.ConcreteType) ParameterizedType(org.opendaylight.mdsal.binding.model.api.ParameterizedType) ConcreteType(org.opendaylight.mdsal.binding.model.api.ConcreteType) Test(org.junit.Test)

Example 2 with ConcreteType

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();
}
Also used : GeneratedPropertyBuilder(org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedPropertyBuilder) GeneratedTOBuilder(org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTOBuilder) ConcreteType(org.opendaylight.mdsal.binding.model.api.ConcreteType) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 3 with ConcreteType

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));
}
Also used : GeneratedTransferObject(org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject) GeneratedProperty(org.opendaylight.mdsal.binding.model.api.GeneratedProperty) ConcreteType(org.opendaylight.mdsal.binding.model.api.ConcreteType)

Example 4 with ConcreteType

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);
}
Also used : ConcreteType(org.opendaylight.mdsal.binding.model.api.ConcreteType) Test(org.junit.Test)

Aggregations

ConcreteType (org.opendaylight.mdsal.binding.model.api.ConcreteType)4 Test (org.junit.Test)2 NonNull (org.eclipse.jdt.annotation.NonNull)1 GeneratedProperty (org.opendaylight.mdsal.binding.model.api.GeneratedProperty)1 GeneratedTransferObject (org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject)1 ParameterizedType (org.opendaylight.mdsal.binding.model.api.ParameterizedType)1 Type (org.opendaylight.mdsal.binding.model.api.Type)1 GeneratedPropertyBuilder (org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedPropertyBuilder)1 GeneratedTOBuilder (org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTOBuilder)1