mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
add warning on switch by inaccessible enums (IDEA-65961 )
This commit is contained in:
@@ -47,9 +47,11 @@ import com.intellij.psi.scope.processor.VariablesNotProcessor;
|
||||
import com.intellij.psi.scope.util.PsiScopesUtil;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.refactoring.util.RefactoringUIUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.xml.util.XmlStringUtil;
|
||||
import gnu.trove.THashMap;
|
||||
@@ -1068,6 +1070,12 @@ public class HighlightUtil {
|
||||
if (PsiType.LONG.equals(type) || PsiType.FLOAT.equals(type) || PsiType.DOUBLE.equals(type)) {
|
||||
QuickFixAction.registerQuickFixAction(errorResult, new AddTypeCastFix(PsiType.INT, expression));
|
||||
}
|
||||
} else {
|
||||
final PsiClass member = PsiUtil.resolveClassInClassTypeOnly(type);
|
||||
if (member != null && !PsiUtil.isAccessible(member, expression, null)) {
|
||||
String message = PsiFormatUtil.formatClass(member, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_FQ_NAME) + " is inaccessible here";
|
||||
errorResult = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, expression, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
return errorResult;
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
interface A {
|
||||
B getB();
|
||||
|
||||
class B {
|
||||
public C c;
|
||||
|
||||
private enum C {
|
||||
SOME
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class D {
|
||||
public static void f(A a) {
|
||||
A.B b = a.getB();
|
||||
switch (<error descr="A.B.C is inaccessible here">b.c</error>) {
|
||||
case SOME:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+4
@@ -75,6 +75,10 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase {
|
||||
doTest(false, false);
|
||||
}
|
||||
|
||||
public void testSwitchByInaccessibleEnum() throws Exception {
|
||||
doTest(false, false);
|
||||
}
|
||||
|
||||
public void testDiamondPos1() throws Exception {
|
||||
doTest(false, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user