use of org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTOBuilder in project mdsal by opendaylight.
the class AnnotationBuilderTest method generatedPropertyAnnotationTest.
@Test
public void generatedPropertyAnnotationTest() {
final GeneratedTOBuilder genTOBuilder = new CodegenGeneratedTOBuilder(JavaTypeName.create("org.opendaylight.controller", "AnnotInterface"));
final GeneratedPropertyBuilder propertyBuilder = genTOBuilder.addProperty("simpleProperty");
propertyBuilder.setReturnType(Types.typeForClass(Integer.class));
final AnnotationTypeBuilder annotManAttr = propertyBuilder.addAnnotation("org.springframework.jmx.export.annotation", "ManagedAttribute");
annotManAttr.addParameter("description", "\"The Name Attribute\"");
annotManAttr.addParameter("currencyTimeLimit", "20");
annotManAttr.addParameter("defaultValue", "\"bar\"");
annotManAttr.addParameter("persistPolicy", "\"OnUpdate\"");
final AnnotationTypeBuilder annotManProp = propertyBuilder.addAnnotation("org.springframework.jmx.export.annotation", "ManagedOperation");
final List<String> typeValues = new ArrayList<>();
typeValues.add("\"val1\"");
typeValues.add("\"val2\"");
typeValues.add("\"val3\"");
annotManProp.addParameters("types", typeValues);
final GeneratedTransferObject genTransObj = genTOBuilder.build();
assertNotNull(genTransObj);
assertNotNull(genTransObj.getAnnotations());
assertNotNull(genTransObj.getProperties());
assertNotNull(genTransObj.getProperties().get(0));
assertNotNull(genTransObj.getProperties().get(0).getAnnotations());
final List<AnnotationType> annotations = genTransObj.getProperties().get(0).getAnnotations();
assertEquals(2, annotations.size());
int annotCount = 0;
for (final AnnotationType annotation : annotations) {
if (annotation.getPackageName().equals("org.springframework.jmx.export.annotation") && annotation.getName().equals("ManagedAttribute")) {
annotCount++;
assertEquals(4, annotation.getParameters().size());
assertNotNull(annotation.getParameter("description"));
assertNotNull(annotation.getParameter("currencyTimeLimit"));
assertNotNull(annotation.getParameter("defaultValue"));
assertNotNull(annotation.getParameter("persistPolicy"));
assertEquals("\"The Name Attribute\"", annotation.getParameter("description").getValue());
assertEquals("20", annotation.getParameter("currencyTimeLimit").getValue());
assertEquals("\"bar\"", annotation.getParameter("defaultValue").getValue());
assertEquals("\"OnUpdate\"", annotation.getParameter("persistPolicy").getValue());
}
if (annotation.getPackageName().equals("org.springframework.jmx.export.annotation") && annotation.getName().equals("ManagedOperation")) {
annotCount++;
assertEquals(1, annotation.getParameters().size());
assertNotNull(annotation.getParameter("types"));
assertEquals(3, annotation.getParameter("types").getValues().size());
}
}
assertEquals(2, annotCount);
}
use of org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTOBuilder in project mdsal by opendaylight.
the class GeneratedTOBuilderTest method testToString.
@Test
public void testToString() {
final GeneratedTOBuilder genTypeBuilder = new CodegenGeneratedTOBuilder(JavaTypeName.create("org.opendaylight.controller", "AnnotClassCache"));
assertThat(genTypeBuilder.toString(), startsWith("CodegenGeneratedTOBuilder{identifier=org.opendaylight.controller.AnnotClassCache"));
}
use of org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTOBuilder in project mdsal by opendaylight.
the class GeneratedTypeBuilderTest method addEnclosingTransferObjectTest.
@Test
public void addEnclosingTransferObjectTest() {
GeneratedTypeBuilder generatedTypeBuilder = new CodegenGeneratedTypeBuilder(JavaTypeName.create("my.package", "MyName"));
GeneratedTOBuilder enclosingTransferObject = new CodegenGeneratedTOBuilder(generatedTypeBuilder.getIdentifier().createEnclosed("myTOName"));
GeneratedTOBuilder enclosingTransferObject2 = new CodegenGeneratedTOBuilder(generatedTypeBuilder.getIdentifier().createEnclosed("myTOName2"));
GeneratedTOBuilder enclosingTransferObject3 = new CodegenGeneratedTOBuilder(generatedTypeBuilder.getIdentifier().createEnclosed("myTOName3"));
generatedTypeBuilder.addEnclosingTransferObject(enclosingTransferObject.build());
generatedTypeBuilder.addEnclosingTransferObject(enclosingTransferObject2.build());
generatedTypeBuilder.addEnclosingTransferObject(enclosingTransferObject3.build());
GeneratedType instance = generatedTypeBuilder.build();
List<GeneratedType> enclosedTypes = instance.getEnclosedTypes();
assertEquals(3, enclosedTypes.size());
assertTrue(enclosedTypes.contains(enclosingTransferObject.build()));
assertTrue(enclosedTypes.contains(enclosingTransferObject2.build()));
assertTrue(enclosedTypes.contains(enclosingTransferObject3.build()));
assertFalse(enclosedTypes.contains(new CodegenGeneratedTOBuilder(generatedTypeBuilder.getIdentifier().createEnclosed("myTOName4")).build()));
}
use of org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTOBuilder 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.type.builder.GeneratedTOBuilder in project mdsal by opendaylight.
the class AbstractTypeObjectGenerator method restrictType.
@NonNull
private static Type restrictType(@NonNull final Type baseType, final Restrictions restrictions, final TypeBuilderFactory builderFactory) {
if (restrictions == null || restrictions.isEmpty()) {
// No additional restrictions, return base type
return baseType;
}
if (!(baseType instanceof GeneratedTransferObject)) {
// This is a simple Java type, just wrap it with new restrictions
return Types.restrictedType(baseType, restrictions);
}
// Base type is a GTO, we need to re-adjust it with new restrictions
final GeneratedTransferObject gto = (GeneratedTransferObject) baseType;
final GeneratedTOBuilder builder = builderFactory.newGeneratedTOBuilder(gto.getIdentifier());
final GeneratedTransferObject parent = gto.getSuperType();
if (parent != null) {
builder.setExtendsType(parent);
}
builder.setRestrictions(restrictions);
for (GeneratedProperty gp : gto.getProperties()) {
builder.addProperty(gp.getName()).setValue(gp.getValue()).setReadOnly(gp.isReadOnly()).setAccessModifier(gp.getAccessModifier()).setReturnType(gp.getReturnType()).setFinal(gp.isFinal()).setStatic(gp.isStatic());
}
return builder.build();
}
Aggregations