PsiType (final PsiTypeParameter typeParameter, final PsiParameter[] parameters, PsiExpression[] arguments, PsiSubstitutor partialSubstitutor, PsiElement parent, ReductionSystem system) { PsiType substitution = PsiTypes.nullType(); PsiResolveHelper helper = JavaPsiFacade.getInstance(typeParameter.getProject()).getResolveHelper(); if (parameters.length > 0) { for (int j = 0; j < arguments.length; j++) { PsiExpression argument = arguments[j]; final PsiParameter parameter = parameters[Math.min(j, parameters.length - 1)]; if (j >= parameters.length && !parameter.isVarArgs()) break; PsiType parameterType = parameter.getType(); PsiType argumentType = evaluateType(argument, system); if (parameterType instanceof PsiEllipsisType) { parameterType = ((PsiEllipsisType)parameterType).getComponentType(); if (arguments.length == parameters.length && argumentType instanceof PsiArrayType && !(((PsiArrayType)argumentType).getComponentType() instanceof PsiPrimitiveType)) { argumentType = ((PsiArrayType)argumentType).getComponentType(); } } final PsiType currentSubstitution = helper.getSubstitutionForTypeParameter(typeParameter, parameterType, argumentType, true, PsiUtil.getLanguageLevel(parent)); if (currentSubstitution == null) { substitution = null; break; } else if (currentSubstitution instanceof PsiWildcardType) { if (substitution instanceof PsiWildcardType) return PsiTypes.nullType(); } else if (PsiTypes.nullType().equals(currentSubstitution)) continue; if (PsiTypes.nullType().equals(substitution)) { substitution = currentSubstitution; continue; } if (!substitution.equals(currentSubstitution)) { if (substitution instanceof PsiTypeVariable || currentSubstitution instanceof PsiTypeVariable) { substitution = GenericsUtil.getLeastUpperBound(substitution, currentSubstitution, typeParameter.getManager()); if (substitution == null) break; } } } } if (PsiTypes.nullType().equals(substitution)) { substitution = inferMethodTypeParameterFromParent(typeParameter, partialSubstitutor, parent, system); } return substitution; }