mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
make "Private member access between outer and inner classes" inspection not warn on uncompilable code
This commit is contained in:
+10
-24
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -59,11 +59,6 @@ public class PrivateMemberAccessBetweenOuterAndInnerClassInspection
|
||||
final PsiMember member = (PsiMember)infos[1];
|
||||
@NonNls final String memberName;
|
||||
if (member instanceof PsiMethod) {
|
||||
final PsiMethod method = (PsiMethod)member;
|
||||
if (method.isConstructor()) {
|
||||
|
||||
}
|
||||
|
||||
memberName = member.getName() + "()";
|
||||
}
|
||||
else {
|
||||
@@ -168,10 +163,10 @@ public class PrivateMemberAccessBetweenOuterAndInnerClassInspection
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new PrivateMemberAccessFromInnerClassVisior();
|
||||
return new PrivateMemberAccessFromInnerClassVisitor();
|
||||
}
|
||||
|
||||
private static class PrivateMemberAccessFromInnerClassVisior
|
||||
private static class PrivateMemberAccessFromInnerClassVisitor
|
||||
extends BaseInspectionVisitor {
|
||||
|
||||
@Override
|
||||
@@ -225,9 +220,6 @@ public class PrivateMemberAccessBetweenOuterAndInnerClassInspection
|
||||
return;
|
||||
}
|
||||
super.visitReferenceExpression(expression);
|
||||
if (expression.getQualifierExpression() == null) {
|
||||
return;
|
||||
}
|
||||
final PsiElement referenceNameElement =
|
||||
expression.getReferenceNameElement();
|
||||
if (referenceNameElement == null) {
|
||||
@@ -246,12 +238,9 @@ public class PrivateMemberAccessBetweenOuterAndInnerClassInspection
|
||||
if (!member.hasModifierProperty(PsiModifier.PRIVATE)) {
|
||||
return;
|
||||
}
|
||||
final PsiClass memberClass =
|
||||
ClassUtils.getContainingClass(member);
|
||||
if (memberClass == null) {
|
||||
return;
|
||||
}
|
||||
if (memberClass.equals(containingClass)) {
|
||||
final PsiClass memberClass = ClassUtils.getContainingClass(member);
|
||||
if (memberClass == null || memberClass.equals(containingClass) ||
|
||||
(!PsiTreeUtil.isAncestor(containingClass, memberClass, true) && !PsiTreeUtil.isAncestor(memberClass, containingClass, true))) {
|
||||
return;
|
||||
}
|
||||
registerError(referenceNameElement, memberClass, member);
|
||||
@@ -259,14 +248,11 @@ public class PrivateMemberAccessBetweenOuterAndInnerClassInspection
|
||||
|
||||
@Nullable
|
||||
private static PsiClass getContainingContextClass(PsiElement element) {
|
||||
final PsiClass aClass =
|
||||
ClassUtils.getContainingClass(element);
|
||||
final PsiClass aClass = ClassUtils.getContainingClass(element);
|
||||
if (aClass instanceof PsiAnonymousClass) {
|
||||
final PsiAnonymousClass anonymousClass =
|
||||
(PsiAnonymousClass)aClass;
|
||||
final PsiExpressionList args = anonymousClass.getArgumentList();
|
||||
if (args != null &&
|
||||
PsiTreeUtil.isAncestor(args, element, true)) {
|
||||
final PsiAnonymousClass anonymousClass = (PsiAnonymousClass)aClass;
|
||||
final PsiExpressionList arguments = anonymousClass.getArgumentList();
|
||||
if (arguments != null && PsiTreeUtil.isAncestor(arguments, element, true)) {
|
||||
return ClassUtils.getContainingClass(aClass);
|
||||
}
|
||||
}
|
||||
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
package com.siyeh.igtest.j2me;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
|
||||
public class PrivateMemberAccessBetweenOuterAndInnerClass {
|
||||
private String caption = "Button";
|
||||
|
||||
private void initialize() {
|
||||
Button btn = new Button(caption) {
|
||||
public void foo() {
|
||||
System.out.println(caption);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.siyeh.igtest.j2me.private_member_access_between_outer_and_inner_class;
|
||||
|
||||
public class PrivateMemberAccessBetweenOuterAndInnerClass {
|
||||
private String caption = "Button";
|
||||
|
||||
private void initialize() {
|
||||
System.out.println(caption);
|
||||
Object btn = new Object() {
|
||||
public void foo() {
|
||||
System.out.println(<warning descr="Access to private member of class 'PrivateMemberAccessBetweenOuterAndInnerClass'">caption</warning>);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.siyeh.igtest.j2me.private_member_access_between_outer_and_inner_class;
|
||||
|
||||
public class Simple {
|
||||
|
||||
private int i;
|
||||
|
||||
private Simple() {}
|
||||
|
||||
private void foo() {}
|
||||
|
||||
class Inner {{
|
||||
new <warning descr="Access to private member of class 'Simple'">Simple</warning>();
|
||||
System.out.println(<warning descr="Access to private member of class 'Simple'">i</warning>);
|
||||
<warning descr="Access to private member of class 'Simple'">foo</warning>();
|
||||
}}
|
||||
}
|
||||
class Other {
|
||||
void foo(Simple o) {
|
||||
System.out.println(o.<error descr="'i' has private access in 'com.siyeh.igtest.j2me.private_member_access_between_outer_and_inner_class.Simple'">i</error>);
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.siyeh.ig.j2me;
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.siyeh.ig.LightInspectionTestCase;
|
||||
|
||||
/**
|
||||
* @author Bas Leijdekkers
|
||||
*/
|
||||
public class PrivateMemberAccessBetweenOuterAndInnerClassInspectionTest extends LightInspectionTestCase {
|
||||
|
||||
public void testSimple() { doTest(); }
|
||||
public void testPrivateMemberAccessBetweenOuterAndInnerClass() { doTest(); }
|
||||
|
||||
@Override
|
||||
protected InspectionProfileEntry getInspection() {
|
||||
return new PrivateMemberAccessBetweenOuterAndInnerClassInspection();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user