Do not mark kotlin.test.Test annotated declarations as unused
So #KT-20523 Fixed
This commit is contained in:
@@ -76,7 +76,14 @@ class UnusedSymbolInspection : AbstractKotlinInspection() {
|
||||
companion object {
|
||||
private val javaInspection = UnusedDeclarationInspection()
|
||||
|
||||
private val KOTLIN_ADDITIONAL_ANNOTATIONS = listOf("kotlin.test.*")
|
||||
|
||||
private fun KtDeclaration.hasKotlinAdditionalAnnotation() =
|
||||
this is KtNamedDeclaration && checkAnnotatedUsingPatterns(this, KOTLIN_ADDITIONAL_ANNOTATIONS)
|
||||
|
||||
fun isEntryPoint(declaration: KtNamedDeclaration): Boolean {
|
||||
if (declaration.hasKotlinAdditionalAnnotation()) return true
|
||||
if (declaration is KtClass && declaration.declarations.any { it.hasKotlinAdditionalAnnotation() }) return true
|
||||
val lightElement: PsiElement? = when (declaration) {
|
||||
is KtClassOrObject -> declaration.toLightClass()
|
||||
is KtNamedFunction, is KtSecondaryConstructor -> LightClassUtil.getLightClassMethod(declaration as KtFunction)
|
||||
@@ -111,6 +118,7 @@ class UnusedSymbolInspection : AbstractKotlinInspection() {
|
||||
declaration: KtNamedDeclaration,
|
||||
annotationPatterns: Collection<String>
|
||||
): Boolean {
|
||||
if (declaration.annotationEntries.isEmpty()) return false
|
||||
val context = declaration.analyze()
|
||||
val annotationsPresent = declaration.annotationEntries.mapNotNull {
|
||||
context[BindingContext.ANNOTATION, it]?.fqName?.asString()
|
||||
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
package kotlin.test
|
||||
|
||||
annotation class Test
|
||||
|
||||
fun assertEquals(expected: Any, actual: Any) {}
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class SomeTest {
|
||||
|
||||
@Test
|
||||
fun testSomething() {
|
||||
assertEquals(4, 2 + 2)
|
||||
}
|
||||
}
|
||||
idea/testData/multiFileLocalInspections/unusedSymbol/fromKotlinTest/before/kotlin/test/KotlinTest.kt
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
package kotlin.test
|
||||
|
||||
annotation class Test
|
||||
|
||||
fun assertEquals(expected: Any, actual: Any) {}
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class SomeTest {
|
||||
|
||||
@Test
|
||||
fun <caret>testSomething() {
|
||||
assertEquals(4, 2 + 2)
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"inspectionClass": "org.jetbrains.kotlin.idea.inspections.UnusedSymbolInspection",
|
||||
"problem": "none",
|
||||
"mainFile": "test.kt"
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package kotlin.test
|
||||
|
||||
annotation class Test
|
||||
|
||||
fun assertEquals(expected: Any, actual: Any) {}
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class SomeTest {
|
||||
|
||||
@Test
|
||||
fun testSomething() {
|
||||
assertEquals(4, 2 + 2)
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package kotlin.test
|
||||
|
||||
annotation class Test
|
||||
|
||||
fun assertEquals(expected: Any, actual: Any) {}
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class <caret>SomeTest {
|
||||
|
||||
@Test
|
||||
fun testSomething() {
|
||||
assertEquals(4, 2 + 2)
|
||||
}
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"inspectionClass": "org.jetbrains.kotlin.idea.inspections.UnusedSymbolInspection",
|
||||
"problem": "none",
|
||||
"mainFile": "test.kt"
|
||||
}
|
||||
Generated
+10
@@ -78,4 +78,14 @@ public class MultiFileLocalInspectionTestGenerated extends AbstractMultiFileLoca
|
||||
public void testReconcilePackageWithDirectory_packageMatchesDirectory_PackageMatchesDirectory() throws Exception {
|
||||
runTest("idea/testData/multiFileLocalInspections/reconcilePackageWithDirectory/packageMatchesDirectory/packageMatchesDirectory.test");
|
||||
}
|
||||
|
||||
@TestMetadata("unusedSymbol/fromKotlinTest/fromKotlinTest.test")
|
||||
public void testUnusedSymbol_fromKotlinTest_FromKotlinTest() throws Exception {
|
||||
runTest("idea/testData/multiFileLocalInspections/unusedSymbol/fromKotlinTest/fromKotlinTest.test");
|
||||
}
|
||||
|
||||
@TestMetadata("unusedSymbol/fromKotlinTestClass/fromKotlinTestClass.test")
|
||||
public void testUnusedSymbol_fromKotlinTestClass_FromKotlinTestClass() throws Exception {
|
||||
runTest("idea/testData/multiFileLocalInspections/unusedSymbol/fromKotlinTestClass/fromKotlinTestClass.test");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user