diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/whileloop/ExtractWhileLoopConditionToIfStatementIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/whileloop/ExtractWhileLoopConditionToIfStatementIntention.java index 406e7ec9b19c..7fd9daac6128 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/whileloop/ExtractWhileLoopConditionToIfStatementIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/whileloop/ExtractWhileLoopConditionToIfStatementIntention.java @@ -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 diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/whileloop/extract_while_loop_condition_to_if_statement/True.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/whileloop/extract_while_loop_condition_to_if_statement/True.java new file mode 100644 index 000000000000..099240782e49 --- /dev/null +++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/whileloop/extract_while_loop_condition_to_if_statement/True.java @@ -0,0 +1,7 @@ +class TrueCondition { + + private volatile boolean flag; + void m() { + while (true) System.out.println(); + } +} \ No newline at end of file diff --git a/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/whileloop/ExtractWhileLoopConditionToIfStatementIntentionTest.java b/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/whileloop/ExtractWhileLoopConditionToIfStatementIntentionTest.java index 317c22e9897c..a0284ff37ebf 100644 --- a/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/whileloop/ExtractWhileLoopConditionToIfStatementIntentionTest.java +++ b/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/whileloop/ExtractWhileLoopConditionToIfStatementIntentionTest.java @@ -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() {