Search in sources :

Example 6 with ConstructorMetadataBuilder

use of org.springframework.roo.classpath.details.ConstructorMetadataBuilder in project spring-roo by spring-projects.

the class JavaParserConstructorMetadataBuilder method build.

@Override
public ConstructorMetadata build() {
    final ConstructorMetadataBuilder constructorBuilder = new ConstructorMetadataBuilder(declaredByMetadataId);
    constructorBuilder.setAnnotations(annotations);
    constructorBuilder.setBodyBuilder(InvocableMemberBodyBuilder.getInstance().append(body));
    constructorBuilder.setModifier(modifier);
    constructorBuilder.setParameterNames(parameterNames);
    constructorBuilder.setParameterTypes(parameterTypes);
    constructorBuilder.setThrowsTypes(throwsTypes);
    return constructorBuilder.build();
}
Also used : ConstructorMetadataBuilder(org.springframework.roo.classpath.details.ConstructorMetadataBuilder)

Example 7 with ConstructorMetadataBuilder

use of org.springframework.roo.classpath.details.ConstructorMetadataBuilder in project spring-roo by spring-projects.

the class SeiImplMetadata method getConstructor.

/**
 * This method obtains the constructor method of the annotated endpoint
 *
 * @return constructor method for this endpoint
 */
private ConstructorMetadata getConstructor() {
    // Check if constructor has been generated before
    if (constructor != null) {
        return constructor;
    }
    // Creating new constructor
    ConstructorMetadataBuilder constructorMethod = new ConstructorMetadataBuilder(getId());
    constructorMethod.setModifier(Modifier.PUBLIC);
    constructorMethod.addParameter(getServiceField().getFieldName().getSymbolNameUnCapitalisedFirstLetter(), getServiceField().getFieldType());
    // Generating constructor body
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    bodyBuilder.appendFormalLine("%s(%s);", getMutatorMethod(getServiceField()).getMethodName(), getServiceField().getFieldName().getSymbolNameUnCapitalisedFirstLetter());
    constructorMethod.setBodyBuilder(bodyBuilder);
    constructor = constructorMethod.build();
    return constructor;
}
Also used : ConstructorMetadataBuilder(org.springframework.roo.classpath.details.ConstructorMetadataBuilder) InvocableMemberBodyBuilder(org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder)

Example 8 with ConstructorMetadataBuilder

use of org.springframework.roo.classpath.details.ConstructorMetadataBuilder in project spring-roo by spring-projects.

the class JSONMetadata method getConstructor.

private ConstructorMetadata getConstructor(boolean autowired) {
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    // Generating constructor
    ConstructorMetadataBuilder constructor = new ConstructorMetadataBuilder(getId());
    constructor.setModifier(Modifier.PUBLIC);
    if (autowired) {
        constructor.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.AUTOWIRED));
    }
    // Getting serviceFieldName
    String serviceFieldName = controllerMetadata.getServiceField().getFieldName().getSymbolName();
    constructor.addParameter(serviceFieldName, controllerMetadata.getService());
    // Generating body
    bodyBuilder.appendFormalLine(String.format("this.%s = %s;", serviceFieldName, serviceFieldName));
    if (this.type == ControllerType.DETAIL || this.type == ControllerType.DETAIL_ITEM) {
        for (FieldMetadata serviceField : controllerMetadata.getDetailsServiceFields().values()) {
            // Getting parentServiceFieldName
            String childServiceFieldName = serviceField.getFieldName().getSymbolName();
            // Adding parameters
            constructor.addParameter(childServiceFieldName, serviceField.getFieldType());
            // Generating body
            bodyBuilder.appendFormalLine(String.format("this.%s = %s;", childServiceFieldName, childServiceFieldName));
        }
    }
    // Adding body
    constructor.setBodyBuilder(bodyBuilder);
    return constructor.build();
}
Also used : FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) ConstructorMetadataBuilder(org.springframework.roo.classpath.details.ConstructorMetadataBuilder) InvocableMemberBodyBuilder(org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 9 with ConstructorMetadataBuilder

use of org.springframework.roo.classpath.details.ConstructorMetadataBuilder in project spring-roo by spring-projects.

the class DtoMetadata method getConstructor.

/**
 * Builds constructor for initializing <code>final</code> fields.
 *
 * @return ConstructorMetadataBuilder for adding constructor to ITD
 */
private ConstructorMetadataBuilder getConstructor() {
    ConstructorMetadataBuilder constructorBuilder = new ConstructorMetadataBuilder(getId());
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    if (annotationValues.getImmutable() == true) {
        for (FieldMetadata field : fields) {
            // Add all fields excluding Serializable field
            if (!field.getFieldName().equals(serialField)) {
                String fieldName = field.getFieldName().getSymbolName();
                constructorBuilder.addParameter(fieldName, field.getFieldType());
                bodyBuilder.appendFormalLine(String.format("this.%s = %s;", fieldName, fieldName));
            }
        }
    }
    constructorBuilder.setModifier(Modifier.PUBLIC);
    constructorBuilder.setBodyBuilder(bodyBuilder);
    return constructorBuilder;
}
Also used : FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) ConstructorMetadataBuilder(org.springframework.roo.classpath.details.ConstructorMetadataBuilder) InvocableMemberBodyBuilder(org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder)

