Skip to content

Commit e46f0bd

Browse files
broadwaylambcypressious
authored andcommitted
Suppress "unused declaration" inspection for certain declarations
1 parent 21e2b36 commit e46f0bd

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
displayType="STICKY_BALLOON"
3636
key="compiler.devkit.run_apply"/>
3737

38+
<lang.inspectionSuppressor language="kotlin" implementationClass="org.jetbrains.kotlin.test.helper.inspections.UnusedDeclarationSuppressor"/>
3839
</extensions>
3940

4041
<extensions defaultExtensionNs="org.jetbrains.kotlin">
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.jetbrains.kotlin.test.helper.inspections
2+
3+
import com.intellij.codeInspection.InspectionSuppressor
4+
import com.intellij.codeInspection.SuppressQuickFix
5+
import com.intellij.psi.PsiElement
6+
import org.jetbrains.kotlin.idea.base.psi.KotlinPsiHeuristics
7+
import org.jetbrains.kotlin.name.FqName
8+
import org.jetbrains.kotlin.psi.KtAnnotated
9+
10+
/**
11+
* Suppresses the "unused declaration" inspection for declarations annotated with one of the [entryPoints] annotations.
12+
*/
13+
class UnusedDeclarationSuppressor : InspectionSuppressor {
14+
override fun isSuppressedFor(element: PsiElement, toolId: String): Boolean =
15+
toolId.lowercase() == "unused" &&
16+
element is KtAnnotated &&
17+
entryPoints.any { KotlinPsiHeuristics.hasAnnotation(element, it) }
18+
19+
override fun getSuppressActions(element: PsiElement?, toolId: String): Array<out SuppressQuickFix?> =
20+
SuppressQuickFix.EMPTY_ARRAY
21+
}
22+
23+
private val entryPoints: List<FqName> = listOf(
24+
// Compiler
25+
"org.jetbrains.kotlin.utils.IDEAPluginsCompatibilityAPI",
26+
27+
// Standard library
28+
"kotlin.internal.UsedFromCompilerGeneratedCode",
29+
"kotlin.js.JsIntrinsic",
30+
"kotlin.wasm.internal.ExcludedFromCodegen",
31+
).map(::FqName)

0 commit comments

Comments
 (0)