use of org.opendaylight.mdsal.binding.model.api.GeneratedType in project mdsal by opendaylight.
the class DataObjectCodecContext method getAugmentationPrototype.
@NonNull
private DataContainerCodecPrototype<?> getAugmentationPrototype(final AugmentRuntimeType augment) {
final BindingRuntimeContext ctx = factory().getRuntimeContext();
final GeneratedType javaType = augment.javaType();
final Class<? extends Augmentation<?>> augClass;
try {
augClass = ctx.loadClass(javaType);
} catch (final ClassNotFoundException e) {
throw new IllegalStateException("RuntimeContext references type " + javaType + " but failed to load its class", e);
}
// TODO: at some point we need the effective children
return DataContainerCodecPrototype.from(augClass, new AugmentationIdentifier(augment.statement().streamEffectiveSubstatements(SchemaTreeEffectiveStatement.class).map(SchemaTreeEffectiveStatement::getIdentifier).collect(ImmutableSet.toImmutableSet())), augment, factory());
}
use of org.opendaylight.mdsal.binding.model.api.GeneratedType in project mdsal by opendaylight.
the class AnnotationBuilderTest method generatedTypeAnnotationTest.
@Test
public void generatedTypeAnnotationTest() {
final GeneratedTypeBuilder genTypeBuilder = new CodegenGeneratedTypeBuilder(JavaTypeName.create("org.opendaylight.controller", "AnnotInterface"));
genTypeBuilder.addAnnotation("javax.management", "MXBean");
final AnnotationTypeBuilder annotDesc = genTypeBuilder.addAnnotation("javax.management", "Description");
annotDesc.addParameter("description", "some sort of interface");
final GeneratedType genType = genTypeBuilder.build();
assertNotNull(genType);
assertNotNull(genType.getAnnotations());
assertEquals(2, genType.getAnnotations().size());
int annotCount = 0;
for (final AnnotationType annotation : genType.getAnnotations()) {
if (annotation.getPackageName().equals("javax.management") && annotation.getName().equals("MXBean")) {
annotCount++;
assertEquals(0, annotation.getParameters().size());
}
if (annotation.getPackageName().equals("javax.management") && annotation.getName().equals("Description")) {
annotCount++;
assertEquals(1, annotation.getParameters().size());
AnnotationType.Parameter param = annotation.getParameter("description");
assertNotNull(param);
assertEquals("description", param.getName());
assertNotNull(param.getValue());
assertEquals("some sort of interface", param.getValue());
assertNotNull(param.getValues());
assertTrue(param.getValues().isEmpty());
}
}
assertEquals(2, annotCount);
}
use of org.opendaylight.mdsal.binding.model.api.GeneratedType in project mdsal by opendaylight.
the class GeneratedTypeBuilderTest method addMethodTest.
@Test
public void addMethodTest() {
GeneratedTypeBuilder generatedTypeBuilder = new CodegenGeneratedTypeBuilder(JavaTypeName.create("my.package", "MyName"));
MethodSignatureBuilder methodBuilder = generatedTypeBuilder.addMethod("myMethodName");
MethodSignatureBuilder methodBuilder2 = generatedTypeBuilder.addMethod("myMethodName2");
assertNotNull(methodBuilder);
assertNotNull(methodBuilder2);
assertTrue(generatedTypeBuilder.containsMethod("myMethodName"));
assertTrue(generatedTypeBuilder.containsMethod("myMethodName2"));
assertFalse(generatedTypeBuilder.containsMethod("myMethodName3"));
GeneratedType instance = generatedTypeBuilder.build();
List<MethodSignature> methodDefinitions = instance.getMethodDefinitions();
assertEquals(2, methodDefinitions.size());
assertTrue(methodDefinitions.contains(methodBuilder.toInstance(instance)));
assertTrue(methodDefinitions.contains(methodBuilder2.toInstance(instance)));
assertFalse(methodDefinitions.contains(new MethodSignatureBuilderImpl("myMethodName3").toInstance(instance)));
}
use of org.opendaylight.mdsal.binding.model.api.GeneratedType in project mdsal by opendaylight.
the class GeneratedTypeBuilderTest method addConstantTest.
@Test
public void addConstantTest() {
GeneratedTypeBuilder generatedTypeBuilder = new CodegenGeneratedTypeBuilder(JavaTypeName.create("my.package", "MyName"));
// assertNotNull(generatedTypeBuilder.addComment("My comment ..."));
Constant constant = generatedTypeBuilder.addConstant(Types.typeForClass(String.class), "myConstant", "myConstantValue");
// Constant constantx =
// generatedTypeBuilder.addConstant(Types.typeForClass(String.class),
// "myConstant", "myConstantValue");
Constant constant2 = generatedTypeBuilder.addConstant(Types.typeForClass(int.class, mock(Restrictions.class)), "myIntConstant", 1);
Constant constant3 = new ConstantImpl(Types.typeForClass(String.class), "myConstant", "myConstantValue");
final Constant constant4 = new ConstantImpl(Types.typeForClass(String.class), "myConstant2", "myConstantValue");
final Constant constant5 = new ConstantImpl(Types.typeForClass(String.class), "myConstant", "myConstantValue2");
assertNotNull(constant);
assertNotNull(constant2);
assertNotNull(constant3);
assertNotNull(constant4);
assertNotNull(constant5);
// assertNotNull(constantx);
// assertTrue(constant!=constantx);
assertFalse(constant.equals(null));
assertFalse(constant.equals(new Object()));
assertTrue(constant.equals(constant));
assertTrue(constant.equals(constant3));
assertFalse(constant.equals(constant2));
assertFalse(constant.equals(constant4));
assertFalse(constant.equals(constant5));
assertTrue(constant.hashCode() == constant.hashCode());
assertTrue(constant.hashCode() == constant3.hashCode());
assertFalse(constant.hashCode() == constant2.hashCode());
assertFalse(constant.hashCode() == constant4.hashCode());
assertTrue(constant.hashCode() == constant5.hashCode());
assertEquals("Constant [type=ConcreteTypeImpl{identifier=java.lang.String}, name=myConstant, value=myConstantValue]", constant.toString());
GeneratedType instance = generatedTypeBuilder.build();
List<Constant> constantDefinitions = instance.getConstantDefinitions();
assertNotNull(constantDefinitions);
assertEquals(2, constantDefinitions.size());
assertTrue(constantDefinitions.contains(constant));
assertTrue(constantDefinitions.contains(constant2));
assertTrue(constantDefinitions.contains(constant3));
assertFalse(constantDefinitions.contains(constant4));
assertFalse(constantDefinitions.contains(constant5));
assertEquals("myConstant", constant.getName());
assertEquals("myConstantValue", constant.getValue());
assertEquals(Types.typeForClass(String.class), constant.getType());
}
use of org.opendaylight.mdsal.binding.model.api.GeneratedType in project mdsal by opendaylight.
the class GeneratedTypeBuilderTest method addImplementsTypeTest.
@Test
public void addImplementsTypeTest() {
CodegenGeneratedTypeBuilder generatedTypeBuilder = new CodegenGeneratedTypeBuilder(JavaTypeName.create("my.package", "MyName"));
assertEquals(generatedTypeBuilder, generatedTypeBuilder.addImplementsType(Types.typeForClass(Serializable.class)));
assertEquals(generatedTypeBuilder, generatedTypeBuilder.addImplementsType(Types.typeForClass(Runnable.class)));
GeneratedType instance = generatedTypeBuilder.build();
List<Type> implementTypes = instance.getImplements();
assertEquals(2, implementTypes.size());
assertTrue(implementTypes.contains(Types.typeForClass(Serializable.class)));
assertTrue(implementTypes.contains(Types.typeForClass(Runnable.class)));
assertFalse(implementTypes.contains(Types.typeForClass(Throwable.class)));
}
Aggregations