AbstractKotlinInspection: fix suppressor
#KT-37576 Fixed
This commit is contained in:
+4
-54
@@ -1,57 +1,21 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.inspections
|
||||
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel
|
||||
import com.intellij.codeInspection.*
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiNamedElement
|
||||
import com.intellij.psi.util.parents
|
||||
import org.jetbrains.kotlin.asJava.unwrapped
|
||||
import org.jetbrains.kotlin.caches.resolve.KotlinCacheService
|
||||
import org.jetbrains.kotlin.diagnostics.Severity
|
||||
import org.jetbrains.kotlin.idea.highlighter.createSuppressWarningActions
|
||||
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtPropertyAccessor
|
||||
import org.jetbrains.kotlin.psi.KtValVarKeywordOwner
|
||||
|
||||
abstract class AbstractKotlinInspection : LocalInspectionTool(), CustomSuppressableInspectionTool {
|
||||
override fun getSuppressActions(element: PsiElement?): Array<SuppressIntentionAction>? {
|
||||
if (element == null) return emptyArray()
|
||||
|
||||
return createSuppressWarningActions(element, toSeverity(defaultLevel), suppressionKey).toTypedArray()
|
||||
}
|
||||
|
||||
override fun isSuppressedFor(element: PsiElement): Boolean {
|
||||
if (SuppressManager.getInstance()!!.isSuppressedFor(element, id)) {
|
||||
return true
|
||||
}
|
||||
|
||||
val project = element.project
|
||||
if (KotlinCacheService.getInstance(project).getSuppressionCache().isSuppressed(element, suppressionKey, toSeverity(defaultLevel))) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
protected open val suppressionKey: String get() = this.shortName.removePrefix("Kotlin")
|
||||
|
||||
abstract class AbstractKotlinInspection : LocalInspectionTool() {
|
||||
protected fun ProblemsHolder.registerProblemWithoutOfflineInformation(
|
||||
element: PsiElement,
|
||||
description: String,
|
||||
@@ -75,6 +39,7 @@ abstract class AbstractKotlinInspection : LocalInspectionTool(), CustomSuppressa
|
||||
registerProblem(problemDescriptor)
|
||||
}
|
||||
|
||||
// BUNCH: 191
|
||||
// a workaround for IDEA-211491
|
||||
override fun getProblemElement(psiElement: PsiElement): PsiNamedElement? {
|
||||
val parent = psiElement.parents().firstOrNull { parent ->
|
||||
@@ -91,21 +56,6 @@ abstract class AbstractKotlinInspection : LocalInspectionTool(), CustomSuppressa
|
||||
}
|
||||
}
|
||||
|
||||
fun toSeverity(highlightDisplayLevel: HighlightDisplayLevel): Severity {
|
||||
return when (highlightDisplayLevel) {
|
||||
HighlightDisplayLevel.DO_NOT_SHOW -> Severity.INFO
|
||||
|
||||
HighlightDisplayLevel.WARNING,
|
||||
HighlightDisplayLevel.WEAK_WARNING -> Severity.WARNING
|
||||
|
||||
HighlightDisplayLevel.ERROR,
|
||||
HighlightDisplayLevel.GENERIC_SERVER_ERROR_OR_WARNING,
|
||||
HighlightDisplayLevel.NON_SWITCHABLE_ERROR -> Severity.ERROR
|
||||
|
||||
else -> Severity.ERROR
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
fun Array<ProblemDescriptor>.registerWithElementsUnwrapped(
|
||||
holder: ProblemsHolder,
|
||||
|
||||
+4
-13
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.idea.inspections
|
||||
|
||||
import com.intellij.codeInspection.InspectionSuppressor
|
||||
import com.intellij.codeInspection.ProblemDescriptor
|
||||
import com.intellij.codeInspection.SuppressManager
|
||||
import com.intellij.codeInspection.SuppressQuickFix
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiElement
|
||||
@@ -33,15 +32,7 @@ class KotlinInspectionSuppressor : InspectionSuppressor {
|
||||
}.toTypedArray()
|
||||
}
|
||||
|
||||
override fun isSuppressedFor(element: PsiElement, toolId: String): Boolean {
|
||||
if (SuppressManager.getInstance()!!.isSuppressedFor(element, toolId)) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (KotlinCacheService.getInstance(element.project).getSuppressionCache().isSuppressed(element, toolId, Severity.WARNING)) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
override fun isSuppressedFor(element: PsiElement, toolId: String): Boolean = KotlinCacheService.getInstance(element.project)
|
||||
.getSuppressionCache()
|
||||
.isSuppressed(element, toolId, Severity.WARNING)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user