/** * 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); }
protected MethodMetadataBuilder getAccessorMethod(final JavaSymbolName fieldName, final JavaType fieldType) { return getAccessorMethod(fieldName, fieldType, InvocableMemberBodyBuilder.getInstance() .appendFormalLine("return " + fieldName + ";")); }
protected FieldMetadataBuilder getField(final JavaSymbolName fieldName, final JavaType fieldType) { return getField(PRIVATE, fieldName, fieldType, null); }
/** * Convenience method for returning a simple private field based on the * field name, type, and initializer. * * @param fieldName the field name * @param fieldType the field type * @param fieldInitializer the string to initialize the field with * @return null if the field exists on the governor, otherwise a new field * with the given field name and type */ protected FieldMetadataBuilder getField(final int modifier, final JavaSymbolName fieldName, final JavaType fieldType, final String fieldInitializer) { if (governorTypeDetails.getField(fieldName) != null) { return null; } addToImports(Arrays.asList(fieldType)); return new FieldMetadataBuilder(getId(), modifier, fieldName, fieldType, fieldInitializer); }
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(); }
/** * Ensures that the governor has provided method * * @param MethodMetadataBuilder the method to include(required) * @since 2.0 */ protected final void ensureGovernorHasMethod(final MethodMetadataBuilder methodMetadata) { if (!hasToExcludeMethod(methodMetadata) && governorTypeDetails.getMethod(methodMetadata.getMethodName(), AnnotatedJavaType.convertFromAnnotatedJavaTypes(methodMetadata.getParameterTypes())) == null && methodMetadata.getDeclaredByMetadataId().equals(getId()) && MemberFindingUtils.getDeclaredMethod(builder.build(), methodMetadata.getMethodName(), AnnotatedJavaType.convertFromAnnotatedJavaTypes(methodMetadata.getParameterTypes())) == null) { builder.addMethod(methodMetadata); } }
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(); }
/** * Ensures that the governor has provided field. You could indicates if * is necessary to generate the accessor and the mutator methods for this new field manually. * * @param FieldMetadataBuilder the field to include(required) * @since 2.0 */ protected final void ensureGovernorHasField(final FieldMetadataBuilder fieldMetadata, boolean includeAccessor, boolean includeMutator) { if (governorTypeDetails.getField(fieldMetadata.getFieldName()) == null) { builder.addField(fieldMetadata); } if (includeAccessor) { MethodMetadata accessorMethod = getAccessorMethod(fieldMetadata.build()); if (accessorMethod != null && governorTypeDetails.getMethod(accessorMethod.getMethodName()) == null) { builder.addMethod(accessorMethod); } } if (includeMutator) { MethodMetadata mutatorMethod = getMutatorMethod(fieldMetadata.build()); if (mutatorMethod != null && governorTypeDetails.getMethod(mutatorMethod.getMethodName()) == null) { builder.addMethod(mutatorMethod); } } }
protected MethodMetadataBuilder getAccessorMethod(final JavaSymbolName fieldName, final JavaType fieldType, final InvocableMemberBodyBuilder bodyBuilder) { return getMethod(PUBLIC, BeanInfoUtils.getAccessorMethodName(fieldName, fieldType), fieldType, null, null, bodyBuilder); }
/** * Indicates whether the governor has a method with the given signature. * * @param methodName the name of the method for which to search * @param parameterTypes the method's parameter types * @return see above * @since 1.2.0 */ protected boolean governorHasMethod(final JavaSymbolName methodName, final JavaType... parameterTypes) { return getGovernorMethod(methodName, parameterTypes) != null; }
@Override public String toString() { final ToStringBuilder builder = new ToStringBuilder(this); builder.append("identifier", getId()); builder.append("valid", valid); builder.append("aspectName", aspectName); builder.append("governor", governorPhysicalTypeMetadata.getId()); builder.append("itdTypeDetails", itdTypeDetails); return builder.toString(); }
protected MethodMetadataBuilder getMutatorMethod(final JavaSymbolName fieldName, final JavaType parameterType) { return getMutatorMethod( fieldName, parameterType, InvocableMemberBodyBuilder.getInstance().appendFormalLine( "this." + fieldName.getSymbolName() + " = " + fieldName.getSymbolName() + ";")); }
/** * Returns String which represents type inside ITD * * Delegates on {@link JavaType#getNameIncludingTypeParameters(boolean, org.springframework.roo.model.ImportRegistrationResolver)} * (asStatic = false) * * @param type * @return */ protected String getNameOfJavaType(JavaType type) { return getNameOfJavaType(type, false); }
/** * Ensures that the governor has provided field. If the provided field is private, * this method always includes the accessor method. The mutator method will not be * generated if the provided field is annotated with @Autowired annotation * * @param FieldMetadataBuilder the field to include(required) * @since 2.0 */ protected final void ensureGovernorHasField(final FieldMetadataBuilder fieldMetadata) { boolean includeAccessor = false; boolean includeMutator = false; int modifier = fieldMetadata.getModifier(); if (modifier >= Modifier.PRIVATE && modifier <= Modifier.PRIVATE + Modifier.STATIC + Modifier.FINAL && modifier % 2 == 0) { includeAccessor = true; if (fieldMetadata.getDeclaredTypeAnnotation(SpringJavaType.AUTOWIRED) == null && modifier < Modifier.FINAL) { includeMutator = true; } } ensureGovernorHasField(fieldMetadata, includeAccessor, includeMutator); }
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(); }
/** * Ensures that the governor has provided method * * @param MethodMetadataBuilder the method to include(required) * @since 2.0 */ protected final void ensureGovernorHasMethod(final MethodMetadataBuilder methodMetadata) { if (!hasToExcludeMethod(methodMetadata) && governorTypeDetails.getMethod(methodMetadata.getMethodName(), AnnotatedJavaType.convertFromAnnotatedJavaTypes(methodMetadata.getParameterTypes())) == null && methodMetadata.getDeclaredByMetadataId().equals(getId()) && MemberFindingUtils.getDeclaredMethod(builder.build(), methodMetadata.getMethodName(), AnnotatedJavaType.convertFromAnnotatedJavaTypes(methodMetadata.getParameterTypes())) == null) { builder.addMethod(methodMetadata); } }
/** * Convenience method for returning a simple private field based on the * field name, type, and initializer. * * @param fieldName the field name * @param fieldType the field type * @param fieldInitializer the string to initialize the field with * @return null if the field exists on the governor, otherwise a new field * with the given field name and type */ protected FieldMetadataBuilder getField(final int modifier, final JavaSymbolName fieldName, final JavaType fieldType, final String fieldInitializer) { if (governorTypeDetails.getField(fieldName) != null) { return null; } addToImports(Arrays.asList(fieldType)); return new FieldMetadataBuilder(getId(), modifier, fieldName, fieldType, fieldInitializer); }
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(); }
/** * Ensures that the governor has provided field. You could indicates if * is necessary to generate the accessor and the mutator methods for this new field manually. * * @param FieldMetadataBuilder the field to include(required) * @since 2.0 */ protected final void ensureGovernorHasField(final FieldMetadataBuilder fieldMetadata, boolean includeAccessor, boolean includeMutator) { if (governorTypeDetails.getField(fieldMetadata.getFieldName()) == null) { builder.addField(fieldMetadata); } if (includeAccessor) { MethodMetadata accessorMethod = getAccessorMethod(fieldMetadata.build()); if (accessorMethod != null && governorTypeDetails.getMethod(accessorMethod.getMethodName()) == null) { builder.addMethod(accessorMethod); } } if (includeMutator) { MethodMetadata mutatorMethod = getMutatorMethod(fieldMetadata.build()); if (mutatorMethod != null && governorTypeDetails.getMethod(mutatorMethod.getMethodName()) == null) { builder.addMethod(mutatorMethod); } } }
protected MethodMetadataBuilder getMutatorMethod(final JavaSymbolName fieldName, final JavaType parameterType, final InvocableMemberBodyBuilder bodyBuilder) { return getMethod(PUBLIC, BeanInfoUtils.getMutatorMethodName(fieldName), JavaType.VOID_PRIMITIVE, Arrays.asList(parameterType), Arrays.asList(fieldName), bodyBuilder); }