mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-highlighting] IDEA-366905 'Label is dominated by a preceding case label' error highlighting appears in a case when there is no compilation error
GitOrigin-RevId: a6cb61a29153fbd0524b15995427cd2dc285c653
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1fda15509a
commit
26a09a1c53
-8
@@ -375,8 +375,6 @@ public class PatternsInSwitchBlockHighlightingModel extends SwitchBlockHighlight
|
||||
@NotNull PsiElement who,
|
||||
@NotNull PsiType selectorType) {
|
||||
boolean isOverWhomUnconditionalForSelector = JavaPsiPatternUtil.isUnconditionalForType(overWhom, selectorType);
|
||||
boolean isWhoUnconditionalForSelector = who instanceof PsiCaseLabelElement whoCase &&
|
||||
JavaPsiPatternUtil.isUnconditionalForType(whoCase, selectorType);
|
||||
if (!isOverWhomUnconditionalForSelector &&
|
||||
((!(overWhom instanceof PsiExpression expression) || ExpressionUtils.isNullLiteral(expression)) &&
|
||||
who instanceof PsiKeyword &&
|
||||
@@ -387,12 +385,6 @@ public class PatternsInSwitchBlockHighlightingModel extends SwitchBlockHighlight
|
||||
// A 'case null, default' label dominates all other switch labels.
|
||||
return true;
|
||||
}
|
||||
if (isWhoUnconditionalForSelector && !isOverWhomUnconditionalForSelector &&
|
||||
!(isInCaseNullDefaultLabel(overWhom) ||
|
||||
(overWhom instanceof PsiKeyword && PsiKeyword.DEFAULT.equals(overWhom.getText())) ||
|
||||
(overWhom instanceof PsiExpression expression && ExpressionUtils.isNullLiteral(expression)))) {
|
||||
return true;
|
||||
}
|
||||
if (who instanceof PsiCaseLabelElement currentElement) {
|
||||
if (JavaPsiPatternUtil.isGuarded(currentElement)) return false;
|
||||
if (isConstantLabelElement(overWhom)) {
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ public class UnconditionalForSelectTypeAndDominated {
|
||||
private static void testAA(AA aa){
|
||||
switch (aa) {
|
||||
case AA1 aa1 -> System.out.println(1);
|
||||
case <error descr="Label is dominated by a preceding case label 'AA1 aa1'">B aa1</error> -> System.out.println(1);
|
||||
case B aa1 -> System.out.println(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
@@ -1202,4 +1202,18 @@ public class SwitchPrimitivePatternDominated {
|
||||
case <error descr="Label is dominated by a preceding case label 'Object b'">boolean b</error> -> System.out.println("2");//error
|
||||
}
|
||||
}
|
||||
|
||||
static void switchInteger(Integer i) {
|
||||
switch (i) {
|
||||
case Integer i2 -> System.out.println("int" + i2);
|
||||
case long l1 -> System.out.println("long" + l1);
|
||||
}
|
||||
}
|
||||
|
||||
static void switchDouble(double i) {
|
||||
switch (i) {
|
||||
case double i2 -> System.out.println("double" + i2);
|
||||
case long l1 -> System.out.println("long" + l1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -172,8 +172,8 @@ public class SwitchPrimitivePatternList {
|
||||
case short d -> System.out.println("1");
|
||||
case int d -> System.out.println("1");
|
||||
case long d -> System.out.println("1");
|
||||
case <error descr="Label is dominated by a preceding case label 'long d'">float d</error> -> System.out.println("1");
|
||||
case <error descr="Label is dominated by a preceding case label 'long d'">double d</error> -> System.out.println("1");
|
||||
case float d -> System.out.println("1");
|
||||
case double d -> System.out.println("1");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user