Search in sources :

Example 26 with EnumDetails

use of org.springframework.roo.model.EnumDetails in project spring-roo by spring-projects.

the class DateField method decorateAnnotationsList.

@Override
public void decorateAnnotationsList(final List<AnnotationMetadataBuilder> annotations) {
    super.decorateAnnotationsList(annotations);
    if (past) {
        annotations.add(new AnnotationMetadataBuilder(PAST));
    }
    if (future) {
        annotations.add(new AnnotationMetadataBuilder(FUTURE));
    }
    if (persistenceType != null) {
        // Add JSR 220 @Temporal annotation
        String value = null;
        if (persistenceType == DateFieldPersistenceType.JPA_DATE) {
            value = "DATE";
        } else if (persistenceType == DateFieldPersistenceType.JPA_TIME) {
            value = "TIME";
        } else if (persistenceType == DateFieldPersistenceType.JPA_TIMESTAMP) {
            value = "TIMESTAMP";
        }
        final List<AnnotationAttributeValue<?>> attrs = new ArrayList<AnnotationAttributeValue<?>>();
        attrs.add(new EnumAttributeValue(new JavaSymbolName("value"), new EnumDetails(TEMPORAL_TYPE, new JavaSymbolName(value))));
        annotations.add(new AnnotationMetadataBuilder(TEMPORAL, attrs));
    }
    // Only add a DateTimeFormat annotation if class is not a DTO
    final List<AnnotationAttributeValue<?>> attributes = new ArrayList<AnnotationAttributeValue<?>>();
    if (pattern != null) {
        attributes.add(new StringAttributeValue(new JavaSymbolName("pattern"), pattern));
    } else {
        final String dateStyle = null != dateFormat ? String.valueOf(dateFormat.getShortKey()) : "M";
        final String timeStyle = null != timeFormat ? String.valueOf(timeFormat.getShortKey()) : "-";
        attributes.add(new StringAttributeValue(new JavaSymbolName("style"), dateStyle + timeStyle));
    }
    annotations.add(new AnnotationMetadataBuilder(DATE_TIME_FORMAT, attributes));
}
Also used : AnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) ArrayList(java.util.ArrayList) EnumAttributeValue(org.springframework.roo.classpath.details.annotations.EnumAttributeValue) EnumDetails(org.springframework.roo.model.EnumDetails) StringAttributeValue(org.springframework.roo.classpath.details.annotations.StringAttributeValue) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Aggregations

EnumDetails (org.springframework.roo.model.EnumDetails)26 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)25 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)17 ArrayList (java.util.ArrayList)16 JavaType (org.springframework.roo.model.JavaType)12 AnnotationAttributeValue (org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue)11 EnumAttributeValue (org.springframework.roo.classpath.details.annotations.EnumAttributeValue)11 StringAttributeValue (org.springframework.roo.classpath.details.annotations.StringAttributeValue)9 NestedAnnotationAttributeValue (org.springframework.roo.classpath.details.annotations.NestedAnnotationAttributeValue)7 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)6 RooJavaType (org.springframework.roo.model.RooJavaType)6 ArrayAttributeValue (org.springframework.roo.classpath.details.annotations.ArrayAttributeValue)5 JdkJavaType (org.springframework.roo.model.JdkJavaType)5 List (java.util.List)4 FieldMetadataBuilder (org.springframework.roo.classpath.details.FieldMetadataBuilder)4 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)3 FieldDetails (org.springframework.roo.classpath.details.FieldDetails)3 BooleanAttributeValue (org.springframework.roo.classpath.details.annotations.BooleanAttributeValue)3 ClassAttributeValue (org.springframework.roo.classpath.details.annotations.ClassAttributeValue)3 StringField (org.springframework.roo.classpath.operations.jsr303.StringField)3