use of org.springframework.roo.classpath.details.annotations.AnnotatedJavaType in project spring-roo by spring-projects.
the class RepositoryJpaMetadata method getFinderMethod.
/**
* Method that generates finder method on current interface
*
* @param finderMethod
* @return
*/
private MethodMetadataBuilder getFinderMethod(FinderMethod finderMethod) {
// Define method parameter types and parameter names
List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
for (FinderParameter param : finderMethod.getParameters()) {
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(param.getType()));
parameterNames.add(param.getName());
}
// Add additional Pageable method
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(SpringJavaType.PAGEABLE));
parameterNames.add(new JavaSymbolName("pageable"));
// Use the MethodMetadataBuilder for easy creation of MethodMetadata
MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.ABSTRACT, finderMethod.getMethodName(), finderMethod.getReturnType(), parameterTypes, parameterNames, null);
// Build and return a MethodMetadata
return methodBuilder;
// instance
}
use of org.springframework.roo.classpath.details.annotations.AnnotatedJavaType in project spring-roo by spring-projects.
the class RepositoryJpaMetadata method getFindOneMethod.
private MethodMetadata getFindOneMethod(JavaType entity, FieldMetadata identifierFieldMetadata) {
// Define method parameter type and name
List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(identifierFieldMetadata.getFieldType()));
parameterNames.add(identifierFieldMetadata.getFieldName());
MethodMetadata existingMethod = getGovernorMethod(FIND_ONE_METHOD_NAME, AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes));
if (existingMethod != null) {
return existingMethod;
}
// Use the MethodMetadataBuilder for easy creation of MethodMetadata
return new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.ABSTRACT, FIND_ONE_METHOD_NAME, entity, parameterTypes, parameterNames, null).build();
}
use of org.springframework.roo.classpath.details.annotations.AnnotatedJavaType in project spring-roo by spring-projects.
the class RepositoryJpaMetadata method getCountMethod.
/**
* Method that generates finder method on current interface
*
* @param finderMethod
* @return
*/
private MethodMetadataBuilder getCountMethod(FinderMethod finderMethod) {
// Define method parameter types and parameter names
List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
for (FinderParameter param : finderMethod.getParameters()) {
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(param.getType()));
parameterNames.add(param.getName());
}
// Create count method name
String countName = finderMethod.getMethodName().getSymbolName();
if (StringUtils.startsWith(countName, "find")) {
countName = StringUtils.removeStart(countName, "find");
} else if (StringUtils.startsWith(countName, "query")) {
countName = StringUtils.removeStart(countName, "query");
} else if (StringUtils.startsWith(countName, "read")) {
countName = StringUtils.removeStart(countName, "read");
}
countName = "count".concat(countName);
JavaSymbolName countMethodName = new JavaSymbolName(countName);
// Use the MethodMetadataBuilder for easy creation of MethodMetadata
MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.ABSTRACT, countMethodName, JavaType.LONG_PRIMITIVE, parameterTypes, parameterNames, null);
// Build and return a MethodMetadata
return methodBuilder;
// instance
}
use of org.springframework.roo.classpath.details.annotations.AnnotatedJavaType in project spring-roo by spring-projects.
the class ServiceImplMetadata method getIdentifierTypeGetterMethod.
/**
* Builds a method which returns the class of the entity identifier JavaType.
*
* @return MethodMetadataBuilder
*/
private MethodMetadata getIdentifierTypeGetterMethod() {
List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
MethodMetadata existingMethod = getGovernorMethod(GET_ID_TYPE_METHOD_NAME, AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes));
if (existingMethod != null) {
return existingMethod;
}
InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
// return IDENTIFIER_TYPE.class;
bodyBuilder.appendFormalLine("return %s.class;", getNameOfJavaType(this.entityIdentifierType));
// Use the MethodMetadataBuilder for easy creation of MethodMetadata
MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, GET_ID_TYPE_METHOD_NAME, JavaType.wrapperOf(JavaType.CLASS, this.serviceMetadata.getIdType()), parameterTypes, parameterNames, bodyBuilder);
// Build and return a MethodMetadata instance
return methodBuilder.build();
}
use of org.springframework.roo.classpath.details.annotations.AnnotatedJavaType in project spring-roo by spring-projects.
the class ServiceImplMetadata method addFieldToConstructor.
/**
* Adds a field to constructor parameters and body
*
* @param bodyBuilder
* @param constructorBuilder
* @param field
* @param lazy
*/
private void addFieldToConstructor(final InvocableMemberBodyBuilder bodyBuilder, final ConstructorMetadataBuilder constructorBuilder, final FieldMetadata field, final boolean lazy) {
final String fieldName = field.getFieldName().getSymbolName();
final JavaType fieldType = field.getFieldType();
if (lazy) {
importResolver.addImport(SpringJavaType.LAZY);
constructorBuilder.addParameterName(field.getFieldName());
constructorBuilder.addParameterType(new AnnotatedJavaType(fieldType, LAZY_ANNOTATION));
} else {
constructorBuilder.addParameter(fieldName, fieldType);
}
bodyBuilder.appendFormalLine(String.format("%s(" + fieldName + ");", getMutatorMethod(field).getMethodName()));
}
Aggregations