dfa: don't suggest to simplify boolean expressions with side effects (IDEA-145401)

This commit is contained in:
peter
2015-10-06 15:29:27 +02:00
parent 4d76c50f69
commit f98d01be5e
3 changed files with 16 additions and 0 deletions
@@ -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" +