diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties
index 8c147e371e80..f8b944b82cc0 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties
@@ -650,7 +650,7 @@ method.may.be.static.display.name=Method may be 'static'
class.initializer.may.be.static.display.name=Class initializer may be 'static'
class.initializer.option=Only warn when the class has one or more constructors
class.initializer.move.code.to.constructor.quickfix=Move initializer code to constructor
-nested.switch.statement.display.name=Nested 'switch' statement
+nested.switch.statement.display.name=Nested 'switch'
c.style.array.declaration.display.name=C-style array declaration
final.method.in.final.class.display.name='final' method in 'final' class
extends.annotation.display.name=Class extends annotation interface
@@ -867,7 +867,7 @@ conditional.expression.quickfix=Replace with 'if' statement
conditional.expression.semantics.quickfix=Replace with 'if' statement (may change semantics)
nested.conditional.expression.problem.descriptor=Nested conditional expression #ref #loc
long.literals.ending.with.lowercase.l.problem.descriptor='long' literal #ref ends with lowercase 'l' #loc
-nested.switch.statement.problem.descriptor=Nested #ref statement #loc
+nested.switch.statement.problem.descriptor=Nested #ref {0} #loc
chained.method.call.problem.descriptor=Chained method call #ref() #loc
nested.method.call.problem.descriptor=Nested method call #ref() #loc
octal.literal.problem.descriptor=Octal integer #ref #loc
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/NestedSwitchStatementInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/NestedSwitchStatementInspection.java
index 3174e0b3b5a4..0325750ab3a5 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/NestedSwitchStatementInspection.java
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/NestedSwitchStatementInspection.java
@@ -15,6 +15,8 @@
*/
package com.siyeh.ig.controlflow;
+import com.intellij.psi.PsiSwitchBlock;
+import com.intellij.psi.PsiSwitchExpression;
import com.intellij.psi.PsiSwitchStatement;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
@@ -35,7 +37,7 @@ public class NestedSwitchStatementInspection extends BaseInspection {
@NotNull
protected String buildErrorString(Object... infos) {
return InspectionGadgetsBundle.message(
- "nested.switch.statement.problem.descriptor");
+ "nested.switch.statement.problem.descriptor", infos[0] instanceof PsiSwitchStatement ? "statement" : "expression");
}
@Override
@@ -48,8 +50,16 @@ public class NestedSwitchStatementInspection extends BaseInspection {
@Override
public void visitSwitchStatement(@NotNull PsiSwitchStatement statement) {
super.visitSwitchStatement(statement);
- if (ControlFlowUtils.isNestedElement(statement, PsiSwitchStatement.class)) {
- registerStatementError(statement);
+ if (ControlFlowUtils.isNestedElement(statement, PsiSwitchBlock.class)) {
+ registerStatementError(statement, statement);
+ }
+ }
+
+ @Override
+ public void visitSwitchExpression(PsiSwitchExpression expression) {
+ super.visitSwitchExpression(expression);
+ if (ControlFlowUtils.isNestedElement(expression, PsiSwitchBlock.class)) {
+ registerError(expression.getFirstChild(), expression);
}
}
}
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/NestedSwitchStatement.html b/plugins/InspectionGadgets/src/inspectionDescriptions/NestedSwitchStatement.html
index b6b0597ecac0..4cee5c2807a9 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/NestedSwitchStatement.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/NestedSwitchStatement.html
@@ -1,6 +1,6 @@
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/nested_switch_statement/NestedSwitch.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/nested_switch_statement/NestedSwitch.java
new file mode 100644
index 000000000000..1f8552ceda74
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/nested_switch_statement/NestedSwitch.java
@@ -0,0 +1,11 @@
+class MyTest {
+ int y(int i) {
+ return switch (i) {
+ case 0 -> 0;
+ default ->