From e8ee43cdeee6c00751746e8f9b5dd46b136b10f7 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 5 Aug 2013 11:01:38 +0200 Subject: [PATCH] disable constant value warnings in complex assignments (IDEA-111478) --- .../codeInspection/dataFlow/ControlFlowAnalyzer.java | 3 ++- .../ReportConstantReferences_NotInComplexAssignment.java | 6 ++++++ .../com/intellij/codeInspection/DataFlowInspectionTest.java | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/inspection/dataFlow/fixture/ReportConstantReferences_NotInComplexAssignment.java diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java index 409a8a99fc5f..d927d8cb78a4 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java @@ -1673,7 +1673,8 @@ class ControlFlowAnalyzer extends JavaElementVisitor { addInstruction(expression.resolve() instanceof PsiField ? new FieldReferenceInstruction(expression, null) : new PopInstruction()); } - addInstruction(new PushInstruction(getExpressionDfaValue(expression), expression, PsiUtil.isAccessedForReading(expression))); + boolean referenceRead = PsiUtil.isAccessedForReading(expression) && !PsiUtil.isAccessedForWriting(expression); + addInstruction(new PushInstruction(getExpressionDfaValue(expression), expression, referenceRead)); finishElement(expression); } diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/ReportConstantReferences_NotInComplexAssignment.java b/java/java-tests/testData/inspection/dataFlow/fixture/ReportConstantReferences_NotInComplexAssignment.java new file mode 100644 index 000000000000..a13f0f1b5d60 --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/ReportConstantReferences_NotInComplexAssignment.java @@ -0,0 +1,6 @@ +class Test { + void foo() { + int x = 42; + x += 100; + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java index 32fc5d688f6c..6de4bef6febd 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java @@ -175,6 +175,11 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase { myFixture.launchAction(myFixture.findSingleIntention("Replace with 'FOO'")); myFixture.checkResultByFile(getTestName(false) + "_after.java"); } + public void testReportConstantReferences_NotInComplexAssignment() { + myFixture.addClass("package foo; public enum MyEnum { FOO }"); + doTestReplaceConstantReferences(); + assertEmpty(myFixture.filterAvailableIntentions("Replace with")); + } public void testReportConstantReferences_Switch() { doTestReplaceConstantReferences(); } public void testCheckFieldInitializers() {