Skip to content

Commit

Permalink
ROO-2579: Post 1.1.5.RELEASE code refactor and clean up - created Spr…
Browse files Browse the repository at this point in the history
…ingJavaType class with JavaType constants for common Spring types; applied these constants throughout
  • Loading branch information
Andrew Swan committed Aug 18, 2011
1 parent df541aa commit 8b90f06
Show file tree
Hide file tree
Showing 27 changed files with 481 additions and 293 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.springframework.roo.addon.configurable;

import static org.springframework.roo.model.SpringJavaType.CONFIGURABLE;

import org.springframework.roo.classpath.PhysicalTypeIdentifierNamingUtils;
import org.springframework.roo.classpath.PhysicalTypeMetadata;
import org.springframework.roo.classpath.details.MemberFindingUtils;
Expand All @@ -19,6 +21,8 @@
* @since 1.0
*/
public class ConfigurableMetadata extends AbstractItdTypeDetailsProvidingMetadataItem {

// Constants
private static final String PROVIDES_TYPE_STRING = ConfigurableMetadata.class.getName();
private static final String PROVIDES_TYPE = MetadataIdentificationUtils.create(PROVIDES_TYPE_STRING);

Expand All @@ -45,14 +49,12 @@ public ConfigurableMetadata(String identifier, JavaType aspectName, PhysicalType
* @return the annotation is already exists or will be created, or null if it will not be created (required)
*/
public AnnotationMetadata getConfigurableAnnotation() {
JavaType javaType = new JavaType("org.springframework.beans.factory.annotation.Configurable");

if (isConfigurableAnnotationIntroduced()) {
AnnotationMetadataBuilder annotationBuilder = new AnnotationMetadataBuilder(javaType);
AnnotationMetadataBuilder annotationBuilder = new AnnotationMetadataBuilder(CONFIGURABLE);
return annotationBuilder.build();
}

return MemberFindingUtils.getDeclaredTypeAnnotation(governorTypeDetails, javaType);
return MemberFindingUtils.getDeclaredTypeAnnotation(governorTypeDetails, CONFIGURABLE);
}

/**
Expand All @@ -62,8 +64,7 @@ public AnnotationMetadata getConfigurableAnnotation() {
* @return true if it will be introduced, false otherwise
*/
public boolean isConfigurableAnnotationIntroduced() {
JavaType javaType = new JavaType("org.springframework.beans.factory.annotation.Configurable");
AnnotationMetadata result = MemberFindingUtils.getDeclaredTypeAnnotation(governorTypeDetails, javaType);
AnnotationMetadata result = MemberFindingUtils.getDeclaredTypeAnnotation(governorTypeDetails, CONFIGURABLE);
return result == null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.springframework.roo.addon.dbre;

import static org.springframework.roo.model.RooJavaType.ROO_TO_STRING;
import static org.springframework.roo.model.SpringJavaType.DATE_TIME_FORMAT;

import java.lang.reflect.Modifier;
import java.util.ArrayList;
Expand Down Expand Up @@ -672,7 +673,7 @@ private FieldMetadata getField(JavaSymbolName fieldName, Column column, String t
temporalBuilder.addEnumAttribute(VALUE, new EnumDetails(new JavaType("javax.persistence.TemporalType"), new JavaSymbolName(column.getJdbcType())));
annotations.add(temporalBuilder);

AnnotationMetadataBuilder dateTimeFormatBuilder = new AnnotationMetadataBuilder(new JavaType("org.springframework.format.annotation.DateTimeFormat"));
AnnotationMetadataBuilder dateTimeFormatBuilder = new AnnotationMetadataBuilder(DATE_TIME_FORMAT);
dateTimeFormatBuilder.addStringAttribute("style", "M-");
annotations.add(dateTimeFormatBuilder);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.springframework.roo.addon.dod;

import static org.springframework.roo.model.SpringJavaType.AUTOWIRED;
import static org.springframework.roo.model.SpringJavaType.COMPONENT;

import java.lang.reflect.Modifier;
import java.math.BigDecimal;
import java.util.ArrayList;
Expand Down Expand Up @@ -54,7 +57,6 @@ public class DataOnDemandMetadata extends AbstractItdTypeDetailsProvidingMetadat
// Constants
private static final JavaType BIG_DECIMAL = new JavaType("java.math.BigDecimal");
private static final JavaType BIG_INTEGER = new JavaType("java.math.BigInteger");
private static final JavaType COMPONENT = new JavaType("org.springframework.stereotype.Component");
private static final JavaType MAX = new JavaType("javax.validation.constraints.Max");
private static final JavaType MIN = new JavaType("javax.validation.constraints.Min");
private static final JavaType SIZE = new JavaType("javax.validation.constraints.Size");
Expand Down Expand Up @@ -266,7 +268,7 @@ private void addCollaboratingDoDFieldsToBuilder() {
// We really expect the field to be correct if we're going to rely on it
Assert.isTrue(candidate.getFieldType().equals(collaboratorType), "Field '" + collaboratingFieldName + "' on '" + destination.getFullyQualifiedTypeName() + "' must be of type '" + collaboratorType.getFullyQualifiedTypeName() + "'");
Assert.isTrue(Modifier.isPrivate(candidate.getModifier()), "Field '" + collaboratingFieldName + "' on '" + destination.getFullyQualifiedTypeName() + "' must be private");
Assert.notNull(MemberFindingUtils.getAnnotationOfType(candidate.getAnnotations(), new JavaType("org.springframework.beans.factory.annotation.Autowired")), "Field '" + collaboratingFieldName + "' on '" + destination.getFullyQualifiedTypeName() + "' must be @Autowired");
Assert.notNull(MemberFindingUtils.getAnnotationOfType(candidate.getAnnotations(), AUTOWIRED), "Field '" + collaboratingFieldName + "' on '" + destination.getFullyQualifiedTypeName() + "' must be @Autowired");
// It's ok, so we can move onto the new field
continue;
}
Expand All @@ -275,7 +277,7 @@ private void addCollaboratingDoDFieldsToBuilder() {
if (!fields.contains(fieldSymbolName)) {
// Must make the field
List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
annotations.add(new AnnotationMetadataBuilder(new JavaType("org.springframework.beans.factory.annotation.Autowired")));
annotations.add(new AnnotationMetadataBuilder(AUTOWIRED));
FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(getId(), Modifier.PRIVATE, annotations, fieldSymbolName, collaboratorType);
FieldMetadata field = fieldBuilder.build();
builder.addField(field);
Expand Down
Loading

0 comments on commit 8b90f06

Please sign in to comment.