From 27df426af5e4a339db7c84a9ada07ef3fb689678 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 2 Oct 2013 10:28:21 +0200 Subject: [PATCH] extract jdk8-specific dfa test --- .../fixture/FieldInitializerInAnonymous.java | 2 +- .../DataFlowInspection8Test.java | 67 +++++++++++++++++++ .../DataFlowInspectionTest.java | 41 ++++-------- .../DataFlowInspectionTestSuite.java | 1 + .../LightCodeInsightFixtureTestCase.java | 6 ++ 5 files changed, 87 insertions(+), 30 deletions(-) create mode 100644 java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspection8Test.java diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/FieldInitializerInAnonymous.java b/java/java-tests/testData/inspection/dataFlow/fixture/FieldInitializerInAnonymous.java index 5dc28740cba1..b55ce84f7bad 100644 --- a/java/java-tests/testData/inspection/dataFlow/fixture/FieldInitializerInAnonymous.java +++ b/java/java-tests/testData/inspection/dataFlow/fixture/FieldInitializerInAnonymous.java @@ -2,7 +2,7 @@ import org.jetbrains.annotations.Nullable; class Zoo2 { - void foo(@Nullable Object foo, @Nullable Object bar) { + void foo(@Nullable final Object foo, @Nullable final Object bar) { if (foo == null) { return; } diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspection8Test.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspection8Test.java new file mode 100644 index 000000000000..0e7d62016f42 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspection8Test.java @@ -0,0 +1,67 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInspection; + +import com.intellij.JavaTestUtil; +import com.intellij.codeInsight.NullableNotNullManager; +import com.intellij.codeInspection.dataFlow.DataFlowInspection; +import com.intellij.openapi.Disposable; +import com.intellij.openapi.util.Disposer; +import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; + +/** + * @author peter + */ +public class DataFlowInspection8Test extends LightCodeInsightFixtureTestCase { + + @Override + protected String getTestDataPath() { + return JavaTestUtil.getJavaTestDataPath() + "/inspection/dataFlow/fixture/"; + } + + private void doTest() { + final DataFlowInspection inspection = new DataFlowInspection(); + inspection.SUGGEST_NULLABLE_ANNOTATIONS = true; + inspection.REPORT_CONSTANT_REFERENCE_VALUES = false; + myFixture.enableInspections(inspection); + myFixture.testHighlighting(true, false, true, getTestName(false) + ".java"); + } + + public void testAnnotatedTypeParameters() throws Throwable { + setupCustomAnnotations(); + doTest(); + } + + private void setupCustomAnnotations() { + myFixture.addClass("package foo;\n\nimport java.lang.annotation.*;\n\n@Target({ElementType.TYPE_USE}) public @interface Nullable { }"); + myFixture.addClass("package foo;\n\nimport java.lang.annotation.*;\n\n@Target({ElementType.TYPE_USE}) public @interface NotNull { }"); + final NullableNotNullManager nnnManager = NullableNotNullManager.getInstance(getProject()); + nnnManager.setNotNulls("foo.NotNull"); + nnnManager.setNullables("foo.Nullable"); + Disposer.register(myTestRootDisposable, new Disposable() { + @Override + public void dispose() { + nnnManager.setNotNulls(); + nnnManager.setNullables(); + } + }); + } + + public void testNullableForeachVariable() { + setupCustomAnnotations(); + doTest(); + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java index b018e7fa41d8..0518daa3fe83 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java @@ -16,14 +16,15 @@ package com.intellij.codeInspection; import com.intellij.JavaTestUtil; -import com.intellij.codeInsight.*; +import com.intellij.codeInsight.ConditionCheckManager; +import com.intellij.codeInsight.ConditionChecker; import com.intellij.codeInspection.dataFlow.DataFlowInspection; -import com.intellij.openapi.Disposable; -import com.intellij.openapi.util.Disposer; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiMethod; +import com.intellij.testFramework.LightProjectDescriptor; import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; -import org.jetbrains.annotations.*; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.IOException; @@ -31,6 +32,13 @@ import java.io.IOException; * @author peter */ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase { + + @NotNull + @Override + protected LightProjectDescriptor getProjectDescriptor() { + return JAVA_1_7; + } + @Override protected void setUp() throws Exception { super.setUp(); @@ -122,26 +130,6 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase { public void testEqualsImpliesNotNull() throws Throwable { doTest(); } public void testEffectivelyUnqualified() throws Throwable { doTest(); } - public void testAnnotatedTypeParameters() throws Throwable { - setupCustomAnnotations(); - doTest(); - } - - private void setupCustomAnnotations() { - myFixture.addClass("package foo;\n\nimport java.lang.annotation.*;\n\n@Target({ElementType.TYPE_USE}) public @interface Nullable { }"); - myFixture.addClass("package foo;\n\nimport java.lang.annotation.*;\n\n@Target({ElementType.TYPE_USE}) public @interface NotNull { }"); - final NullableNotNullManager nnnManager = NullableNotNullManager.getInstance(getProject()); - nnnManager.setNotNulls("foo.NotNull"); - nnnManager.setNullables("foo.Nullable"); - Disposer.register(myTestRootDisposable, new Disposable() { - @Override - public void dispose() { - nnnManager.setNotNulls(); - nnnManager.setNullables(); - } - }); - } - public void testSkipAssertions() { final DataFlowInspection inspection = new DataFlowInspection(); inspection.DONT_REPORT_TRUE_ASSERT_STATEMENTS = true; @@ -207,11 +195,6 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase { public void testNullCheckDoesntAffectUncheckedCast() { doTest(); } public void testThrowNull() { doTest(); } - public void testNullableForeachVariable() { - setupCustomAnnotations(); - doTest(); - } - public void testTryWithResourcesNullability() { doTest(); } public void testTryWithResourcesInstanceOf() { doTest(); } public void testOmnipresentExceptions() { doTest(); } diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTestSuite.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTestSuite.java index c7dacef88b0d..e5704b62ca1a 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTestSuite.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTestSuite.java @@ -26,6 +26,7 @@ public class DataFlowInspectionTestSuite { public static Test suite() { TestSuite suite = new TestSuite(); suite.addTestSuite(DataFlowInspectionTest.class); + suite.addTestSuite(DataFlowInspection8Test.class); suite.addTestSuite(DataFlowInspectionAncientTest.class); suite.addTestSuite(SliceTreeTest.class); suite.addTestSuite(SliceBackwardTest.class); diff --git a/java/testFramework/src/com/intellij/testFramework/fixtures/LightCodeInsightFixtureTestCase.java b/java/testFramework/src/com/intellij/testFramework/fixtures/LightCodeInsightFixtureTestCase.java index 4d284cfc2bb3..f1eaaf2dece7 100644 --- a/java/testFramework/src/com/intellij/testFramework/fixtures/LightCodeInsightFixtureTestCase.java +++ b/java/testFramework/src/com/intellij/testFramework/fixtures/LightCodeInsightFixtureTestCase.java @@ -41,6 +41,12 @@ public abstract class LightCodeInsightFixtureTestCase extends UsefulTestCase{ model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(LanguageLevel.JDK_1_6); } }; + public static final LightProjectDescriptor JAVA_1_7 = new DefaultLightProjectDescriptor() { + @Override + public void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) { + model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(LanguageLevel.JDK_1_7); + } + }; public static final LightProjectDescriptor JAVA_LATEST = new DefaultLightProjectDescriptor();