IDEA-53845 groovy: incorrect return value is ignored

This commit is contained in:
Maxim Medvedev
2010-08-09 12:55:03 +04:00
parent 9d3f0f2828
commit b17472e816
4 changed files with 17 additions and 21 deletions
@@ -65,14 +65,10 @@ public class GroovyResultOfObjectAllocationIgnoredInspection extends BaseInspect
if (refElement == null) return; //new expression is not correct so we shouldn't check it
final PsiElement parent = newExpression.getParent();
if (parent instanceof GrClosableBlock) {
return;
}
if (parent instanceof GrCodeBlock || parent instanceof GroovyFile) {
if (parent instanceof GrOpenBlock) {
final GrOpenBlock openBlock = (GrOpenBlock)parent;
if (ControlFlowUtils.openBlockCompletesWithStatement(openBlock, newExpression)) {
if (parent instanceof GrOpenBlock || parent instanceof GrClosableBlock) {
if (ControlFlowUtils.openBlockCompletesWithStatement(((GrCodeBlock)parent), newExpression)) {
return;
}
}
@@ -330,22 +330,16 @@ public class ControlFlowUtils {
}
}
public static boolean openBlockCompletesWithStatement(
@NotNull GrOpenBlock body,
@NotNull GrStatement statement) {
public static boolean openBlockCompletesWithStatement(@NotNull GrCodeBlock body, @NotNull GrStatement statement) {
GroovyPsiElement elementToCheck = statement;
while (true) {
if (elementToCheck == null) {
return false;
}
final GroovyPsiElement container =
getContainingStatementOrBlock(elementToCheck);
if (container == null) {
return false;
}
if (isLoop(container)) {
return false;
}
if (elementToCheck == null) return false;
final GroovyPsiElement container = getContainingStatementOrBlock(elementToCheck);
if (container == null) return false;
if (isLoop(container)) return false;
if (container instanceof GrCodeBlock) {
if (elementToCheck instanceof GrStatement) {
final GrCodeBlock codeBlock = (GrCodeBlock) container;
@@ -353,7 +347,7 @@ public class ControlFlowUtils {
return false;
}
}
if (container instanceof GrOpenBlock) {
if (container instanceof GrOpenBlock || container instanceof GrClosableBlock) {
if (container.equals(body)) {
return true;
}
@@ -149,6 +149,7 @@ public class GroovyHighlightingTest extends LightCodeInsightFixtureTestCase {
public void testDefaultMapConstructorWhenDefConstructorExists() throws Throwable {doTest();}
public void testSingleAllocationInClosure() throws Throwable {doTest(new GroovyResultOfObjectAllocationIgnoredInspection());}
public void testUnusedAllocationInClosure() throws Throwable {doTest(new GroovyResultOfObjectAllocationIgnoredInspection());}
public void testUnresolvedLhsAssignment() throws Throwable { doTest(new GroovyUnresolvedAccessInspection()); }
@@ -0,0 +1,5 @@
def cl = {
new <warning descr="Result of 'new Object()' is ignored">Object</warning>()
new Object()
}
print cl()