public Method processMethod(Resource parentResource, ExecutableElement element) { Collection<HttpVariable> variables = parentResource.getEndPointDetails().getHttpVariables(); Collection<String> existingVariableNames = FluentIterable.from(variables) .transform(HttpVariable::getName) .toList(); return new Method(element, existingVariableNames); }
private void resolveRestActionResult(Method method) { List<Type> typeArguments = method.getReturnType().getTypeArguments(); if (typeArguments.size() == 1) { resultType = typeArguments.get(0); } else { ExecutableElement element = method.getElement(); logger.error().context(element).log(BAD_REST_ACTION, NameUtils.qualifiedMethodName(element)); throw new UnableToProcessException(); } }
private void createVariables(Method method) { httpVariables = new ArrayList<>(httpVariables); for (Variable variable : method.getParameters()) { resolveVariable(method, variable); } httpVariables = ImmutableList.copyOf(httpVariables); logPotentialErrors(method); }
private void processVerb(Method method) { verb = new HttpVerbResolver(logger).resolve(method.getElement()); }
@Override public Collection<String> getImports() { return FluentIterable.from(getMethod().getImports()) .append(getSubResource().getType().getImports()) .toList(); } }
public static String qualifiedMethodName(ResourceMethod method) { return method.getParentResource().getType() + "#" + method.getMethod().getName(); }
public Method( ExecutableElement element, Collection<String> existingVariableNames) { this.element = element; this.returnType = new Type(element.getReturnType()); this.name = element.getSimpleName().toString(); this.parameters = processParameters(element, existingVariableNames); }
private void processResult(Method method) { String restActionName = RestAction.class.getCanonicalName(); Type returnType = method.getReturnType(); if (restActionName.equals(returnType.getQualifiedName())) { resolveRestActionResult(method); } else { Optional<Primitives> primitive = findByPrimitive(returnType.getQualifiedParameterizedName()); if (primitive.isPresent()) { resultType = new Type(primitive.get().getBoxedClass().getCanonicalName()); } else { resultType = returnType; } } }
void processMethod(Method method) { processElement(method.getElement()); processVerb(method); processResult(method); createVariables(method); }
@Override public Collection<String> getImports() { return FluentIterable.from(getMethod().getImports()) .append(getEndPoint().getType().getImports()) .toList(); } }
public CodeSnippet process(ResourceMethod context) { ensureInitialized(); for (ResourceMethodProcessor processor : processors) { if (processor.canProcess(context)) { return processor.process(context); } } logger.error(NO_PROCESSORS_FOUND, context.getMethod().getName()); throw new UnableToProcessException(); }
private void resolveVariable(Method method, Variable variable) { HttpVariable httpVariable = new HttpVariable(logger, utils, getPath(), variable); if (body.isPresent() && httpVariable.isBody()) { ExecutableElement methodElement = method.getElement(); logger.error() .context(methodElement) .log(MANY_POTENTIAL_BODY, NameUtils.qualifiedMethodName(methodElement)); throw new UnableToProcessException(); } if (httpVariable.isBody()) { body = Optional.of(httpVariable); } else { httpVariables.add(httpVariable); } }
public List<Variable> processFields(ResourceMethod method) { List<Variable> fields = new ArrayList<>(); Resource parent = method.getParentResource(); if (parent instanceof SubResource) { fields.addAll(((SubResource) parent).getFields()); } fields.addAll(method.getMethod().getParameters()); return fields; } }
private void logPotentialErrors(Method method) { ExecutableElement methodElement = method.getElement(); String methodName = NameUtils.qualifiedMethodName(methodElement); boolean containsFormVariables = containsFormVariables(); boolean containsBody = body.isPresent(); if (containsBody && containsFormVariables) { logger.error().context(methodElement).log(FORM_AND_BODY_PARAM, methodName); throw new UnableToProcessException(); } if ((verb == HttpVerb.GET || verb == HttpVerb.HEAD) && (containsBody || containsFormVariables)) { logger.error().context(methodElement).log(GET_WITH_BODY, methodName); throw new UnableToProcessException(); } }