use of org.springframework.roo.classpath.details.FieldMetadataBuilder in project spring-roo by spring-projects.
the class JpaUnitTestMetadata method getMockitoRuleField.
/**
* Creates MockitoRule field for validating and initialize mocks.
*
* @return {@link FieldMetadataBuilder} for building field into ITD.
*/
private FieldMetadataBuilder getMockitoRuleField() {
// Create field @Rule
List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
AnnotationMetadataBuilder ruleAnnotation = new AnnotationMetadataBuilder(RULE);
annotations.add(ruleAnnotation);
// Create field
FieldMetadataBuilder ruleField = new FieldMetadataBuilder(getId(), Modifier.PUBLIC, annotations, new JavaSymbolName("mockito"), MOCKITO_RULE);
return ruleField;
}
use of org.springframework.roo.classpath.details.FieldMetadataBuilder in project spring-roo by spring-projects.
the class JpaAuditOperationsImpl method getCreatedByField.
/**
* Builds createdBy field for storing user who creates entity registers
*
* @return FieldMetadataBuilder
*/
private FieldMetadataBuilder getCreatedByField(ClassOrInterfaceTypeDetails entityDetails, String columnName) {
// Create field annotations
List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
// Only add @Column if required by annotation @RooJpaAudit
if (StringUtils.isNotBlank(columnName)) {
AnnotationMetadataBuilder columnAnnotation = new AnnotationMetadataBuilder(JpaJavaType.COLUMN);
columnAnnotation.addStringAttribute("name", columnName);
annotations.add(columnAnnotation);
}
AnnotationMetadataBuilder createdDateAnnotation = new AnnotationMetadataBuilder(SpringJavaType.CREATED_BY);
annotations.add(createdDateAnnotation);
// Create field
FieldDetails fieldDetails = new FieldDetails(PhysicalTypeIdentifier.createIdentifier(entityDetails), JavaType.STRING, new JavaSymbolName("createdBy"));
fieldDetails.setModifiers(Modifier.PRIVATE);
fieldDetails.setAnnotations(annotations);
FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(fieldDetails);
return fieldBuilder;
}
use of org.springframework.roo.classpath.details.FieldMetadataBuilder in project spring-roo by spring-projects.
the class JpaAuditOperationsImpl method getModifiedByField.
/**
* Builds modifiedBy field for storing user who last modifies entity registers
*
* @return FieldMetadataBuilder
*/
private FieldMetadataBuilder getModifiedByField(ClassOrInterfaceTypeDetails entityDetails, String columnName) {
// Create field annotations
List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
// Only add @Column if required by annotation @RooJpaAudit
if (StringUtils.isNotBlank(columnName)) {
AnnotationMetadataBuilder columnAnnotation = new AnnotationMetadataBuilder(JpaJavaType.COLUMN);
columnAnnotation.addStringAttribute("name", columnName);
annotations.add(columnAnnotation);
}
AnnotationMetadataBuilder createdDateAnnotation = new AnnotationMetadataBuilder(SpringJavaType.LAST_MODIFIED_BY);
annotations.add(createdDateAnnotation);
// Create field
FieldDetails fieldDetails = new FieldDetails(PhysicalTypeIdentifier.createIdentifier(entityDetails), JavaType.STRING, new JavaSymbolName("modifiedBy"));
fieldDetails.setModifiers(Modifier.PRIVATE);
fieldDetails.setAnnotations(annotations);
FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(fieldDetails);
return fieldBuilder;
}
use of org.springframework.roo.classpath.details.FieldMetadataBuilder in project spring-roo by spring-projects.
the class JpaDataOnDemandMetadata method getDataField.
/**
* @return the "data" field to use, which is either provided by the user or
* produced on demand (never returns null)
*/
private FieldMetadataBuilder getDataField() {
final List<JavaType> parameterTypes = Arrays.asList(entity);
final JavaType listType = new JavaType(LIST.getFullyQualifiedTypeName(), 0, DataType.TYPE, null, parameterTypes);
int index = -1;
while (true) {
// Compute the required field name
index++;
// The type parameters to be used by the field type
final JavaSymbolName fieldName = new JavaSymbolName("data" + StringUtils.repeat("_", index));
dataFieldName = fieldName;
final FieldMetadata candidate = governorTypeDetails.getField(fieldName);
if (candidate != null) {
// Verify if candidate is suitable
if (!Modifier.isPrivate(candidate.getModifier())) {
// next possible name)
continue;
}
if (!candidate.getFieldType().equals(listType)) {
// The equals method also verifies type params are present
continue;
}
// we assume the user knows what they're doing and have made one
return new FieldMetadataBuilder(candidate);
}
// Candidate not found, so let's create one
FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(getId(), Modifier.PRIVATE, new ArrayList<AnnotationMetadataBuilder>(), fieldName, listType);
CommentStructure comment = new CommentStructure();
comment.addComment(new JavadocComment("List of created entities."), CommentLocation.BEGINNING);
fieldBuilder.setCommentStructure(comment);
return fieldBuilder;
}
}
use of org.springframework.roo.classpath.details.FieldMetadataBuilder in project spring-roo by spring-projects.
the class JpaDataOnDemandMetadata method getSizeField.
/**
* Creates size field.
*
* @return {@link FieldMetadataBuilder} for building field into ITD.
*/
private FieldMetadata getSizeField() {
// Create field
FieldMetadataBuilder sizeField = new FieldMetadataBuilder(getId(), Modifier.PRIVATE, new ArrayList<AnnotationMetadataBuilder>(), new JavaSymbolName(SIZE_VAR), JavaType.INT_PRIMITIVE);
CommentStructure comment = new CommentStructure();
comment.addComment(new JavadocComment("Number of elements to create and persist."), CommentLocation.BEGINNING);
sizeField.setCommentStructure(comment);
return sizeField.build();
}
Aggregations