mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-185965 Do not suggest to extract condition to internal 'if' for 'while(true)' loop
This commit is contained in:
+4
-1
@@ -20,6 +20,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.siyeh.ig.psiutils.BlockUtils;
|
||||
import com.siyeh.ig.psiutils.BoolUtils;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import com.siyeh.ipp.base.Intention;
|
||||
import com.siyeh.ipp.base.PsiElementPredicate;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -29,7 +30,9 @@ public class ExtractWhileLoopConditionToIfStatementIntention extends Intention {
|
||||
@Override
|
||||
@NotNull
|
||||
protected PsiElementPredicate getElementPredicate() {
|
||||
return new WhileLoopPredicate();
|
||||
WhileLoopPredicate predicate = new WhileLoopPredicate();
|
||||
return e -> predicate.satisfiedBy(e) &&
|
||||
!(ExpressionUtils.computeConstantExpression(((PsiWhileStatement)e.getParent()).getCondition()) instanceof Boolean);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class TrueCondition {
|
||||
|
||||
private volatile boolean flag;
|
||||
void m() {
|
||||
<caret>while (true) System.out.println();
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -1,6 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.siyeh.ipp.whileloop;
|
||||
|
||||
import com.siyeh.IntentionPowerPackBundle;
|
||||
@@ -14,6 +12,7 @@ public class ExtractWhileLoopConditionToIfStatementIntentionTest extends IPPTest
|
||||
|
||||
public void testSimple() { doTest(); }
|
||||
public void testNoBody() { doTest(); }
|
||||
public void testTrue() { assertIntentionNotAvailable(); }
|
||||
|
||||
@Override
|
||||
protected String getRelativePath() {
|
||||
|
||||
Reference in New Issue
Block a user