/**
   * Extracts parameters from a method call and attaches these with the comments extracted from the
   * javadoc
   *
   * @param apiAction The Verb of the action containing these parametes
   * @param method The method to inspect
   * @param parameterComments The parameter comments associated with these parameters
   * @return A collection of parameters keyed by name
   */
  protected Map<String, RamlQueryParameter> extractQueryParameters(
      RamlActionType apiAction, Method method, Map<String, String> parameterComments) {
    // Since POST requests have a body we choose to keep all request data in one place as much as
    // possible
    if (apiAction.equals(RamlActionType.POST) || method.getParameterCount() == 0) {
      return Collections.emptyMap();
    }
    Map<String, RamlQueryParameter> queryParams = new LinkedHashMap<>();

    for (Parameter param : method.getParameters()) {
      if (isQueryParameter(
          param)) { // Lets skip resourceIds since these are going to be going in the URL
        RamlParamType simpleType = SchemaHelper.mapSimpleType(param.getType());

        if (simpleType == null) {
          queryParams.putAll(
              SchemaHelper.convertClassToQueryParameters(
                  param, javaDocs.getJavaDoc(param.getType())));
        } else {
          // Check if we have comments
          String paramComment = parameterComments.get(param.getName());
          queryParams.putAll(SchemaHelper.convertParameterToQueryParameter(param, paramComment));
        }
      }
    }
    return queryParams;
  }
