use of org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedPropertyBuilder in project mdsal by opendaylight.
the class AbstractGeneratedTypeBuilder method addProperty.
@Override
public GeneratedPropertyBuilder addProperty(final String name) {
checkArgument(name != null, "Parameter name can't be null");
checkArgument(!containsProperty(name), "This generated type already contains property with the same name.");
final GeneratedPropertyBuilder builder = new GeneratedPropertyBuilderImpl(name);
builder.setAccessModifier(AccessModifier.PUBLIC);
this.properties = LazyCollections.lazyAdd(this.properties, builder);
return builder;
}
use of org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedPropertyBuilder 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.GeneratedPropertyBuilder 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.GeneratedPropertyBuilder in project mdsal by opendaylight.
the class Generator method addSerialVersionUID.
static final void addSerialVersionUID(final GeneratedTOBuilder gto) {
final GeneratedPropertyBuilder prop = new GeneratedPropertyBuilderImpl("serialVersionUID");
prop.setValue(Long.toString(SerialVersionHelper.computeDefaultSUID(gto)));
gto.setSUID(prop);
}
use of org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedPropertyBuilder in project mdsal by opendaylight.
the class SerialVersionHelper method computeDefaultSUID.
public static long computeDefaultSUID(final GeneratedTypeBuilderBase<?> to) {
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
try (DataOutputStream dout = new DataOutputStream(bout)) {
dout.writeUTF(to.getName());
dout.writeInt(to.isAbstract() ? 3 : 7);
for (final Type ifc : sortedCollection(SUID_NAME_COMPARATOR, filteredImplementsTypes(to))) {
dout.writeUTF(ifc.getFullyQualifiedName());
}
for (final GeneratedPropertyBuilder gp : sortedCollection(SUID_MEMBER_COMPARATOR, to.getProperties())) {
dout.writeUTF(gp.getName());
}
for (final MethodSignatureBuilder m : sortedCollection(SUID_MEMBER_COMPARATOR, to.getMethodDefinitions())) {
if (!m.getAccessModifier().equals(AccessModifier.PRIVATE)) {
dout.writeUTF(m.getName());
dout.write(m.getAccessModifier().ordinal());
}
}
dout.flush();
} catch (final IOException e) {
throw new IllegalStateException("Failed to hash object " + to, e);
}
final byte[] hashBytes = SHA1_MD.get().digest(bout.toByteArray());
long hash = 0;
for (int i = Math.min(hashBytes.length, 8) - 1; i >= 0; i--) {
hash = hash << 8 | hashBytes[i] & 0xFF;
}
return hash;
}
Aggregations