Allow to override suppression key for inspections
This commit is contained in:
committed by
Nikolay Krasko
parent
8196621be5
commit
697132561f
+15
-12
@@ -30,7 +30,7 @@ public abstract class AbstractKotlinInspection: LocalInspectionTool(), CustomSup
|
|||||||
public override fun getSuppressActions(element: PsiElement?): Array<SuppressIntentionAction>? {
|
public override fun getSuppressActions(element: PsiElement?): Array<SuppressIntentionAction>? {
|
||||||
if (element == null) return emptyArray()
|
if (element == null) return emptyArray()
|
||||||
|
|
||||||
return createSuppressWarningActions(element, toSeverity(defaultLevel), this.shortName).toTypedArray()
|
return createSuppressWarningActions(element, toSeverity(defaultLevel), suppressionKey).toTypedArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
public override fun isSuppressedFor(element: PsiElement): Boolean {
|
public override fun isSuppressedFor(element: PsiElement): Boolean {
|
||||||
@@ -39,25 +39,28 @@ public abstract class AbstractKotlinInspection: LocalInspectionTool(), CustomSup
|
|||||||
}
|
}
|
||||||
|
|
||||||
val project = element.project
|
val project = element.project
|
||||||
if (KotlinCacheService.getInstance(project).getSuppressionCache().isSuppressed(element, this.shortName, toSeverity(defaultLevel))) {
|
if (KotlinCacheService.getInstance(project).getSuppressionCache().isSuppressed(element, suppressionKey, toSeverity(defaultLevel))) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun toSeverity(highlightDisplayLevel: HighlightDisplayLevel): Severity {
|
protected open val suppressionKey: String get() = this.shortName.removePrefix("Kotlin")
|
||||||
return when (highlightDisplayLevel) {
|
}
|
||||||
HighlightDisplayLevel.DO_NOT_SHOW -> Severity.INFO
|
|
||||||
|
|
||||||
HighlightDisplayLevel.WARNING,
|
private fun toSeverity(highlightDisplayLevel: HighlightDisplayLevel): Severity {
|
||||||
HighlightDisplayLevel.WEAK_WARNING -> Severity.WARNING
|
return when (highlightDisplayLevel) {
|
||||||
|
HighlightDisplayLevel.DO_NOT_SHOW -> Severity.INFO
|
||||||
|
|
||||||
HighlightDisplayLevel.ERROR,
|
HighlightDisplayLevel.WARNING,
|
||||||
HighlightDisplayLevel.GENERIC_SERVER_ERROR_OR_WARNING,
|
HighlightDisplayLevel.WEAK_WARNING -> Severity.WARNING
|
||||||
HighlightDisplayLevel.NON_SWITCHABLE_ERROR -> Severity.ERROR
|
|
||||||
|
|
||||||
else -> Severity.ERROR
|
HighlightDisplayLevel.ERROR,
|
||||||
}
|
HighlightDisplayLevel.GENERIC_SERVER_ERROR_OR_WARNING,
|
||||||
|
HighlightDisplayLevel.NON_SWITCHABLE_ERROR -> Severity.ERROR
|
||||||
|
|
||||||
|
else -> Severity.ERROR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||||
|
|
||||||
public class UnusedReceiverParameterInspection : AbstractKotlinInspection() {
|
public class UnusedReceiverParameterInspection : AbstractKotlinInspection() {
|
||||||
|
override val suppressionKey: String get() = "unused"
|
||||||
|
|
||||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
|
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
|
||||||
return object : KtVisitorVoid() {
|
return object : KtVisitorVoid() {
|
||||||
private fun check(callableDeclaration: KtCallableDeclaration) {
|
private fun check(callableDeclaration: KtCallableDeclaration) {
|
||||||
|
|||||||
@@ -189,6 +189,8 @@ public class UnusedSymbolInspection : AbstractKotlinInspection() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override val suppressionKey: String get() = "unused"
|
||||||
|
|
||||||
private fun classOrObjectHasTextUsages(classOrObject: KtClassOrObject): Boolean {
|
private fun classOrObjectHasTextUsages(classOrObject: KtClassOrObject): Boolean {
|
||||||
var hasTextUsages = false
|
var hasTextUsages = false
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
@file:Suppress("UnusedImport")
|
||||||
|
|
||||||
|
import java.io.* // unused
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
@Suppress("warnings")
|
||||||
|
val Any.v: Int
|
||||||
|
get() = 123
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
|
val Any.v1: Int
|
||||||
|
get() = 123
|
||||||
@@ -2,13 +2,13 @@ class Klass {
|
|||||||
fun unusedFun() {
|
fun unusedFun() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UnusedSymbol")
|
@Suppress("unused")
|
||||||
fun unusedNoWarn() {
|
fun unusedNoWarn() {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UnusedSymbol")
|
@Suppress("unused")
|
||||||
class OtherKlass {
|
class OtherKlass {
|
||||||
fun unusedNoWarn() {
|
fun unusedNoWarn() {
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ fun outer() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UnusedSymbol")
|
@Suppress("unused")
|
||||||
fun localNoWarn() {
|
fun localNoWarn() {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UnusedSymbol")
|
@Suppress("unused")
|
||||||
fun otherFun() {
|
fun otherFun() {
|
||||||
fun localNoWarn() {
|
fun localNoWarn() {
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -3,7 +3,7 @@ class Klass {
|
|||||||
fun f() {
|
fun f() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UnusedSymbol")
|
@Suppress("unused")
|
||||||
fun fNoWarn() {}
|
fun fNoWarn() {}
|
||||||
|
|
||||||
val p = 5
|
val p = 5
|
||||||
@@ -19,17 +19,17 @@ class Klass {
|
|||||||
fun f() {
|
fun f() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UnusedSymbol")
|
@Suppress("unused")
|
||||||
fun fNoWarn() {}
|
fun fNoWarn() {}
|
||||||
|
|
||||||
val p = 5
|
val p = 5
|
||||||
}
|
}
|
||||||
|
|
||||||
fun localObject3() = @Suppress("UnusedSymbol") object {
|
fun localObject3() = @Suppress("unused") object {
|
||||||
fun fNoWarn() {}
|
fun fNoWarn() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UnusedSymbol")
|
@Suppress("unused")
|
||||||
private val localObject4 = object {
|
private val localObject4 = object {
|
||||||
fun fNoWarn() {}
|
fun fNoWarn() {}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -14,13 +14,13 @@ fun main(args: Array<String>) {
|
|||||||
fun f() {
|
fun f() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UnusedSymbol")
|
@Suppress("unused")
|
||||||
fun fNoWarn() {}
|
fun fNoWarn() {}
|
||||||
|
|
||||||
val p = 5
|
val p = 5
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UnusedSymbol")
|
@Suppress("unused")
|
||||||
fun localObject3() = object {
|
fun localObject3() = object {
|
||||||
fun fNoWarn() {}
|
fun fNoWarn() {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ fun main(args: Array<String>) {
|
|||||||
fun f() {
|
fun f() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UnusedSymbol")
|
@Suppress("unused")
|
||||||
fun fNoWarn() {}
|
fun fNoWarn() {}
|
||||||
|
|
||||||
val p = 5
|
val p = 5
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UnusedSymbol")
|
@Suppress("unused")
|
||||||
class OtherClass {
|
class OtherClass {
|
||||||
fun fNoWarn() {}
|
fun fNoWarn() {}
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,7 @@ fun main(args: Array<String>) {
|
|||||||
LocalClass().p
|
LocalClass().p
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UnusedSymbol")
|
@Suppress("unused")
|
||||||
fun other() {
|
fun other() {
|
||||||
class OtherClass {
|
class OtherClass {
|
||||||
fun fNoWarn() {}
|
fun fNoWarn() {}
|
||||||
|
|||||||
@@ -7,5 +7,5 @@ fun onlyInImport() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UnusedSymbol")
|
@Suppress("unused")
|
||||||
fun onlyInImportNoWarn() {}
|
fun onlyInImportNoWarn() {}
|
||||||
|
|||||||
@@ -2,5 +2,5 @@ fun unusedFun() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UnusedSymbol")
|
@Suppress("unused")
|
||||||
fun unusedNoWarn() {}
|
fun unusedNoWarn() {}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ fun usedOnlyRecursively() {
|
|||||||
usedOnlyRecursively()
|
usedOnlyRecursively()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UnusedSymbol")
|
@Suppress("unused")
|
||||||
fun usedOnlyRecursivelyNoWarn() {
|
fun usedOnlyRecursivelyNoWarn() {
|
||||||
usedOnlyRecursivelyNoWarn()
|
usedOnlyRecursivelyNoWarn()
|
||||||
}
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package suppressed
|
||||||
|
|
||||||
|
@Suppress("InvalidBundleOrProperty")
|
||||||
|
fun testSuppressedOnFun() {
|
||||||
|
K.message("foo.bar")
|
||||||
|
J.message("foo.bar")
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// "Suppress 'KotlinUnusedImport' for file ${file}" "true"
|
// "Suppress 'UnusedImport' for file ${file}" "true"
|
||||||
|
|
||||||
import<caret> java.io.*
|
import<caret> java.io.*
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// "Suppress 'KotlinUnusedImport' for file ${file}" "true"
|
// "Suppress 'UnusedImport' for file ${file}" "true"
|
||||||
|
|
||||||
@file:Suppress("KotlinUnusedImport")
|
@file:Suppress("UnusedImport")
|
||||||
|
|
||||||
import java.io.*
|
import java.io.*
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user