IDEA-215436: Inspection that checks if declaration with "unstable" API type in signature is "unstable" on its own.

GitOrigin-RevId: 6ba9bf7a8ebfd8b34488cb98536c5fa3e781deb7
This commit is contained in:
Sergey Patrikeev
2019-06-20 20:58:41 +03:00
committed by intellij-monorepo-bot
parent 11c66faeaa
commit 6c8d9ccd9b
8 changed files with 370 additions and 11 deletions

View File

@@ -0,0 +1,83 @@
package test;
import java.util.List;
import org.jetbrains.annotations.ApiStatus;
@ApiStatus.Experimental
class ExperimentalClass { }
class Warnings {
public ExperimentalClass <warning descr="Field must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its type references unstable type 'test.ExperimentalClass'">field</warning>;
public ExperimentalClass[] <warning descr="Field must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its type references unstable type 'test.ExperimentalClass'">arrayField</warning>;
public List<ExperimentalClass> <warning descr="Field must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its type references unstable type 'test.ExperimentalClass'">listField</warning>;
public void <warning descr="Method must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its signature references unstable type 'test.ExperimentalClass'">methodWithExperimentalParam</warning>(ExperimentalClass param) {
}
public void <warning descr="Method must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its signature references unstable type 'test.ExperimentalClass'">methodWithExperimentalParamArray</warning>(ExperimentalClass[] param) {
}
public void <warning descr="Method must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its signature references unstable type 'test.ExperimentalClass'">methodWithExperimentalParamArray</warning>(List<ExperimentalClass> param) {
}
public ExperimentalClass <warning descr="Method must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its signature references unstable type 'test.ExperimentalClass'">methodWithExperimentalReturnType</warning>() {
return null;
}
public ExperimentalClass[] <warning descr="Method must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its signature references unstable type 'test.ExperimentalClass'">methodWithExperimentalReturnTypeArray</warning>() {
return null;
}
public List<ExperimentalClass> <warning descr="Method must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its signature references unstable type 'test.ExperimentalClass'">methodWithExperimentalReturnTypeList</warning>() {
return null;
}
public <T extends ExperimentalClass> T <warning descr="Method must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its signature references unstable type 'test.ExperimentalClass'">methodWithUnstableTypeParameter</warning>() {
return null;
}
public void <warning descr="Method must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its signature references unstable type 'test.ExperimentalClass'">methodWithUnstableTypeParameterExtendsWildcard</warning>(List<? extends ExperimentalClass> list) {
}
public void <warning descr="Method must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its signature references unstable type 'test.ExperimentalClass'">methodWithUnstableTypeParameterSuperWildcard</warning>(List<? super ExperimentalClass> list) {
}
}
class <warning descr="Class must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its declaration references unstable type 'test.ExperimentalClass'">WarningTypeParameter</warning><T extends ExperimentalClass> {
}
// No warnings should be produced because the declaring class is experimental itself.
@ApiStatus.Experimental
class NoWarningsClassLevel {
public ExperimentalClass field;
public void methodWithExperimentalParam(ExperimentalClass param) {
}
public ExperimentalClass methodWithExperimentalReturnType() {
return null;
}
}
// No warnings should be produced because methods and fields are already marked with @ApiStatus.Experimental annotation.
class NoWarnings {
@ApiStatus.Experimental
public ExperimentalClass field;
@ApiStatus.Experimental
public void methodWithExperimentalParam(ExperimentalClass param) {
}
@ApiStatus.Experimental
public ExperimentalClass methodWithExperimentalReturnType() {
return null;
}
}

View File

