[^romka] IDEA-68894 Usages in switch case don't count for unused definition inspection(cherry picked from commit 884425d)

This commit is contained in:
peter
2011-11-28 14:50:41 +01:00
parent 350dabcdd5
commit 5bc4158216
3 changed files with 15 additions and 0 deletions
@@ -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);
}
@@ -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();}
@@ -0,0 +1,9 @@
def m = [a: 1, b: 2]
def <warning descr="Assignment is not used">m1</warning> = [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"
}