extract jdk8-specific dfa test

This commit is contained in:
peter
2013-10-02 10:28:21 +02:00
parent 4542fe6ee9
commit 27df426af5
5 changed files with 87 additions and 30 deletions
@@ -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;
}
@@ -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();
}
}
@@ -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(); }
@@ -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);
@@ -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();