Do not report "unused symbol" on experimental annotations
#KT-25609 Fixed
This commit is contained in:
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.asJava.LightClassUtil
|
||||
import org.jetbrains.kotlin.asJava.classes.KtLightClass
|
||||
import org.jetbrains.kotlin.asJava.toLightClass
|
||||
import org.jetbrains.kotlin.asJava.toLightMethods
|
||||
import org.jetbrains.kotlin.config.AnalysisFlag
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil
|
||||
import org.jetbrains.kotlin.idea.caches.project.implementingDescriptors
|
||||
@@ -47,6 +48,7 @@ import org.jetbrains.kotlin.idea.core.toDescriptor
|
||||
import org.jetbrains.kotlin.idea.findUsages.KotlinFindUsagesHandlerFactory
|
||||
import org.jetbrains.kotlin.idea.findUsages.handlers.KotlinFindClassUsagesHandler
|
||||
import org.jetbrains.kotlin.idea.imports.importableFqName
|
||||
import org.jetbrains.kotlin.idea.project.languageVersionSettings
|
||||
import org.jetbrains.kotlin.idea.quickfix.RemoveUnusedFunctionParameterFix
|
||||
import org.jetbrains.kotlin.idea.references.mainReference
|
||||
import org.jetbrains.kotlin.idea.references.resolveMainReferenceToDescriptors
|
||||
@@ -65,6 +67,7 @@ import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.util.findCallableMemberBySignature
|
||||
import java.awt.GridBagConstraints
|
||||
import java.awt.GridBagLayout
|
||||
@@ -163,6 +166,14 @@ class UnusedSymbolInspection : AbstractKotlinInspection() {
|
||||
if (declaration is KtNamedFunction && declaration.isSerializationImplicitlyUsedMethod()) return
|
||||
// properties can be referred by component1/component2, which is too expensive to search, don't mark them as unused
|
||||
if (declaration is KtParameter && declaration.dataClassComponentFunction() != null) return
|
||||
// experimental annotations
|
||||
if (descriptor is ClassDescriptor && descriptor.kind == ClassKind.ANNOTATION_CLASS) {
|
||||
val fqName = descriptor.fqNameSafe.asString()
|
||||
val languageVersionSettings = declaration.languageVersionSettings
|
||||
if (fqName in languageVersionSettings.getFlag(AnalysisFlag.experimental) ||
|
||||
fqName in languageVersionSettings.getFlag(AnalysisFlag.useExperimental)
|
||||
) return
|
||||
}
|
||||
|
||||
// Main checks: finding reference usages && text usages
|
||||
if (hasNonTrivialUsages(declaration, descriptor)) return
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Safe delete 'Marker'" "false"
|
||||
// COMPILER_ARGUMENTS: -Xuse-experimental=kotlin.Experimental -Xuse-experimental=test.Marker
|
||||
// WITH_RUNTIME
|
||||
// ACTION: Rename file to Marker.kt
|
||||
// TOOL: org.jetbrains.kotlin.idea.inspections.UnusedSymbolInspection
|
||||
|
||||
package test
|
||||
|
||||
@Experimental
|
||||
annotation class <caret>Marker
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Safe delete 'Marker'" "false"
|
||||
// COMPILER_ARGUMENTS: -Xuse-experimental=kotlin.Experimental -Xexperimental=test.Marker
|
||||
// WITH_RUNTIME
|
||||
// ACTION: Rename file to Marker.kt
|
||||
// TOOL: org.jetbrains.kotlin.idea.inspections.UnusedSymbolInspection
|
||||
|
||||
package test
|
||||
|
||||
@Experimental
|
||||
annotation class <caret>Marker
|
||||
@@ -6204,6 +6204,16 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
runTest("idea/testData/quickfix/experimental/doNotSwitchOn.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("experimentalUnused.kt")
|
||||
public void testExperimentalUnused() throws Exception {
|
||||
runTest("idea/testData/quickfix/experimental/experimentalUnused.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("experimentalUnused2.kt")
|
||||
public void testExperimentalUnused2() throws Exception {
|
||||
runTest("idea/testData/quickfix/experimental/experimentalUnused2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("functionInLocalClass.kt")
|
||||
public void testFunctionInLocalClass() throws Exception {
|
||||
runTest("idea/testData/quickfix/experimental/functionInLocalClass.kt");
|
||||
|
||||
Reference in New Issue
Block a user