mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 11:50:54 +07:00
java: fix static import choice during interface method resolve (IDEA-262462)
GitOrigin-RevId: 349b3353be22c324dfd06871320347b3b3ebc72d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
89bf390fb1
commit
32b9ee5304
@@ -25,6 +25,7 @@ import com.intellij.psi.impl.source.resolve.SymbolCollectingProcessor;
|
||||
import com.intellij.psi.impl.source.resolve.SymbolCollectingProcessor.ResultWithContext;
|
||||
import com.intellij.psi.impl.source.tree.JavaElementType;
|
||||
import com.intellij.psi.scope.*;
|
||||
import com.intellij.psi.scope.processor.MethodsProcessor;
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.*;
|
||||
@@ -245,13 +246,26 @@ public abstract class PsiJavaFileBaseImpl extends PsiFileImpl implements PsiJava
|
||||
@Override
|
||||
public boolean execute(@NotNull final PsiElement element, @NotNull final ResolveState state) {
|
||||
if (element instanceof PsiModifierListOwner && ((PsiModifierListOwner)element).hasModifierProperty(PsiModifier.STATIC)) {
|
||||
PsiScopeProcessor delegate = getDelegate();
|
||||
if (element instanceof PsiNamedElement) {
|
||||
final String name = ((PsiNamedElement)element).getName();
|
||||
Iterable<ResultWithContext> shadowing = myExplicitlyEnumerated.get(name);
|
||||
if (shadowing != null && ContainerUtil.exists(shadowing, rwc -> hasSameDeclarationKind(element, rwc.getElement()))) return true;
|
||||
|
||||
if (delegate instanceof MethodsProcessor && element instanceof PsiMethod) {
|
||||
PsiClass containingClass = ((PsiMethod)element).getContainingClass();
|
||||
if (containingClass != null && containingClass.isInterface()) {
|
||||
PsiElement currentFileContext = ((MethodsProcessor)delegate).getCurrentFileContext();
|
||||
if (currentFileContext instanceof PsiImportStaticStatement &&
|
||||
((PsiImportStaticStatement)currentFileContext).isOnDemand() &&
|
||||
!containingClass.isEquivalentTo(((PsiImportStaticStatement)currentFileContext).resolveTargetClass())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (myCollectedElements.add(element)) {
|
||||
return getDelegate().execute(element, state);
|
||||
return delegate.execute(element, state);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -85,6 +85,10 @@ public abstract class MethodsProcessor extends ConflictFilterProcessor implement
|
||||
return myIsConstructor;
|
||||
}
|
||||
|
||||
public PsiElement getCurrentFileContext() {
|
||||
return myCurrentFileContext;
|
||||
}
|
||||
|
||||
public void setIsConstructor(boolean myIsConstructor) {
|
||||
this.myIsConstructor = myIsConstructor;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import static foo.Foo.Inner.*;
|
||||
import static foo.Foo.*;
|
||||
|
||||
class Bar {
|
||||
{
|
||||
foo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import static foo.Foo.foo;
|
||||
|
||||
class Bar {
|
||||
{
|
||||
foo();
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,13 @@ public class OptimizeImportsTest extends OptimizeImportsTestCase {
|
||||
public void testIDEADEV10716() { doTest(); }
|
||||
public void testUnresolvedImports() { doTest(); }
|
||||
public void testUnresolvedImports2() { doTest(); }
|
||||
public void testInterfaceMethodThroughInheritance() {
|
||||
myFixture.addClass("package foo; public interface Foo {" +
|
||||
" static void foo() {}" +
|
||||
" interface Inner extends Foo {}" +
|
||||
"}");
|
||||
doTest();
|
||||
}
|
||||
public void testNewImportListIsEmptyAndCommentPreserved() { doTest(); }
|
||||
public void testNewImportListIsEmptyAndJavaDocWithInvalidCodePreserved() { doTest(); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user