mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 21:41:24 +07:00
[java] ConditionalBreakInInfiniteLoopInspection invert variable name and condition + fix test data
GitOrigin-RevId: f00028d2e207670784887a66d2cd12cb61f11127
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7fffa465a2
commit
86406ca919
@@ -124,7 +124,7 @@ public class ConditionalBreakInInfiniteLoopInspection extends AbstractBaseJavaLo
|
||||
@Nullable
|
||||
private static Context from(@NotNull PsiConditionalLoopStatement loopStatement,
|
||||
boolean noConversionToDoWhile,
|
||||
boolean dontConvertWhenIfIsSingleStmtInLoop) {
|
||||
boolean suggestConversionWhenIfIsASingleStmtInLoop) {
|
||||
boolean isEndlessLoop = ControlFlowUtils.isEndlessLoop(loopStatement);
|
||||
if (!isEndlessLoop) {
|
||||
if (loopStatement instanceof PsiForStatement) {
|
||||
@@ -139,7 +139,7 @@ public class ConditionalBreakInInfiniteLoopInspection extends AbstractBaseJavaLo
|
||||
if (body == null) return null;
|
||||
PsiStatement[] statements = ControlFlowUtils.unwrapBlock(body);
|
||||
if (statements.length < 1) return null;
|
||||
if (statements.length == 1 && dontConvertWhenIfIsSingleStmtInLoop) return null;
|
||||
if (statements.length == 1 && !suggestConversionWhenIfIsASingleStmtInLoop) return null;
|
||||
if (StreamEx.ofTree((PsiElement)body, el -> StreamEx.of(el.getChildren()))
|
||||
.select(PsiBreakStatement.class)
|
||||
.filter(stmt -> ControlFlowUtils.statementBreaksLoop(stmt, loopStatement))
|
||||
|
||||
@@ -4,6 +4,7 @@ class Main {
|
||||
int i = 0;
|
||||
while (i < 12) {
|
||||
i++;
|
||||
System.out.println("asda");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ class Main {
|
||||
int i = 0;
|
||||
while (i < 13) {
|
||||
i++;
|
||||
System.out.println("asd");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ class Main {
|
||||
int i = 0;
|
||||
while (i < 14) {
|
||||
i++;
|
||||
System.out.println("asd");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ class Main {
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
System.out.println("asda");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Move condition to loop" "false"
|
||||
class Main {
|
||||
public static void main(String[] args) {
|
||||
while<caret> (true) {
|
||||
if (!outputParser.processMessageLine(callback)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ class Main {
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
System.out.println("asd");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ class Main {
|
||||
break;
|
||||
else
|
||||
i++;
|
||||
System.out.println("asd");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user