use of org.springframework.roo.classpath.details.ConstructorMetadataBuilder in project spring-roo by spring-projects.
the class DomainModelModuleMetadata method getConstructor.
private ConstructorMetadata getConstructor() {
InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
// Generating constructor
ConstructorMetadataBuilder constructor = new ConstructorMetadataBuilder(getId());
constructor.setModifier(Modifier.PUBLIC);
bodyBuilder.appendFormalLine("// Mixin registration");
bodyBuilder.newLine();
// Generating body
for (Entry<JavaType, JavaType> item : mixins.entrySet()) {
bodyBuilder.appendFormalLine("setMixInAnnotation(%s.class, %s.class);", getNameOfJavaType(item.getKey()), getNameOfJavaType(item.getValue()));
}
// 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 ExceptionsMetadata method getConstructor.
private ConstructorMetadata getConstructor() {
// Getting MessageSource field name
final String messageSource = String.valueOf(this.messageSourceField.getFieldName());
// Generating constructor
ConstructorMetadataBuilder constructor = new ConstructorMetadataBuilder(getId());
constructor.setModifier(Modifier.PUBLIC);
constructor.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.AUTOWIRED));
// Adding parameters
constructor.addParameter(messageSource, SpringJavaType.MESSAGE_SOURCE);
// Generating body
InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
bodyBuilder.appendFormalLine(String.format("this.%s = %s;", messageSource, messageSource));
// 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 JpaDataOnDemandConfigurationMetadata method getConstructor.
/**
* Builds and returns a class constructor which injects
* {@link EntityManager} field.
*
* @return a ConstructorMetadataBuilder to add to ITD.
*/
private ConstructorMetadataBuilder getConstructor() {
// Create instance and add parameters
ConstructorMetadataBuilder constructorBuilder = new ConstructorMetadataBuilder(this.getId());
constructorBuilder.addParameter(ENTITY_MANAGER_FIELD_NAME, JpaJavaType.ENTITY_MANAGER);
// Add body
InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
bodyBuilder.appendFormalLine("%1$s(%2$s);", getMutatorMethod(getEntityManagerField().build()).getMethodName(), ENTITY_MANAGER_FIELD_NAME);
constructorBuilder.setBodyBuilder(bodyBuilder);
constructorBuilder.setModifier(Modifier.PUBLIC);
// Add @Autowired
constructorBuilder.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.AUTOWIRED));
return constructorBuilder;
}
use of org.springframework.roo.classpath.details.ConstructorMetadataBuilder in project spring-roo by spring-projects.
the class IdentifierMetadata method getParameterizedConstructor.
/**
* Locates the parameterised constructor consisting of the id fields for
* this class.
*
* @param fields
* @return the constructor, never null.
*/
private ConstructorMetadataBuilder getParameterizedConstructor(final List<FieldMetadataBuilder> fields) {
// Search for an existing constructor
final List<JavaType> parameterTypes = new ArrayList<JavaType>();
for (final FieldMetadataBuilder field : fields) {
parameterTypes.add(field.getFieldType());
}
final ConstructorMetadata result = governorTypeDetails.getDeclaredConstructor(parameterTypes);
if (result != null) {
// Found an existing parameterised constructor on this class
publicNoArgConstructor = true;
return null;
}
final List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
bodyBuilder.appendFormalLine("super();");
for (final FieldMetadataBuilder field : fields) {
final String fieldName = field.getFieldName().getSymbolName();
bodyBuilder.appendFormalLine("this." + fieldName + " = " + fieldName + ";");
parameterNames.add(field.getFieldName());
}
// Create the constructor
final ConstructorMetadataBuilder constructorBuilder = new ConstructorMetadataBuilder(getId());
constructorBuilder.setModifier(Modifier.PUBLIC);
constructorBuilder.setParameterTypes(AnnotatedJavaType.convertFromJavaTypes(parameterTypes));
constructorBuilder.setParameterNames(parameterNames);
constructorBuilder.setBodyBuilder(bodyBuilder);
return constructorBuilder;
}
use of org.springframework.roo.classpath.details.ConstructorMetadataBuilder in project spring-roo by spring-projects.
the class JpaDataOnDemandMetadata method getConstructorWithEntityManagerAndSize.
/**
* Builds constructor with EntityManager and size arguments.
*
* @return {@link ConstructorMetadataBuilder} for adding constructor to ITD
*/
private ConstructorMetadataBuilder getConstructorWithEntityManagerAndSize() {
ConstructorMetadataBuilder constructorBuilder = new ConstructorMetadataBuilder(getId());
InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
constructorBuilder.addParameter(ENTITY_MANAGER_VAR, JpaJavaType.ENTITY_MANAGER);
constructorBuilder.addParameter(SIZE_VAR, JavaType.INT_PRIMITIVE);
bodyBuilder.appendFormalLine(String.format("%1$s(%2$s);", getMutatorMethod(getEntityManagerField().build()).getMethodName(), ENTITY_MANAGER_VAR));
bodyBuilder.appendFormalLine(String.format("%1$s(%2$s);", getMutatorMethod(getSizeField()).getMethodName(), SIZE_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");
paramsInfo.add(SIZE_VAR + " the number of entities to create and persist initially.");
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