CreateMissingSwitchBranchesAction: disable for long type

Fixes EA-218697 - IAE: CreateMissingSwitchBranchesAction$Value.fromConstant

GitOrigin-RevId: 4d12ab41954dd0dbcebeadaccbeaea1d064078d4
This commit is contained in:
Tagir Valeev
2019-11-26 04:35:01 +00:00
committed by intellij-monorepo-bot
parent b9e6d12fb6
commit 42c3f75c71
3 changed files with 14 additions and 1 deletions
@@ -85,7 +85,7 @@ public class CreateMissingSwitchBranchesAction extends PsiElementBaseIntentionAc
PsiType type = expression.getType();
if (dfr != null) {
LongRangeSet range = dfr.getExpressionFact(expression, DfaFactType.RANGE);
if (range != null && !range.isCardinalityBigger(MAX_NUMBER_OF_BRANCHES)) {
if (range != null && type != null && PsiType.INT.isAssignableFrom(type) && !range.isCardinalityBigger(MAX_NUMBER_OF_BRANCHES)) {
return range.stream().mapToObj(c -> Value.fromConstant(TypeConversionUtil.computeCastTo(c, type))).collect(Collectors.toList());
}
Set<Object> values = dfr.getExpressionValues(expression);
@@ -0,0 +1,9 @@
class DataflowLong {
void test() {
long x = Math.random() > 0.5 ? 1 : 2;
switch<caret> (x) {
}
}
}
@@ -11,6 +11,10 @@ public class CreateMissingSwitchBranchesActionTest extends IPPTestCase {
public void testDataflowInt() {
doTest(CreateSwitchBranchesUtil.getActionName(Arrays.asList("1", "3", "5", "7", "9")));
}
public void testDataflowLong() {
assertIntentionNotAvailable(CreateSwitchBranchesUtil.getActionName(Arrays.asList("1", "2")));
}
public void testDataflowIntMixedTypes() {
doTest(CreateSwitchBranchesUtil.getActionName(Arrays.asList("0", "1", "3", "4", "6", "7", "9")));