@Override public MethodSource<O> removeParameter(Class<?> type, String name) { ParameterSource<O> parameter = null; for (ParameterSource<O> param : getParameters()) { if (param.getType().isType(type) && param.getName().equals(name)) { parameter = param; break; } } if (parameter != null) { removeParameter(parameter); } return this; }
if (parameters != null) { for (ParameterSource<JavaClassSource> param : parameters) { if (param.getAnnotations() != null && param.getAnnotations().size() > 0) { return false; //we never add annotations to parameters expectedLine = "this." + param.getName() + "=" + param.getName() + ";"; expectedLines.add(expectedLine);
@Override public String toSignature() { StringBuilder signature = new StringBuilder(); signature.append(Visibility.PACKAGE_PRIVATE.equals(this.getVisibility().scope()) ? "" : this.getVisibility() .scope()); signature.append(" "); signature.append(this.getName()).append("("); List<ParameterSource<O>> parameters = this.getParameters(); for (ParameterSource<O> p : parameters) { signature.append(p.getType().getName()); if (parameters.indexOf(p) < (parameters.size() - 1)) { signature.append(", "); } } signature.append(") : ").append((this.getReturnType() == null ? "void" : this.getReturnType().getName())); return signature.toString(); }
throws MojoExecutionException log.debug("Processing parameter \"" + parameterSource.getName() + "\"."); AnnotationSource<JavaClassSource> requestParamAnnotationSource = parameterSource.getAnnotation(RequestParam.class); AnnotationSource<JavaClassSource> requestBodyAnnotationSource = parameterSource.getAnnotation(RequestBody.class); AnnotationSource<JavaClassSource> pathVariableAnnotationSource = parameterSource.getAnnotation(PathVariable.class); log.debug("Parameter \"" + parameterSource.getName() + "\" is a RequestParam."); QueryParameter queryParameter = new QueryParameter(); log.debug("Parameter \"" + parameterSource.getName() + "\" is a RequestBody."); exampleClassNames.add(parameterSource.getType().getSimpleName()); XmlType xmlType = getXmlType(Class.forName(parameterSource.getType().getQualifiedName())); String name = xmlType.name().trim(); bodyParameter.name(name); log.debug("Parameter \"" + parameterSource.getName() + "\" is a PathVariable."); PathParameter pathParameter = new PathParameter(); pathParameter.name(pathVariableAnnotationSource.getStringValue("value").trim()); throw new MojoExecutionException("Unable to instantiate class \"" + parameterSource.getType().getQualifiedName() + "\". Reason: " + e.getMessage(), e);
public void visit(MethodSource<? extends JavaClassSource> methodSource) { for (ParameterSource<? extends JavaClassSource> paramSource : methodSource.getParameters()) { // Method parameters addJavaResourceReference(paramSource.getType().getQualifiedName()); // Method parameter annotations for (AnnotationSource<? extends JavaClassSource> annoSource : paramSource.getAnnotations()) { visit(annoSource); } } Type<? extends JavaClassSource> returnType = methodSource.getReturnType(); if (returnType != null) { String returnTypeQualifiedName = returnType.getQualifiedName(); if (!returnTypeQualifiedName.endsWith(".void")) { addJavaResourceReference(returnTypeQualifiedName); } } // method annotations for (AnnotationSource<? extends JavaClassSource> annoSource : methodSource.getAnnotations()) { visit(annoSource); } }
/** * Sets a Swagger parameter description. * * @param parameterSource the parameter source information. * @param methodParamDescriptions the map of parameter names to their descriptions. * @param swaggerParam the Swagger parameter metadata to update. */ private void setParamDescription(ParameterSource<JavaClassSource> parameterSource, Map<String, String> methodParamDescriptions, io.swagger.models.parameters.Parameter swaggerParam) { // Set the parameter description if one was found. String parameterDescription = methodParamDescriptions.get(parameterSource.getName()); log.debug("Parameter \"" + parameterSource.getName() + "\" has description\"" + parameterDescription + "\"."); if (parameterDescription != null) { swaggerParam.setDescription(parameterDescription); } }
case GET: greeting.addAnnotation(RequestMapping.class).setStringValue("/greeting"); greeting.addParameter(String.class, "name").addAnnotation(RequestParam.class).setLiteralValue("value", "\"name\"").setLiteralValue("defaultValue", "\"world\""); greeting.setBody("return new Greeting(this.counter.incrementAndGet(), String.format(this.properties.getMessage(), name));"); break;
@Override public String toSignature() { StringBuilder signature = new StringBuilder(); signature.append(Visibility.PACKAGE_PRIVATE.equals(this.getVisibility().scope()) ? "" : this.getVisibility() .scope()); signature.append(" "); signature.append(this.getName()).append("("); List<ParameterSource<O>> parameters = this.getParameters(); for (ParameterSource<O> p : parameters) { signature.append(p.getType().getName()); if (parameters.indexOf(p) < (parameters.size() - 1)) { signature.append(", "); } } signature.append(") : ").append((this.getReturnType() == null ? "void" : this.getReturnType().getName())); return signature.toString(); }
@Override public MethodSource<O> removeParameter(String type, String name) { ParameterSource<O> parameter = null; for (ParameterSource<O> param : getParameters()) { if (param.getType().isType(type) && param.getName().equals(name)) { parameter = param; break; } } if (parameter != null) { removeParameter(parameter); } return this; }
@Override public MethodSource<Body> getMethod(final String name, final String... paramTypes) { for (MethodSource<Body> local : getMethods()) { if (local.getName().equals(name)) { final List<ParameterSource<Body>> localParams = local.getParameters(); if (paramTypes != null) { if (localParams.isEmpty() || (localParams.size() == paramTypes.length)) { boolean matches = true; for (int i = 0; i < localParams.size(); i++) { if (!Types.areEquivalent(localParams.get(i).getType().getName(), paramTypes[i])) { matches = false; } } if (matches) { return local; } } } } } return null; }
@Override public MethodSource<O> removeParameter(Class<?> type, String name) { ParameterSource<O> parameter = null; for (ParameterSource<O> param : getParameters()) { if (param.getType().isType(type) && param.getName().equals(name)) { parameter = param; break; } } if (parameter != null) { removeParameter(parameter); } return this; }
@Override public MethodSource<Body> getMethod(final String name, final String... paramTypes) { for (MethodSource<Body> local : getMethods()) { if (local.getName().equals(name)) { final List<ParameterSource<Body>> localParams = local.getParameters(); if (paramTypes != null) { if (localParams.isEmpty() || (localParams.size() == paramTypes.length)) { boolean matches = true; for (int i = 0; i < localParams.size(); i++) { if (!Types.areEquivalent(localParams.get(i).getType().getName(), paramTypes[i])) { matches = false; } } if (matches) { return local; } } } } } return null; }
@Override public MethodSource<O> removeParameter(String type, String name) { ParameterSource<O> parameter = null; for (ParameterSource<O> param : getParameters()) { if (param.getType().isType(type) && param.getName().equals(name)) { parameter = param; break; } } if (parameter != null) { removeParameter(parameter); } return this; }
@Override public MethodSource<Body> getMethod(final String name, final String... paramTypes) { for (MethodSource<Body> local : getMethods()) { if (local.getName().equals(name)) { final List<ParameterSource<Body>> localParams = local.getParameters(); if (paramTypes != null) { if (localParams.isEmpty() || (localParams.size() == paramTypes.length)) { boolean matches = true; for (int i = 0; i < localParams.size(); i++) { if (!Types.areEquivalent(localParams.get(i).getType().getName(), paramTypes[i])) { matches = false; } } if (matches) { return local; } } } } } return null; }
@Override public MethodSource<O> removeParameter(JavaType<?> type, String name) { ParameterSource<O> parameter = null; for (ParameterSource<O> param : getParameters()) { if (param.getType().isType(type.getQualifiedName()) && param.getName().equals(name)) { parameter = param; break; } } if (parameter != null) { removeParameter(parameter); } return this; }
@Override public MethodSource<O> getMethod(final String name, final String... paramTypes) { for (MethodSource<O> local : getMethods()) { if (local.getName().equals(name)) { List<ParameterSource<O>> localParams = local.getParameters(); if (paramTypes != null) { if (localParams.isEmpty() || (localParams.size() == paramTypes.length)) { boolean matches = true; for (int i = 0; i < localParams.size(); i++) { ParameterSource<O> localParam = localParams.get(i); String type = paramTypes[i]; if (!Types.areEquivalent(localParam.getType().getName(), type)) { matches = false; } } if (matches) return local; } } } } return null; }
@Override public MethodSource<O> removeParameter(JavaType<?> type, String name) { ParameterSource<O> parameter = null; for (ParameterSource<O> param : getParameters()) { if (param.getType().isType(type.getQualifiedName()) && param.getName().equals(name)) { parameter = param; break; } } if (parameter != null) { removeParameter(parameter); } return this; }
@Override public MethodSource<O> getMethod(final String name, final String... paramTypes) { for (MethodSource<O> local : getMethods()) { if (local.getName().equals(name)) { List<ParameterSource<O>> localParams = local.getParameters(); if (paramTypes != null) { if (localParams.size() == paramTypes.length) { boolean matches = true; for (int i = 0; i < localParams.size(); i++) { ParameterSource<O> localParam = localParams.get(i); String type = paramTypes[i]; if (!Types.areEquivalent(localParam.getType().getName(), type)) { matches = false; } } if (matches) return local; } } } } return null; }
public boolean paramMatchesWithProperty(ParameterSource<JavaClassSource> param, ObjectProperty property, ClassTypeResolver classTypeResolver) { if (!param.getName().equals(property.getName())) { return false; } try { return DriverUtils.equalsType(param.getType(), property.getClassName(), property.isMultiple(), property.getBag(), classTypeResolver); } catch (Exception e) { //TODO check if we need to propagate this exception. logger.error("An error was produced on parameter matching test with param: " + param.getName() + " and field: " + property.getName(), e); return false; } }
@Override public MethodSource<O> getMethod(final String name, final String... paramTypes) { for (MethodSource<O> local : getMethods()) { if (local.getName().equals(name)) { List<ParameterSource<O>> localParams = local.getParameters(); if (paramTypes != null) { if (localParams.size() == paramTypes.length) { boolean matches = true; for (int i = 0; i < localParams.size(); i++) { ParameterSource<O> localParam = localParams.get(i); String type = paramTypes[i]; if (!Types.areEquivalent(localParam.getType().getName(), type)) { matches = false; } } if (matches) return local; } } } } return null; }