mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
EnumSwitchStatementWhichMissesCasesInspection: utilize possible values list
This commit is contained in:
+7
-2
@@ -120,12 +120,17 @@ public class EnumSwitchStatementWhichMissesCasesInspection extends AbstractBaseJ
|
||||
if (constants.isEmpty()) return;
|
||||
CommonDataflow.DataflowResult dataflow = CommonDataflow.getDataflowResult(expression);
|
||||
if (dataflow != null) {
|
||||
Set<Object> values = dataflow.getValuesNotEqualToExpression(expression);
|
||||
for (Object value : values) {
|
||||
Set<Object> notValues = dataflow.getValuesNotEqualToExpression(expression);
|
||||
for (Object value : notValues) {
|
||||
if (value instanceof PsiEnumConstant) {
|
||||
constants.remove(((PsiEnumConstant)value).getName());
|
||||
}
|
||||
}
|
||||
Set<String> values = StreamEx.of(dataflow.getExpressionValues(expression)).select(PsiEnumConstant.class)
|
||||
.map(PsiEnumConstant::getName).toSet();
|
||||
if (!values.isEmpty()) {
|
||||
constants.retainAll(values);
|
||||
}
|
||||
}
|
||||
if (constants.isEmpty()) return;
|
||||
String message = buildErrorString(aClass.getQualifiedName(), constants);
|
||||
|
||||
+31
-1
@@ -24,6 +24,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
/**
|
||||
* @author Bas Leijdekkers
|
||||
*/
|
||||
@SuppressWarnings("EnumSwitchStatementWhichMissesCases")
|
||||
public class EnumSwitchStatementWhichMissesCasesInspectionTest extends LightInspectionTestCase {
|
||||
|
||||
public void testSimple() {
|
||||
@@ -120,7 +121,36 @@ public class EnumSwitchStatementWhichMissesCasesInspectionTest extends LightInsp
|
||||
" }\n" +
|
||||
"}");
|
||||
}
|
||||
|
||||
|
||||
public void testDfaPossibleValues() {
|
||||
doTest("enum E {A, B, C}\n" +
|
||||
"\n" +
|
||||
"class X {\n" +
|
||||
" void m(E e) {\n" +
|
||||
" if(e == E.A || e == E.B) {\n" +
|
||||
" switch (e) {\n" +
|
||||
" case A:\n" +
|
||||
" case B:\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}");
|
||||
}
|
||||
|
||||
public void testDfaPossibleValuesNotCovered() {
|
||||
doTest("enum E {A, B, C}\n" +
|
||||
"\n" +
|
||||
"class X {\n" +
|
||||
" void m(E e) {\n" +
|
||||
" if(e == E.A || e == E.B) {\n" +
|
||||
" /*'switch' statement on enum type 'E' misses case 'B'*/switch/**/ (e) {\n" +
|
||||
" case A:\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}");
|
||||
}
|
||||
|
||||
public void testJava12Preview() {
|
||||
doTest("enum E {A, B, C}\n" +
|
||||
"\n" +
|
||||
|
||||
Reference in New Issue
Block a user