mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-04 17:20:55 +07:00
[java] IDEA-297182 Consider overrides when finding last incompatible language level
GitOrigin-RevId: 84893f943abbeaf7585253873291b46859754898
This commit is contained in:
committed by
intellij-monorepo-bot
parent
97e1e23514
commit
0a12e23ace
@@ -2,13 +2,7 @@ package com.intellij.codeInspection.tests.java
|
||||
|
||||
import com.intellij.codeInspection.tests.JavaApiUsageInspectionTestBase
|
||||
import com.intellij.codeInspection.tests.ULanguage
|
||||
import com.intellij.jvm.analysis.JavaJvmAnalysisTestUtil
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.roots.ContentEntry
|
||||
import com.intellij.openapi.roots.ModifiableRootModel
|
||||
import com.intellij.pom.java.LanguageLevel
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import com.intellij.testFramework.PsiTestUtil
|
||||
|
||||
/**
|
||||
* This is a base test case for test cases that highlight all the use of API
|
||||
@@ -23,16 +17,6 @@ import com.intellij.testFramework.PsiTestUtil
|
||||
* </ol>
|
||||
*/
|
||||
class JavaJavaApiUsageInspectionTest : JavaApiUsageInspectionTestBase() {
|
||||
override fun getBasePath(): String = JavaJvmAnalysisTestUtil.TEST_DATA_PROJECT_RELATIVE_BASE_PATH
|
||||
|
||||
override fun getProjectDescriptor(): LightProjectDescriptor = object : ProjectDescriptor(sdkLevel) {
|
||||
override fun configureModule(module: Module, model: ModifiableRootModel, contentEntry: ContentEntry) {
|
||||
super.configureModule(module, model, contentEntry)
|
||||
val dataDir = "$testDataPath/codeInspection/apiUsage"
|
||||
PsiTestUtil.newLibrary("JDKMock").classesRoot("$dataDir/classes").addTo(model)
|
||||
}
|
||||
}
|
||||
|
||||
fun `test constructor`() {
|
||||
myFixture.setLanguageLevel(LanguageLevel.JDK_1_4)
|
||||
myFixture.testHighlighting(ULanguage.JAVA, """
|
||||
@@ -103,6 +87,32 @@ class JavaJavaApiUsageInspectionTest : JavaApiUsageInspectionTestBase() {
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test minimum since highlighting`() {
|
||||
myFixture.setLanguageLevel(LanguageLevel.JDK_1_7)
|
||||
myFixture.testHighlighting(ULanguage.JAVA, """
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
class MinimumSince {
|
||||
void test() {
|
||||
"foo".<error descr="Usage of API documented as @since 1.8+">chars</error>();
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test minimum since no higlighting`() {
|
||||
myFixture.setLanguageLevel(LanguageLevel.JDK_1_8)
|
||||
myFixture.testHighlighting(ULanguage.JAVA, """
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
class MinimumSince {
|
||||
void test() {
|
||||
"foo".chars();
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test default methods`() {
|
||||
myFixture.setLanguageLevel(LanguageLevel.JDK_1_6)
|
||||
myFixture.testHighlighting(ULanguage.JAVA, """
|
||||
@@ -185,43 +195,4 @@ class JavaJavaApiUsageInspectionTest : JavaApiUsageInspectionTestBase() {
|
||||
abstract class AbstractCCM<T> extends <error descr="Usage of generified after 1.6 API which would cause compilation problems with JDK 6">AbstractListModel<T></error> { }
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test language level 14 with JDK 15`() {
|
||||
myFixture.setLanguageLevel(LanguageLevel.JDK_14)
|
||||
myFixture.testHighlighting(ULanguage.JAVA, """
|
||||
class Main {
|
||||
{
|
||||
g("%s".<error descr="Usage of API documented as @since 15+">formatted</error>(1),
|
||||
"".<error descr="Usage of API documented as @since 15+">stripIndent</error>(),
|
||||
"".<error descr="Usage of API documented as @since 15+">translateEscapes</error>());
|
||||
}
|
||||
|
||||
private void g(String formatted, String stripIndent, String translateEscapes) {}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test language level 15 with JDK 16`() {
|
||||
myFixture.setLanguageLevel(LanguageLevel.JDK_15)
|
||||
myFixture.testHighlighting(ULanguage.JAVA, """
|
||||
class Main {
|
||||
{
|
||||
String.class.<error descr="Usage of API documented as @since 16+">isRecord</error>();
|
||||
Class.class.<error descr="Usage of API documented as @since 16+">getRecordComponents</error>();
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test language level 16 with JDK 17`() {
|
||||
myFixture.setLanguageLevel(LanguageLevel.JDK_16)
|
||||
myFixture.testHighlighting(ULanguage.JAVA, """
|
||||
class Main {
|
||||
{
|
||||
String.class.isRecord();
|
||||
String.class.<error descr="Usage of API documented as @since 17+">isSealed</error>();
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.intellij.codeInspection.tests.java
|
||||
|
||||
import com.intellij.codeInspection.tests.JavaApiUsageInspectionTestBase
|
||||
import com.intellij.codeInspection.tests.ULanguage
|
||||
import com.intellij.jvm.analysis.JavaJvmAnalysisTestUtil
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.roots.ContentEntry
|
||||
import com.intellij.openapi.roots.ModifiableRootModel
|
||||
import com.intellij.pom.java.LanguageLevel
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import com.intellij.testFramework.PsiTestUtil
|
||||
|
||||
class JavaJavaApiUsageInspectionWithCustomMockJdkTest : JavaApiUsageInspectionTestBase() {
|
||||
override fun getBasePath(): String = JavaJvmAnalysisTestUtil.TEST_DATA_PROJECT_RELATIVE_BASE_PATH
|
||||
|
||||
override fun getProjectDescriptor(): LightProjectDescriptor = object : ProjectDescriptor(sdkLevel) {
|
||||
override fun configureModule(module: Module, model: ModifiableRootModel, contentEntry: ContentEntry) {
|
||||
super.configureModule(module, model, contentEntry)
|
||||
val dataDir = "$testDataPath/codeInspection/apiUsage"
|
||||
PsiTestUtil.newLibrary("JDKMock").classesRoot("$dataDir/classes").addTo(model)
|
||||
}
|
||||
}
|
||||
|
||||
fun `test language level 14 with JDK 15`() {
|
||||
myFixture.setLanguageLevel(LanguageLevel.JDK_14)
|
||||
myFixture.testHighlighting(ULanguage.JAVA, """
|
||||
class Main {
|
||||
{
|
||||
g("%s".<error descr="Usage of API documented as @since 15+">formatted</error>(1),
|
||||
"".<error descr="Usage of API documented as @since 15+">stripIndent</error>(),
|
||||
"".<error descr="Usage of API documented as @since 15+">translateEscapes</error>());
|
||||
}
|
||||
|
||||
private void g(String formatted, String stripIndent, String translateEscapes) {}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test language level 15 with JDK 16`() {
|
||||
myFixture.setLanguageLevel(LanguageLevel.JDK_15)
|
||||
myFixture.testHighlighting(ULanguage.JAVA, """
|
||||
class Main {
|
||||
{
|
||||
String.class.<error descr="Usage of API documented as @since 16+">isRecord</error>();
|
||||
Class.class.<error descr="Usage of API documented as @since 16+">getRecordComponents</error>();
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test language level 16 with JDK 17`() {
|
||||
myFixture.setLanguageLevel(LanguageLevel.JDK_16)
|
||||
myFixture.testHighlighting(ULanguage.JAVA, """
|
||||
class Main {
|
||||
{
|
||||
String.class.isRecord();
|
||||
String.class.<error descr="Usage of API documented as @since 17+">isSealed</error>();
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user