mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
[java-highlighting] IDEA-324327 IJ-CR-110223 Constant associated with switch block must be used with primitives or String
GitOrigin-RevId: fab5d57dc37c1694607686e268072473ec60a4de
This commit is contained in:
committed by
intellij-monorepo-bot
parent
fef71943cd
commit
21d97bbbb0
@@ -161,7 +161,7 @@ public class SwitchBlockHighlightingModel {
|
||||
|
||||
if (kind == null || requiredLevel != null && !myLevel.isAtLeast(requiredLevel)) {
|
||||
boolean is7 = myLevel.isAtLeast(LanguageLevel.JDK_1_7);
|
||||
String expected = JavaErrorBundle.message(is7 ? "valid.switch.17.selector.types" : "valid.switch.selector.types");
|
||||
String expected = JavaErrorBundle.message(is7 ? "valid.switch.1_7.selector.types" : "valid.switch.selector.types");
|
||||
HighlightInfo.Builder info =
|
||||
createError(mySelector, JavaErrorBundle.message("incompatible.types", expected, JavaHighlightUtil.formatType(mySelectorType)));
|
||||
registerFixesOnInvalidSelector(info);
|
||||
@@ -706,9 +706,9 @@ public class SwitchBlockHighlightingModel {
|
||||
if (kind == SelectorKind.INT || kind == SelectorKind.STRING) {
|
||||
return;
|
||||
}
|
||||
String expected = JavaErrorBundle.message("valid.switch.21.constant.types");
|
||||
HighlightInfo.Builder infoIncompatibleTypes =
|
||||
createError(expr, JavaErrorBundle.message("unexpected.type", expected, JavaHighlightUtil.formatType(expr.getType())));
|
||||
createError(expr, JavaErrorBundle.message("incompatible.label.types", JavaHighlightUtil.formatType(expr.getType()),
|
||||
JavaHighlightUtil.formatType(mySelectorType)));
|
||||
holder.add(infoIncompatibleTypes.create());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -230,13 +230,13 @@ exception.already.caught.warn=Unreachable section: {1, choice, 0#exception|2#exc
|
||||
not.a.statement=Not a statement
|
||||
invalid.statement=Invalid statement
|
||||
incompatible.types=Incompatible types. Found: ''{1}'', required: ''{0}''
|
||||
incompatible.label.types=Incompatible types. Type of constant label: ''{0}'', switch selector type: ''{1}''
|
||||
unexpected.type=Unexpected type. Found: ''{1}'', required: ''{0}''
|
||||
incompatible.types.reason.ambiguous.method.reference=<br/>reason: method reference is ambiguous: both ''{0}'' and ''{1}'' match
|
||||
incompatible.switch.null.type=''{0}'' cannot be converted to ''{1}''
|
||||
inaccessible.type=''{0}'' is inaccessible here
|
||||
valid.switch.selector.types=byte, char, short or int
|
||||
valid.switch.17.selector.types=char, byte, short, int, Character, Byte, Short, Integer, String, or an enum
|
||||
valid.switch.21.constant.types=char, byte, short, int, Character, Byte, Short, Integer, String
|
||||
valid.switch.1_7.selector.types=char, byte, short, int, Character, Byte, Short, Integer, String, or an enum
|
||||
switch.illegal.fall.through.from=Illegal fall-through from a pattern
|
||||
switch.illegal.fall.through.to=Illegal fall-through to a pattern
|
||||
invalid.case.label.combination.constants.and.patterns=Invalid case label combination: A case label must consist of either a list of case constants or a single case pattern
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
public class ConstantAssignment {
|
||||
void dd(Double i) {
|
||||
switch (i) {
|
||||
case <error descr="Unexpected type. Found: 'double', required: 'char, byte, short, int, Character, Byte, Short, Integer, String'">1.0</error> -> System.out.println(1);
|
||||
case <error descr="Incompatible types. Type of constant label: 'double', switch selector type: 'java.lang.Double'">1.0</error> -> System.out.println(1);
|
||||
default -> throw new IllegalStateException("Unexpected value: " + i);
|
||||
}
|
||||
}
|
||||
|
||||
void dd2(Long i) {
|
||||
switch (i) {
|
||||
case <error descr="Unexpected type. Found: 'long', required: 'char, byte, short, int, Character, Byte, Short, Integer, String'">1L</error>:
|
||||
case <error descr="Incompatible types. Type of constant label: 'long', switch selector type: 'java.lang.Long'">1L</error>:
|
||||
System.out.println(1);
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected value: " + i);
|
||||
|
||||
Reference in New Issue
Block a user