Search in sources :

Example 1 with MethodSignatureBuilder

use of org.opendaylight.mdsal.binding.model.api.type.builder.MethodSignatureBuilder in project mdsal by opendaylight.

the class AbstractGeneratedTOBuilder method addMethod.

/**
 * Add new Method Signature definition for Generated Type Builder and
 * returns Method Signature Builder for specifying all Method parameters. <br>
 * Name of Method cannot be <code>null</code>, if it is <code>null</code>
 * the method SHOULD throw {@link IllegalArgumentException} <br>
 * By <i>Default</i> the MethodSignatureBuilder SHOULD be pre-set as
 * {@link MethodSignatureBuilder#setAbstract(boolean)},
 * {TypeMemberBuilder#setFinal(boolean)} and
 * {TypeMemberBuilder#setAccessModifier(boolean)}
 *
 * @param name
 *            Name of Method
 * @return <code>new</code> instance of Method Signature Builder.
 */
@Override
public final MethodSignatureBuilder addMethod(final String name) {
    final MethodSignatureBuilder builder = super.addMethod(name);
    builder.setAbstract(false);
    return builder;
}
Also used : MethodSignatureBuilder(org.opendaylight.mdsal.binding.model.api.type.builder.MethodSignatureBuilder)

Example 2 with MethodSignatureBuilder

use of org.opendaylight.mdsal.binding.model.api.type.builder.MethodSignatureBuilder in project mdsal by opendaylight.

the class AbstractGeneratedTypeBuilder method addMethod.

@Override
public MethodSignatureBuilder addMethod(final String name) {
    checkArgument(name != null, "Name of method cannot be null!");
    final MethodSignatureBuilder builder = new MethodSignatureBuilderImpl(name);
    builder.setAccessModifier(AccessModifier.PUBLIC);
    builder.setAbstract(true);
    this.methodDefinitions = LazyCollections.lazyAdd(this.methodDefinitions, builder);
    return builder;
}
Also used : MethodSignatureBuilder(org.opendaylight.mdsal.binding.model.api.type.builder.MethodSignatureBuilder)

Example 3 with MethodSignatureBuilder

use of org.opendaylight.mdsal.binding.model.api.type.builder.MethodSignatureBuilder 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)));
}
Also used : GeneratedTypeBuilder(org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder) MethodSignature(org.opendaylight.mdsal.binding.model.api.MethodSignature) GeneratedType(org.opendaylight.mdsal.binding.model.api.GeneratedType) MethodSignatureBuilder(org.opendaylight.mdsal.binding.model.api.type.builder.MethodSignatureBuilder) Test(org.junit.Test)

Example 4 with MethodSignatureBuilder

use of org.opendaylight.mdsal.binding.model.api.type.builder.MethodSignatureBuilder in project mdsal by opendaylight.

the class AbstractExplicitGenerator method constructGetter.

final MethodSignatureBuilder constructGetter(final GeneratedTypeBuilderBase<?> builder, final Type returnType, final String methodName) {
    final MethodSignatureBuilder getMethod = builder.addMethod(methodName).setReturnType(returnType);
    annotateDeprecatedIfNecessary(getMethod);
    statement.findFirstEffectiveSubstatementArgument(DescriptionEffectiveStatement.class).map(TypeMemberComment::referenceOf).ifPresent(getMethod::setComment);
    return getMethod;
}
Also used : MethodSignatureBuilder(org.opendaylight.mdsal.binding.model.api.type.builder.MethodSignatureBuilder)

Example 5 with MethodSignatureBuilder

use of org.opendaylight.mdsal.binding.model.api.type.builder.MethodSignatureBuilder in project mdsal by opendaylight.

the class Generator method defineImplementedInterfaceMethod.

private static MethodSignatureBuilder defineImplementedInterfaceMethod(final GeneratedTypeBuilder typeBuilder, final Type classType) {
    final MethodSignatureBuilder ret = typeBuilder.addMethod(BindingMapping.DATA_CONTAINER_IMPLEMENTED_INTERFACE_NAME).setAccessModifier(AccessModifier.PUBLIC).setReturnType(classType(classType));
    ret.addAnnotation(OVERRIDE_ANNOTATION);
    return ret;
}
Also used : MethodSignatureBuilder(org.opendaylight.mdsal.binding.model.api.type.builder.MethodSignatureBuilder)

Aggregations

MethodSignatureBuilder (org.opendaylight.mdsal.binding.model.api.type.builder.MethodSignatureBuilder)13 Test (org.junit.Test)4 GeneratedTypeBuilder (org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder)4 GeneratedType (org.opendaylight.mdsal.binding.model.api.GeneratedType)3 ConcreteType (org.opendaylight.mdsal.binding.model.api.ConcreteType)2 Type (org.opendaylight.mdsal.binding.model.api.Type)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 ResolvedLeafref (org.opendaylight.mdsal.binding.generator.impl.reactor.TypeReference.ResolvedLeafref)1 AnnotationType (org.opendaylight.mdsal.binding.model.api.AnnotationType)1 MethodSignature (org.opendaylight.mdsal.binding.model.api.MethodSignature)1 TypeMemberComment (org.opendaylight.mdsal.binding.model.api.TypeMemberComment)1 AnnotationTypeBuilder (org.opendaylight.mdsal.binding.model.api.type.builder.AnnotationTypeBuilder)1 GeneratedPropertyBuilder (org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedPropertyBuilder)1 CodegenGeneratedTypeBuilder (org.opendaylight.mdsal.binding.model.ri.generated.type.builder.CodegenGeneratedTypeBuilder)1 RuntimeType (org.opendaylight.mdsal.binding.runtime.api.RuntimeType)1 QName (org.opendaylight.yangtools.yang.common.QName)1