mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 06:50:54 +07:00
[java-psi] IDEA-367231 Incorrect use scope for public class inside non-public non-final containing class
(cherry picked from commit 9238a1c2cb5749f4a711815150c14324d8d7f64e) IJ-CR-154834 GitOrigin-RevId: ecfa67d0b540e43d1054d2e283ec4e85badc3dae
This commit is contained in:
committed by
intellij-monorepo-bot
parent
69e0ecef4c
commit
27e21144a2
@@ -285,7 +285,9 @@ public final class PsiClassImplUtil {
|
||||
PsiClass containingClass = aClass.getContainingClass();
|
||||
if (aClass.hasModifierProperty(PsiModifier.PUBLIC) ||
|
||||
aClass.hasModifierProperty(PsiModifier.PROTECTED)) {
|
||||
return containingClass == null ? maximalUseScope : containingClass.getUseScope();
|
||||
// If the containing class is not final, it's possible to expose nested class through public subclass of containing class
|
||||
return containingClass == null || !containingClass.hasModifierProperty(PsiModifier.FINAL) ?
|
||||
maximalUseScope : containingClass.getUseScope();
|
||||
}
|
||||
else if (aClass.hasModifierProperty(PsiModifier.PRIVATE) || aClass instanceof PsiTypeParameter) {
|
||||
PsiClass topClass = PsiUtil.getTopLevelClass(aClass);
|
||||
|
||||
@@ -114,6 +114,25 @@ public class ClassInheritorsTest extends JavaCodeInsightFixtureTestCase {
|
||||
assertSize(5, ClassInheritorsSearch.search(myFixture.findClass("one.Test.A")).findAll());
|
||||
assertSize(4, ClassInheritorsSearch.search(myFixture.findClass("one.Test.B")).findAll());
|
||||
}
|
||||
|
||||
public void testClassExposedViaContainingClassSubclass() {
|
||||
myFixture.addClass("""
|
||||
package one;
|
||||
interface OuterSuper {
|
||||
interface Inner {}
|
||||
}
|
||||
""");
|
||||
myFixture.addClass("""
|
||||
package one;
|
||||
public interface Child extends OuterSuper {
|
||||
}
|
||||
""");
|
||||
myFixture.addClass("""
|
||||
package two;
|
||||
interface InnerChild extends one.Child.Inner {}
|
||||
""");
|
||||
assertSize(1, ClassInheritorsSearch.search(myFixture.findClass("one.OuterSuper.Inner")).findAll());
|
||||
}
|
||||
|
||||
public void testInheritorsInAnotherModuleWithNoDirectDependency() throws IOException {
|
||||
myFixture.addFileToProject("A.java", "class A {}");
|
||||
|
||||
Reference in New Issue
Block a user