Example #2
0
  PrivilegeNG addController(Class<?> controller_class, Method method) {
    StringBuilder sb = new StringBuilder();
    sb.append(controller_class.getName());
    sb.append(": ");

    if (method.getReturnType().getSimpleName().equalsIgnoreCase("void") == false) {
      sb.append(method.getReturnType().getSimpleName());
      sb.append(" ");
    }
    sb.append(method.getName());
    sb.append("(");
    if (method.getParameterCount() > 0) {
      Parameter[] params = method.getParameters();
      for (int pos = 0; pos < params.length; pos++) {
        sb.append(params[pos].getType().getSimpleName());
        if (pos + 1 < params.length) {
          sb.append(", ");
        }
      }
    }
    sb.append(")");

    associated_controllers.add(sb.toString());
    return this;
  }
 private static List<CacheParameterDetail> initializeAllParameterDetails(Method method) {
   List<CacheParameterDetail> result = new ArrayList<CacheParameterDetail>();
   for (int i = 0; i < method.getParameterCount(); i++) {
     CacheParameterDetail detail = new CacheParameterDetail(method, i);
     result.add(detail);
   }
   return result;
 }
  /**
   * Internal logic for verification of method signatures that will receive events
   *
   * @param methodParent class containing the method
   * @param method method
   * @throws InvalidListenerException if the method signature is invalid
   */
  private static void validateMethodSignature(Class methodParent, Method method)
      throws InvalidListenerException {
    // Firstly, the method should be unary
    if (method.getParameterCount() != 1) throw new InvalidListenerException(methodParent, method);

    // Check assignability
    if (!Event.class.isAssignableFrom(method.getParameterTypes()[0]))
      throw new InvalidListenerException(methodParent, method);
  }
 private void parseArguments(Method method) {
   ImmutableSet<String> typeParameterNames =
       typeParameters.stream().map(TypeParameter::value).collect(toImmutableSet());
   for (int i = 0; i < method.getParameterCount(); i++) {
     Annotation[] annotations = method.getParameterAnnotations()[i];
     Class<?> parameterType = method.getParameterTypes()[i];
     // Skip injected parameters
     if (parameterType == ConnectorSession.class) {
       continue;
     }
     if (containsMetaParameter(annotations)) {
       checkArgument(
           annotations.length == 1, "Meta parameters may only have a single annotation");
       checkArgument(argumentTypes.isEmpty(), "Meta parameter must come before parameters");
       Annotation annotation = annotations[0];
       if (annotation instanceof TypeParameter) {
         checkArgument(
             typeParameters.contains(annotation),
             "Injected type parameters must be declared with @TypeParameter annotation on the method");
       }
       dependencies.add(parseDependency(annotation));
     } else {
       SqlType type = null;
       boolean nullableArgument = false;
       for (Annotation annotation : annotations) {
         if (annotation instanceof SqlType) {
           type = (SqlType) annotation;
         }
         if (annotation instanceof Nullable) {
           nullableArgument = true;
         }
       }
       requireNonNull(type, format("@SqlType annotation missing for argument to %s", method));
       if (typeParameterNames.contains(type.value())
           && !(parameterType == Object.class && nullableArgument)) {
         // Infer specialization on this type parameter. We don't do this for @Nullable Object
         // because it could match a type like BIGINT
         Class<?> specialization = specializedTypeParameters.get(type.value());
         Class<?> nativeParameterType = Primitives.unwrap(parameterType);
         checkArgument(
             specialization == null || specialization.equals(nativeParameterType),
             "%s has conflicting specializations %s and %s",
             type.value(),
             specialization,
             nativeParameterType);
         specializedTypeParameters.put(type.value(), nativeParameterType);
       }
       argumentNativeContainerTypes.add(parameterType);
       argumentTypes.add(type.value());
       nullableArguments.add(nullableArgument);
     }
   }
 }
  /**
   * Extracts the TOs and other parameters from a method and will convert into JsonSchema for
   * inclusion in the body TODO refactor this code structure
   *
   * @param apiAction The Verb of the action to be added
   * @param method The method to be inspected
   * @param parameterComments The parameter comments associated with these parameters
   * @return A map of supported mime types for the request
   */
  protected Map<String, RamlMimeType> extractRequestBodyFromMethod(
      RamlActionType apiAction, Method method, Map<String, String> parameterComments) {

    if (!(doesActionTypeSupportRequestBody(apiAction)) || method.getParameterCount() == 0) {
      return Collections.emptyMap();
    }

    String comment = null;
    List<ApiParameterMetadata> apiParameters = getApiParameters(method, false, true);
    if (apiParameters.size() == 0) {
      // We only have url params it seems
      return Collections.emptyMap();
    }
    Pair<String, RamlMimeType> schemaAndMime =
        extractRequestBody(method, parameterComments, comment, apiParameters);

    return Collections.singletonMap(schemaAndMime.getFirst(), schemaAndMime.getSecond());
  }
 /** Determines if a given method is the substitute method of this plugin. */
 private boolean isSubstitute(Method m) {
   if (Modifier.isStatic(m.getModifiers()) && m.getName().equals(name)) {
     if (parameters.length == m.getParameterCount()) {
       Class<?>[] mparams = m.getParameterTypes();
       int start = 0;
       if (!originalIsStatic) {
         start = 1;
         if (!mparams[0].isAssignableFrom(resolveType(parameters[0], false))) {
           return false;
         }
       }
       for (int i = start; i < mparams.length; i++) {
         if (mparams[i] != resolveType(parameters[i], false)) {
           return false;
         }
       }
     }
     return true;
   }
   return false;
 }
 private Method getFinder(Class<?> entityClass) {
   String finderMethod = "find" + getEntityName(entityClass);
   Method[] methods;
   boolean localOnlyFiltered;
   try {
     methods = entityClass.getDeclaredMethods();
     localOnlyFiltered = true;
   } catch (SecurityException ex) {
     // Not allowed to access non-public methods...
     // Fallback: check locally declared public methods only.
     methods = entityClass.getMethods();
     localOnlyFiltered = false;
   }
   for (Method method : methods) {
     if (Modifier.isStatic(method.getModifiers())
         && method.getName().equals(finderMethod)
         && method.getParameterCount() == 1
         && method.getReturnType().equals(entityClass)
         && (localOnlyFiltered || method.getDeclaringClass().equals(entityClass))) {
       return method;
     }
   }
   return null;
 }
 /**
  * Models a configured field and provides mechanisms for injection.
  *
  * @param method the method instance.
  */
 public ConfiguredSetterMethod(Method method) {
   if (void.class.equals(method.getReturnType()) && method.getParameterCount() == 1) {
     this.setterMethod = method;
   }
 }