Search in sources :

Example 26 with AnnotationMetadataBuilder

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;
        }
    }
}
Also used : DeclaredFieldAnnotationDetails(org.springframework.roo.classpath.details.DeclaredFieldAnnotationDetails) AnnotationMetadata(org.springframework.roo.classpath.details.annotations.AnnotationMetadata) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 27 with AnnotationMetadataBuilder

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));
}
Also used : ArrayList(java.util.ArrayList) ClassOrInterfaceTypeDetailsBuilder(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder) Dependency(org.springframework.roo.project.Dependency) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 28 with AnnotationMetadataBuilder

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());
}
Also used : JdkJavaType(org.springframework.roo.model.JdkJavaType) RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) ArrayList(java.util.ArrayList) ClassOrInterfaceTypeDetailsBuilder(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 29 with AnnotationMetadataBuilder

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();
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) ArrayList(java.util.ArrayList) FieldDetails(org.springframework.roo.classpath.details.FieldDetails) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder) FieldMetadataBuilder(org.springframework.roo.classpath.details.FieldMetadataBuilder)

Example 30 with AnnotationMetadataBuilder

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());
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) ArrayList(java.util.ArrayList) ClassOrInterfaceTypeDetailsBuilder(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) StringAttributeValue(org.springframework.roo.classpath.details.annotations.StringAttributeValue) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Aggregations

AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)232 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)155 ArrayList (java.util.ArrayList)129 InvocableMemberBodyBuilder (org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder)90 MethodMetadataBuilder (org.springframework.roo.classpath.details.MethodMetadataBuilder)87 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)81 JavaType (org.springframework.roo.model.JavaType)78 MethodMetadata (org.springframework.roo.classpath.details.MethodMetadata)73 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)54 SpringJavaType (org.springframework.roo.model.SpringJavaType)47 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)42 FieldMetadataBuilder (org.springframework.roo.classpath.details.FieldMetadataBuilder)40 JdkJavaType (org.springframework.roo.model.JdkJavaType)39 AnnotationAttributeValue (org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue)31 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)30 RooJavaType (org.springframework.roo.model.RooJavaType)28 SpringletsJavaType (org.springframework.roo.model.SpringletsJavaType)28 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)26 Jsr303JavaType (org.springframework.roo.model.Jsr303JavaType)25 StringAttributeValue (org.springframework.roo.classpath.details.annotations.StringAttributeValue)23