diff --git a/java/java-tests/testSrc/com/intellij/java/codeInspection/ExplicitToImplicitClassMigrationInspectionInspectionTest.java b/java/java-tests/testSrc/com/intellij/java/codeInspection/ExplicitToImplicitClassMigrationInspectionInspectionTest.java index 602062dc8332..57742a9f2920 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInspection/ExplicitToImplicitClassMigrationInspectionInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInspection/ExplicitToImplicitClassMigrationInspectionInspectionTest.java @@ -106,7 +106,6 @@ public class ExplicitToImplicitClassMigrationInspectionInspectionTest extends Li } private void doTest() { - MigrateToJavaLangIoInspectionTest.addIOClass(myFixture); myFixture.enableInspections(new ExplicitToImplicitClassMigrationInspection()); myFixture.testHighlighting(true, false, true, "before" + getTestName(false) + ".java"); myFixture.checkPreviewAndLaunchAction(myFixture.findSingleIntention( diff --git a/java/java-tests/testSrc/com/intellij/java/codeInspection/MigrateFromJavaLangIoInspection21Test.java b/java/java-tests/testSrc/com/intellij/java/codeInspection/MigrateFromJavaLangIoInspection21Test.java new file mode 100644 index 000000000000..2d988ed80835 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/java/codeInspection/MigrateFromJavaLangIoInspection21Test.java @@ -0,0 +1,29 @@ +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.java.codeInspection; + +import com.intellij.JavaTestUtil; +import com.intellij.codeInspection.MigrateFromJavaLangIoInspection; +import com.intellij.testFramework.LightProjectDescriptor; +import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase; +import org.jetbrains.annotations.NotNull; + +public class MigrateFromJavaLangIoInspection21Test extends LightJavaCodeInsightFixtureTestCase { + + @NotNull + @Override + protected LightProjectDescriptor getProjectDescriptor() { + return JAVA_21; + } + + @Override + protected String getTestDataPath() { + return JavaTestUtil.getJavaTestDataPath() + "/inspection/migrateFromJavaLangIo/"; + } + + public void testPrintUnresolved() { + myFixture.enableInspections(new MigrateFromJavaLangIoInspection()); + myFixture.testHighlighting(true, true, true, "before" + getTestName(false) + ".java"); + myFixture.checkPreviewAndLaunchAction(myFixture.findSingleIntention("Replace with 'System.out.print()'")); + myFixture.checkResultByFile("after" + getTestName(false) + ".java"); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInspection/MigrateFromJavaLangIoInspectionTest.java b/java/java-tests/testSrc/com/intellij/java/codeInspection/MigrateFromJavaLangIoInspectionTest.java index 512267e043fb..bbf66a64d07b 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInspection/MigrateFromJavaLangIoInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInspection/MigrateFromJavaLangIoInspectionTest.java @@ -25,12 +25,9 @@ public class MigrateFromJavaLangIoInspectionTest extends LightJavaCodeInsightFix } public void testPrintlnResolved() { - MigrateToJavaLangIoInspectionTest.addIOClass(myFixture); doTest("Replace with 'System.out.println()'"); } - public void testPrintUnresolved() { doTest("Replace with 'System.out.print()'"); } - public void testPrintArrayChar() { doNotFind(getFixAllMessage()); } @@ -46,7 +43,6 @@ public class MigrateFromJavaLangIoInspectionTest extends LightJavaCodeInsightFix } private void doNotFind(String message) { - MigrateToJavaLangIoInspectionTest.addIOClass(myFixture); MigrateFromJavaLangIoInspection inspection = new MigrateFromJavaLangIoInspection(); myFixture.enableInspections(inspection); myFixture.testHighlighting(true, true, true, "before" + getTestName(false) + ".java"); diff --git a/java/java-tests/testSrc/com/intellij/java/codeInspection/MigrateToJavaLangIoInspectionTest.java b/java/java-tests/testSrc/com/intellij/java/codeInspection/MigrateToJavaLangIoInspectionTest.java index 2423b4fd75b6..be2e788c0ea9 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInspection/MigrateToJavaLangIoInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInspection/MigrateToJavaLangIoInspectionTest.java @@ -7,7 +7,6 @@ import com.intellij.codeInspection.InspectionsBundle; import com.intellij.codeInspection.MigrateToJavaLangIoInspection; import com.intellij.java.JavaBundle; import com.intellij.testFramework.LightProjectDescriptor; -import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture; import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase; import org.jetbrains.annotations.NotNull; @@ -41,7 +40,6 @@ public class MigrateToJavaLangIoInspectionTest extends LightJavaCodeInsightFixtu } private void doNotFind(String message) { - addIOClass(myFixture); MigrateToJavaLangIoInspection inspection = new MigrateToJavaLangIoInspection(); myFixture.enableInspections(inspection); myFixture.testHighlighting(true, true, true, "before" + getTestName(false) + ".java"); @@ -50,21 +48,9 @@ public class MigrateToJavaLangIoInspectionTest extends LightJavaCodeInsightFixtu } private void doTest(String message) { - addIOClass(myFixture); myFixture.enableInspections(new MigrateToJavaLangIoInspection()); myFixture.testHighlighting(true, true, true, "before" + getTestName(false) + ".java"); myFixture.checkPreviewAndLaunchAction(myFixture.findSingleIntention(message)); myFixture.checkResultByFile("after" + getTestName(false) + ".java"); } - - public static void addIOClass(@NotNull JavaCodeInsightTestFixture fixture) { - fixture.addClass(""" - package java.lang; - public final class IO { - public static void println(Object obj) {} - public static void println() {} - public static void print(Object obj) {} - } - """); - } } \ No newline at end of file diff --git a/java/java-tests/testSrc/com/siyeh/ig/bugs/ImplicitArrayToStringInspection25Test.java b/java/java-tests/testSrc/com/siyeh/ig/bugs/ImplicitArrayToStringInspection25Test.java new file mode 100644 index 000000000000..2fe7d5ecbe64 --- /dev/null +++ b/java/java-tests/testSrc/com/siyeh/ig/bugs/ImplicitArrayToStringInspection25Test.java @@ -0,0 +1,27 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.siyeh.ig.bugs; + +import com.intellij.codeInspection.InspectionProfileEntry; +import com.intellij.testFramework.LightProjectDescriptor; +import com.siyeh.ig.LightJavaInspectionTestCase; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class ImplicitArrayToStringInspection25Test extends LightJavaInspectionTestCase { + + public void testImplicitArrayToStringIO() { + doTest(); + } + + @NotNull + @Override + protected LightProjectDescriptor getProjectDescriptor() { + return JAVA_25; + } + + @Nullable + @Override + protected InspectionProfileEntry getInspection() { + return new ImplicitArrayToStringInspection(); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/siyeh/ig/bugs/ImplicitArrayToStringInspectionTest.java b/java/java-tests/testSrc/com/siyeh/ig/bugs/ImplicitArrayToStringInspectionTest.java index f79699920658..1637d3d17d25 100644 --- a/java/java-tests/testSrc/com/siyeh/ig/bugs/ImplicitArrayToStringInspectionTest.java +++ b/java/java-tests/testSrc/com/siyeh/ig/bugs/ImplicitArrayToStringInspectionTest.java @@ -2,9 +2,6 @@ package com.siyeh.ig.bugs; import com.intellij.codeInspection.InspectionProfileEntry; -import com.intellij.java.codeInspection.MigrateToJavaLangIoInspectionTest; -import com.intellij.pom.java.LanguageLevel; -import com.intellij.testFramework.IdeaTestUtil; import com.intellij.testFramework.LightProjectDescriptor; import com.siyeh.ig.LightJavaInspectionTestCase; import org.jetbrains.annotations.NotNull; @@ -16,13 +13,6 @@ public class ImplicitArrayToStringInspectionTest extends LightJavaInspectionTest doTest(); } - public void testImplicitArrayToStringIO() { - IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_25, () -> { - MigrateToJavaLangIoInspectionTest.addIOClass(myFixture); - doTest(); - }); - } - @NotNull @Override protected LightProjectDescriptor getProjectDescriptor() { diff --git a/java/testFramework/shared/src/com/intellij/testFramework/IdeaTestUtil.java b/java/testFramework/shared/src/com/intellij/testFramework/IdeaTestUtil.java index b8ccd5f4da5e..a2b6fb4b1847 100644 --- a/java/testFramework/shared/src/com/intellij/testFramework/IdeaTestUtil.java +++ b/java/testFramework/shared/src/com/intellij/testFramework/IdeaTestUtil.java @@ -108,7 +108,8 @@ public final class IdeaTestUtil { } public static @NotNull Sdk getMockJdk(@NotNull JavaVersion version) { - int mockJdk = version.feature >= 21 ? 21 : + int mockJdk = version.feature >= 25 ? 25 : + version.feature >= 21 ? 21 : version.feature >= 11 ? 11 : version.feature >= 9 ? 9 : version.feature >= 7 ? version.feature : @@ -128,7 +129,7 @@ public final class IdeaTestUtil { private static Sdk createMockJdkFromRepository(String name, int version) { List repos = MavenDependencyUtil.getRemoteRepositoryDescriptions(); - String coordinates = "org.jetbrains.mockjdk:" + MOCK_JDK_GROUP_ID + ":" + version + ".0"; + String coordinates = "org.jetbrains.mockjdk:" + MOCK_JDK_GROUP_ID + ":" + version + ".0.0"; RepositoryLibraryProperties libraryProperties = new RepositoryLibraryProperties(coordinates, false); Collection roots = JarRepositoryManager.loadDependenciesModal(ProjectManager.getInstance().getDefaultProject(), libraryProperties, false, false, null, diff --git a/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/JavaJavaApiUsageInspectionTest.kt b/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/JavaJavaApiUsageInspectionTest.kt index d00e11bd5e12..2858da50a4da 100644 --- a/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/JavaJavaApiUsageInspectionTest.kt +++ b/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/JavaJavaApiUsageInspectionTest.kt @@ -260,7 +260,7 @@ class JavaJavaApiUsageInspectionTest : JavaApiUsageInspectionTestBase() { import java.time.Duration; class Main { - { + static { try { Thread.sleep(Duration.ofSeconds(5)); } catch (InterruptedException e) { } @@ -325,14 +325,12 @@ class JavaJavaApiUsageInspectionTest : JavaApiUsageInspectionTestBase() { fun `test language level 24 with JDK 25`() { myFixture.setLanguageLevel(LanguageLevel.JDK_24) - addPreviewFeature() - addStableValue() myFixture.testHighlighting(JvmLanguage.JAVA, """ - import java.util.concurrent.StructuredTaskScope; + import java.util.concurrent.StructuredTaskScope; class Main { static void main() { - StructuredTaskScope a; // JEP 505 + StructuredTaskScope a; // JEP 505 StableValue b = StableValue.of("foo"); } } @@ -344,8 +342,6 @@ class JavaJavaApiUsageInspectionTest : JavaApiUsageInspectionTestBase() { fun `test language level 24 preview with JDK 25`() { myFixture.setLanguageLevel(LanguageLevel.JDK_24_PREVIEW) - addPreviewFeature() - addStableValue() myFixture.testHighlighting(JvmLanguage.JAVA, """ import java.util.concurrent.StructuredTaskScope; @@ -360,53 +356,4 @@ class JavaJavaApiUsageInspectionTest : JavaApiUsageInspectionTestBase() { myFixture.runQuickFix("Set language level to 25 (Preview) - Primitive Types in Patterns, etc.") assertEquals(LanguageLevel.JDK_25_PREVIEW, LanguageLevelUtil.getEffectiveLanguageLevel(myFixture.module)) } - - private fun addStableValue() { - myFixture.addClass(""" - package java.lang; - - import jdk.internal.javac.PreviewFeature; - - /** - * @since 25 - */ - @PreviewFeature(feature = PreviewFeature.Feature.STABLE_VALUES) - public class StableValue { - private StableValue(T value) {} - public static StableValue of(X value) { - return new StableValue<>(value); - } - } - """.trimIndent()) - } - - private fun addPreviewFeature() { - // This code is copied from JDK sources - myFixture.addClass(""" - package jdk.internal.javac; - - import java.lang.annotation.*; - - @Target({ElementType.METHOD, - ElementType.CONSTRUCTOR, - ElementType.FIELD, - ElementType.PACKAGE, - ElementType.TYPE}) - // CLASS retention will hopefully be sufficient for the purposes at hand - @Retention(RetentionPolicy.RUNTIME) - // *Not* @Documented - public @interface PreviewFeature { - /** - * Name of the preview feature the annotated API is associated - * with. - */ - public Feature feature(); - - public enum Feature { - PEM_API, - STABLE_VALUES - } - } - """.trimIndent()) - } } \ No newline at end of file