diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/branch/GrAssertStatement.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/branch/GrAssertStatement.java index 8aa2dd5edc83..852940aa35ff 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/branch/GrAssertStatement.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/branch/GrAssertStatement.java @@ -16,6 +16,7 @@ package org.jetbrains.plugins.groovy.lang.psi.api.statements.branch; +import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; @@ -24,4 +25,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpres */ public interface GrAssertStatement extends GrStatement { GrExpression getAssertion(); + + @Nullable + GrExpression getErrorMessage(); } 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 baa859d3371a..0d8005882c0e 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 @@ -252,6 +252,10 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor { if (assertion != null) { assertion.accept(this); final InstructionImpl assertInstruction = startNode(assertStatement); + GrExpression errorMessage = assertStatement.getErrorMessage(); + if (errorMessage != null) { + errorMessage.accept(this); + } final PsiType type = TypesUtil.createTypeByFQClassName("java.lang.AssertionError", assertStatement); ExceptionInfo info = findCatch(type); if (info != null) { @@ -419,41 +423,6 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor { if (elseEnd != null) addEdge(elseEnd, end); } finishNode(ifInstruction); - - - - /*InstructionImpl ifInstruction = startNode(ifStatement); - final GrCondition condition = ifStatement.getCondition(); - - final InstructionImpl head = myHead; - final GrStatement thenBranch = ifStatement.getThenBranch(); - if (thenBranch != null) { - if (condition != null) { - condition.accept(this); - } - thenBranch.accept(this); - handlePossibleReturn(thenBranch); - addPendingEdge(ifStatement, myHead); - } - - myHead = head; - if (condition != null) { - myNegate = !myNegate; - final boolean old = myAssertionsOnly; - myAssertionsOnly = true; - condition.accept(this); - myNegate = !myNegate; - myAssertionsOnly = old; - } - - final GrStatement elseBranch = ifStatement.getElseBranch(); - if (elseBranch != null) { - elseBranch.accept(this); - handlePossibleReturn(elseBranch); - addPendingEdge(ifStatement, myHead); - } - - finishNode(ifInstruction);*/ } public void visitForStatement(GrForStatement forStatement) { @@ -706,7 +675,6 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor { private void finishNode(InstructionImpl instruction) { assert instruction.equals(myProcessingStack.pop()); -/* myHead = myProcessingStack.peek();*/ } public void visitField(GrField field) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/branch/GrAssertStatementImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/branch/GrAssertStatementImpl.java index 7656938c9c4f..7f86a473f3f7 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/branch/GrAssertStatementImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/branch/GrAssertStatementImpl.java @@ -42,4 +42,10 @@ public class GrAssertStatementImpl extends GroovyPsiElementImpl implements GrAss public GrExpression getAssertion() { return findChildByClass(GrExpression.class); } + + @Override + public GrExpression getErrorMessage() { + GrExpression[] exprs = findChildrenByClass(GrExpression.class); + return exprs.length >= 2 ? exprs[1] : null; + } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java index 1fe08ab782b3..e2a9829b3395 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java @@ -306,7 +306,7 @@ public class GroovyHighlightingTest extends LightCodeInsightFixtureTestCase { public void testMapParamWithNoArgs() {doTest(new GroovyAssignabilityCheckInspection());} public void testGroovyEnumInJavaFile() { - myFixture.copyFileToProject(getTestName(false)+".groovy"); + myFixture.copyFileToProject(getTestName(false) + ".groovy"); myFixture.testHighlighting(true, false, false, getTestName(false) + ".java"); } @@ -359,6 +359,8 @@ public class GroovyHighlightingTest extends LightCodeInsightFixtureTestCase { doTest(new GroovyUnresolvedAccessInspection(), new GroovyUntypedAccessInspection()); } + public void testUsageInInjection() { doTest(new UnusedDefInspection()); } + public void testDuplicatedNamedArgs() {doTest();} public void testAnonymousClassArgList() { diff --git a/plugins/groovy/testdata/highlighting/UsageInInjection.groovy b/plugins/groovy/testdata/highlighting/UsageInInjection.groovy new file mode 100644 index 000000000000..2d222f6d5511 --- /dev/null +++ b/plugins/groovy/testdata/highlighting/UsageInInjection.groovy @@ -0,0 +1,5 @@ +def x = new Date() +def y = new Date() +def z = new Date() +assert false : "should have thrown exception, but returned $x" +assert false : "should have thrown exception, but returned ${y}" \ No newline at end of file