mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-67879 Groovy Inspection: false 'unused code' warning
This commit is contained in:
+4
@@ -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();
|
||||
}
|
||||
|
||||
+4
-36
@@ -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) {
|
||||
|
||||
+6
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
def x = new Date()
|
||||
def y = new Date()
|
||||
def <warning descr="Assignment is not used">z</warning> = new Date()
|
||||
assert false : "should have thrown exception, but returned $x"
|
||||
assert false : "should have thrown exception, but returned ${y}"
|
||||
Reference in New Issue
Block a user