mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[groovy] honor returns when computing last statement (IDEA-178598)
This commit is contained in:
+2
-12
@@ -415,20 +415,10 @@ public class ControlFlowUtils {
|
||||
}
|
||||
|
||||
private static boolean statementIsLastInBlock(@NotNull GrStatementOwner block, @NotNull GrStatement statement) {
|
||||
final GrStatement[] statements = block.getStatements();
|
||||
for (int i = statements.length - 1; i >= 0; i--) {
|
||||
final GrStatement childStatement = statements[i];
|
||||
if (statement.equals(childStatement)) {
|
||||
return true;
|
||||
}
|
||||
if (!(childStatement instanceof GrReturnStatement)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
GrStatement lastStatement = ArrayUtil.getLastElement(block.getStatements());
|
||||
return statement == lastStatement;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public static List<GrStatement> collectReturns(@Nullable PsiElement element) {
|
||||
return collectReturns(element, element instanceof GrCodeBlock || element instanceof GroovyFile);
|
||||
|
||||
+16
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -292,6 +292,21 @@ for(i in []) {
|
||||
print 4
|
||||
}
|
||||
}
|
||||
|
||||
for (i in []) {
|
||||
if (cond) {
|
||||
continue
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
for (i in []) {
|
||||
if (cond) {
|
||||
<warning descr="continue is unnecessary as the last statement in a loop">continue</warning>
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
''', GroovyUnnecessaryContinueInspection)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user