graph inference: take into account present type args during graph inference (IDEA-103023)

(cherry picked from commit e9e05d9d47210f6e315cef233f8b5b33192df7fc)
This commit is contained in:
anna
2013-03-21 10:40:44 +01:00
parent 5651726786
commit ec801909f9
4 changed files with 32 additions and 1 deletions
@@ -151,6 +151,23 @@ public class MethodCandidateInfo extends CandidateInfo{
: PsiExpression.EMPTY_ARRAY);
}
public PsiSubstitutor inferSubstitutorFromArgs(final ParameterTypeInferencePolicy policy, final PsiExpression[] arguments) {
if (myTypeArguments == null) {
return inferTypeArguments(policy, arguments);
}
else {
PsiSubstitutor incompleteSubstitutor = super.getSubstitutor();
PsiMethod method = getElement();
if (method != null) {
PsiTypeParameter[] typeParams = method.getTypeParameters();
for (int i = 0; i < myTypeArguments.length && i < typeParams.length; i++) {
incompleteSubstitutor = incompleteSubstitutor.put(typeParams[i], myTypeArguments[i]);
}
}
return incompleteSubstitutor;
}
}
public PsiSubstitutor inferTypeArguments(final ParameterTypeInferencePolicy policy, final PsiExpression[] arguments) {
Map<PsiElement, Pair<PsiMethod, PsiSubstitutor>> map = CURRENT_CANDIDATE.get();
if (map == null) {
@@ -71,7 +71,7 @@ public class ProcessCandidateParameterTypeInferencePolicy extends DefaultParamet
protected PsiSubstitutor getSubstitutor(PsiCallExpression contextCall, PsiExpression[] expressions, int i, JavaResolveResult result) {
if (result instanceof MethodCandidateInfo) {
List<PsiExpression> leftArgs = getExpressions(expressions, i);
return ((MethodCandidateInfo)result).inferTypeArguments(this, leftArgs.toArray(new PsiExpression[leftArgs.size()]));
return ((MethodCandidateInfo)result).inferSubstitutorFromArgs(this, leftArgs.toArray(new PsiExpression[leftArgs.size()]));
}
else {
return result.getSubstitutor();
@@ -0,0 +1,10 @@
import java.util.*;
public class DiamondTest {
public <U> void foo(ArrayList<U> p) {}
public void test() {
DiamondTest diamondTest = new DiamondTest();
diamondTest.<Integer>foo(new ArrayList<>(3));
}
}
@@ -76,6 +76,10 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
doTest();
}
public void testInferFromTypeArgs() throws Exception {
doTest();
}
private void doTest() throws Exception {
doTest(false);
}