use of org.springframework.roo.classpath.details.FieldMetadataBuilder in project spring-roo by spring-projects.
the class RepositoryJpaIntegrationTestMetadata method getRepositoryField.
/**
* Builds and returns a `private` Roo repository field.
*
* @return {@link FieldMetadataBuilder}
*/
private FieldMetadataBuilder getRepositoryField() {
FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(this.getId(), Modifier.PRIVATE, REPOSITORY_FIELD_NAME, this.annotationValues.getTargetClass(), null);
// Add @Autowired
fieldBuilder.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.AUTOWIRED));
return fieldBuilder;
}
use of org.springframework.roo.classpath.details.FieldMetadataBuilder in project spring-roo by spring-projects.
the class ServiceImplMetadata method getFieldFor.
/**
* This method returns field to included on service for a Service or
* Repository
*
* @param service
* @return
*/
private FieldMetadata getFieldFor(JavaType type) {
// Generating service field name
final JavaSymbolName fieldName = new JavaSymbolName(StringUtils.uncapitalize(type.getSimpleTypeName()));
FieldMetadata currentField = governorTypeDetails.getField(fieldName);
if (currentField != null) {
Validate.isTrue(currentField.getFieldType().equals(type), "Field %s already in %s but type not match: expected %s", currentField.getFieldName(), governorTypeDetails.getType(), type);
return currentField;
}
return new FieldMetadataBuilder(getId(), Modifier.PRIVATE, new ArrayList<AnnotationMetadataBuilder>(), fieldName, type).build();
}
use of org.springframework.roo.classpath.details.FieldMetadataBuilder in project spring-roo by spring-projects.
the class RepositoryJpaCustomImplMetadata method getConstantForField.
/**
* This method returns the associated constant to the provided
* fieldName.
*
* If doesn't exists any constat defined to the provided fieldName
* this method will create a new one.
*
* If exists, this method will return the constant.
*
* @param fieldName
* @return
*/
private FieldMetadata getConstantForField(String fieldName) {
Validate.notEmpty(fieldName, "ERROR: You must provide a valid fieldName to be able to generate" + " the finder content");
// to this field
if (constantsForFields.get(fieldName) != null) {
return constantsForFields.get(fieldName);
}
// If not exists, generate it and then, return its name
String[] fieldNameParts = StringUtils.splitByCharacterTypeCamelCase(fieldName);
String constantName = "";
for (String part : fieldNameParts) {
constantName = constantName.concat(part).concat(CONSTANT_SEPARATOR);
}
Validate.notEmpty(constantName, "ERROR: Some error appears during field constant generation.");
// Creating the new constant name
JavaSymbolName constantSymbolName = new JavaSymbolName(constantName.substring(0, constantName.length() - CONSTANT_SEPARATOR.length()).toUpperCase());
// Creating field and adding it to the builder. Contants will be always publics to be used
// in different locations.
FieldMetadataBuilder constantField = new FieldMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.STATIC + Modifier.FINAL, constantSymbolName, JavaType.STRING, "\"".concat(fieldName).concat("\""));
// Cache it to prevent generate the same constant again
constantsForFields.put(fieldName, constantField.build());
return constantField.build();
}
use of org.springframework.roo.classpath.details.FieldMetadataBuilder in project spring-roo by spring-projects.
the class PushInOperationsImpl method getNewField.
/**
* This method generates new field instance using an existing FieldMetadata
*
* @param declaredByMetadataId
* @param field
*
* @return
*/
private FieldMetadata getNewField(String declaredByMetadataId, FieldMetadata field) {
// Use the FieldMetadataBuilder for easy creation of FieldMetadata
// based on existing field
FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(declaredByMetadataId, field.getModifier(), field.getFieldName(), field.getFieldType(), field.getFieldInitializer());
fieldBuilder.setAnnotations(field.getAnnotations());
return fieldBuilder.build();
}
use of org.springframework.roo.classpath.details.FieldMetadataBuilder in project spring-roo by spring-projects.
the class ThymeleafControllerIntegrationTestMetadata method getMockMvcField.
/**
* Builds and returns a {@link MockMvc} field, annotated with @Autowired
*
* @return {@link FieldMetadataBuilder}
*/
private FieldMetadataBuilder getMockMvcField() {
FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(this.getId(), Modifier.PUBLIC, MOCK_MVC_FIELD_NAME, SpringJavaType.MOCK_MVC, null);
// Add @Autowired
fieldBuilder.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.AUTOWIRED));
return fieldBuilder;
}
Aggregations