final JavaSymbolName methodName = new JavaSymbolName("show"); parameterTypes.add(new AnnotatedJavaType(entity, ANN_MODEL_ATTRIBUTE)); parameterNames.add(new JavaSymbolName(entityItemName)); AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes)); if (existingMethod != null) { return existingMethod; AnnotationMetadataBuilder getMappingAnnotation = new AnnotationMetadataBuilder(GET_MAPPING); getMappingAnnotation.addStringAttribute("name", methodName.getSymbolName()); annotations.add(getMappingAnnotation); InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.appendFormalLine("return %s.ok(%s);", getNameOfJavaType(RESPONSE_ENTITY), entityItemName); new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, JavaType.wrapperWilcard(RESPONSE_ENTITY), parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); return methodBuilder.build();
/** * Obtains a method annotated with @After for doing the test class teardown phase * after finishing each test. * * @return {@link MethodMetadataBuilder} */ private MethodMetadataBuilder getCleanMethod() { final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.newLine(); bodyBuilder.appendFormalLine("// Clean needed after executing each test method"); bodyBuilder.appendFormalLine("// To be implemented by developer"); bodyBuilder.newLine(); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, new JavaSymbolName("clean"), JavaType.VOID_PRIMITIVE, bodyBuilder); // Add @After methodBuilder.addAnnotation(new AnnotationMetadataBuilder(AFTER).build()); // Add comment CommentStructure comment = new CommentStructure(); JavadocComment javaDocComment = new JavadocComment( "This method will be automatically executed after each test method for freeing resources allocated with @Before annotated method."); comment.addComment(javaDocComment, CommentLocation.BEGINNING); methodBuilder.setCommentStructure(comment); return methodBuilder; }
for (AnnotatedJavaType type : seiMethod.getParameterTypes()) { parameters.add(type.getJavaType()); new MethodMetadataBuilder(getId(), Modifier.PUBLIC, seiMethod.getMethodName(), seiMethod.getReturnType(), AnnotatedJavaType.convertFromJavaTypes(parameters), seiMethod.getParameterNames(), null); InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); for (JavaSymbolName param : seiMethod.getParameterNames()) { parametersList = parametersList.concat(param.getSymbolName()).concat(", "); bodyBuilder.appendFormalLine("%s%s().%s(%s);", seiMethod.getReturnType() != JavaType.VOID_PRIMITIVE ? "return " : "", getAccessorMethod(getServiceField()).getMethodName(), serviceMethod.getMethodName() .getSymbolName(), parametersList); endpointMethod.setBodyBuilder(bodyBuilder); endpointMethods.add(endpointMethod.build());
@Override public MethodMetadata build() { final MethodMetadataBuilder methodMetadataBuilder = new MethodMetadataBuilder(declaredByMetadataId); methodMetadataBuilder.setMethodName(methodName); methodMetadataBuilder.setReturnType(returnType); methodMetadataBuilder.setAnnotations(annotations); methodMetadataBuilder.setBodyBuilder(InvocableMemberBodyBuilder.getInstance().append(body)); methodMetadataBuilder.setModifier(modifier); methodMetadataBuilder.setParameterNames(parameterNames); methodMetadataBuilder.setParameterTypes(parameterTypes); methodMetadataBuilder.setThrowsTypes(throwsTypes); return methodMetadataBuilder.build(); } }
/** * Constructor for a method with parameters * * @param declaredbyMetadataId * @param modifier * @param methodName * @param returnType * @param parameterTypes * @param parameterNames * @param bodyBuilder */ public MethodMetadataBuilder(final String declaredbyMetadataId, final int modifier, final JavaSymbolName methodName, final JavaType returnType, final List<AnnotatedJavaType> parameterTypes, final List<JavaSymbolName> parameterNames, final InvocableMemberBodyBuilder bodyBuilder) { this(declaredbyMetadataId); setModifier(modifier); setParameterTypes(parameterTypes); setParameterNames(parameterNames); init(methodName, returnType); setBodyBuilder(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 }
JavaSymbolName methodName = findAllGlobalSearchMethod.getMethodName(); List<AnnotatedJavaType> parameterTypes = findAllGlobalSearchMethod.getParameterTypes(); List<JavaSymbolName> parameterNames = findAllGlobalSearchMethod.getParameterNames(); AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes)); if (existingMethod != null) { return existingMethod; new MethodMetadataBuilder(getId(), Modifier.PUBLIC, findAllGlobalSearchMethod.getMethodName(), findAllGlobalSearchMethod.getReturnType(), findAllGlobalSearchMethod.getParameterTypes(), InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); String entity = this.entity.getSimpleTypeName(); String entityVariable = StringUtils.uncapitalize(entity); bodyBuilder.newLine(); bodyBuilder.appendFormalLine(String.format("%1$s %2$s = %1$s.%2$s;", entityQtype.getNameIncludingTypeParameters(false, importResolver), entityVariable)); bodyBuilder.newLine(); methodBuilder.setBodyBuilder(bodyBuilder); return methodBuilder.build(); // Build and return a MethodMetadata
JavaSymbolName methodName = new JavaSymbolName("localeChangeInterceptor"); new JavaType("org.springframework.web.servlet.i18n.LocaleChangeInterceptor"); AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes))) { return getGovernorMethod(methodName, AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes)); InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); .appendFormalLine("LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();"); bodyBuilder.appendFormalLine("localeChangeInterceptor.setParamName(\"lang\");"); new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, returnType, parameterTypes, parameterNames, bodyBuilder); methodBuilder.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.BEAN)); return methodBuilder.build(); // Build and return a MethodMetadata
new JavaSymbolName("get" + StringUtils.capitalize(pathVariable)); serviceMetadata.getCurrentFindOneMethod().getParameterTypes().get(0).getJavaType(); final JavaSymbolName idName = serviceMetadata.getCurrentFindOneMethod().getParameterNames().get(0); final JavaType entityType = serviceMetadata.getCurrentFindOneMethod().getReturnType(); new AnnotationMetadataBuilder(SpringJavaType.PATH_VARIABLE); pathVariableAnnotation.addStringAttribute("value", StringUtils.uncapitalize(pathVariable)); parameterTypes.add(new AnnotatedJavaType(idType, pathVariableAnnotation.build())); AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes)); if (existingMethod != null) { return existingMethod; InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.appendFormalLine("%s %s = %s.%s(%s);", getNameOfJavaType(entityType), pathVariable, serviceField.getFieldName(), serviceMetadata.getCurrentFindOneMethod().getMethodName(), idName); new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, entityType, parameterTypes, parameterNames, bodyBuilder); methodBuilder.addAnnotation(ANN_MODEL_ATTRIBUTE); return methodBuilder.build();
new AnnotationMetadataBuilder(SpringJavaType.EXCEPTION_HANDLER); exceptionHandler.addClassAttribute("value", exception); annotationTypes.add(exceptionHandler); parameterTypes.add(AnnotatedJavaType.convertFromJavaType(HTTP_SERVLET_REQUEST)); parameterTypes.add(AnnotatedJavaType.convertFromJavaType(JdkJavaType.EXCEPTION)); parameterTypes.add(AnnotatedJavaType.convertFromJavaType(JdkJavaType.LOCALE)); parameterNames.add(new JavaSymbolName(HTTP_SERVLET_REQUEST_PARAM_NAME)); parameterNames.add(new JavaSymbolName(EXCEPTION_PARAM_NAME)); parameterNames.add(new JavaSymbolName(LOCALE_PARAM_NAME)); JavaSymbolName methodName = new JavaSymbolName("handle".concat(exception.getSimpleTypeName())); MethodMetadata existingMethod = getGovernorMethod(methodName); if (existingMethod != null) { InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.indent(); new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, SpringJavaType.MODEL_AND_VIEW, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setThrowsTypes(throwTypes); methodBuilder.setAnnotations(annotationTypes); return methodBuilder.build();
parameterNames.add(LOCALE_PARAM_NAME); InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); JavaType defaultReturnType = findAllMethod.getReturnType(); bodyBuilder.appendFormalLine("// Obtain the filtered and ordered elements"); bodyBuilder.appendFormalLine("%s %s = %s().%s(%s, %s);", getNameOfJavaType(defaultReturnType), this.entityPluralUncapitalized, getAccessorMethod(this.controllerMetadata.getServiceField()).getMethodName(), findAllMethod .getMethodName().getSymbolName(), GLOBAL_SEARCH_PARAM_NAME, PAGEABLE_PARAM_NAME); bodyBuilder.newLine(); new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, JavaType.VOID_PRIMITIVE, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setCommentStructure(commentStructure); return methodBuilder.build();
final JavaSymbolName methodName = new JavaSymbolName("list"); parameterTypes.add(new AnnotatedJavaType(SpringletsJavaType.SPRINGLETS_GLOBAL_SEARCH)); parameterTypes.add(new AnnotatedJavaType(SpringJavaType.PAGEABLE)); AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes)); if (existingMethod != null) { return existingMethod; AnnotationMetadataBuilder getMappingAnnotation = new AnnotationMetadataBuilder(GET_MAPPING); getMappingAnnotation.addStringAttribute("name", methodName.getSymbolName()); annotations.add(getMappingAnnotation); JavaType serviceReturnType = findAllMethod.getReturnType(); JavaType returnType = JavaType.wrapperOf(RESPONSE_ENTITY, serviceReturnType); InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.newLine(); bodyBuilder.appendFormalLine("%s %s = %s().%s(%s, %s);", getNameOfJavaType(serviceReturnType), itemNames, getAccessorMethod(controllerMetadata.getServiceField()).getMethodName(), findAllMethod.getMethodName(), GLOBAL_SEARCH_NAME, PAGEABLE_PARAM_NAME); new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, returnType, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); return methodBuilder.build();
parameterTypes.add(new AnnotatedJavaType(FAST_REPORT_BUILDER)); parameterTypes.add(LOCALE_PARAM); parameterTypes.add(STRING_PARAM); InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.appendFormalLine("try {"); String fieldName = fieldMetadata.getFieldName().getSymbolName(); if (i == 0) { bodyBuilder.appendFormalLine("if (columnName.equals(\"%s\")) {", fieldName); } else { if (fieldType.isPrimitive()) { getAccessorMethod(this.messageSourceField).getMethodName(), this.entityLabel, new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, JavaType.VOID_PRIMITIVE, parameterTypes, parameterNames, bodyBuilder); commentStructure.addComment(new JavadocComment(description, paramInfo, null, null), CommentLocation.BEGINNING); methodBuilder.setCommentStructure(commentStructure); return methodBuilder.build();
new JavaSymbolName("getRandom" + this.entity.getSimpleTypeName()); Validate.isTrue(userMethod.getReturnType().equals(this.entity), "Method '%s' on '%s' must return '%s'", methodName, this.destination, this.entity.getSimpleTypeName()); this.randomPersistentEntityMethod = userMethod; return userMethod; final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.appendFormalLine("init();"); bodyBuilder.appendFormalLine("return %1$s().get(%2$s().nextInt(%1$s().size()));", getAccessorMethod(getDataField().build()).getMethodName(), getAccessorMethod(getRndField().build()).getMethodName()); new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, this.entity, bodyBuilder); this.entity.getSimpleTypeName()), null); comment.addComment(javadocComment, CommentLocation.BEGINNING); methodBuilder.setCommentStructure(comment); this.randomPersistentEntityMethod = methodBuilder.build(); return this.randomPersistentEntityMethod;
new JavaSymbolName("init" + entity.getSimpleTypeName() + "Binder"); parameterTypes.add(AnnotatedJavaType.convertFromJavaType(SpringJavaType.WEB_DATA_BINDER)); List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(); parameterNames.add(new JavaSymbolName("binder")); AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes)); if (existingMethod != null) { return existingMethod; InvocableMemberBodyBuilder body = new InvocableMemberBodyBuilder(); body.appendFormalLine("binder.setDisallowedFields(\"%s\");", entityIdentifier); body.appendFormalLine("binder.setDisallowedFields(\"%s.%s\");", item.getKey().fieldName, item .getValue().getCurrentIndentifierField().getFieldName()); new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, JavaType.VOID_PRIMITIVE, parameterTypes, parameterNames, body); AnnotationMetadataBuilder getInitBinderAnnotation = new AnnotationMetadataBuilder(INIT_BINDER); getInitBinderAnnotation.addStringAttribute("value", StringUtils.uncapitalize(entity.getSimpleTypeName())); annotations.add(getInitBinderAnnotation); methodBuilder.setAnnotations(annotations); return methodBuilder.build();
throwTypes.add(CLASS_NOT_FOUND_EXCEPTION); InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.appendFormalLine("export(%s, %s, %s, %s, %s, \"%s\", %s);", GLOBAL_SEARCH_PARAM_NAME, PAGEABLE_PARAM_NAME, DATATABLES_COLUMNS_PARAM_NAME, RESPONSE_PARAM_NAME, exporterClassInstantiation, fileName, LOCALE_PARAM_NAME.getSymbolName()); bodyBuilder.appendFormalLine("return %s.ok().build();", getNameOfJavaType(RESPONSE_ENTITY)); new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, JavaType.wrapperWilcard(RESPONSE_ENTITY), parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setCommentStructure(commentStructure); return methodBuilder.build();
new JavaSymbolName(JpaEntityFactoryMetadata.SPECIFIC_METHOD_PREFIX + this.entity.getSimpleTypeName()); final JavaType parameterType = JavaType.INT_PRIMITIVE; final List<JavaSymbolName> parameterNames = Arrays.asList(INDEX_SYMBOL); Validate.isTrue(userMethod.getReturnType().equals(this.entity), "Method '%s on '%s' must return '%s'", methodName, this.destination, this.entity.getSimpleTypeName()); this.specificEntityMethod = userMethod; return userMethod; final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.appendFormalLine("init();"); bodyBuilder.appendFormalLine("if (" + INDEX_VAR + " < 0) {"); bodyBuilder.indent(); bodyBuilder.appendFormalLine(INDEX_VAR + " = 0;"); new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, this.entity, AnnotatedJavaType.convertFromJavaTypes(parameterType), parameterNames, bodyBuilder); "%1$s the specific {@link %1$s}", this.entity.getSimpleTypeName()), null); comment.addComment(javadocComment, CommentLocation.BEGINNING); methodBuilder.setCommentStructure(comment); this.specificEntityMethod = methodBuilder.build(); return this.specificEntityMethod;
parameterTypes.add(new AnnotatedJavaType(JavaType.STRING)); .add(new JavaType("com.vividsolutions.jts.io.ParseException")); parameterNames.add(new JavaSymbolName("wkt")); InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); buildParseWktMethodBody(bodyBuilder); MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder( getId(), Modifier.PUBLIC, PARSE_WKT_METHOD, GEOMETRY_TYPE, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata
.convertFromJavaTypes(MAP_STRING_OBJECT); annotations.add(new AnnotationMetadataBuilder( SpringJavaType.TRANSACTIONAL)); parameterNames.add(new JavaSymbolName("propertyValues")); InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); buildDeleteByValuesMethodBody(bodyBuilder); MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder( getId(), Modifier.PUBLIC, DELETE_BY_VALUES_METHOD, JavaType.LONG_PRIMITIVE, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata
final JavaSymbolName methodName = new JavaSymbolName("init"); final JavaType[] parameterTypes = {}; final List<JavaSymbolName> parameterNames = Collections.<JavaSymbolName>emptyList(); Validate.isTrue(userMethod.getReturnType().equals(returnType), "Method '%s' on '%s' must return '%s'", methodName, destination, returnType.getNameIncludingTypeParameters()); return new MethodMetadataBuilder(userMethod); final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.appendFormalLine("int from = 0;"); bodyBuilder.appendFormalLine("int to = " + quantity + ";"); bodyBuilder.appendFormalLine("%s cb = %s().getCriteriaBuilder();", getNameOfJavaType(JpaJavaType.CRITERIA_BUILDER), getAccessorMethod(getEntityManagerField().build()).getMethodName()); bodyBuilder.indent(); bodyBuilder.appendFormalLine("%s().createQuery(all).setFirstResult(from).setMaxResults(to);", getAccessorMethod(getEntityManagerField().build()).getMethodName()); new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, returnType, AnnotatedJavaType.convertFromJavaTypes(parameterTypes), parameterNames, bodyBuilder); new JavadocComment("Creates the initial list of generated entities."); comment.addComment(javadocComment, CommentLocation.BEGINNING); methodBuilder.setCommentStructure(comment);