mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
respect "do not suggest private for inners" in case of anonymous class
This commit is contained in:
+2
-1
@@ -225,7 +225,8 @@ class AccessCanBeTightenedInspection extends BaseJavaBatchLocalInspectionTool {
|
||||
if (annotation != null && annotation.getParent() instanceof PsiModifierList && annotation.getParent().getParent() == aClass) {
|
||||
return suggestPackageLocal(member);
|
||||
}
|
||||
return myVisibilityInspection.SUGGEST_PRIVATE_FOR_INNERS || memberClass == aClass ? PsiUtil.ACCESS_LEVEL_PRIVATE : suggestPackageLocal(member);
|
||||
return myVisibilityInspection.SUGGEST_PRIVATE_FOR_INNERS ||
|
||||
memberClass == aClass && memberClass.getContainingClass() == null ? PsiUtil.ACCESS_LEVEL_PRIVATE : suggestPackageLocal(member);
|
||||
}
|
||||
//if (file == memberFile) {
|
||||
// return PsiUtil.ACCESS_LEVEL_PACKAGE_LOCAL;
|
||||
|
||||
+3
-1
@@ -367,7 +367,9 @@ public class VisibilityInspection extends GlobalJavaBatchInspectionTool {
|
||||
if (fromTopLevelElement != null && isInExtendsList(to, fromTopLevelElement.getExtendsList())) return false;
|
||||
if (fromTopLevelElement != null && isInExtendsList(to, fromTopLevelElement.getImplementsList())) return false;
|
||||
if (fromTopLevelElement != null && isInAnnotations(to, fromTopLevelElement)) return false;
|
||||
return fromTopLevel == toOwner || fromOwner == toTopLevel || toOwner != null && refUtil.getOwnerClass(toOwner) == from;
|
||||
return fromTopLevel == toOwner || fromOwner == toTopLevel || toOwner != null && (
|
||||
refUtil.getOwnerClass(toOwner) == from || from instanceof RefMethod && toOwner == ((RefMethod)from).getOwnerClass() ||
|
||||
from instanceof RefField && toOwner == ((RefField)from).getOwnerClass());
|
||||
}
|
||||
|
||||
if (fromOwner != null && fromOwner.isStatic() && !to.isStatic() && refUtil.isInheritor(fromOwner, toOwner)) return false;
|
||||
|
||||
+22
-2
@@ -13,10 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.siyeh.ig.visibility;
|
||||
package com.intellij.codeInspection.visibility;
|
||||
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.visibility.VisibilityInspection;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileImpl;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
|
||||
import com.intellij.util.ReflectionUtil;
|
||||
import com.siyeh.ig.LightInspectionTestCase;
|
||||
|
||||
public class AccessCanBeTightenedInspectionTest extends LightInspectionTestCase {
|
||||
@@ -88,6 +90,24 @@ public class AccessCanBeTightenedInspectionTest extends LightInspectionTestCase
|
||||
myFixture.checkHighlighting();
|
||||
}
|
||||
|
||||
public void testDoNotSuggestPrivateInAnonymousClassIfPrivatesForInnersIsOff() {
|
||||
InspectionProfileImpl profile = (InspectionProfileImpl)InspectionProjectProfileManager.getInstance(getProject()).getInspectionProfile();
|
||||
AccessCanBeTightenedInspection inspection = (AccessCanBeTightenedInspection)profile.getInspectionTool(VisibilityInspection.SHORT_NAME, getProject()).getTool();
|
||||
VisibilityInspection visibilityInspection =
|
||||
ReflectionUtil.getField(inspection.getClass(), inspection, VisibilityInspection.class, "myVisibilityInspection");
|
||||
visibilityInspection.SUGGEST_PACKAGE_LOCAL_FOR_MEMBERS = false;
|
||||
|
||||
doTest("class C {\n" +
|
||||
" {\n" +
|
||||
" new Runnable() {\n" +
|
||||
" @Override\n" +
|
||||
" public void run() {}\n"+
|
||||
" boolean isVisible() { return true; }\n" +
|
||||
" }.run();\n" +
|
||||
" }\n"+
|
||||
"}");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LocalInspectionTool getInspection() {
|
||||
VisibilityInspection inspection = new VisibilityInspection();
|
||||
Reference in New Issue
Block a user