diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/AbstractKotlinInspection.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/AbstractKotlinInspection.kt index 424504d1acc..0e6010c1e27 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/AbstractKotlinInspection.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/AbstractKotlinInspection.kt @@ -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? { - 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.registerWithElementsUnwrapped( holder: ProblemsHolder, diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/KotlinInspectionSuppressor.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/KotlinInspectionSuppressor.kt index d5625fb07aa..e652953e6b5 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/KotlinInspectionSuppressor.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/KotlinInspectionSuppressor.kt @@ -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) } diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/inspections/api/IncompatibleAPIInspection.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/inspections/api/IncompatibleAPIInspection.kt index b038a78acd6..444b7fc21d8 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/inspections/api/IncompatibleAPIInspection.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/inspections/api/IncompatibleAPIInspection.kt @@ -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? { - 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 { diff --git a/idea/resources/META-INF/i18n.xml b/idea/resources/META-INF/i18n.xml index ed67c0798c3..a9216291b8f 100644 --- a/idea/resources/META-INF/i18n.xml +++ b/idea/resources/META-INF/i18n.xml @@ -7,6 +7,7 @@ groupName="Kotlin" enabledByDefault="true" level="ERROR" + suppressId="InvalidBundleOrProperty" /> \ No newline at end of file diff --git a/idea/resources/META-INF/plugin-common.xml b/idea/resources/META-INF/plugin-common.xml index bf5ab6a07c7..e1bf2b4c4b4 100644 --- a/idea/resources/META-INF/plugin-common.xml +++ b/idea/resources/META-INF/plugin-common.xml @@ -1908,6 +1908,7 @@ level="WARNING" runForWholeFile="true" language="kotlin" + suppressId="unused" />