diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/AssertThat.java b/java/java-tests/testData/inspection/dataFlow/fixture/AssertThat.java
index 4f3b6ddcec3b..747027445fa6 100644
--- a/java/java-tests/testData/inspection/dataFlow/fixture/AssertThat.java
+++ b/java/java-tests/testData/inspection/dataFlow/fixture/AssertThat.java
@@ -93,9 +93,7 @@ class Contracts {
private void testNotArraySize() {
String[] things = retrieveThings();
assertThat(things, not(is(arrayWithSize(2))));
- assertThat(things[0], is(equalTo("...")));
- things = null;
- assertThat(things[0], is(equalTo("...")));
+ assertThat(things[0], is(equalTo("...")));
}
void testBoxed(Contracts c) {
diff --git a/java/java-tests/testSrc/com/intellij/java/codeInspection/HardcodedContractsTest.java b/java/java-tests/testSrc/com/intellij/java/codeInspection/HardcodedContractsTest.java
index 73042a12034c..88eecc9c1ceb 100644
--- a/java/java-tests/testSrc/com/intellij/java/codeInspection/HardcodedContractsTest.java
+++ b/java/java-tests/testSrc/com/intellij/java/codeInspection/HardcodedContractsTest.java
@@ -33,54 +33,11 @@ public class HardcodedContractsTest extends DataFlowInspectionTestCase {
return JavaTestUtil.getJavaTestDataPath() + "/inspection/dataFlow/fixture/";
}
-
private void checkHighlighting() {
myFixture.enableInspections(new DataFlowInspection(), new ConstantValueInspection());
myFixture.testHighlighting(true, false, true, getTestName(false) + ".java");
}
- public void testAssertThat() {
- myFixture.addClass("""
- package org.hamcrest; public class CoreMatchers { public static Matcher notNullValue() {}
- public static Matcher nullValue() {}
- public static Matcher not(Matcher matcher) {}
- public static Matcher is(Matcher matcher) {}
- public static Matcher is(T operand) {}
- public static Matcher equalTo(T operand) {}
- public static Matcher arrayWithSize(int size) {}\s
- }""");
- myFixture.addClass("package org.hamcrest; public interface Matcher {}");
- myFixture.addClass("""
- package org.junit; public class Assert { public static void assertThat(T actual, org.hamcrest.Matcher super T> matcher) {}
- public static void assertThat(String msg, T actual, org.hamcrest.Matcher super T> matcher) {}
- }""");
-
- myFixture.addClass("""
- package org.assertj.core.api; public class Assertions { public static AbstractAssert, T> assertThat(Object actual) {}
- public static AbstractAssert, T> assertThat(java.util.concurrent.atomic.AtomicBoolean actual) {}
- public static AbstractAssert, T> assertThat(boolean actual) {}
- }""");
- myFixture.addClass("package org.assertj.core.api; public class AbstractAssert, A> {" +
- "public S isNotNull() {}" +
- "public S describedAs(String s) {}" +
- "public S isTrue() {}" +
- "public S isNotEmpty() {}" +
- "public S isEmpty() {}" +
- "public S isPresent() {}" +
- "public S isNotBlank() {}" +
- "public S isEqualTo(Object expected) {}" +
- "public S map(java.util.function.Function mapper) {}" +
- "public S hasSize(int size) {}" +
- "public S hasSizeBetween(int min, int max) {}" +
- "public S hasSizeGreaterThan(int size) {}" +
- "public S hasSizeGreaterThanOrEqualTo(int size) {}" +
- "public S hasSizeLessThan(int size) {}" +
- "public S hasSizeLessThanOrEqualTo(int size) {}" +
- "}");
-
- checkHighlighting();
- }
-
public void testAssumeThat() {
myFixture.addClass("package org.hamcrest; public class CoreMatchers { " +
"public static Matcher notNullValue() {}\n" +
diff --git a/java/java-tests/testSrc/com/intellij/java/codeInspection/HardcodedContractsWithoutTypeUseAnnotationTest.java b/java/java-tests/testSrc/com/intellij/java/codeInspection/HardcodedContractsWithoutTypeUseAnnotationTest.java
new file mode 100644
index 000000000000..f2089f10a540
--- /dev/null
+++ b/java/java-tests/testSrc/com/intellij/java/codeInspection/HardcodedContractsWithoutTypeUseAnnotationTest.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2000-2017 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.java.codeInspection;
+
+import com.intellij.JavaTestUtil;
+import com.intellij.codeInspection.dataFlow.ConstantValueInspection;
+import com.intellij.codeInspection.dataFlow.DataFlowInspection;
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.roots.ContentEntry;
+import com.intellij.openapi.roots.LanguageLevelModuleExtension;
+import com.intellij.openapi.roots.ModifiableRootModel;
+import com.intellij.pom.java.LanguageLevel;
+import com.intellij.testFramework.LightProjectDescriptor;
+import org.jetbrains.annotations.NotNull;
+
+public class HardcodedContractsWithoutTypeUseAnnotationTest extends DataFlowInspectionTestCase {
+
+ private static final ProjectDescriptor JDK_21_WITH_NOT_TYPE_USE_ANNOTATION = new ProjectDescriptor(LanguageLevel.JDK_21) {
+ @Override
+ public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
+ model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(myLanguageLevel);
+ addJetBrainsAnnotations(model);
+ }
+ };
+
+ @NotNull
+ @Override
+ protected LightProjectDescriptor getProjectDescriptor() {
+ //it is necessary for some tests
+ return JDK_21_WITH_NOT_TYPE_USE_ANNOTATION;
+ }
+
+ @Override
+ protected String getTestDataPath() {
+ return JavaTestUtil.getJavaTestDataPath() + "/inspection/dataFlow/fixture/";
+ }
+
+
+ private void checkHighlighting() {
+ myFixture.enableInspections(new DataFlowInspection(), new ConstantValueInspection());
+ myFixture.testHighlighting(true, false, true, getTestName(false) + ".java");
+ }
+
+ public void testAssertThat() {
+ myFixture.addClass("""
+ package org.hamcrest; public class CoreMatchers { public static Matcher notNullValue() {}
+ public static Matcher nullValue() {}
+ public static Matcher not(Matcher matcher) {}
+ public static Matcher is(Matcher matcher) {}
+ public static Matcher is(T operand) {}
+ public static Matcher equalTo(T operand) {}
+ public static Matcher arrayWithSize(int size) {}\s
+ }""");
+ myFixture.addClass("package org.hamcrest; public interface Matcher {}");
+ myFixture.addClass("""
+ package org.junit; public class Assert { public static void assertThat(T actual, org.hamcrest.Matcher super T> matcher) {}
+ public static void assertThat(String msg, T actual, org.hamcrest.Matcher super T> matcher) {}
+ }""");
+
+ myFixture.addClass("""
+ package org.assertj.core.api; public class Assertions { public static AbstractAssert, T> assertThat(Object actual) {}
+ public static AbstractAssert, T> assertThat(java.util.concurrent.atomic.AtomicBoolean actual) {}
+ public static AbstractAssert, T> assertThat(boolean actual) {}
+ }""");
+ myFixture.addClass("package org.assertj.core.api; public class AbstractAssert, A> {" +
+ "public S isNotNull() {}" +
+ "public S describedAs(String s) {}" +
+ "public S isTrue() {}" +
+ "public S isNotEmpty() {}" +
+ "public S isEmpty() {}" +
+ "public S isPresent() {}" +
+ "public S isNotBlank() {}" +
+ "public S isEqualTo(Object expected) {}" +
+ "public S map(java.util.function.Function mapper) {}" +
+ "public S hasSize(int size) {}" +
+ "public S hasSizeBetween(int min, int max) {}" +
+ "public S hasSizeGreaterThan(int size) {}" +
+ "public S hasSizeGreaterThanOrEqualTo(int size) {}" +
+ "public S hasSizeLessThan(int size) {}" +
+ "public S hasSizeLessThanOrEqualTo(int size) {}" +
+ "}");
+
+ checkHighlighting();
+ }
+}
diff --git a/java/java-tests/testSrc/com/intellij/java/refactoring/SafeDeleteTest.java b/java/java-tests/testSrc/com/intellij/java/refactoring/SafeDeleteTest.java
index edb3d11125a5..5096cdfc1007 100644
--- a/java/java-tests/testSrc/com/intellij/java/refactoring/SafeDeleteTest.java
+++ b/java/java-tests/testSrc/com/intellij/java/refactoring/SafeDeleteTest.java
@@ -33,7 +33,7 @@ public class SafeDeleteTest extends MultiFileTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsJava8AndHigher);
+ ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsWithTypeUse);
}
@Override
diff --git a/java/java-tests/testSrc/com/siyeh/ig/fixes/PointlessBooleanExpressionFixTest.java b/java/java-tests/testSrc/com/siyeh/ig/fixes/PointlessBooleanExpressionFixTest.java
index 662d522e1d44..13186c93ee0b 100644
--- a/java/java-tests/testSrc/com/siyeh/ig/fixes/PointlessBooleanExpressionFixTest.java
+++ b/java/java-tests/testSrc/com/siyeh/ig/fixes/PointlessBooleanExpressionFixTest.java
@@ -19,7 +19,7 @@ public class PointlessBooleanExpressionFixTest extends IGQuickFixesTestCase {
myFixture.enableInspections(inspection);
myRelativePath = "pointlessboolean";
myDefaultHint = InspectionGadgetsBundle.message("constant.conditional.expression.simplify.quickfix");
- ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsJava8AndHigher);
+ ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsWithTypeUse);
}
public void testNegation() { doTest(); }
diff --git a/java/java-tests/testSrc/com/siyeh/ig/fixes/dataflow/CreateNullBranchFixTest.java b/java/java-tests/testSrc/com/siyeh/ig/fixes/dataflow/CreateNullBranchFixTest.java
index 519c96288726..a1b3669aa6f1 100644
--- a/java/java-tests/testSrc/com/siyeh/ig/fixes/dataflow/CreateNullBranchFixTest.java
+++ b/java/java-tests/testSrc/com/siyeh/ig/fixes/dataflow/CreateNullBranchFixTest.java
@@ -16,7 +16,7 @@ public class CreateNullBranchFixTest extends IGQuickFixesTestCase {
super.setUp();
myFixture.enableInspections(new DataFlowInspection());
myRelativePath = "dataflow/create_null_branch";
- ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsJava8AndHigher);
+ ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsWithTypeUse);
}
@Override
diff --git a/java/java-tests/testSrc/com/siyeh/ig/fixes/migration/IfCanBePatternSwitchFixTest.java b/java/java-tests/testSrc/com/siyeh/ig/fixes/migration/IfCanBePatternSwitchFixTest.java
index 16f9fd9dfc8c..0688f879d1bd 100644
--- a/java/java-tests/testSrc/com/siyeh/ig/fixes/migration/IfCanBePatternSwitchFixTest.java
+++ b/java/java-tests/testSrc/com/siyeh/ig/fixes/migration/IfCanBePatternSwitchFixTest.java
@@ -20,7 +20,7 @@ public class IfCanBePatternSwitchFixTest extends IGQuickFixesTestCase {
myFixture.enableInspections(inspection);
myRelativePath = "migration/if_can_be_switch";
myDefaultHint = CommonQuickFixBundle.message("fix.replace.x.with.y", PsiKeyword.IF, PsiKeyword.SWITCH);
- ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsJava8AndHigher);
+ ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsWithTypeUse);
}
@Override
diff --git a/java/java-tests/testSrc/com/siyeh/ig/fixes/migration/IfCanBePrimitivePatternSwitchFixTest.java b/java/java-tests/testSrc/com/siyeh/ig/fixes/migration/IfCanBePrimitivePatternSwitchFixTest.java
index 71e46206e6fd..1a64bd658b48 100644
--- a/java/java-tests/testSrc/com/siyeh/ig/fixes/migration/IfCanBePrimitivePatternSwitchFixTest.java
+++ b/java/java-tests/testSrc/com/siyeh/ig/fixes/migration/IfCanBePrimitivePatternSwitchFixTest.java
@@ -20,7 +20,7 @@ public class IfCanBePrimitivePatternSwitchFixTest extends IGQuickFixesTestCase {
myFixture.enableInspections(inspection);
myRelativePath = "migration/if_can_be_switch";
myDefaultHint = CommonQuickFixBundle.message("fix.replace.x.with.y", PsiKeyword.IF, PsiKeyword.SWITCH);
- ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsJava8AndHigher);
+ ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsWithTypeUse);
}
@Override
diff --git a/java/java-tests/testSrc/com/siyeh/ig/fixes/style/LambdaCanBeReplacedWithAnonymousFixTest.java b/java/java-tests/testSrc/com/siyeh/ig/fixes/style/LambdaCanBeReplacedWithAnonymousFixTest.java
index 7f2b9e6a14e6..4c85a75c6e30 100644
--- a/java/java-tests/testSrc/com/siyeh/ig/fixes/style/LambdaCanBeReplacedWithAnonymousFixTest.java
+++ b/java/java-tests/testSrc/com/siyeh/ig/fixes/style/LambdaCanBeReplacedWithAnonymousFixTest.java
@@ -31,7 +31,7 @@ public class LambdaCanBeReplacedWithAnonymousFixTest extends IGQuickFixesTestCas
super.setUp();
myFixture.enableInspections(new LambdaCanBeReplacedWithAnonymousInspection());
myDefaultHint = InspectionGadgetsBundle.message("lambda.can.be.replaced.with.anonymous.quickfix");
- ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsJava8AndHigher);
+ ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsWithTypeUse);
}
public void testSimpleRunnable() {
diff --git a/java/testFramework/src/com/intellij/testFramework/LightJavaCodeInsightTestCase.java b/java/testFramework/src/com/intellij/testFramework/LightJavaCodeInsightTestCase.java
index 9eb8ea33dae2..864af2883772 100644
--- a/java/testFramework/src/com/intellij/testFramework/LightJavaCodeInsightTestCase.java
+++ b/java/testFramework/src/com/intellij/testFramework/LightJavaCodeInsightTestCase.java
@@ -98,7 +98,7 @@ public abstract class LightJavaCodeInsightTestCase extends LightPlatformCodeInsi
@Override
protected void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
if (languageLevel.isAtLeast(LanguageLevel.JDK_1_8)) {
- DefaultLightProjectDescriptor.addJetBrainsAnnotationsJava8AndHigher(model);
+ DefaultLightProjectDescriptor.addJetBrainsAnnotationsWithTypeUse(model);
}
else {
DefaultLightProjectDescriptor.addJetBrainsAnnotations(model);
diff --git a/java/testFramework/src/com/intellij/testFramework/fixtures/DefaultLightProjectDescriptor.java b/java/testFramework/src/com/intellij/testFramework/fixtures/DefaultLightProjectDescriptor.java
index 44fdbc57a2b2..d89833da0a9b 100644
--- a/java/testFramework/src/com/intellij/testFramework/fixtures/DefaultLightProjectDescriptor.java
+++ b/java/testFramework/src/com/intellij/testFramework/fixtures/DefaultLightProjectDescriptor.java
@@ -73,11 +73,11 @@ public class DefaultLightProjectDescriptor extends LightProjectDescriptor {
return withRepositoryLibrary(JETBRAINS_ANNOTATIONS_COORDINATES);
}
- public DefaultLightProjectDescriptor withJetBrainsAnnotationsJava8AndHigher() {
+ public DefaultLightProjectDescriptor withJetBrainsAnnotationsWithTypeUse() {
return withRepositoryLibrary(JETBRAINS_ANNOTATIONS_COORDINATES_JAVA_8);
}
- public static void addJetBrainsAnnotationsJava8AndHigher(ModifiableRootModel model) {
+ public static void addJetBrainsAnnotationsWithTypeUse(ModifiableRootModel model) {
MavenDependencyUtil.addFromMaven(model, JETBRAINS_ANNOTATIONS_COORDINATES_JAVA_8);
}
diff --git a/java/testFramework/src/com/intellij/testFramework/fixtures/LightJavaCodeInsightFixtureTestCase.java b/java/testFramework/src/com/intellij/testFramework/fixtures/LightJavaCodeInsightFixtureTestCase.java
index 381cb1a693d9..4bcf3eded883 100644
--- a/java/testFramework/src/com/intellij/testFramework/fixtures/LightJavaCodeInsightFixtureTestCase.java
+++ b/java/testFramework/src/com/intellij/testFramework/fixtures/LightJavaCodeInsightFixtureTestCase.java
@@ -63,7 +63,7 @@ public abstract class LightJavaCodeInsightFixtureTestCase extends UsefulTestCase
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(myLanguageLevel);
if (myLanguageLevel.isAtLeast(LanguageLevel.JDK_1_8)) {
- addJetBrainsAnnotationsJava8AndHigher(model);
+ addJetBrainsAnnotationsWithTypeUse(model);
}
else {
addJetBrainsAnnotations(model);
diff --git a/plugins/lombok/src/test/java/de/plushnikov/intellij/plugin/LombokTestUtil.java b/plugins/lombok/src/test/java/de/plushnikov/intellij/plugin/LombokTestUtil.java
index 7bdf3ce80dc1..06e00bfbcbea 100644
--- a/plugins/lombok/src/test/java/de/plushnikov/intellij/plugin/LombokTestUtil.java
+++ b/plugins/lombok/src/test/java/de/plushnikov/intellij/plugin/LombokTestUtil.java
@@ -20,7 +20,7 @@ public final class LombokTestUtil {
public static final DefaultLightProjectDescriptor LOMBOK_DESCRIPTOR = new DefaultLightProjectDescriptor() {
@Override
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
- DefaultLightProjectDescriptor.addJetBrainsAnnotationsJava8AndHigher(model);
+ DefaultLightProjectDescriptor.addJetBrainsAnnotationsWithTypeUse(model);
MavenDependencyUtil.addFromMaven(model, LOMBOK_MAVEN_COORDINATES, true, DependencyScope.PROVIDED);
MavenDependencyUtil.addFromMaven(model, JACKSON_MAVEN_COORDINATES);
MavenDependencyUtil.addFromMaven(model, "com.google.guava:guava:27.0.1-jre");
@@ -37,7 +37,7 @@ public final class LombokTestUtil {
public static final DefaultLightProjectDescriptor WITHOUT_LOMBOK_DESCRIPTOR = new DefaultLightProjectDescriptor() {
@Override
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
- DefaultLightProjectDescriptor.addJetBrainsAnnotationsJava8AndHigher(model);
+ DefaultLightProjectDescriptor.addJetBrainsAnnotationsWithTypeUse(model);
MavenDependencyUtil.addFromMaven(model, JACKSON_MAVEN_COORDINATES);
MavenDependencyUtil.addFromMaven(model, "com.google.guava:guava:27.0.1-jre");
MavenDependencyUtil.addFromMaven(model, "org.slf4j:slf4j-api:1.7.30");