List of usage examples for java.lang.reflect Modifier PUBLIC
int PUBLIC
To view the source code for java.lang.reflect Modifier PUBLIC.
Click Source Link
From source file:org.gvnix.web.screen.roo.addon.AbstractPatternMetadata.java
protected MethodMetadata getDeleteMethod(String patternName) { // Specify the desired method name JavaSymbolName methodName = new JavaSymbolName("deletePattern" + patternName); FieldMetadata formBackingObjectIdField = entityTypeDetails.getPersistenceDetails().getIdentifierField(); // Define method parameter types List<AnnotatedJavaType> methodParamTypes = new ArrayList<AnnotatedJavaType>(); List<AnnotationAttributeValue<?>> reqParamAttrPathVar = new ArrayList<AnnotationAttributeValue<?>>(); reqParamAttrPathVar.add(new StringAttributeValue(VALUE_ATTRIBUTE_NAME, formBackingObjectIdField.getFieldName().getSymbolName())); List<AnnotationMetadata> methodAttrPathVarAnnotations = new ArrayList<AnnotationMetadata>(); AnnotationMetadataBuilder methodAttPathVarAnnotation = new AnnotationMetadataBuilder( new JavaType("org.springframework.web.bind.annotation.PathVariable"), reqParamAttrPathVar); methodAttrPathVarAnnotations.add(methodAttPathVarAnnotation.build()); methodParamTypes/*from w w w . ja va2 s.com*/ .add(new AnnotatedJavaType(formBackingObjectIdField.getFieldType(), methodAttrPathVarAnnotations)); methodParamTypes.add(getPatternRequestParam(false).getValue()); List<AnnotationAttributeValue<?>> reqParamAttrPage = new ArrayList<AnnotationAttributeValue<?>>(); reqParamAttrPage.add(new StringAttributeValue(VALUE_ATTRIBUTE_NAME, "page")); reqParamAttrPage.add(new BooleanAttributeValue(new JavaSymbolName(REQUIRED_TXT), false)); List<AnnotationMetadata> methodAttrPageAnnotations = new ArrayList<AnnotationMetadata>(); AnnotationMetadataBuilder methodAttrPageAnnotation = new AnnotationMetadataBuilder( new JavaType(RQST_PARAM_PATH), reqParamAttrPage); methodAttrPageAnnotations.add(methodAttrPageAnnotation.build()); methodParamTypes.add(new AnnotatedJavaType(JavaType.INT_OBJECT, methodAttrPageAnnotations)); List<AnnotationAttributeValue<?>> reqParamAttrSize = new ArrayList<AnnotationAttributeValue<?>>(); reqParamAttrSize.add(new StringAttributeValue(VALUE_ATTRIBUTE_NAME, "size")); reqParamAttrSize.add(new BooleanAttributeValue(new JavaSymbolName(REQUIRED_TXT), false)); List<AnnotationMetadata> methodAttrSizeAnnotations = new ArrayList<AnnotationMetadata>(); AnnotationMetadataBuilder methodAttrSizeAnnotation = new AnnotationMetadataBuilder( new JavaType(RQST_PARAM_PATH), reqParamAttrSize); methodAttrSizeAnnotations.add(methodAttrSizeAnnotation.build()); methodParamTypes.add(new AnnotatedJavaType(JavaType.INT_OBJECT, methodAttrSizeAnnotations)); Entry<JavaSymbolName, AnnotatedJavaType> modelRequestParam = MODEL_REQUEST_PARAM; methodParamTypes.add(modelRequestParam.getValue()); Entry<JavaSymbolName, AnnotatedJavaType> httpServletRequest = HTTP_SERVLET_REQUEST_PARAM; methodParamTypes.add(httpServletRequest.getValue()); MethodMetadata method = methodExists(methodName, methodParamTypes); if (method != null) { // If it already exists, just return null and omit its // generation via the ITD return null; } // Define method parameter names // id, pattern, page, size, uiModel, httpServletRequest List<JavaSymbolName> methodParamNames = new ArrayList<JavaSymbolName>(); methodParamNames.add(formBackingObjectIdField.getFieldName()); Entry<JavaSymbolName, AnnotatedJavaType> patternRequestParam = getPatternRequestParam(false); methodParamNames.add(patternRequestParam.getKey()); methodParamNames.add(PAGE_PARAM_NAME); methodParamNames.add(SIZE_PARAM_NAME); methodParamNames.add(modelRequestParam.getKey()); methodParamNames.add(httpServletRequest.getKey()); // Create method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); String entityNamePlural = entityTypeDetails.getPlural(); bodyBuilder.appendFormalLine("delete(".concat(formBackingObjectIdField.getFieldName().getSymbolName()) .concat(", page, size, uiModel);")); bodyBuilder.appendFormalLine(RETURN_TXT.concat("redirect:/").concat(entityNamePlural.toLowerCase()) .concat("?gvnixform&\" + refererQuery(" + httpServletRequest.getKey() + ");")); MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, JavaType.STRING, methodParamTypes, methodParamNames, bodyBuilder); // Get Method RequestMapping annotation List<AnnotationAttributeValue<?>> requestMappingAttributes = new ArrayList<AnnotationAttributeValue<?>>(); requestMappingAttributes.add(new StringAttributeValue(VALUE_ATTRIBUTE_NAME, "/{" + formBackingObjectIdField.getFieldName().getSymbolName() + "}")); List<AnnotationAttributeValue<? extends Object>> paramValues = new ArrayList<AnnotationAttributeValue<? extends Object>>(); paramValues.add(getPatternParamRequestMapping(patternName)); requestMappingAttributes.add(new ArrayAttributeValue<AnnotationAttributeValue<? extends Object>>( PARAMS_ATTRIBUTE_NAME, paramValues)); requestMappingAttributes.add(getMethodRequestMapping(RequestMethod.DELETE)); requestMappingAttributes.add(PRODUCES_PARAM_MAPPING); AnnotationMetadataBuilder requestMapping = new AnnotationMetadataBuilder(RQST_MAP_ANN_TYPE, requestMappingAttributes); List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); annotations.add(requestMapping); methodBuilder.setAnnotations(annotations); method = methodBuilder.build(); controllerMethods.add(method); return method; }
From source file:com.github.geequery.codegen.ast.JavaUnit.java
public JavaField addFieldWithGetterAndSetter(JavaField field) { JavaField result = addField(field);//from w w w .j a va2s . co m if (result == null) return null; String name = field.getName(); if (trimUnderlineInMethod && name.charAt(0) == '_') { name = name.substring(1); } JavaMethod setMethod = new JavaMethod("set" + BeanUtils.capitalizeFieldName(name)); setMethod.setModifier(Modifier.PUBLIC); setMethod.addparam(field.getType(), "obj", 0); setMethod.addContent("this." + field.getName() + " = obj;"); addMethod(setMethod); boolean isBoolean = field.getType().getSimpleName().equalsIgnoreCase("boolean") && !name.startsWith("is"); JavaMethod getMethod = new JavaMethod((isBoolean ? "is" : "get") + BeanUtils.capitalizeFieldName(name)); getMethod.setModifier(Modifier.PUBLIC); getMethod.setReturnType(field.getType()); getMethod.addContent("return " + field.getName() + ";"); addMethod(getMethod); return result; }
From source file:org.gvnix.addon.datatables.addon.DatatablesMetadataProvider.java
/** * @see DynamicFinderServicesImpl#isMethodOfInterest */// ww w. j a v a 2 s. co m private boolean isMethodOfInterest(final MethodMetadata method) { return method.getMethodName().getSymbolName().startsWith("set") && method.getModifier() == Modifier.PUBLIC; }
From source file:org.codehaus.groovy.grails.compiler.web.ControllerActionTransformer.java
protected void addMethodToInvokeClosure(ClassNode controllerClassNode, PropertyNode closureProperty, SourceUnit source, GeneratorContext context) { MethodNode method = controllerClassNode.getMethod(closureProperty.getName(), ZERO_PARAMETERS); if (method == null || !method.getDeclaringClass().equals(controllerClassNode)) { ClosureExpression closureExpression = (ClosureExpression) closureProperty.getInitialExpression(); final Parameter[] parameters = closureExpression.getParameters(); final BlockStatement newMethodCode = initializeActionParameters(controllerClassNode, closureProperty, closureProperty.getName(), parameters, source, context); final ArgumentListExpression closureInvocationArguments = new ArgumentListExpression(); if (parameters != null) { for (Parameter p : parameters) { closureInvocationArguments.addExpression(new VariableExpression(p.getName())); }/*w ww .j a v a2 s . c o m*/ } final MethodCallExpression methodCallExpression = new MethodCallExpression(closureExpression, "call", closureInvocationArguments); newMethodCode.addStatement(new ExpressionStatement(methodCallExpression)); final MethodNode methodNode = new MethodNode(closureProperty.getName(), Modifier.PUBLIC, new ClassNode(Object.class), ZERO_PARAMETERS, EMPTY_CLASS_ARRAY, newMethodCode); annotateActionMethod(parameters, methodNode); controllerClassNode.addMethod(methodNode); } }
From source file:org.gvnix.addon.geo.addon.GvNIXGeoConversionServiceMetadata.java
/** * Gets <code>getStringToLineStringConverter</code> method. <br> * //from w ww . j ava 2 s . c om * @return */ private MethodMetadata getStringToLineStringConverterMethod() { // Define method parameter types List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>(); // Check if a method with the same signature already exists in the // target type final MethodMetadata method = methodExists(STRING_TO_LINESTRING_METHOD, parameterTypes); if (method != null) { // If it already exists, just return the method and omit its // generation via the ITD return method; } // Define method annotations List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); // Define method throws types List<JavaType> throwsTypes = new ArrayList<JavaType>(); // Define method parameter names List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(); // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); buildGetStringToLineStringConverterMethodBody(bodyBuilder); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, STRING_TO_LINESTRING_METHOD, CONVERTER_STRING_LINESTRING, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata // instance }
From source file:com.mobile.system.db.abatis.AbatisService.java
/** * /*w w w .j a va 2s . c o m*/ * @param jsonStr * JSON String * @param beanClass * Bean class * @param basePackage * Base package name which includes all Bean classes * @return Object Bean * @throws Exception */ @SuppressWarnings({ "rawtypes", "unchecked" }) public Object parse(String jsonStr, Class beanClass, String basePackage) throws Exception { Object obj = null; JSONObject jsonObj = new JSONObject(jsonStr); // Check bean object if (beanClass == null) { Log.d(TAG, "Bean class is null"); return null; } // Read Class member fields Field[] props = beanClass.getDeclaredFields(); if (props == null || props.length == 0) { Log.d(TAG, "Class" + beanClass.getName() + " has no fields"); return null; } // Create instance of this Bean class obj = beanClass.newInstance(); // Set value of each member variable of this object for (int i = 0; i < props.length; i++) { String fieldName = props[i].getName(); // Skip public and static fields if (props[i].getModifiers() == (Modifier.PUBLIC | Modifier.STATIC)) { continue; } // Date Type of Field Class type = props[i].getType(); String typeName = type.getName(); // Check for Custom type if (typeName.equals("int")) { Class[] parms = { type }; Method m = beanClass.getDeclaredMethod(getBeanMethodName(fieldName, 1), parms); m.setAccessible(true); // Set value try { m.invoke(obj, jsonObj.getInt(fieldName)); } catch (Exception ex) { Log.d(TAG, ex.getMessage()); } } else if (typeName.equals("long")) { Class[] parms = { type }; Method m = beanClass.getDeclaredMethod(getBeanMethodName(fieldName, 1), parms); m.setAccessible(true); // Set value try { m.invoke(obj, jsonObj.getLong(fieldName)); } catch (Exception ex) { Log.d(TAG, ex.getMessage()); } } else if (typeName.equals("java.lang.String")) { Class[] parms = { type }; Method m = beanClass.getDeclaredMethod(getBeanMethodName(fieldName, 1), parms); m.setAccessible(true); // Set value try { m.invoke(obj, jsonObj.getString(fieldName)); } catch (Exception ex) { Log.d(TAG, ex.getMessage()); } } else if (typeName.equals("double")) { Class[] parms = { type }; Method m = beanClass.getDeclaredMethod(getBeanMethodName(fieldName, 1), parms); m.setAccessible(true); // Set value try { m.invoke(obj, jsonObj.getDouble(fieldName)); } catch (Exception ex) { Log.d(TAG, ex.getMessage()); } } else if (typeName.equals("java.util.Date")) { // modify Class[] parms = { type }; Method m = beanClass.getDeclaredMethod(getBeanMethodName(fieldName, 1), parms); m.setAccessible(true); String dateString = jsonObj.getString(fieldName); dateString = dateString.replace(" KST", ""); SimpleDateFormat genderFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy", Locale.KOREA); // Set value try { Date afterDate = genderFormat.parse(dateString); m.invoke(obj, afterDate); } catch (Exception e) { Log.d(TAG, e.getMessage()); } } else if (type.getName().equals(List.class.getName()) || type.getName().equals(ArrayList.class.getName())) { // Find out the Generic String generic = props[i].getGenericType().toString(); if (generic.indexOf("<") != -1) { String genericType = generic.substring(generic.lastIndexOf("<") + 1, generic.lastIndexOf(">")); if (genericType != null) { JSONArray array = null; try { array = jsonObj.getJSONArray(fieldName); } catch (Exception ex) { Log.d(TAG, ex.getMessage()); array = null; } if (array == null) { continue; } ArrayList arrayList = new ArrayList(); for (int j = 0; j < array.length(); j++) { arrayList.add(parse(array.getJSONObject(j).toString(), Class.forName(genericType), basePackage)); } // Set value Class[] parms = { type }; Method m = beanClass.getDeclaredMethod(getBeanMethodName(fieldName, 1), parms); m.setAccessible(true); m.invoke(obj, arrayList); } } else { // No generic defined generic = null; } } else if (typeName.startsWith(basePackage)) { Class[] parms = { type }; Method m = beanClass.getDeclaredMethod(getBeanMethodName(fieldName, 1), parms); m.setAccessible(true); // Set value try { JSONObject customObj = jsonObj.getJSONObject(fieldName); if (customObj != null) { m.invoke(obj, parse(customObj.toString(), type, basePackage)); } } catch (JSONException ex) { Log.d(TAG, ex.getMessage()); } } else { // Skip Log.d(TAG, "Field " + fieldName + "#" + typeName + " is skip"); } } return obj; }
From source file:org.gvnix.web.report.roo.addon.addon.ReportMetadata.java
/** * Returns a new MethodMetadata based on given parameters. It uses * AbstractMetadataItem.builder for add the new method and add needed * imports/*from ww w .j a v a2 s . c o m*/ * * @param reportName * @param entity * @param reportNameFormat * @return */ private MethodMetadata addGenerateReportMethod(JavaType entity, String reportName, String reportFormats) { // Specify the desired method name Map<String, String> properties = new HashMap<String, String>(); JavaSymbolName methodName = new JavaSymbolName(generateMethodName(reportName, false)); List<AnnotationAttributeValue<?>> reportAttributes = new ArrayList<AnnotationAttributeValue<?>>(); reportAttributes.add(new StringAttributeValue(VALUE_SYMBOL_NAME, "format")); reportAttributes.add(new BooleanAttributeValue(new JavaSymbolName("required"), true)); List<AnnotationMetadata> reportAttributesAnnotations = new ArrayList<AnnotationMetadata>(); AnnotationMetadataBuilder reportAttributesAnnotation = new AnnotationMetadataBuilder(REQUEST_PARAM_TYPE, reportAttributes); reportAttributesAnnotations.add(reportAttributesAnnotation.build()); // Define method parameter types List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>(); parameterTypes .add(new AnnotatedJavaType(new JavaType(String.class.getName()), reportAttributesAnnotations)); parameterTypes.add(new AnnotatedJavaType(MODEL_TYPE, new ArrayList<AnnotationMetadata>())); // Check if a method with the same signature already exists in the // target type MethodMetadata reportMethod = reportMethodExists(methodName); if (reportMethod != null) { // If it already exists, just return the method and omit its // generation via the ITD return reportMethod; } // Define method parameter names List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(); parameterNames.add(new JavaSymbolName("format")); parameterNames.add(new JavaSymbolName("uiModel")); // Define method annotations List<AnnotationAttributeValue<?>> requestMappingAttributes = new ArrayList<AnnotationAttributeValue<?>>(); requestMappingAttributes.add(new StringAttributeValue(VALUE_SYMBOL_NAME, "/reports/".concat(reportName))); requestMappingAttributes.add(new EnumAttributeValue(METHOD_SYMBOL_NAME, new EnumDetails(REQUEST_METHOD_TYPE, new JavaSymbolName("GET")))); AnnotationMetadataBuilder requestMapping = new AnnotationMetadataBuilder(REQUEST_MAPPING_TYPE, requestMappingAttributes); List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); annotations.add(requestMapping); // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); // test if format is not informed and return to the report form if so bodyBuilder.appendFormalLine("if ( null == format || format.length() <= 0 ) {"); bodyBuilder.appendIndent() .appendFormalLine("uiModel.addAttribute(\"error\", \"message_format_required\");"); bodyBuilder.appendIndent().appendFormalLine( "return \"".concat(annotationValues.getPath()).concat("/").concat(reportName).concat("\";")); bodyBuilder.appendFormalLine("}"); // Add the message error to the application.properties properties.put("message_format_required", "Format required: (pdf, xls, csv, html)"); /* * This is the trick to make changes in the ITD when a new format is * added to the report. This changes triggers ReportJspMetadataListener * performing changes in JSPXs */ // test if requested format is supported for this report bodyBuilder.appendFormalLine( "final String REGEX = \"(".concat(reportFormats.replace(",", "|")).concat(")\";")); bodyBuilder.appendFormalLine("Pattern pattern = Pattern.compile(REGEX, Pattern.CASE_INSENSITIVE);"); bodyBuilder.appendFormalLine("Matcher matcher = pattern.matcher(format);"); bodyBuilder.appendFormalLine("if ( !matcher.matches() ) {"); bodyBuilder.appendIndent().appendFormalLine("uiModel.addAttribute(\"error\", \"message_format_invalid\");"); bodyBuilder.appendIndent().appendFormalLine( "return \"".concat(annotationValues.getPath()).concat("/").concat(reportName).concat("\";")); bodyBuilder.appendFormalLine("}"); // Add the message error to the application.properties properties.put("message_format_invalid", "The requested format is not supported by this report"); // ImportRegistrationResolver gives access to imports in the // Java/AspectJ source ImportRegistrationResolver irr = builder.getImportRegistrationResolver(); // We need import java.util.regex.Matcher and java.util.regex.Pattern irr.addImport(new JavaType("java.util.regex.Matcher")); irr.addImport(new JavaType("java.util.regex.Pattern")); // Code populating the JasperReport DataSource bodyBuilder.appendFormalLine("Collection<".concat(entity.getSimpleTypeName()).concat("> dataSource = ") .concat(entity.getSimpleTypeName()).concat(".find").concat(entity.getSimpleTypeName()) .concat("Entries(0, 10);")); // test if DataSource is empty and return to the report form if so bodyBuilder.appendFormalLine("if (dataSource.isEmpty()) {"); bodyBuilder.appendIndent() .appendFormalLine("uiModel.addAttribute(\"error\", \"message_emptyresults_noreportgeneration\");"); bodyBuilder.appendIndent().appendFormalLine( "return \"".concat(annotationValues.getPath()).concat("/").concat(reportName).concat("\";")); bodyBuilder.appendFormalLine("}"); // Add the message error to the application.properties properties.put("message_emptyresults_noreportgeneration", "No results found to generate report"); // We need import java.util.Collection and the Entity irr.addImport(new JavaType("java.util.Collection")); irr.addImport(entity); // set required attributes bodyBuilder.appendFormalLine("uiModel.addAttribute(\"format\", format);"); bodyBuilder.appendFormalLine( "uiModel.addAttribute(\"title\", \"".concat(reportName.toUpperCase()).concat("\");")); bodyBuilder.appendFormalLine("uiModel.addAttribute(\"".concat(reportName).concat("List\", dataSource);")); // return the JasperReport View bodyBuilder.appendFormalLine("return \"".concat(entity.getSimpleTypeName().toLowerCase()).concat("_") .concat(reportName.toLowerCase()).concat("\";")); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, JavaType.STRING, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); reportMethod = methodBuilder.build(); builder.addMethod(reportMethod); controllerMethods.add(reportMethod); propFileOperations.addProperties(LogicalPath.getInstance(Path.SRC_MAIN_WEBAPP, ""), "/WEB-INF/i18n/application.properties", properties, true, false); return reportMethod; }
From source file:org.codehaus.groovy.grails.compiler.injection.GrailsASTUtils.java
/** * Adds a static method to the given class node that delegates to the given method * and resolves the object to invoke the method on from the given expression. * * @param expression The expression//from w w w. j a v a2 s .co m * @param classNode The class node * @param delegateMethod The delegate method * @param markerAnnotation A marker annotation to be added to all methods * @return The added method node or null if it couldn't be added */ public static MethodNode addDelegateStaticMethod(Expression expression, ClassNode classNode, MethodNode delegateMethod, AnnotationNode markerAnnotation, Map<String, ClassNode> genericsPlaceholders) { Parameter[] parameterTypes = delegateMethod.getParameters(); String declaredMethodName = delegateMethod.getName(); if (classNode.hasDeclaredMethod(declaredMethodName, copyParameters(parameterTypes, genericsPlaceholders))) { return null; } BlockStatement methodBody = new BlockStatement(); ArgumentListExpression arguments = new ArgumentListExpression(); for (Parameter parameterType : parameterTypes) { arguments.addExpression(new VariableExpression(parameterType.getName())); } MethodCallExpression methodCallExpression = new MethodCallExpression(expression, declaredMethodName, arguments); methodCallExpression.setMethodTarget(delegateMethod); ThrowStatement missingMethodException = createMissingMethodThrowable(classNode, delegateMethod); VariableExpression apiVar = addApiVariableDeclaration(expression, delegateMethod, methodBody); IfStatement ifStatement = createIfElseStatementForApiMethodCall(methodCallExpression, apiVar, missingMethodException); methodBody.addStatement(ifStatement); ClassNode returnType = replaceGenericsPlaceholders(delegateMethod.getReturnType(), genericsPlaceholders); if (METHOD_MISSING_METHOD_NAME.equals(declaredMethodName)) { declaredMethodName = STATIC_METHOD_MISSING_METHOD_NAME; } MethodNode methodNode = classNode.getDeclaredMethod(declaredMethodName, parameterTypes); if (methodNode == null) { methodNode = new MethodNode(declaredMethodName, Modifier.PUBLIC | Modifier.STATIC, returnType, copyParameters(parameterTypes, genericsPlaceholders), GrailsArtefactClassInjector.EMPTY_CLASS_ARRAY, methodBody); methodNode.addAnnotations(delegateMethod.getAnnotations()); if (shouldAddMarkerAnnotation(markerAnnotation, methodNode)) { methodNode.addAnnotation(markerAnnotation); } classNode.addMethod(methodNode); } return methodNode; }
From source file:org.gvnix.addon.geo.addon.GvNIXGeoConversionServiceMetadata.java
/** * Gets <code>getPolygonToStringConverter</code> method. <br> * //from w ww . j av a 2s. c o m * @return */ private MethodMetadata getPolygonToStringConverterMethod() { // Define method parameter types List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>(); // Check if a method with the same signature already exists in the // target type final MethodMetadata method = methodExists(POLYGON_TO_STRING_METHOD, parameterTypes); if (method != null) { // If it already exists, just return the method and omit its // generation via the ITD return method; } // Define method annotations List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); // Define method throws types List<JavaType> throwsTypes = new ArrayList<JavaType>(); // Define method parameter names List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(); // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); buildGetPolygonToStringConverterMethodBody(bodyBuilder); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, POLYGON_TO_STRING_METHOD, CONVERTER_POLYGON_STRING, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata // instance }
From source file:org.gvnix.addon.web.mvc.addon.batch.WebJpaBatchMetadata.java
/** * Return method <code>delete</code> * /*from w w w .j av a 2 s. c om*/ * @return */ private MethodMetadata getDeleteMethod() { // method name JavaSymbolName methodName = DELETE_METHOD; // Define method parameter types final List<AnnotatedJavaType> parameterTypes = Arrays.asList( helper.createRequestParam(JavaType.BOOLEAN_PRIMITIVE, ALL_PARAM.getSymbolName(), false, null), helper.createRequestParam(JavaType.BOOLEAN_OBJECT, DELETE_IN_PARAM.getSymbolName(), false, null), helper.createRequestParam(listOfIdentifiersType, ID_LIST_PARAM.getSymbolName().concat("[]"), false, null), new AnnotatedJavaType(entity, new AnnotationMetadataBuilder(SpringJavaType.MODEL_ATTRIBUTE).build()), new AnnotatedJavaType(WEB_REQUEST)); // Check if a method exist in type final MethodMetadata method = methodExists(methodName, parameterTypes); if (method != null) { // If it already exists, just return the method return method; } // Define method annotations List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); // @RequestMapping AnnotationMetadataBuilder requestMappingAnnotation = helper.getRequestMappingAnnotation("/delete", "POST", null, APP_JSON, null, null); annotations.add(requestMappingAnnotation); // Define method throws types (none in this case) List<JavaType> throwsTypes = new ArrayList<JavaType>(); // Define method parameter names (none in this case) List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(); parameterNames.add(ALL_PARAM); parameterNames.add(DELETE_IN_PARAM); parameterNames.add(ID_LIST_PARAM); parameterNames.add(new JavaSymbolName(entityName)); parameterNames.add(REQUEST_NAME); // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); buildDeleteMethod(bodyBuilder); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, RESPONSE_ENTITY_OBJECT, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata // instance }