@Override protected String stringify(final MethodMetadata object) { return object.getMethodName().getSymbolName(); } });
/** * gets Mvc URL name for a controller method * * @param controller * @param methodName * @return */ public static String getMvcUrlNameFor(JavaType controller, MethodMetadata method) { return getMvcUrlNameFor(controller, method.getMethodName()); }
public boolean hasSameName(final MethodMetadata... otherMethods) { for (final MethodMetadata otherMethod : otherMethods) { if (otherMethod != null && methodName.equals(otherMethod.getMethodName())) { return true; } } return false; }
@Override public int compare(MethodMetadata method1, MethodMetadata method2) { return method1.getMethodName().getSymbolName() .compareTo(method2.getMethodName().getSymbolName()); } };
/** * Indicates if the presented method compiles with the JavaBean conventions * around accessor methods (public, "set" or "is", 0 args etc). * * @param method to evaluate (required) * @return true if the presented method is an accessor, otherwise false */ public static boolean isAccessorMethod(final MethodMetadata method) { Validate.notNull(method, "Method is required"); return (method.getMethodName().getSymbolName().startsWith("get") || method.getMethodName() .getSymbolName().startsWith("is")) && method.getParameterTypes().isEmpty() && Modifier.isPublic(method.getModifier()); }
/** * Indicates if the presented method compiles with the JavaBean conventions * around mutator methods (public, "set", 1 arg etc). * * @param method to evaluate (required) * @return true if the presented method is a mutator, otherwise false */ public static boolean isMutatorMethod(final MethodMetadata method) { Validate.notNull(method, "Method is required"); return method.getMethodName().getSymbolName().startsWith("set") && method.getParameterTypes().size() == 1 && Modifier.isPublic(method.getModifier()); }
public MethodMetadataBuilder(final MethodMetadata existing) { super(existing); init(existing.getMethodName(), existing.getReturnType()); }
public MethodMetadataBuilder(final String declaredbyMetadataId, final MethodMetadata existing) { super(declaredbyMetadataId, existing); init(existing.getMethodName(), existing.getReturnType()); }
/** * Locates a method on the specified {@link MemberHoldingTypeDetails} based * on the method name. * * @param memberHoldingTypeDetails the {@link MemberHoldingTypeDetails} to * search; can be <code>null</code> * @param methodName to locate; can be <code>null</code> * @return the method, or <code>null</code> if the given name was * <code>null</code> or it was simply not found */ public static MethodMetadata getDeclaredMethod( final MemberHoldingTypeDetails memberHoldingTypeDetails, final JavaSymbolName methodName) { if (memberHoldingTypeDetails == null) { return null; } for (final MethodMetadata method : memberHoldingTypeDetails.getDeclaredMethods()) { if (method.getMethodName().equals(methodName)) { return method; } } return null; }
@Override public boolean matchSignature(MethodMetadata otherMethod) { if (methodName.getSymbolName().equals(otherMethod.getMethodName().getSymbolName())) { if (otherMethod.getParameterTypes().size() == getParameterTypes().size()) { List<JavaType> params = AnnotatedJavaType.convertFromAnnotatedJavaTypes(this.getParameterTypes()); List<JavaType> paramsOther = AnnotatedJavaType.convertFromAnnotatedJavaTypes(otherMethod.getParameterTypes()); boolean parametersEquals = true; for (int i = 0; i < params.size(); i++) { if (!params.get(i).equals(paramsOther.get(i))) { parametersEquals = false; } } if (parametersEquals) { return true; } } } return false; }
/** * Returns the `equals` method to be generated * * @return `null` if no generation is required */ private MethodMetadata getEqualsMethod() { MethodMetadata method = getGovernorMethod(EQUALS_METHOD_NAME, OBJECT); if (method != null) { return method; } return generateEqualsMethod(getId(), destination, annotationValues, identifierField == null ? null : getAccessorMethod(identifierField).getMethodName(), locatedFields, builder).build(); }
private void doModification(final MethodMetadata method, final CustomData customData) { final MemberHoldingTypeDetails memberHoldingTypeDetails = memberHoldingTypeDetailsMap.get(method.getDeclaredByMetadataId()); if (memberHoldingTypeDetails != null) { final MethodMetadata matchedMethod = memberHoldingTypeDetails.getMethod(method.getMethodName(), AnnotatedJavaType.convertFromAnnotatedJavaTypes(method.getParameterTypes())); if (matchedMethod != null && !matchedMethod.getCustomData().keySet().containsAll(customData.keySet())) { final TypeDetailsBuilder typeDetailsBuilder = getTypeDetailsBuilder(memberHoldingTypeDetails); typeDetailsBuilder.addDataToMethod(method, customData); changed = true; } } }
/** * Build "findOneForUpdate" method body which delegates on repository * * @param methodToBeImplemented * @return */ private InvocableMemberBodyBuilder buildFindOneForUpdateBody(MethodMetadata methodToBeImplemented) { // Generate body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); final JavaSymbolName param0 = methodToBeImplemented.getParameterNames().get(0); // return entityRepository.findOneDetached(id); bodyBuilder.appendFormalLine("%s %s().%s(%s);", methodToBeImplemented.getReturnType().equals(JavaType.VOID_PRIMITIVE) ? "" : "return", getAccessorMethod(repositoryFieldMetadata).getMethodName(), FIND_ONE_DETACHED.getSymbolName(), param0); return bodyBuilder; }
/** * Method that generates custom count method. * * @return MethodMetadata */ private MethodMetadata getCustomCountMethod(MethodMetadata customCountMethod) { // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.ABSTRACT, customCountMethod.getMethodName(), customCountMethod.getReturnType(), customCountMethod.getParameterTypes(), customCountMethod.getParameterNames(), null); return methodBuilder.build(); // Build and return a MethodMetadata // instance }
/** * Generate the default method body for "createForm" method * * @param bodyBuilder */ protected void generateDefaultCreateFormMethodBody(InvocableMemberBodyBuilder bodyBuilder) { // populateForm(model); bodyBuilder.appendFormalLine("%s(model);", populateFormMethod.getMethodName()); bodyBuilder.newLine(); // model.addAttribute("entity", new Entity()); bodyBuilder.appendFormalLine(String.format("model.addAttribute(\"%s\", new %s());", StringUtils.uncapitalize(getNameOfJavaType(this.entity)), getNameOfJavaType(this.entity))); // return "path/create"; bodyBuilder.appendFormalLine("return new %s(\"%s/create\");", getNameOfJavaType(SpringJavaType.MODEL_AND_VIEW), viewsPath); }
/** * Method that generates finder method on current interface * * @param finderMethod * @return */ private MethodMetadata getFinderMethod(MethodMetadata finderMethod) { // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.ABSTRACT, finderMethod.getMethodName(), finderMethod.getReturnType(), finderMethod.getParameterTypes(), finderMethod.getParameterNames(), null); return methodBuilder.build(); // Build and return a MethodMetadata // instance }
/** * Generate default method body for "createForm" method of a details controller * * @param entity * @param bodyBuilder */ protected void generateDefaultCreateFormDetailsBody(final JavaType entity, InvocableMemberBodyBuilder bodyBuilder) { // populateForm(model); bodyBuilder.appendFormalLine("%s(model);", populateFormMethod.getMethodName()); // model.addAttribute("entity", new Entity()); bodyBuilder.appendFormalLine(String.format("model.addAttribute(\"%s\", new %s());", StringUtils.uncapitalize(getNameOfJavaType(entity)), getNameOfJavaType(entity))); // return new ModelAndView("path/create"); bodyBuilder.appendFormalLine("return new %s(\"%s/%s/create\");", getNameOfJavaType(SpringJavaType.MODEL_AND_VIEW), viewsPath, controllerMetadata.getDetailsPathAsString("/")); }
public void addMethodAnnotation( final DeclaredMethodAnnotationDetails declaredMethodAnnotationDetails) { if (declaredMethodAnnotationDetails == null) { return; } final boolean hasAnnotation = MemberFindingUtils.getAnnotationOfType(declaredMethodAnnotationDetails.getMethodMetadata() .getAnnotations(), declaredMethodAnnotationDetails.getMethodAnnotation() .getAnnotationType()) != null; Validate.isTrue(!hasAnnotation, "Method annotation '@%s' is already present on the target field '%s' (ITD target '%s')", declaredMethodAnnotationDetails.getMethodAnnotation().getAnnotationType() .getSimpleTypeName(), declaredMethodAnnotationDetails.getMethodMetadata() .getMethodName().getSymbolName(), aspect.getFullyQualifiedTypeName()); methodAnnotations.add(declaredMethodAnnotationDetails); }
public void addDataToMethod(final MethodMetadata replacement, final CustomData customData) { // If the MIDs don't match then the proposed can't be a replacement if (!replacement.getDeclaredByMetadataId().equals(getDeclaredByMetadataId())) { return; } for (final MethodMetadataBuilder existingMethod : getDeclaredMethods()) { if (existingMethod.getMethodName().equals(replacement.getMethodName())) { if (AnnotatedJavaType.convertFromAnnotatedJavaTypes(existingMethod.getParameterTypes()) .equals( AnnotatedJavaType.convertFromAnnotatedJavaTypes(replacement.getParameterTypes()))) { for (final Object key : customData.keySet()) { existingMethod.putCustomData(key, customData.get(key)); } break; } } } }
/** * Builds and returns a class constructor which injects * {@link EntityManager} field. * * @return a ConstructorMetadataBuilder to add to ITD. */ private ConstructorMetadataBuilder getConstructor() { // Create instance and add parameters ConstructorMetadataBuilder constructorBuilder = new ConstructorMetadataBuilder(this.getId()); constructorBuilder.addParameter(ENTITY_MANAGER_FIELD_NAME, JpaJavaType.ENTITY_MANAGER); // Add body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.appendFormalLine("%1$s(%2$s);", getMutatorMethod(getEntityManagerField().build()) .getMethodName(), ENTITY_MANAGER_FIELD_NAME); constructorBuilder.setBodyBuilder(bodyBuilder); constructorBuilder.setModifier(Modifier.PUBLIC); // Add @Autowired constructorBuilder.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.AUTOWIRED)); return constructorBuilder; }