mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-53845 groovy: incorrect return value is ignored
This commit is contained in:
+2
-6
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+9
-15
@@ -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()
|
||||
Reference in New Issue
Block a user