mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 05:21:29 +07:00
method refs: mark as potentially incompatible expression based reference of non-static method with incorrect number of parameters; contradict spec (15.12.2.1)
This commit is contained in:
@@ -178,7 +178,7 @@ public class PsiMethodReferenceUtil {
|
||||
PsiClassType.ClassResolveResult result = PsiUtil.resolveGenericsClassInType(type);
|
||||
containingClass = result.getElement();
|
||||
if (containingClass != null) {
|
||||
substitutor = result.getSubstitutor();
|
||||
return new QualifierResolveResult(containingClass, result.getSubstitutor(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,8 +97,8 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase
|
||||
final PsiElement element = resolveResult.getElement();
|
||||
if (element instanceof PsiMethod) {
|
||||
final boolean isStatic = ((PsiMethod)element).hasModifierProperty(PsiModifier.STATIC);
|
||||
final int parametersCount = ((PsiMethod)element).getParameterList().getParametersCount();
|
||||
if (qualifierResolveResult.isReferenceTypeQualified() && getReferenceNameElement() instanceof PsiIdentifier) {
|
||||
final int parametersCount = ((PsiMethod)element).getParameterList().getParametersCount();
|
||||
if (parametersCount == interfaceArity && isStatic) {
|
||||
return true;
|
||||
}
|
||||
@@ -106,8 +106,11 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase
|
||||
return true;
|
||||
}
|
||||
if (((PsiMethod)element).isVarArgs()) return true;
|
||||
} else if (!isStatic) {
|
||||
return true;
|
||||
}
|
||||
else if (!isStatic) {
|
||||
if (parametersCount == interfaceArity || ((PsiMethod)element).isVarArgs()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (element instanceof PsiClass) {
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.Function;
|
||||
class Test {
|
||||
private List<String> query(String request) {
|
||||
System.out.println(request);
|
||||
return null;
|
||||
}
|
||||
private List<String> <warning descr="Private method 'query(java.lang.String, java.lang.Object)' is never used">query</warning>(String request, Object context) {
|
||||
System.out.println(request + context);
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<String> <warning descr="Private method 'query1()' is never used">query1</warning>(){ return null;}
|
||||
private List<String> <warning descr="Private method 'query1(java.lang.String)' is never used">query1</warning>(String request) {
|
||||
System.out.println(request);
|
||||
return null;
|
||||
}
|
||||
private List<String> <warning descr="Private method 'query1(java.lang.String, java.lang.Object)' is never used">query1</warning>(String request, Object context) {
|
||||
System.out.println(request + context);
|
||||
return null;
|
||||
}
|
||||
|
||||
private static <Message, Reply> Set<Message> replyWith(Function<Message, List<Reply>> futureFn){
|
||||
System.out.println(futureFn);
|
||||
return null;
|
||||
}
|
||||
private static <Message, Reply> Set<Message> <warning descr="Private method 'replyWith(java.util.concurrent.Callable<java.util.List<Reply>>)' is never used">replyWith</warning>(Callable<List<Reply>> fn) {
|
||||
System.out.println(fn);
|
||||
return null;
|
||||
}
|
||||
|
||||
{
|
||||
Set<String> m = replyWith(this::query);
|
||||
System.out.println(m);
|
||||
Set<String> m1 = replyWith<error descr="Ambiguous method call: both 'Test.replyWith(Function<String, List<String>>)' and 'Test.replyWith(Callable<List<String>>)' match">(this::query1)</error>;
|
||||
System.out.println(m1);
|
||||
}
|
||||
}
|
||||
@@ -334,6 +334,10 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testPotentialCompatibilityWithInvalidShape() throws Exception {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user