Java: fix PsiClass.getScope() method which was broken by the migration to the new stubs api (IDEA-376896)

GitOrigin-RevId: e204142d2cd57a6cdb83285064ec21fe15b8270b
This commit is contained in:
Bas Leijdekkers
2025-08-11 19:24:55 +00:00
committed by intellij-monorepo-bot
parent 1030e9fc1f
commit 77536725b9
4 changed files with 27 additions and 14 deletions
@@ -21,7 +21,6 @@ import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.psi.scope.PsiScopeProcessor;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.stub.JavaStubImplUtil;
import com.intellij.psi.stubs.IStubElementType;
import com.intellij.psi.stubs.PsiFileStub;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.tree.IElementType;
@@ -116,18 +115,7 @@ public class PsiClassImpl extends JavaStubPsiElement<PsiClassStub<?>> implements
if (stub != null) {
return stub.getParentStub().getPsi();
}
ASTNode treeElement = getNode();
ASTNode parent = treeElement.getTreeParent();
while(parent != null) {
if (parent.getElementType() instanceof IStubElementType){
return parent.getPsi();
}
parent = parent.getTreeParent();
}
return getContainingFile();
return PsiTreeUtil.getParentOfType(this, PsiMember.class, PsiFile.class);
}
@Override
@@ -0,0 +1,12 @@
class NoStaticInInnerClass {
{
new Inner();
}
class Inner {
{
System.out.println("Sunshine and happiness");
}
}
}
@@ -97,4 +97,11 @@ class WithArrayReference {
private void <warning descr="Method 'foo()' may be 'static'">foo</warning>() {
IntSupplier aNew = Object[]::new;
}
}
class InnerClassScope {
class Inner {}
Inner create() {
return new Inner();
}
}
@@ -1,7 +1,9 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.siyeh.ig.performance;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.testFramework.IdeaTestUtil;
import com.siyeh.ig.LightJavaInspectionTestCase;
import org.jetbrains.annotations.Nullable;
@@ -14,6 +16,10 @@ public class ClassInitializerMayBeStaticInspectionTest extends LightJavaInspecti
public void testAnonymousClass() {
doTest();
}
public void testNoStaticInInnerClass() {
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_15, this::doTest);
}
@Nullable
@Override