mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
visibility inspection: prefer extension visibility to default one (IDEA-166543)
This commit is contained in:
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>ThisClass.java</file>
|
||||
<line>2</line>
|
||||
<description>Can be package-private</description>
|
||||
</problem>
|
||||
</problems>
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
public class ThisClass {
|
||||
public void foo() {}
|
||||
public void bar() {}
|
||||
|
||||
public static void main(String[] args) {}
|
||||
}
|
||||
@@ -1,8 +1,23 @@
|
||||
package com.intellij.codeInspection;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.ToolExtensionPoints;
|
||||
import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.visibility.EntryPointWithVisibilityLevel;
|
||||
import com.intellij.codeInspection.visibility.VisibilityInspection;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMember;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.testFramework.InspectionTestCase;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class VisibilityInspectionTest extends InspectionTestCase {
|
||||
private VisibilityInspection myTool = new VisibilityInspection();
|
||||
@@ -122,4 +137,57 @@ public class VisibilityInspectionTest extends InspectionTestCase {
|
||||
myTool.SUGGEST_PRIVATE_FOR_INNERS = true;
|
||||
doTest("visibility/usedFromAnotherPackage", myTool, false, true);
|
||||
}
|
||||
|
||||
public void testEntryPointWithPredefinedVisibility() throws Exception {
|
||||
PlatformTestUtil.registerExtension(Extensions.getRootArea(), ExtensionPointName.create(ToolExtensionPoints.DEAD_CODE_TOOL), new EntryPointWithVisibilityLevel() {
|
||||
@Override
|
||||
public void readExternal(Element element) throws InvalidDataException {}
|
||||
|
||||
@Override
|
||||
public void writeExternal(Element element) throws WriteExternalException {}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "accepted visibility";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEntryPoint(@NotNull RefElement refElement, @NotNull PsiElement psiElement) {
|
||||
return isEntryPoint(psiElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEntryPoint(@NotNull PsiElement psiElement) {
|
||||
return psiElement instanceof PsiMethod && "foo".equals(((PsiMethod)psiElement).getName()) || psiElement instanceof PsiClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinVisibilityLevel(PsiMember member) {
|
||||
return member instanceof PsiMethod && isEntryPoint(member) ? PsiUtil.ACCESS_LEVEL_PACKAGE_LOCAL : -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelected() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(boolean selected) {}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return getDisplayName();
|
||||
}
|
||||
}, getTestRootDisposable());
|
||||
myTool.SUGGEST_PACKAGE_LOCAL_FOR_MEMBERS = false;
|
||||
myTool.SUGGEST_PACKAGE_LOCAL_FOR_TOP_CLASSES = false;
|
||||
myTool.SUGGEST_PRIVATE_FOR_INNERS = true;
|
||||
doTest("visibility/entryPointWithPredefinedVisibility", myTool, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user