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();
}
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;
}
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();
}
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;
}
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;
}
Aggregations