@@ -0,0 +1,76 @@
@file:Suppress("UNUSED_PARAMETER")
package test
import org.jetbrains.annotations.ApiStatus
@ApiStatus.Experimental
open class ExperimentalClass
class Warnings {
var <warning descr="Field must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its type references unstable type 'test.ExperimentalClass'">field</warning>: ExperimentalClass? = null
var <warning descr="Field must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its type references unstable type 'test.ExperimentalClass'">arrayField</warning>: Array<ExperimentalClass>? = null
var <warning descr="Field must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its type references unstable type 'test.ExperimentalClass'">listField</warning>: List<ExperimentalClass>? = null
fun <warning descr="Method must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its signature references unstable type 'test.ExperimentalClass'">methodWithExperimentalParam</warning>(param: ExperimentalClass) {}
fun <warning descr="Method must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its signature references unstable type 'test.ExperimentalClass'">methodWithExperimentalParamArray</warning>(param: Array<ExperimentalClass>) {}
fun <warning descr="Method must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its signature references unstable type 'test.ExperimentalClass'">methodWithExperimentalParamArray</warning>(param: List<ExperimentalClass>) {}
fun <warning descr="Method must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its signature references unstable type 'test.ExperimentalClass'">methodWithExperimentalReturnType</warning>(): ExperimentalClass? {
return null
}
fun <warning descr="Method must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its signature references unstable type 'test.ExperimentalClass'">methodWithExperimentalReturnTypeArray</warning>(): Array<ExperimentalClass>? {
return null
}
fun <warning descr="Method must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its signature references unstable type 'test.ExperimentalClass'">methodWithExperimentalReturnTypeList</warning>(): List<ExperimentalClass>? {
return null
}
fun <T : ExperimentalClass> <warning descr="Method must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its signature references unstable type 'test.ExperimentalClass'">methodWithUnstableTypeParameter</warning>(): T? {
return null
}
fun <warning descr="Method must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its signature references unstable type 'test.ExperimentalClass'">methodWithUnstableTypeParameterExtendsWildcard</warning>(list: List<ExperimentalClass>) {}
fun <warning descr="Method must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its signature references unstable type 'test.ExperimentalClass'">methodWithUnstableTypeParameterSuperWildcard</warning>(list: List<ExperimentalClass>) {}
}
class <warning descr="Class must be marked with '@org.jetbrains.annotations.ApiStatus.Experimental' annotation because its declaration references unstable type 'test.ExperimentalClass'">WarningTypeParameter</warning><T : ExperimentalClass>
// No warnings should be produced because the declaring class is experimental itself.
@ApiStatus.Experimental
class NoWarningsClassLevel {
var field: ExperimentalClass? = null
fun methodWithExperimentalParam(param: ExperimentalClass) {}
fun methodWithExperimentalReturnType(): ExperimentalClass? {
return null
}
}
// No warnings should be produced because methods and fields are already marked with @ApiStatus.Experimental annotation.
class NoWarnings {
@ApiStatus.Experimental
var field: ExperimentalClass? = null
@ApiStatus.Experimental
fun methodWithExperimentalParam(param: ExperimentalClass) {
}
@ApiStatus.Experimental
fun methodWithExperimentalReturnType(): ExperimentalClass? {
return null
}
}

View File

@@ -0,0 +1,35 @@
package com.intellij.codeInspection
import com.intellij.jvm.analysis.JvmAnalysisKtTestsUtil
import com.intellij.testFramework.TestDataPath
import com.intellij.testFramework.builders.JavaModuleFixtureBuilder
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase
import com.intellij.util.PathUtil
import org.jetbrains.annotations.ApiStatus
@TestDataPath("\$CONTENT_ROOT/testData/codeInspection/unstableTypeUsedInSignature")
class UnstableTypeUsedInSignatureTest : JavaCodeInsightFixtureTestCase() {
override fun getBasePath() = JvmAnalysisKtTestsUtil.TEST_DATA_PROJECT_RELATIVE_BASE_PATH + "/codeInspection/unstableTypeUsedInSignature"
override fun setUp() {
super.setUp()
val inspection = UnstableTypeUsedInSignatureInspection()
inspection.unstableApiAnnotations.clear()
inspection.unstableApiAnnotations.add(ApiStatus.Experimental::class.java.canonicalName)
myFixture.enableInspections(inspection)
}
override fun tuneFixture(moduleBuilder: JavaModuleFixtureBuilder<*>) {
moduleBuilder.addLibrary("util", PathUtil.getJarPathForClass(ApiStatus.Experimental::class.java))
}
fun `test kotlin missing unstable annotation`() {
myFixture.testHighlighting("unstableTypeUsedInSignature.kt")
}
fun `test java missing unstable annotation`() {
myFixture.testHighlighting("unstableTypeUsedInSignature.java")
}
}