mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
dfa: don't suggest to simplify boolean expressions with side effects (IDEA-145401)
This commit is contained in:
+2
@@ -737,6 +737,8 @@ public class DataFlowInspectionBase extends BaseJavaBatchLocalInspectionTool {
|
||||
|
||||
private static SimplifyBooleanExpressionFix createIntention(PsiElement element, boolean value) {
|
||||
if (!(element instanceof PsiExpression)) return null;
|
||||
if (PsiTreeUtil.findChildOfType(element, PsiAssignmentExpression.class) != null) return null;
|
||||
|
||||
final PsiExpression expression = (PsiExpression)element;
|
||||
while (element.getParent() instanceof PsiExpression) {
|
||||
element = element.getParent();
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class Contracts {
|
||||
|
||||
boolean x;
|
||||
|
||||
public boolean testSideEffect() {
|
||||
return x && <warning descr="Condition '!(x = false)' is always 'true' when reached">!(x =<caret> false)</warning>;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -371,6 +371,11 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
|
||||
myFixture.checkResultByFile(getTestName(false) + "_after.java");
|
||||
}
|
||||
|
||||
public void testDontSimplifyAssignment() {
|
||||
doTest();
|
||||
assertEmpty(myFixture.filterAvailableIntentions("Simplify"));
|
||||
}
|
||||
|
||||
public void testAssertThat() {
|
||||
myFixture.addClass("package org.hamcrest; public class CoreMatchers { " +
|
||||
"public static <T> Matcher<T> notNullValue() {}\n" +
|
||||
|
||||
Reference in New Issue
Block a user