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)
|
||||
}
|
||||
|
||||
+4
-38
@@ -5,8 +5,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.inspections.api
|
||||
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey
|
||||
import com.intellij.codeInspection.*
|
||||
import com.intellij.codeInspection.LocalInspectionTool
|
||||
import com.intellij.codeInspection.ProblemHighlightType
|
||||
import com.intellij.codeInspection.ProblemsHolder
|
||||
import com.intellij.ide.actions.QualifiedNameProvider
|
||||
import com.intellij.lang.java.JavaLanguage
|
||||
import com.intellij.openapi.extensions.Extensions
|
||||
@@ -16,14 +17,11 @@ import com.intellij.psi.PsiElementVisitor
|
||||
import com.intellij.psi.PsiReference
|
||||
import com.intellij.util.xmlb.annotations.Attribute
|
||||
import org.jdom.Element
|
||||
import org.jetbrains.kotlin.caches.resolve.KotlinCacheService
|
||||
import org.jetbrains.kotlin.idea.KotlinJvmBundle
|
||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||
import org.jetbrains.kotlin.idea.highlighter.createSuppressWarningActions
|
||||
import org.jetbrains.kotlin.idea.inspections.api.IncompatibleAPIInspection.Companion.DEFAULT_REASON
|
||||
import org.jetbrains.kotlin.idea.inspections.toSeverity
|
||||
|
||||
class IncompatibleAPIInspection : LocalInspectionTool(), CustomSuppressableInspectionTool {
|
||||
class IncompatibleAPIInspection : LocalInspectionTool() {
|
||||
class Problem(
|
||||
@Attribute var reference: String? = "",
|
||||
@Attribute var reason: String? = ""
|
||||
@@ -62,38 +60,6 @@ class IncompatibleAPIInspection : LocalInspectionTool(), CustomSuppressableInspe
|
||||
}
|
||||
}
|
||||
|
||||
override fun getSuppressActions(element: PsiElement?): Array<SuppressIntentionAction>? {
|
||||
return when {
|
||||
element == null -> emptyArray()
|
||||
|
||||
element.language == JavaLanguage.INSTANCE -> {
|
||||
val key = HighlightDisplayKey.find(shortName)
|
||||
?: throw AssertionError("HighlightDisplayKey.find($shortName) is null. Inspection: $javaClass")
|
||||
return SuppressManager.getInstance().createSuppressActions(key)
|
||||
}
|
||||
|
||||
element.language == KotlinLanguage.INSTANCE -> {
|
||||
createSuppressWarningActions(element, toSeverity(defaultLevel), suppressionKey).toTypedArray()
|
||||
}
|
||||
|
||||
else -> emptyArray()
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
private val suppressionKey: String get() = this.shortName
|
||||
private val problemsCache = ProblemsCache()
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
groupName="Kotlin"
|
||||
enabledByDefault="true"
|
||||
level="ERROR"
|
||||
suppressId="InvalidBundleOrProperty"
|
||||
/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
@@ -1908,6 +1908,7 @@
|
||||
level="WARNING"
|
||||
runForWholeFile="true"
|
||||
language="kotlin"
|
||||
suppressId="unused"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.UnusedReceiverParameterInspection"
|
||||
@@ -1917,6 +1918,7 @@
|
||||
enabledByDefault="true"
|
||||
level="WARNING"
|
||||
language="kotlin"
|
||||
suppressId="unused"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.KotlinUnusedImportInspection"
|
||||
@@ -1927,6 +1929,7 @@
|
||||
level="WARNING"
|
||||
runForWholeFile="true"
|
||||
language="kotlin"
|
||||
suppressId="UnusedImport"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.RedundantSamConstructorInspection"
|
||||
@@ -2652,6 +2655,7 @@
|
||||
cleanupTool="true"
|
||||
level="WEAK WARNING"
|
||||
language="kotlin"
|
||||
suppressId="DoubleNegation"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.WhenWithOnlyElseInspection"
|
||||
@@ -2760,6 +2764,7 @@
|
||||
cleanupTool="true"
|
||||
level="WEAK WARNING"
|
||||
language="kotlin"
|
||||
suppressId="RedundantOverride"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.SuspiciousEqualsCombination"
|
||||
@@ -3454,6 +3459,7 @@
|
||||
enabledByDefault="true"
|
||||
level="WARNING"
|
||||
language="kotlin"
|
||||
suppressId="ThrowableNotThrown"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.JavaMapForEachInspection"
|
||||
@@ -3481,6 +3487,7 @@
|
||||
enabledByDefault="true"
|
||||
level="WARNING"
|
||||
language="kotlin"
|
||||
suppressId="CovariantEquals"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.ReplaceNotNullAssertionWithElvisReturnInspection"
|
||||
@@ -3544,6 +3551,7 @@
|
||||
enabledByDefault="true"
|
||||
level="WARNING"
|
||||
language="kotlin"
|
||||
suppressId="EqualsBetweenInconvertibleTypes"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.LateinitVarOverridesLateinitVarInspection"
|
||||
|
||||
@@ -1914,6 +1914,7 @@
|
||||
level="WARNING"
|
||||
runForWholeFile="true"
|
||||
language="kotlin"
|
||||
suppressId="unused"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.UnusedReceiverParameterInspection"
|
||||
@@ -1923,6 +1924,7 @@
|
||||
enabledByDefault="true"
|
||||
level="WARNING"
|
||||
language="kotlin"
|
||||
suppressId="unused"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.KotlinUnusedImportInspection"
|
||||
@@ -1933,6 +1935,7 @@
|
||||
level="WARNING"
|
||||
runForWholeFile="true"
|
||||
language="kotlin"
|
||||
suppressId="UnusedImport"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.RedundantSamConstructorInspection"
|
||||
@@ -2658,6 +2661,7 @@
|
||||
cleanupTool="true"
|
||||
level="WEAK WARNING"
|
||||
language="kotlin"
|
||||
suppressId="DoubleNegation"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.WhenWithOnlyElseInspection"
|
||||
@@ -2766,6 +2770,7 @@
|
||||
cleanupTool="true"
|
||||
level="WEAK WARNING"
|
||||
language="kotlin"
|
||||
suppressId="RedundantOverride"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.SuspiciousEqualsCombination"
|
||||
@@ -3460,6 +3465,7 @@
|
||||
enabledByDefault="true"
|
||||
level="WARNING"
|
||||
language="kotlin"
|
||||
suppressId="ThrowableNotThrown"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.JavaMapForEachInspection"
|
||||
@@ -3487,6 +3493,7 @@
|
||||
enabledByDefault="true"
|
||||
level="WARNING"
|
||||
language="kotlin"
|
||||
suppressId="CovariantEquals"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.ReplaceNotNullAssertionWithElvisReturnInspection"
|
||||
@@ -3550,6 +3557,7 @@
|
||||
enabledByDefault="true"
|
||||
level="WARNING"
|
||||
language="kotlin"
|
||||
suppressId="EqualsBetweenInconvertibleTypes"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.LateinitVarOverridesLateinitVarInspection"
|
||||
|
||||
@@ -1914,6 +1914,7 @@
|
||||
level="WARNING"
|
||||
runForWholeFile="true"
|
||||
language="kotlin"
|
||||
suppressId="unused"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.UnusedReceiverParameterInspection"
|
||||
@@ -1923,6 +1924,7 @@
|
||||
enabledByDefault="true"
|
||||
level="WARNING"
|
||||
language="kotlin"
|
||||
suppressId="unused"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.KotlinUnusedImportInspection"
|
||||
@@ -1933,6 +1935,7 @@
|
||||
level="WARNING"
|
||||
runForWholeFile="true"
|
||||
language="kotlin"
|
||||
suppressId="UnusedImport"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.RedundantSamConstructorInspection"
|
||||
@@ -2658,6 +2661,7 @@
|
||||
cleanupTool="true"
|
||||
level="WEAK WARNING"
|
||||
language="kotlin"
|
||||
suppressId="DoubleNegation"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.WhenWithOnlyElseInspection"
|
||||
@@ -2766,6 +2770,7 @@
|
||||
cleanupTool="true"
|
||||
level="WEAK WARNING"
|
||||
language="kotlin"
|
||||
suppressId="RedundantOverride"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.SuspiciousEqualsCombination"
|
||||
@@ -3460,6 +3465,7 @@
|
||||
enabledByDefault="true"
|
||||
level="WARNING"
|
||||
language="kotlin"
|
||||
suppressId="ThrowableNotThrown"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.JavaMapForEachInspection"
|
||||
@@ -3487,6 +3493,7 @@
|
||||
enabledByDefault="true"
|
||||
level="WARNING"
|
||||
language="kotlin"
|
||||
suppressId="CovariantEquals"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.ReplaceNotNullAssertionWithElvisReturnInspection"
|
||||
@@ -3550,6 +3557,7 @@
|
||||
enabledByDefault="true"
|
||||
level="WARNING"
|
||||
language="kotlin"
|
||||
suppressId="EqualsBetweenInconvertibleTypes"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.LateinitVarOverridesLateinitVarInspection"
|
||||
|
||||
+3
-15
@@ -1,22 +1,12 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.codeInsight.FileModificationService
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfoType
|
||||
import com.intellij.codeInspection.*
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiElement
|
||||
@@ -52,8 +42,6 @@ import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
|
||||
class UnusedReceiverParameterInspection : AbstractKotlinInspection() {
|
||||
override val suppressionKey: String get() = "unused"
|
||||
|
||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
|
||||
return object : KtVisitorVoid() {
|
||||
private fun check(callableDeclaration: KtCallableDeclaration) {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/*
|
||||
* Copyright 2000-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2000-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.codeInsight.AnnotationUtil
|
||||
import com.intellij.codeInsight.FileModificationService
|
||||
import com.intellij.codeInsight.daemon.QuickFixBundle
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfoType
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightUtil
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil
|
||||
import com.intellij.codeInspection.*
|
||||
@@ -19,7 +19,6 @@ import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.application.ModalityState
|
||||
import com.intellij.openapi.progress.ProgressManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiElementVisitor
|
||||
@@ -254,8 +253,6 @@ class UnusedSymbolInspection : AbstractKotlinInspection() {
|
||||
})
|
||||
}
|
||||
|
||||
override val suppressionKey: String get() = "unused"
|
||||
|
||||
private fun classOrObjectHasTextUsages(classOrObject: KtClassOrObject): Boolean {
|
||||
var hasTextUsages = false
|
||||
|
||||
|
||||
Reference in New Issue
Block a user