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;
}
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));
}
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));
}
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));
}
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);
}
}
Aggregations