Make context available to suppressors
We've found that the BindingContext is necessary for any meaningful suppressor. This change adds the ability for suppressors to use the BindingContext when available. Change-Id: I14d8148ef659eca273445bf0638bcdb8c3b21f02
This commit is contained in:
committed by
Mikhail Zarechenskiy
parent
5151659006
commit
88db93853f
+9
-1
@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.util.ExtensionProvider
|
|||||||
|
|
||||||
interface DiagnosticSuppressor {
|
interface DiagnosticSuppressor {
|
||||||
fun isSuppressed(diagnostic: Diagnostic): Boolean
|
fun isSuppressed(diagnostic: Diagnostic): Boolean
|
||||||
|
fun isSuppressed(diagnostic: Diagnostic, bindingContext: BindingContext?): Boolean = isSuppressed(diagnostic)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val EP_NAME: ExtensionPointName<DiagnosticSuppressor> =
|
val EP_NAME: ExtensionPointName<DiagnosticSuppressor> =
|
||||||
@@ -68,7 +69,7 @@ abstract class KotlinSuppressCache {
|
|||||||
|
|
||||||
if (request is DiagnosticSuppressRequest) {
|
if (request is DiagnosticSuppressRequest) {
|
||||||
for (suppressor in diagnosticSuppressors.get()) {
|
for (suppressor in diagnosticSuppressors.get()) {
|
||||||
if (suppressor.isSuppressed(request.diagnostic)) return true
|
if (isSuppressedByExtension(suppressor, request.diagnostic)) return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,6 +78,9 @@ abstract class KotlinSuppressCache {
|
|||||||
return isSuppressedByAnnotated(request.suppressKey, request.severity, annotated, 0)
|
return isSuppressedByAnnotated(request.suppressKey, request.severity, annotated, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open fun isSuppressedByExtension(suppressor: DiagnosticSuppressor, diagnostic: Diagnostic): Boolean {
|
||||||
|
return suppressor.isSuppressed(diagnostic)
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The cache is optimized for the case where no warnings are suppressed (most frequent one)
|
The cache is optimized for the case where no warnings are suppressed (most frequent one)
|
||||||
@@ -246,4 +250,8 @@ class BindingContextSuppressCache(val context: BindingContext) : KotlinSuppressC
|
|||||||
annotated.annotationEntries.mapNotNull { context.get(BindingContext.ANNOTATION, it) }
|
annotated.annotationEntries.mapNotNull { context.get(BindingContext.ANNOTATION, it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun isSuppressedByExtension(suppressor: DiagnosticSuppressor, diagnostic: Diagnostic): Boolean {
|
||||||
|
return suppressor.isSuppressed(diagnostic, context)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user