Search in sources :

Example 6 with EnumDetails

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

the class AnnotationMetadataUtils method computeAttributeValue.

private static String computeAttributeValue(final AnnotationAttributeValue<?> value, final ImportRegistrationResolver resolver) {
    String attributeValue = null;
    if (value instanceof BooleanAttributeValue) {
        attributeValue = ((BooleanAttributeValue) value).getValue().toString();
    } else if (value instanceof CharAttributeValue) {
        attributeValue = "'" + ((CharAttributeValue) value).getValue().toString() + "'";
    } else if (value instanceof ClassAttributeValue) {
        final JavaType clazz = ((ClassAttributeValue) value).getValue();
        if (resolver == null || resolver.isFullyQualifiedFormRequiredAfterAutoImport(clazz)) {
            attributeValue = clazz.getFullyQualifiedTypeName() + ".class";
        } else {
            attributeValue = clazz.getSimpleTypeName() + ".class";
        }
    } else if (value instanceof DoubleAttributeValue) {
        final DoubleAttributeValue dbl = (DoubleAttributeValue) value;
        if (dbl.isFloatingPrecisionOnly()) {
            attributeValue = dbl.getValue().toString() + "F";
        } else {
            attributeValue = dbl.getValue().toString() + "D";
        }
    } else if (value instanceof EnumAttributeValue) {
        final EnumDetails enumDetails = ((EnumAttributeValue) value).getValue();
        final JavaType clazz = enumDetails.getType();
        if (resolver == null || resolver.isFullyQualifiedFormRequiredAfterAutoImport(clazz)) {
            attributeValue = clazz.getFullyQualifiedTypeName() + "." + enumDetails.getField().getSymbolName();
        } else {
            attributeValue = clazz.getSimpleTypeName() + "." + enumDetails.getField().getSymbolName();
        }
    } else if (value instanceof IntegerAttributeValue) {
        attributeValue = ((IntegerAttributeValue) value).getValue().toString();
    } else if (value instanceof LongAttributeValue) {
        attributeValue = ((LongAttributeValue) value).getValue().toString() + "L";
    } else if (value instanceof StringAttributeValue) {
        attributeValue = "\"" + ((StringAttributeValue) value).getValue() + "\"";
    } else if (value instanceof NestedAnnotationAttributeValue) {
        final AnnotationMetadata annotationMetadata = ((NestedAnnotationAttributeValue) value).getValue();
        final StringBuilder data = new StringBuilder("@");
        final JavaType annotationType = annotationMetadata.getAnnotationType();
        if (resolver == null || resolver.isFullyQualifiedFormRequiredAfterAutoImport(annotationType)) {
            data.append(annotationType.getFullyQualifiedTypeName());
        } else {
            data.append(annotationType.getSimpleTypeName());
        }
        if (!annotationMetadata.getAttributeNames().isEmpty()) {
            data.append("(");
            int i = 0;
            for (final JavaSymbolName attributeName : annotationMetadata.getAttributeNames()) {
                i++;
                if (i > 1) {
                    data.append(", ");
                }
                data.append(attributeName.getSymbolName()).append(" = ");
                data.append(computeAttributeValue(annotationMetadata.getAttribute(attributeName), resolver));
            }
            data.append(")");
        }
        attributeValue = data.toString();
    } else if (value instanceof ArrayAttributeValue<?>) {
        final ArrayAttributeValue<?> array = (ArrayAttributeValue<?>) value;
        final StringBuilder data = new StringBuilder("{ ");
        int i = 0;
        for (final AnnotationAttributeValue<?> val : array.getValue()) {
            i++;
            if (i > 1) {
                data.append(", ");
            }
            data.append(computeAttributeValue(val, resolver));
        }
        data.append(" }");
        attributeValue = data.toString();
    }
    return attributeValue;
}
Also used : ArrayAttributeValue(org.springframework.roo.classpath.details.annotations.ArrayAttributeValue) AnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue) NestedAnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.NestedAnnotationAttributeValue) ClassAttributeValue(org.springframework.roo.classpath.details.annotations.ClassAttributeValue) DoubleAttributeValue(org.springframework.roo.classpath.details.annotations.DoubleAttributeValue) IntegerAttributeValue(org.springframework.roo.classpath.details.annotations.IntegerAttributeValue) CharAttributeValue(org.springframework.roo.classpath.details.annotations.CharAttributeValue) EnumAttributeValue(org.springframework.roo.classpath.details.annotations.EnumAttributeValue) EnumDetails(org.springframework.roo.model.EnumDetails) AnnotationMetadata(org.springframework.roo.classpath.details.annotations.AnnotationMetadata) BooleanAttributeValue(org.springframework.roo.classpath.details.annotations.BooleanAttributeValue) JavaType(org.springframework.roo.model.JavaType) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) LongAttributeValue(org.springframework.roo.classpath.details.annotations.LongAttributeValue) StringAttributeValue(org.springframework.roo.classpath.details.annotations.StringAttributeValue) NestedAnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.NestedAnnotationAttributeValue)

