mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
graph inference: take into account present type args during graph inference (IDEA-103023)
(cherry picked from commit e9e05d9d47210f6e315cef233f8b5b33192df7fc)
This commit is contained in:
@@ -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) {
|
||||
|
||||
+1
-1
@@ -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();
|
||||
|
||||
+10
@@ -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));
|
||||
}
|
||||
}
|
||||
+4
@@ -76,6 +76,10 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInferFromTypeArgs() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user