mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-21 22:11:40 +07:00
static interface method: if called on wrong qualifier mark as static problem (IDEA-139651)
This commit is contained in:
@@ -528,7 +528,12 @@ public class HighlightMethodUtil {
|
||||
elementToHighlight = referenceToMethod.getReferenceNameElement();
|
||||
}
|
||||
else if (element != null && !resolveResult.isStaticsScopeCorrect()) {
|
||||
description = HighlightUtil.buildProblemWithStaticDescription(element);
|
||||
final LanguageLevel languageLevel = PsiUtil.getLanguageLevel(referenceToMethod);
|
||||
final String staticInterfaceMethodMessage = LambdaUtil
|
||||
.getInvalidQualifier4StaticInterfaceMethodMessage((PsiMethod)element, referenceToMethod, resolveResult.getCurrentFileResolveScope(), languageLevel);
|
||||
description = staticInterfaceMethodMessage != null
|
||||
? staticInterfaceMethodMessage
|
||||
: HighlightUtil.buildProblemWithStaticDescription(element);
|
||||
elementToHighlight = referenceToMethod.getReferenceNameElement();
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -51,11 +51,17 @@ public class MethodCandidatesProcessor extends MethodsProcessor{
|
||||
}
|
||||
}
|
||||
|
||||
public void addMethod(@NotNull PsiMethod method, final PsiSubstitutor substitutor, final boolean staticProblem) {
|
||||
public void addMethod(@NotNull PsiMethod method, final PsiSubstitutor substitutor, boolean staticProblem) {
|
||||
final boolean isAccessible = JavaResolveUtil.isAccessible(method, getContainingClass(method), method.getModifierList(),
|
||||
myPlace, myAccessClass, myCurrentFileContext, myPlaceFile) &&
|
||||
!isShadowed(method);
|
||||
if (isAccepted(method) && !(isInterfaceStaticMethodAccessibleThroughInheritance(method) && ImportsUtil.hasStaticImportOn(myPlace, method, true))) {
|
||||
if (!staticProblem && myAccessClass != null && method.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
if (containingClass != null && containingClass.isInterface() && !containingClass.equals(myAccessClass)) {
|
||||
staticProblem = true;
|
||||
}
|
||||
}
|
||||
add(createCandidateInfo(method, substitutor, staticProblem, isAccessible, false));
|
||||
if (acceptVarargs() && method.isVarArgs() && PsiUtil.isLanguageLevel8OrHigher(myPlace)) {
|
||||
add(createCandidateInfo(method, substitutor, staticProblem, isAccessible, true));
|
||||
|
||||
@@ -20,6 +20,6 @@ class Bug {
|
||||
|
||||
Function<Integer, Integer> g = <error descr="Static method may be invoked on containing interface class only">f.identity();</error>
|
||||
|
||||
Function<Integer, Integer> h = <error descr="Static method may be invoked on containing interface class only">IFunction.identity();</error>
|
||||
Function<Integer, Integer> h = IFunction.<error descr="Static method may be invoked on containing interface class only">identity</error>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import java.util.function.Function;
|
||||
|
||||
interface Test<R> {
|
||||
|
||||
static <T, R> Inner<R> go(T t, Function<T, R> f) {
|
||||
return new Inner<>();
|
||||
}
|
||||
|
||||
class Inner<R> implements Test<R> {
|
||||
|
||||
<T> Inner<R> go(T t, Function<T, R> f) {
|
||||
return new Inner<>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
class App {
|
||||
|
||||
void run(Test.Inner<Integer> go) {
|
||||
|
||||
Test.Inner<Integer> test = go.go(1, (Integer i) -> i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ public class Interface8MethodsHighlightingTest extends LightCodeInsightFixtureTe
|
||||
public void testCyclicSubstitutor() { doTest(false, false); }
|
||||
public void testThisAccessibility() { doTest(false, false); }
|
||||
public void testStaticMethodCalls() { doTest(false, false); }
|
||||
public void testStaticMethodCallsAndOverloadResolution() { doTest(false, false); }
|
||||
public void testDefaultMethodOverrideEquivalentObject() { doTest(false, false); }
|
||||
public void testStaticMethods() { doTest(false, false); }
|
||||
public void testFinalStaticDefaultMethods() { doTest(false, false); }
|
||||
|
||||
Reference in New Issue
Block a user