use of org.springframework.roo.classpath.details.MethodMetadataBuilder in project spring-roo by spring-projects.
the class AbstractItdTypeDetailsProvidingMetadataItem method getMethod.
/**
* Returns a public method given the method name, return type, parameter
* types, parameter names, and method body.
*
* @param modifier the method modifier
* @param methodName the method name
* @param returnType the return type
* @param parameterTypes a list of parameter types
* @param parameterNames a list of parameter names
* @param bodyBuilder the method body
* @return null if the method exists on the governor, otherwise a new method
* is returned
*/
protected MethodMetadataBuilder getMethod(final int modifier, final JavaSymbolName methodName, final JavaType returnType, final List<JavaType> parameterTypes, final List<JavaSymbolName> parameterNames, final InvocableMemberBodyBuilder bodyBuilder) {
final MethodMetadata method = getGovernorMethod(methodName, parameterTypes);
if (method != null) {
return null;
}
addToImports(parameterTypes);
return new MethodMetadataBuilder(getId(), modifier, methodName, returnType, AnnotatedJavaType.convertFromJavaTypes(parameterTypes), parameterNames, bodyBuilder);
}
use of org.springframework.roo.classpath.details.MethodMetadataBuilder in project spring-roo by spring-projects.
the class AbstractItdTypeDetailsProvidingMetadataItem method getMutatorMethod.
protected MethodMetadata getMutatorMethod(final FieldMetadata field) {
// Check if the mutator has been cached
MethodMetadataBuilder mutator = mutatorMethods.get(field);
if (mutator == null) {
mutator = getMutatorMethod(field.getFieldName(), field.getFieldType());
mutatorMethods.put(field, mutator);
}
// Return governor method
if (mutator == null) {
return getGovernorMethod(BeanInfoUtils.getMutatorMethodName(field.getFieldName()), field.getFieldType());
}
return mutator.build();
}
use of org.springframework.roo.classpath.details.MethodMetadataBuilder in project spring-roo by spring-projects.
the class AbstractItdTypeDetailsProvidingMetadataItem method getAccessorMethod.
protected MethodMetadata getAccessorMethod(final FieldMetadata field) {
// Check if this method has been cached
MethodMetadataBuilder accessor = accessorMethods.get(field);
if (accessor == null) {
accessor = getAccessorMethod(field, InvocableMemberBodyBuilder.getInstance().appendFormalLine("return " + field.getFieldName().getSymbolName() + ";"));
accessorMethods.put(field, accessor);
}
// Return governor method if exists
if (accessor == null) {
return getGovernorMethod(BeanInfoUtils.getAccessorMethodName(field));
}
return accessor.build();
}
use of org.springframework.roo.classpath.details.MethodMetadataBuilder in project spring-roo by spring-projects.
the class EqualsMetadata method generateHashCodeMethod.
/**
* Generate hashCode method
*
* @param metadataId
* @param annotationValues
* @param locatedFields
* @param importRegistrationResolver
* @return
*/
protected static MethodMetadataBuilder generateHashCodeMethod(String metadataId, EqualsAnnotationValues annotationValues, List<FieldMetadata> locatedFields, ImportRegistrationResolver importRegistrationResolver) {
// Create the method
final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
StringBuilder builder = null;
if (annotationValues.isJpaEntity()) {
builder = getJpaEntityHashCodeMethodReturnStatment();
} else {
builder = getDefaultHashCodeMethodReturnStatment(annotationValues, locatedFields, importRegistrationResolver);
}
bodyBuilder.appendFormalLine(builder.toString());
MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(metadataId, Modifier.PUBLIC, HASH_CODE_METHOD_NAME, INT_PRIMITIVE, bodyBuilder);
if (annotationValues.isJpaEntity()) {
CommentStructure commentStructure = new CommentStructure();
commentStructure.addComment(new JavadocComment("This `hashCode` implementation is specific for JPA entities and uses a fixed `int` value to be able ".concat(IOUtils.LINE_SEPARATOR).concat("to identify the entity in collections after a new id is assigned to the entity, following the article in ").concat(IOUtils.LINE_SEPARATOR).concat("https://vladmihalcea.com/2016/06/06/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/")), CommentLocation.BEGINNING);
methodBuilder.setCommentStructure(commentStructure);
}
return methodBuilder;
}
use of org.springframework.roo.classpath.details.MethodMetadataBuilder in project spring-roo by spring-projects.
the class JavaBeanMetadata method checkIfInterfaceMethodWasImplemented.
/**
* To check if current method was implemented on all Java classes or ITds
* associated to this entity class.
* If method was implemented, is not necessary to add again.
*
* @param methodBuilder
* @return
*/
private boolean checkIfInterfaceMethodWasImplemented(MethodMetadataBuilder methodBuilder) {
// ROO-3584: Obtain current declared methods
List<MethodMetadataBuilder> declaredMethods = builder.getDeclaredMethods();
for (MethodMetadataBuilder method : declaredMethods) {
// If current method equals to interface method, return false
if (method.getMethodName().equals(methodBuilder.getMethodName())) {
return true;
}
}
// ROO-3587: Obtain ALL declared methods from Java classes and ITDs.
MemberDetails memberDetails = memberDetailsScanner.getMemberDetails(getClass().getName(), governorTypeDetails);
List<MethodMetadata> allMethods = memberDetails.getMethods();
for (MethodMetadata method : allMethods) {
// If current method equals to interface method, return false
if (method.getMethodName().equals(methodBuilder.getMethodName())) {
return true;
}
}
return false;
}
Aggregations