Search in sources :

Example 61 with FieldMetadataBuilder

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

Example 62 with FieldMetadataBuilder

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

Example 63 with FieldMetadataBuilder

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

Example 64 with FieldMetadataBuilder

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

Example 65 with FieldMetadataBuilder

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

Aggregations

FieldMetadataBuilder (org.springframework.roo.classpath.details.FieldMetadataBuilder)66 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)48 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)40 ArrayList (java.util.ArrayList)21 JavaType (org.springframework.roo.model.JavaType)19 JdkJavaType (org.springframework.roo.model.JdkJavaType)10 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)8 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)7 FieldDetails (org.springframework.roo.classpath.details.FieldDetails)7 ForeignKey (org.springframework.roo.addon.dbre.addon.model.ForeignKey)5 CommentStructure (org.springframework.roo.classpath.details.comments.CommentStructure)5 JavadocComment (org.springframework.roo.classpath.details.comments.JavadocComment)5 LinkedHashMap (java.util.LinkedHashMap)4 Reference (org.springframework.roo.addon.dbre.addon.model.Reference)4 Table (org.springframework.roo.addon.dbre.addon.model.Table)4 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)4 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)4 CollectionField (org.springframework.roo.classpath.operations.jsr303.CollectionField)4 DateField (org.springframework.roo.classpath.operations.jsr303.DateField)4 EnumDetails (org.springframework.roo.model.EnumDetails)4