Example 7 with EnumDetails

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

the class AnnotationMetadataBuilder method addEnumAttribute.

public void addEnumAttribute(final String key, final JavaType javaType, final JavaSymbolName enumConstant) {
    final EnumDetails details = new EnumDetails(javaType, enumConstant);
    addAttribute(new EnumAttributeValue(new JavaSymbolName(key), details));
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) EnumDetails(org.springframework.roo.model.EnumDetails)

Example 8 with EnumDetails

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

the class AnnotationMetadataBuilder method addEnumAttribute.

public void addEnumAttribute(final String key, final String fullyQualifiedTypeName, final String enumConstant) {
    final EnumDetails details = new EnumDetails(new JavaType(fullyQualifiedTypeName), new JavaSymbolName(enumConstant));
    addAttribute(new EnumAttributeValue(new JavaSymbolName(key), details));
}
Also used : JavaType(org.springframework.roo.model.JavaType) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) EnumDetails(org.springframework.roo.model.EnumDetails)

Example 9 with EnumDetails

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

the class AnnotationMetadataBuilder method addEnumAttribute.

public void addEnumAttribute(final String key, final JavaType javaType, final String enumConstant) {
    final EnumDetails details = new EnumDetails(javaType, new JavaSymbolName(enumConstant));
    addAttribute(new EnumAttributeValue(new JavaSymbolName(key), details));
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) EnumDetails(org.springframework.roo.model.EnumDetails)

Example 10 with EnumDetails

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

the class ReferenceField method decorateAnnotationsList.

@Override
public void decorateAnnotationsList(final List<AnnotationMetadataBuilder> annotations) {
    super.decorateAnnotationsList(annotations);
    final List<AnnotationAttributeValue<?>> attributes = new ArrayList<AnnotationAttributeValue<?>>();
    // Add cascade if option exists
    if (cascadeType != null) {
        List<EnumAttributeValue> cascadeValues = new ArrayList<EnumAttributeValue>();
        for (Cascade type : cascadeType) {
            cascadeValues.add(new EnumAttributeValue(new JavaSymbolName("cascade"), new EnumDetails(CASCADE_TYPE, new JavaSymbolName(type.name()))));
        }
        attributes.add(new ArrayAttributeValue<EnumAttributeValue>(new JavaSymbolName("cascade"), cascadeValues));
    }
    // Add orphanRemoval if option exists
    if (getOrphanRemoval() != null) {
        attributes.add(new BooleanAttributeValue(new JavaSymbolName("orphanRemoval"), getOrphanRemoval().booleanValue()));
    }
    if (fetch != null) {
        JavaSymbolName value = new JavaSymbolName("EAGER");
        if (fetch == Fetch.LAZY) {
            value = new JavaSymbolName("LAZY");
        }
        attributes.add(new EnumAttributeValue(new JavaSymbolName("fetch"), new EnumDetails(FETCH_TYPE, value)));
    }
    if (mappedBy != null) {
        attributes.add(new StringAttributeValue(new JavaSymbolName("mappedBy"), mappedBy.getSymbolName()));
    }
    switch(cardinality) {
        case ONE_TO_MANY:
            annotations.add(new AnnotationMetadataBuilder(ONE_TO_MANY, attributes));
            break;
        case MANY_TO_MANY:
            annotations.add(new AnnotationMetadataBuilder(MANY_TO_MANY, attributes));
            break;
        case ONE_TO_ONE:
            annotations.add(new AnnotationMetadataBuilder(ONE_TO_ONE, attributes));
            break;
        default:
            annotations.add(new AnnotationMetadataBuilder(MANY_TO_ONE, attributes));
            break;
    }
    // Add additional annotations (if any)
    if (additionaAnnotations != null) {
        annotations.addAll(additionaAnnotations);
    }
}
Also used : AnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue) NestedAnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.NestedAnnotationAttributeValue) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) BooleanAttributeValue(org.springframework.roo.classpath.details.annotations.BooleanAttributeValue) 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) Cascade(org.springframework.roo.classpath.operations.Cascade) 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