From 5bc41582169dbbedc5d5346bcb0efb7b67bb8199 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 28 Nov 2011 14:49:58 +0100 Subject: [PATCH] [^romka] IDEA-68894 Usages in switch case don't count for unused definition inspection(cherry picked from commit 884425d) --- .../lang/psi/controlFlow/impl/ControlFlowBuilder.java | 5 +++++ .../plugins/groovy/lang/GroovyHighlightingTest.groovy | 1 + .../highlighting/DefinitionUsedInSwitchCase.groovy | 9 +++++++++ 3 files changed, 15 insertions(+) create mode 100644 plugins/groovy/testdata/highlighting/DefinitionUsedInSwitchCase.groovy diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/controlFlow/impl/ControlFlowBuilder.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/controlFlow/impl/ControlFlowBuilder.java index 236cbb92b808..c74f573f62d6 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/controlFlow/impl/ControlFlowBuilder.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/controlFlow/impl/ControlFlowBuilder.java @@ -586,6 +586,11 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor { @Override public void visitCaseSection(GrCaseSection caseSection) { + GrExpression value = caseSection.getCaseLabel().getValue(); + if (value != null) { + value.accept(this); + } + for (GrStatement statement : caseSection.getStatements()) { statement.accept(this); } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.groovy index 5b7fd922bb4c..76ade3fc24a0 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.groovy @@ -187,6 +187,7 @@ public class GroovyHighlightingTest extends LightCodeInsightFixtureTestCase { public void testUnusedVariable() throws Exception { doTest(new UnusedDefInspection()); } public void testDefinitionUsedInClosure() throws Exception { doTest(new UnusedDefInspection()); } public void testDefinitionUsedInClosure2() throws Exception { doTest(new UnusedDefInspection()); } + public void testDefinitionUsedInSwitchCase() throws Exception { doTest(new UnusedDefInspection()); } public void testDuplicateInnerClass() throws Throwable{doTest();} public void testThisInStaticContext() throws Throwable {doTest();} diff --git a/plugins/groovy/testdata/highlighting/DefinitionUsedInSwitchCase.groovy b/plugins/groovy/testdata/highlighting/DefinitionUsedInSwitchCase.groovy new file mode 100644 index 000000000000..e864e59f0b8e --- /dev/null +++ b/plugins/groovy/testdata/highlighting/DefinitionUsedInSwitchCase.groovy @@ -0,0 +1,9 @@ +def m = [a: 1, b: 2] +def m1 = [a: 1, b: 2] +def val = 'a' + +switch (val) { + case m: "key in map"; break +// equivalent to case { val in m }: ... + default: "not in map" +} \ No newline at end of file