if (i < args.length && args[i] != null) { final Name nameAnnotation = annotatedParam .getAnnotation(Name.class); if (nameAnnotation != null && nameAnnotation.value() != null) { final String name = nameAnnotation.value();
if (annotatedParams.get(0).getType().equals(ObjectNode.class) && annotatedParams.get(0).getAnnotations().size() == 0) { objects[i + offset] = TypeUtil.inject( paramsObject.get(name), p.getGenericType()); } else { if (isRequired(p)) { "Required parameter '" + name + "' missing."); } else if (p.getType().isPrimitive()) { + "' cannot be both optional and " + "a primitive type (" + p.getType().getSimpleName() + ")"); } else { objects[i + offset] = null;
paramData.put("name", name); paramData.put("type", typeToString(param.getGenericType())); paramData.put("required", isRequired(param)); descParams.add(paramData);
/** * Test whether a method has named parameters. * * @param method * the method * @param requestParams * the request params * @return hasNamedParams */ private static boolean hasNamedParams(final AnnotatedMethod method, final RequestParams requestParams) { for (final AnnotatedParam param : method.getParams()) { boolean found = false; for (final Annotation a : param.getAnnotations()) { if (requestParams != null && requestParams.has(a)) { found = true; break; } else if (a instanceof Name) { found = true; break; } } if (!found) { return false; } } return true; }
/** * Test if a parameter is required Reads the parameter annotation @Required. * Returns True if the annotation is not provided. * * @param param * the param * @return required */ @SuppressWarnings("deprecation") static boolean isRequired(final AnnotatedParam param) { boolean required = true; final com.almende.eve.protocol.jsonrpc.annotation.Required requiredAnnotation = param .getAnnotation(com.almende.eve.protocol.jsonrpc.annotation.Required.class); if (requiredAnnotation != null) { required = requiredAnnotation.value(); } if (param.getAnnotation(Optional.class) != null) { required = false; } return required; }
/** * Test if a parameter is required Reads the parameter annotation @Required. * Returns True if the annotation is not provided. * * @param param * the param * @return required */ @SuppressWarnings("deprecation") static boolean isRequired(final AnnotatedParam param) { boolean required = true; final com.almende.eve.protocol.jsonrpc.annotation.Required requiredAnnotation = param .getAnnotation(com.almende.eve.protocol.jsonrpc.annotation.Required.class); if (requiredAnnotation != null) { required = requiredAnnotation.value(); } if (param.getAnnotation(Optional.class) != null) { required = false; } return required; }
/** * Find a request annotation in the given parameters Returns null if no * system annotation is not found. * * @param param * the param * @param requestParams * the request params * @return annotation */ private static Annotation getRequestAnnotation(final AnnotatedParam param, final RequestParams requestParams) { for (final Annotation annotation : param.getAnnotations()) { if (requestParams != null && requestParams.has(annotation)) { return annotation; } } return null; }
/** * Get the name of a parameter Reads the parameter annotation @Name. Returns * null if the annotation is not provided. * * @param param * the param * @return name */ static String getName(final AnnotatedParam param) { String name = null; final Name nameAnnotation = param.getAnnotation(Name.class); if (nameAnnotation != null) { name = nameAnnotation.value(); } return name; }