Search in sources :

Example 41 with AnnotationAttributeValue

use of org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue 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

AnnotationAttributeValue (org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue)41 ArrayList (java.util.ArrayList)36 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)36 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)31 StringAttributeValue (org.springframework.roo.classpath.details.annotations.StringAttributeValue)23 NestedAnnotationAttributeValue (org.springframework.roo.classpath.details.annotations.NestedAnnotationAttributeValue)22 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)17 ArrayAttributeValue (org.springframework.roo.classpath.details.annotations.ArrayAttributeValue)16 ClassAttributeValue (org.springframework.roo.classpath.details.annotations.ClassAttributeValue)13 JavaType (org.springframework.roo.model.JavaType)13 List (java.util.List)12 EnumAttributeValue (org.springframework.roo.classpath.details.annotations.EnumAttributeValue)11 EnumDetails (org.springframework.roo.model.EnumDetails)11 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)10 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)8 IntegerAttributeValue (org.springframework.roo.classpath.details.annotations.IntegerAttributeValue)7 BooleanAttributeValue (org.springframework.roo.classpath.details.annotations.BooleanAttributeValue)6 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)4 LongAttributeValue (org.springframework.roo.classpath.details.annotations.LongAttributeValue)4 MemberDetails (org.springframework.roo.classpath.scanner.MemberDetails)4