use of org.springframework.roo.classpath.details.FieldMetadataBuilder in project spring-roo by spring-projects.
the class JSONMixinMetadata method getDeseralizerFieldFor.
private FieldMetadataBuilder getDeseralizerFieldFor(FieldMetadata field, JavaType deserializer) {
AnnotationMetadataBuilder annotation = new AnnotationMetadataBuilder(JSON_DESERIALIZE);
annotation.addClassAttribute("using", deserializer);
return new FieldMetadataBuilder(getId(), Modifier.PRIVATE, Arrays.asList(annotation), field.getFieldName(), field.getFieldType());
}
use of org.springframework.roo.classpath.details.FieldMetadataBuilder in project spring-roo by spring-projects.
the class ExceptionsMetadata method getLoggerField.
public FieldMetadata getLoggerField() {
InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
bodyBuilder.append(getNameOfJavaType(LOGGER_FACTORY_JAVA_TYPE));
bodyBuilder.append(".getLogger(");
bodyBuilder.append(governorPhysicalTypeMetadata.getType().getSimpleTypeName());
bodyBuilder.append(".class)");
final String initializer = bodyBuilder.getOutput();
FieldMetadataBuilder field = new FieldMetadataBuilder(getId(), Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL, new JavaSymbolName("LOG"), LOGGER_JAVA_TYPE, initializer);
return field.build();
}
use of org.springframework.roo.classpath.details.FieldMetadataBuilder in project spring-roo by spring-projects.
the class IdentifierMetadata method getParameterizedConstructor.
/**
* Locates the parameterised constructor consisting of the id fields for
* this class.
*
* @param fields
* @return the constructor, never null.
*/
private ConstructorMetadataBuilder getParameterizedConstructor(final List<FieldMetadataBuilder> fields) {
// Search for an existing constructor
final List<JavaType> parameterTypes = new ArrayList<JavaType>();
for (final FieldMetadataBuilder field : fields) {
parameterTypes.add(field.getFieldType());
}
final ConstructorMetadata result = governorTypeDetails.getDeclaredConstructor(parameterTypes);
if (result != null) {
// Found an existing parameterised constructor on this class
publicNoArgConstructor = true;
return null;
}
final List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
bodyBuilder.appendFormalLine("super();");
for (final FieldMetadataBuilder field : fields) {
final String fieldName = field.getFieldName().getSymbolName();
bodyBuilder.appendFormalLine("this." + fieldName + " = " + fieldName + ";");
parameterNames.add(field.getFieldName());
}
// Create the constructor
final ConstructorMetadataBuilder constructorBuilder = new ConstructorMetadataBuilder(getId());
constructorBuilder.setModifier(Modifier.PUBLIC);
constructorBuilder.setParameterTypes(AnnotatedJavaType.convertFromJavaTypes(parameterTypes));
constructorBuilder.setParameterNames(parameterNames);
constructorBuilder.setBodyBuilder(bodyBuilder);
return constructorBuilder;
}
use of org.springframework.roo.classpath.details.FieldMetadataBuilder in project spring-roo by spring-projects.
the class IdentifierMetadata method getMutators.
/**
* Locates the mutator methods.
* <p>
* If {@link #getFieldBuilders()} returns fields created by this ITD, public
* mutators will automatically be produced in the declaring class.
*
* @param fields
* @return the mutators (never returns null)
*/
private List<MethodMetadataBuilder> getMutators(final List<FieldMetadataBuilder> fields) {
final List<MethodMetadataBuilder> mutators = new ArrayList<MethodMetadataBuilder>();
// Compute the names of the mutators that will be produced
for (final FieldMetadataBuilder field : fields) {
final JavaSymbolName requiredMutatorName = BeanInfoUtils.getMutatorMethodName(field.getFieldName());
final JavaType parameterType = field.getFieldType();
final MethodMetadata mutator = getGovernorMethod(requiredMutatorName, parameterType);
if (mutator == null) {
mutators.add(getMutatorMethod(field.getFieldName(), field.getFieldType()));
} else {
Validate.isTrue(Modifier.isPublic(mutator.getModifier()), "User provided field but failed to provide a public '%s(%s)' method in '%s'", requiredMutatorName.getSymbolName(), field.getFieldName().getSymbolName(), destination.getFullyQualifiedTypeName());
mutators.add(new MethodMetadataBuilder(mutator));
}
}
return mutators;
}
use of org.springframework.roo.classpath.details.FieldMetadataBuilder in project spring-roo by spring-projects.
the class IdentifierMetadata method getFieldBuilders.
/**
* Locates declared fields.
* <p>
* If no parent is defined, one will be located or created. All declared
* fields will be returned.
*
* @return fields (never returns null)
*/
private List<FieldMetadataBuilder> getFieldBuilders() {
// Locate all declared fields
final List<? extends FieldMetadata> declaredFields = governorTypeDetails.getDeclaredFields();
// Add fields to ITD from annotation
final List<FieldMetadata> fields = new ArrayList<FieldMetadata>();
if (identifierServiceResult != null) {
for (final Identifier identifier : identifierServiceResult) {
final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
annotations.add(getColumnBuilder(identifier));
if (identifier.getFieldType().equals(DATE)) {
setDateAnnotations(identifier.getColumnDefinition(), annotations);
}
final FieldMetadata idField = new FieldMetadataBuilder(getId(), Modifier.PRIVATE, annotations, identifier.getFieldName(), identifier.getFieldType()).build();
// Only add field to ITD if not declared on governor
if (!hasField(declaredFields, idField)) {
fields.add(idField);
}
}
}
fields.addAll(declaredFields);
// Remove fields with static and transient modifiers
for (final Iterator<FieldMetadata> iter = fields.iterator(); iter.hasNext(); ) {
final FieldMetadata field = iter.next();
if (Modifier.isStatic(field.getModifier()) || Modifier.isTransient(field.getModifier())) {
iter.remove();
}
}
// Remove fields with the @Transient annotation
final List<FieldMetadata> transientAnnotatedFields = governorTypeDetails.getFieldsWithAnnotation(TRANSIENT);
if (fields.containsAll(transientAnnotatedFields)) {
fields.removeAll(transientAnnotatedFields);
}
final List<FieldMetadataBuilder> fieldBuilders = new ArrayList<FieldMetadataBuilder>();
if (!fields.isEmpty()) {
for (final FieldMetadata field : fields) {
fieldBuilders.add(new FieldMetadataBuilder(field));
}
return fieldBuilders;
}
// We need to create a default identifier field
final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
// Compute the column name, as required
final AnnotationMetadataBuilder columnBuilder = new AnnotationMetadataBuilder(COLUMN);
columnBuilder.addStringAttribute("name", "id");
columnBuilder.addBooleanAttribute("nullable", false);
annotations.add(columnBuilder);
fieldBuilders.add(new FieldMetadataBuilder(getId(), Modifier.PRIVATE, annotations, new JavaSymbolName("id"), LONG_OBJECT));
return fieldBuilders;
}
Aggregations