@Override public final TypeVariable<?>[] getTypeParameters() { return method.getTypeParameters(); }
@Override public final TypeVariable<?>[] getTypeParameters() { return method.getTypeParameters(); }
@Override public final TypeVariable<?>[] getTypeParameters() { return method.getTypeParameters(); }
/** * Get method type parameters. * * See also {@link Method#getTypeParameters()}. * * @return method type parameters. */ @SuppressWarnings("UnusedDeclaration") public TypeVariable<Method>[] getTypeParameters() { return am.getTypeParameters(); }
/** * Get method type parameters. * * See also {@link Method#getTypeParameters()}. * * @return method type parameters. */ @SuppressWarnings("UnusedDeclaration") public TypeVariable<Method>[] getTypeParameters() { return am.getTypeParameters(); }
@Override public final TypeVariable<?>[] getTypeParameters() { return method.getTypeParameters(); }
public static boolean isGeneric(Method method) { return method.getTypeParameters().length != 0; }
public static List<TypeVariable<Method>> callGetTypeParameters(Method thiz) { return Arrays.asList(thiz.getTypeParameters()); }
private GenericMetadataSupport resolveGenericType(Type type, Method method) { if (type instanceof Class) { return new NotGenericReturnTypeSupport(this, type); } if (type instanceof ParameterizedType) { return new ParameterizedReturnType(this, method.getTypeParameters(), (ParameterizedType) type); } if (type instanceof TypeVariable) { return new TypeVariableReturnType(this, method.getTypeParameters(), (TypeVariable<?>) type); } throw new MockitoException("Ouch, it shouldn't happen, type '" + type.getClass().getCanonicalName() + "' on method : '" + method.toGenericString() + "' is not supported : " + type); }
/** * As per [JACKSON-468], we need to also allow declaration of local * type bindings; mostly it will allow defining bounds. */ @Override public JavaType getType(TypeBindings bindings) { return getType(bindings, _method.getTypeParameters()); }
MethodSignature(Method method) { name = method.getName(); parameterTypes = Arrays.asList(method.getParameterTypes()); typeSignature = new TypeSignature(method.getTypeParameters()); }
public <T> void testCaptureTypeParameter() throws Exception { TypeVariable<?> variable = new TypeParameter<T>() {}.typeVariable; TypeVariable<?> expected = TypeParameterTest.class.getDeclaredMethod("testCaptureTypeParameter") .getTypeParameters()[0]; assertEquals(expected, variable); }
private JavaTypeDefinition getGenericType(final String parameterName, Method method, List<JavaTypeDefinition> methodTypeArguments) { if (method != null && methodTypeArguments != null) { int paramIndex = getGenericTypeIndex(method.getTypeParameters(), parameterName); if (paramIndex != -1) { return methodTypeArguments.get(paramIndex); } } return getGenericType(parameterName); }
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; }
/** * https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.12.2.1 * Potential applicability. */ public static boolean isMethodApplicable(Method method, String methodName, int argArity, Class<?> accessingClass, List<JavaTypeDefinition> typeArguments) { return method.getName().equals(methodName) // name matches // is visible && isMemberVisibleFromClass(method.getDeclaringClass(), method.getModifiers(), accessingClass) // if method is vararg with arity n, then the invocation's arity >= n - 1 && (!method.isVarArgs() || argArity >= getArity(method) - 1) // if the method isn't vararg, then arity matches && (method.isVarArgs() || argArity == getArity(method)) // isn't generic or arity of type arguments matches that of parameters && (!isGeneric(method) || typeArguments.isEmpty() || method.getTypeParameters().length == typeArguments.size()); }
Assert.notNull(args, "Argument array must not be null"); TypeVariable<Method>[] declaredTypeVariables = method.getTypeParameters(); Type genericReturnType = method.getGenericReturnType(); Type[] methodParameterTypes = method.getGenericParameterTypes();
public static List<Constraint> produceInitialConstraints(Method method, ASTArgumentList argList, List<Variable> variables) { List<Constraint> result = new ArrayList<>(); Type[] methodParameters = method.getGenericParameterTypes(); TypeVariable<Method>[] methodTypeParameters = method.getTypeParameters(); // TODO: add support for variable arity methods for (int i = 0; i < methodParameters.length; i++) { int typeParamIndex = -1; if (methodParameters[i] instanceof TypeVariable) { typeParamIndex = JavaTypeDefinition .getGenericTypeIndex(methodTypeParameters, ((TypeVariable<?>) methodParameters[i]).getName()); } if (typeParamIndex != -1) { // TODO: we are cheating here, it should be a contraint of the form 'var -> expression' not 'var->type' result.add(new Constraint(((TypeNode) argList.jjtGetChild(i)).getTypeDefinition(), variables.get(typeParamIndex), LOOSE_INVOCATION)); } } return result; }
@Test public void testTypesSatisfyVariables() throws SecurityException, NoSuchFieldException, NoSuchMethodException { final Map<TypeVariable<?>, Type> typeVarAssigns = new HashMap<>(); final Integer max = TypeUtilsTest.<Integer> stub(); typeVarAssigns.put(getClass().getMethod("stub").getTypeParameters()[0], Integer.class); assertTrue(TypeUtils.typesSatisfyVariables(typeVarAssigns)); typeVarAssigns.clear(); typeVarAssigns.put(getClass().getMethod("stub2").getTypeParameters()[0], Integer.class); assertTrue(TypeUtils.typesSatisfyVariables(typeVarAssigns)); typeVarAssigns.clear(); typeVarAssigns.put(getClass().getMethod("stub3").getTypeParameters()[0], Integer.class); assertTrue(TypeUtils.typesSatisfyVariables(typeVarAssigns)); }
classToString(javaMethod.getReturnType())); for (TypeVariable<Method> typeVariable : javaMethod.getTypeParameters()) { boolean hasBound = false; StringBuilder s = new StringBuilder(typeVariable.getName());
candidate.getParameterCount() >= minNrOfArgs) { if (candidate.getTypeParameters().length > 0) { try {