mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
access visibility inspection: fix global inspection in case of inner classes IDEA-175921
This commit is contained in:
+3
-7
@@ -406,13 +406,9 @@ public class VisibilityInspection extends GlobalJavaBatchInspectionTool {
|
||||
if (to instanceof RefJavaElementImpl && ((RefJavaElementImpl)to).isUsedQualifiedOutsidePackage()) {
|
||||
return false;
|
||||
}
|
||||
if (SUGGEST_PRIVATE_FOR_INNERS) {
|
||||
return fromTopLevel != null && refUtil.isInheritor(fromTopLevel, toOwner)
|
||||
|| fromOwner != null && refUtil.isInheritor(fromOwner, toTopLevel)
|
||||
|| toOwner != null && refUtil.getOwnerClass(toOwner) == from;
|
||||
}
|
||||
|
||||
return fromTopLevel != null && refUtil.isInheritor(fromTopLevel, toOwner);
|
||||
return fromTopLevel != null && refUtil.isInheritor(fromTopLevel, toOwner)
|
||||
|| fromOwner != null && refUtil.isInheritor(fromOwner, toTopLevel)
|
||||
|| toTopLevel != null && toTopLevel == fromTopLevel;
|
||||
}
|
||||
|
||||
if (accessModifier == PsiModifier.PRIVATE) {
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>Foo.java</file>
|
||||
<line>3</line>
|
||||
<description>Can be package-private</description>
|
||||
</problem>
|
||||
</problems>
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
class Foo {
|
||||
class Bar {
|
||||
public void baz() {
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
class FooImpl extends Foo {
|
||||
void m(Bar b) {
|
||||
b.baz();
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>Foo.java</file>
|
||||
<line>3</line>
|
||||
<description>Can be package-private</description>
|
||||
</problem>
|
||||
</problems>
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
class Foo {
|
||||
private abstract class A {
|
||||
public int getValue() {
|
||||
return 20173;
|
||||
}
|
||||
}
|
||||
|
||||
private class B extends A {
|
||||
private B() {
|
||||
int a = this.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>Foo.java</file>
|
||||
<line>2</line>
|
||||
<description>Can be package-private</description>
|
||||
</problem>
|
||||
</problems>
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
public void boo() {
|
||||
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class FooImpl extends Foo {
|
||||
private class Bar {
|
||||
void m() {
|
||||
boo();
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
@@ -153,6 +153,28 @@ public class VisibilityInspectionTest extends InspectionTestCase {
|
||||
doTest("visibility/usedFromAnotherPackage", myTool, false, true);
|
||||
}
|
||||
|
||||
// IDEA-175921
|
||||
public void testInnerClassMethodUsedInsideOtherInnerClassInheritor() {
|
||||
myTool.SUGGEST_PACKAGE_LOCAL_FOR_MEMBERS = true;
|
||||
myTool.SUGGEST_PACKAGE_LOCAL_FOR_TOP_CLASSES = true;
|
||||
myTool.SUGGEST_PRIVATE_FOR_INNERS = true;
|
||||
doTest("visibility/innerClassMethodUsedInsideOtherInnerClassInheritor", myTool, false, true);
|
||||
}
|
||||
|
||||
public void testMethodUsedInInheritorInnerClass() {
|
||||
myTool.SUGGEST_PACKAGE_LOCAL_FOR_MEMBERS = true;
|
||||
myTool.SUGGEST_PACKAGE_LOCAL_FOR_TOP_CLASSES = true;
|
||||
myTool.SUGGEST_PRIVATE_FOR_INNERS = true;
|
||||
doTest("visibility/methodUsedInInheritorInnerClass", myTool, false, true);
|
||||
}
|
||||
|
||||
public void testInnerClassMethodUsedInsideInheritor() {
|
||||
myTool.SUGGEST_PACKAGE_LOCAL_FOR_MEMBERS = true;
|
||||
myTool.SUGGEST_PACKAGE_LOCAL_FOR_TOP_CLASSES = true;
|
||||
myTool.SUGGEST_PRIVATE_FOR_INNERS = true;
|
||||
doTest("visibility/innerClassMethodUsedInsideInheritor", myTool, false, true);
|
||||
}
|
||||
|
||||
public void testEntryPointWithPredefinedVisibility() throws Exception {
|
||||
PlatformTestUtil.registerExtension(Extensions.getRootArea(), ExtensionPointName.create(ToolExtensionPoints.DEAD_CODE_TOOL), new EntryPointWithVisibilityLevel() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user