Example 10 with ConstructorMetadataBuilder

use of org.springframework.roo.classpath.details.ConstructorMetadataBuilder in project spring-roo by spring-projects.

the class JpaDataOnDemandMetadata method getConstructorWithEntityManager.

/**
 * Builds constructor with EntityManager argument.
 *
 * @return ConstructorMetadataBuilder for adding constructor to ITD
 */
private ConstructorMetadataBuilder getConstructorWithEntityManager() {
    ConstructorMetadataBuilder constructorBuilder = new ConstructorMetadataBuilder(getId());
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    constructorBuilder.addParameter(ENTITY_MANAGER_VAR, JpaJavaType.ENTITY_MANAGER);
    // this(entityManager, 10);
    bodyBuilder.appendFormalLine(String.format("this(%1$s, 10);", ENTITY_MANAGER_VAR));
    constructorBuilder.setModifier(Modifier.PUBLIC);
    constructorBuilder.setBodyBuilder(bodyBuilder);
    CommentStructure comment = new CommentStructure();
    List<String> paramsInfo = new ArrayList<String>();
    paramsInfo.add(ENTITY_MANAGER_VAR + " to persist entities");
    JavadocComment javadocComment = new JavadocComment(String.format("Creates a new {@link %s}.", this.governorPhysicalTypeMetadata.getType().getSimpleTypeName()), paramsInfo, null, null);
    comment.addComment(javadocComment, CommentLocation.BEGINNING);
    constructorBuilder.setCommentStructure(comment);
    return constructorBuilder;
}
Also used : JavadocComment(org.springframework.roo.classpath.details.comments.JavadocComment) ConstructorMetadataBuilder(org.springframework.roo.classpath.details.ConstructorMetadataBuilder) ArrayList(java.util.ArrayList) InvocableMemberBodyBuilder(org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder) CommentStructure(org.springframework.roo.classpath.details.comments.CommentStructure)

Aggregations

ConstructorMetadataBuilder (org.springframework.roo.classpath.details.ConstructorMetadataBuilder)16 InvocableMemberBodyBuilder (org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder)15 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)6 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)6 ArrayList (java.util.ArrayList)5 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)4 JavaType (org.springframework.roo.model.JavaType)4 ConstructorMetadata (org.springframework.roo.classpath.details.ConstructorMetadata)3 CommentStructure (org.springframework.roo.classpath.details.comments.CommentStructure)2 JavadocComment (org.springframework.roo.classpath.details.comments.JavadocComment)2 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)2 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)1 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)1 FieldMetadataBuilder (org.springframework.roo.classpath.details.FieldMetadataBuilder)1 JdkJavaType (org.springframework.roo.model.JdkJavaType)1