Java Code Examples for java.lang.reflect.Method.getTypeParameters()

The following are Jave code examples for showing how to use getTypeParameters() of the java.lang.reflect.Method class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Reer   File: TypeInspector.java   View Source Code Vote up 6 votes
private void visit(Class<?> type, Set<Class<?>> types) {
    if (type.isArray()) {
        visit(type.getComponentType(), types);
        return;
    }

    if (!type.isInterface() || !types.add(type) || stopAt.contains(type)) {
        return;
    }

    for (Type superType : type.getGenericInterfaces()) {
        visit(superType, types);
    }
    for (Method method : type.getDeclaredMethods()) {
        visit(method.getGenericReturnType(), types);
        for (TypeVariable<Method> typeVariable : method.getTypeParameters()) {
            visit(typeVariable, types);
        }
    }
}
 
Example 2
Project: businessworks   File: InjectionPoint.java   View Source Code Vote up 6 votes
private static boolean isValidMethod(InjectableMethod injectableMethod,
    Errors errors) {
  boolean result = true;
  if (injectableMethod.jsr330) {
    Method method = injectableMethod.method;
    if (Modifier.isAbstract(method.getModifiers())) {
      errors.cannotInjectAbstractMethod(method);
      result = false;
    }
    if (method.getTypeParameters().length > 0) {
      errors.cannotInjectMethodWithTypeParameters(method);
      result = false;
    }
  }
  return result;
}
 
Example 3
Project: Reer   File: ModelRuleExtractor.java   View Source Code Vote up 5 votes
private void validateRuleMethod(MethodRuleDefinition<?, ?> ruleDefinition, Method ruleMethod, RuleSourceValidationProblemCollector problems) {
    if (Modifier.isPrivate(ruleMethod.getModifiers())) {
        problems.add(ruleMethod, "A rule method cannot be private");
    }
    if (Modifier.isAbstract(ruleMethod.getModifiers())) {
        problems.add(ruleMethod, "A rule method cannot be abstract");
    }

    if (ruleMethod.getTypeParameters().length > 0) {
        problems.add(ruleMethod, "Cannot have type variables (i.e. cannot be a generic method)");
    }

    // TODO validations on method: synthetic, bridge methods, varargs, abstract, native
    ModelType<?> returnType = ModelType.returnType(ruleMethod);
    if (returnType.isRawClassOfParameterizedType()) {
        problems.add(ruleMethod, "Raw type " + returnType + " used for return type (all type parameters must be specified of parameterized type)");
    }

    for (int i = 0; i < ruleDefinition.getReferences().size(); i++) {
        ModelReference<?> reference = ruleDefinition.getReferences().get(i);
        if (reference.getType().isRawClassOfParameterizedType()) {
            problems.add(ruleMethod, "Raw type " + reference.getType() + " used for parameter " + (i + 1) + " (all type parameters must be specified of parameterized type)");
        }
        if (reference.getPath() != null) {
            try {
                ModelPath.validatePath(reference.getPath().getPath());
            } catch (Exception e) {
                problems.add(ruleDefinition, "The declared model element path '" + reference.getPath().getPath() + "' used for parameter " + (i + 1) + " is not a valid path", e);
            }
        }
    }
}
 
Example 4
Project: guava-mock   File: FauxveridesTest.java   View Source Code Vote up 4 votes
MethodSignature(Method method) {
  name = method.getName();
  parameterTypes = Arrays.asList(method.getParameterTypes());
  typeSignature = new TypeSignature(method.getTypeParameters());
}
 
Example 5
Project: googles-monorepo-demo   File: FauxveridesTest.java   View Source Code Vote up 4 votes
MethodSignature(Method method) {
  name = method.getName();
  parameterTypes = Arrays.asList(method.getParameterTypes());
  typeSignature = new TypeSignature(method.getTypeParameters());
}