mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
new inference: method refs overload resolution: filter static problems for ReferenceType refs only
This commit is contained in:
@@ -123,13 +123,7 @@ public class MethodCandidateInfo extends CandidateInfo{
|
||||
if (level > ApplicabilityLevel.NOT_APPLICABLE && !isTypeArgumentsApplicable(false)) level = ApplicabilityLevel.NOT_APPLICABLE;
|
||||
return level;
|
||||
}
|
||||
Integer boxedLevel = ourOverloadGuard.doPreventingRecursion(myArgumentList, false, new Computable<Integer>() {
|
||||
@Override
|
||||
public Integer compute() {
|
||||
return getApplicabilityLevelInner();
|
||||
}
|
||||
});
|
||||
return boxedLevel != null ? boxedLevel : getApplicabilityLevel();
|
||||
return getApplicabilityLevelInner();
|
||||
}
|
||||
|
||||
public PsiSubstitutor getSiteSubstitutor() {
|
||||
|
||||
@@ -557,11 +557,12 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase
|
||||
}
|
||||
}
|
||||
|
||||
final boolean identifierRef = getReferenceNameElement() instanceof PsiIdentifier;
|
||||
//If the first search produces a static method, and no non-static method is applicable for the second search, then the result of the first search is the compile-time declaration.
|
||||
final List<CandidateInfo> firstCandidateInfos = filterStaticCorrectCandidates(firstCandidates, true);
|
||||
final List<CandidateInfo> firstCandidateInfos = myQualifierResolveResult.isReferenceTypeQualified() && identifierRef ? filterStaticCorrectCandidates(firstCandidates, true) : firstCandidates;
|
||||
|
||||
//If the second search produces a non-static method, and no static method is applicable for the first search, then the result of the second search is the compile-time declaration.
|
||||
final List<CandidateInfo> secondCandidateInfos = filterStaticCorrectCandidates(secondCandidates, false);
|
||||
final List<CandidateInfo> secondCandidateInfos = myQualifierResolveResult.isReferenceTypeQualified() && identifierRef ? filterStaticCorrectCandidates(secondCandidates, false) : secondCandidates;
|
||||
|
||||
final int acceptedCount = firstCandidateInfos.size() + secondCandidateInfos.size();
|
||||
if (acceptedCount == 1) {
|
||||
@@ -569,8 +570,8 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase
|
||||
}
|
||||
|
||||
conflicts.clear();
|
||||
firstCandidates.addAll(secondCandidates);
|
||||
conflicts.addAll(firstCandidates);
|
||||
firstCandidateInfos.addAll(secondCandidateInfos);
|
||||
conflicts.addAll(firstCandidateInfos);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class AlienTest {
|
||||
<error descr="Incompatible types. Found: '<method reference>', required: 'AlienTest.IInt'">IInt i2 = MyTest::foo;</error>
|
||||
<error descr="Incompatible types. Found: '<method reference>', required: 'AlienTest.IInt'">IInt i3 = MyTest::bar;</error>
|
||||
<error descr="Incompatible types. Found: '<method reference>', required: 'AlienTest.IIntInt'">IIntInt i4 = MyTest::bar;</error>
|
||||
IInt i5 = <error descr="Non-static method cannot be referenced from a static context">MyTest::baz</error>;
|
||||
<error descr="Incompatible types. Found: '<method reference>', required: 'AlienTest.IInt'">IInt i5 = MyTest::baz;</error>
|
||||
IInt i6 = <error descr="'foo(int)' is not public in 'MyTest.Foo'. Cannot be accessed from outside package">MyTest.foo::foo</error>;
|
||||
IInt i7 = MyTest.<error descr="'MyTest.Foo' has private access in 'MyTest'">Foo</error>::foo;
|
||||
}
|
||||
|
||||
@@ -41,14 +41,14 @@ class MyTest1 {
|
||||
static void call2(I2 s) { }
|
||||
|
||||
static void test1() {
|
||||
I1 s1 = <error descr="Non-static method cannot be referenced from a static context">MyTest1 ::m1</error>;
|
||||
call1(<error descr="Non-static method cannot be referenced from a static context">MyTest1::m1</error>);
|
||||
<error descr="Incompatible types. Found: '<method reference>', required: 'MyTest1.I1'">I1 s1 = MyTest1 ::m1;</error>
|
||||
call1<error descr="'call1(MyTest1.I1)' in 'MyTest1' cannot be applied to '(<method reference>)'">(MyTest1::m1)</error>;
|
||||
I1 s2 = MyTest1 :: m2;
|
||||
call1(MyTest1::m2);
|
||||
I1 s3 = MyTest1::m3;
|
||||
call1(MyTest1::m3);
|
||||
I1 s4 = <error descr="Non-static method cannot be referenced from a static context">MyTest1::m4</error>;
|
||||
call1(<error descr="Non-static method cannot be referenced from a static context">MyTest1::m4</error>);
|
||||
<error descr="Incompatible types. Found: '<method reference>', required: 'MyTest1.I1'">I1 s4 = MyTest1::m4;</error>
|
||||
call1<error descr="'call1(MyTest1.I1)' in 'MyTest1' cannot be applied to '(<method reference>)'">(MyTest1::m4)</error>;
|
||||
}
|
||||
|
||||
static void test2() {
|
||||
@@ -90,14 +90,14 @@ class MyTest2 {
|
||||
static void call2(I2 s) { }
|
||||
|
||||
static void test1() {
|
||||
I1 s1 = <error descr="Non-static method cannot be referenced from a static context">MyTest2 ::m1</error>;
|
||||
call1(<error descr="Non-static method cannot be referenced from a static context">MyTest2::m1</error>);
|
||||
<error descr="Incompatible types. Found: '<method reference>', required: 'MyTest2.I1'">I1 s1 = MyTest2 ::m1;</error>
|
||||
call1<error descr="'call1(MyTest2.I1)' in 'MyTest2' cannot be applied to '(<method reference>)'">(MyTest2::m1)</error>;
|
||||
I1 s2 = MyTest2 :: m2;
|
||||
call1(MyTest2::m2);
|
||||
I1 s3 = MyTest2::m3;
|
||||
call1(MyTest2::m3);
|
||||
I1 s4 = <error descr="Non-static method cannot be referenced from a static context">MyTest2::m4</error>;
|
||||
call1(<error descr="Non-static method cannot be referenced from a static context">MyTest2::m4</error>);
|
||||
<error descr="Incompatible types. Found: '<method reference>', required: 'MyTest2.I1'">I1 s4 = MyTest2::m4;</error>
|
||||
call1<error descr="'call1(MyTest2.I1)' in 'MyTest2' cannot be applied to '(<method reference>)'">(MyTest2::m4)</error>;
|
||||
}
|
||||
|
||||
static void test2() {
|
||||
@@ -115,9 +115,9 @@ class MyTest2 {
|
||||
static void call3(I1 s) {}
|
||||
static void call3(I2 s) {}
|
||||
static {
|
||||
call3<error descr="Ambiguous method call: both 'MyTest2.call3(I1)' and 'MyTest2.call3(I2)' match">(MyTest2::m1)</error>;
|
||||
call3(MyTest2::m1);
|
||||
call3<error descr="Ambiguous method call: both 'MyTest2.call3(I1)' and 'MyTest2.call3(I2)' match">(MyTest2::m2)</error>;
|
||||
call3<error descr="Cannot resolve method 'call3(<method reference>)'">(MyTest2::m3)</error>;
|
||||
call3(MyTest2::m3);
|
||||
call3<error descr="Cannot resolve method 'call3(<method reference>)'">(MyTest2::m4)</error>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ class MyTest {
|
||||
|
||||
|
||||
{
|
||||
I1 i_1 = <error descr="Non-static method cannot be referenced from a static context">MyTest::_1</error>;
|
||||
<error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I1'">I1 i_1 = MyTest::_1;</error>
|
||||
<error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I1'">I1 i_2 = MyTest::_2;</error>
|
||||
<error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I1'">I1 i_3 = MyTest::_3;</error>
|
||||
<error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I1'">I1 i_4 = MyTest::_4;</error>
|
||||
|
||||
@@ -3,7 +3,7 @@ import java.util.*;
|
||||
class Test {
|
||||
void test() {
|
||||
Comparator<Test> r2 = Test::yyy;
|
||||
Comparator1<Test> c1 = <error descr="Non-static method cannot be referenced from a static context">Test::yyy</error>;
|
||||
<error descr="Incompatible types. Found: '<method reference>', required: 'Comparator1<Test>'">Comparator1<Test> c1 = Test::yyy;</error>
|
||||
<error descr="Incompatible types. Found: '<method reference>', required: 'Comparator1<Test>'">Comparator1<Test> c2 = Test::xxx;</error>
|
||||
}
|
||||
int yyy(Test... p) { return 1; }
|
||||
|
||||
@@ -51,8 +51,8 @@ class Test {
|
||||
|
||||
static {
|
||||
Test s1 = staticCall(Test::n0);
|
||||
Test s2 = staticCall<error descr="Ambiguous method call: both 'Test.staticCall(I1<String & Test>)' and 'Test.staticCall(I2<Test,String>)' match">(Test::n1)</error>;
|
||||
Test s3 = staticCall(<error descr="Non-static method cannot be referenced from a static context">Test::n2</error>);
|
||||
Test s2 = staticCall(Test::n1);
|
||||
Test s3 = staticCall<error descr="Cannot resolve method 'staticCall(<method reference>)'">(Test::n2)</error>;
|
||||
Test s4 = staticCall<error descr="Ambiguous method call: both 'Test.staticCall(I1<Test>)' and 'Test.staticCall(I2<Test,String>)' match">(Test::n01)</error>;
|
||||
Test s5 = staticCall<error descr="Ambiguous method call: both 'Test.staticCall(I1<Test>)' and 'Test.staticCall(I2<Test,String>)' match">(Test::n012)</error>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user