use of org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder in project spring-roo by spring-projects.
the class JavaBeanMetadata method processGaeAnnotations.
private void processGaeAnnotations(final FieldMetadata field) {
for (final AnnotationMetadata annotation : field.getAnnotations()) {
if (annotation.getAnnotationType().equals(ONE_TO_ONE) || annotation.getAnnotationType().equals(MANY_TO_ONE) || annotation.getAnnotationType().equals(ONE_TO_MANY) || annotation.getAnnotationType().equals(MANY_TO_MANY)) {
builder.addFieldAnnotation(new DeclaredFieldAnnotationDetails(field, new AnnotationMetadataBuilder(annotation.getAnnotationType()).build(), true));
builder.addFieldAnnotation(new DeclaredFieldAnnotationDetails(field, new AnnotationMetadataBuilder(TRANSIENT).build()));
break;
}
}
}
use of org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder in project spring-roo by spring-projects.
the class JpaOperationsImpl method newEmbeddableClass.
@Override
public void newEmbeddableClass(final JavaType name, final boolean serializable) {
Validate.notNull(name, "Embeddable name required");
final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(name, getPathResolver().getFocusedPath(Path.SRC_MAIN_JAVA));
final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(Arrays.asList(new AnnotationMetadataBuilder(ROO_JAVA_BEAN), new AnnotationMetadataBuilder(ROO_TO_STRING), new AnnotationMetadataBuilder(EMBEDDABLE)));
if (serializable) {
annotations.add(new AnnotationMetadataBuilder(ROO_SERIALIZABLE));
}
final int modifier = Modifier.PUBLIC;
final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, modifier, name, PhysicalTypeCategory.CLASS);
cidBuilder.setAnnotations(annotations);
getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
getProjectOperations().addDependency(name.getModule(), new Dependency("org.springframework.boot", "spring-boot-starter-data-jpa", null));
}
use of org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder in project spring-roo by spring-projects.
the class JpaOperationsImpl method updateEmbeddableToIdentifier.
@Override
public void updateEmbeddableToIdentifier(final JavaType identifierType, final String identifierField, final String identifierColumn) {
Validate.notNull(identifierType, "Identifier type required");
// Get details from existing JavaType
ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(getTypeLocationService().getTypeDetails(identifierType));
// Create @RooIdentifier with getters and setters
AnnotationMetadataBuilder rooIdentifier = new AnnotationMetadataBuilder(ROO_IDENTIFIER);
rooIdentifier.addBooleanAttribute("settersByDefault", true);
final List<AnnotationMetadataBuilder> identifierAnnotations = Arrays.asList(new AnnotationMetadataBuilder(ROO_TO_STRING), new AnnotationMetadataBuilder(ROO_EQUALS), rooIdentifier);
cidBuilder.setAnnotations(identifierAnnotations);
// Set implement Serializable
List<JavaType> implementTypes = new ArrayList<JavaType>();
implementTypes.add(JdkJavaType.SERIALIZABLE);
cidBuilder.setImplementsTypes(implementTypes);
getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
}
use of org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder in project spring-roo by spring-projects.
the class JpaOperationsImpl method getVersionField.
/**
* This method generates the version field using the provided values
*
* @param entity
* @param versionField
* @param versionType
* @param versionColumn
* @return
*/
private FieldMetadata getVersionField(final JavaType entity, String versionField, final JavaType versionType, final String versionColumn) {
if (StringUtils.isEmpty(versionField)) {
versionField = "version";
}
final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
annotations.add(new AnnotationMetadataBuilder(VERSION));
if (StringUtils.isNotEmpty(versionColumn)) {
final AnnotationMetadataBuilder columnBuilder = new AnnotationMetadataBuilder(COLUMN);
columnBuilder.addStringAttribute("name", versionColumn);
annotations.add(columnBuilder);
}
FieldDetails versionFieldDetails = new FieldDetails(getTypeLocationService().getPhysicalTypeIdentifier(entity), versionType, new JavaSymbolName(versionField));
versionFieldDetails.setModifiers(Modifier.PRIVATE);
versionFieldDetails.addAnnotations(annotations);
return new FieldMetadataBuilder(versionFieldDetails).build();
}
use of org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder in project spring-roo by spring-projects.
the class EqualsOperationsImpl method addEqualsAndHashCodeMethods.
public void addEqualsAndHashCodeMethods(final JavaType javaType, final boolean appendSuper, final Set<String> excludeFields) {
// Add @RooEquals annotation to class if not yet present
final ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(javaType);
if (cid == null || cid.getTypeAnnotation(ROO_EQUALS) != null) {
return;
}
final AnnotationMetadataBuilder annotationBuilder = new AnnotationMetadataBuilder(ROO_EQUALS);
if (appendSuper) {
annotationBuilder.addBooleanAttribute("appendSuper", appendSuper);
}
if (!CollectionUtils.isEmpty(excludeFields)) {
final List<StringAttributeValue> attributes = new ArrayList<StringAttributeValue>();
for (final String excludeField : excludeFields) {
attributes.add(new StringAttributeValue(new JavaSymbolName("value"), excludeField));
}
annotationBuilder.addAttribute(new ArrayAttributeValue<StringAttributeValue>(new JavaSymbolName("excludeFields"), attributes));
}
final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(cid);
cidBuilder.addAnnotation(annotationBuilder.build());
typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
}
Aggregations