Merge pull request #1745 from JetBrains/rr/suppressor

Introduce KotlinInspectionSuppressor
This commit is contained in:
Alexander Podkhalyuzin
2018-07-03 14:37:39 +03:00
committed by GitHub
12 changed files with 138 additions and 0 deletions
@@ -0,0 +1,47 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. 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.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
import org.jetbrains.kotlin.caches.resolve.KotlinCacheService
import org.jetbrains.kotlin.diagnostics.Severity
import org.jetbrains.kotlin.idea.highlighter.createSuppressWarningActions
class KotlinInspectionSuppressor : InspectionSuppressor {
override fun getSuppressActions(element: PsiElement?, toolId: String): Array<SuppressQuickFix> {
element ?: return emptyArray()
return createSuppressWarningActions(element, Severity.WARNING, toolId).map {
object : SuppressQuickFix {
override fun getFamilyName() = it.familyName
override fun getName() = it.text
override fun applyFix(project: Project, descriptor: ProblemDescriptor) = it.invoke(project, null, descriptor.psiElement)
override fun isAvailable(project: Project, context: PsiElement) = it.isAvailable(project, null, context)
override fun isSuppressAll() = it.isSuppressAll
}
}.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
}
}
+2
View File
@@ -1642,6 +1642,8 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
<category>Kotlin</category>
</intentionAction>
<lang.inspectionSuppressor language="kotlin" implementationClass="org.jetbrains.kotlin.idea.inspections.KotlinInspectionSuppressor"/>
<localInspection implementationClass="org.jetbrains.kotlin.idea.intentions.ObjectLiteralToLambdaInspection"
displayName="Object literal can be converted to lambda"
groupPath="Kotlin"
+2
View File
@@ -1639,6 +1639,8 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
<category>Kotlin</category>
</intentionAction>
<lang.inspectionSuppressor language="kotlin" implementationClass="org.jetbrains.kotlin.idea.inspections.KotlinInspectionSuppressor"/>
<localInspection implementationClass="org.jetbrains.kotlin.idea.intentions.ObjectLiteralToLambdaInspection"
displayName="Object literal can be converted to lambda"
groupPath="Kotlin"
+2
View File
@@ -1642,6 +1642,8 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
<category>Kotlin</category>
</intentionAction>
<lang.inspectionSuppressor language="kotlin" implementationClass="org.jetbrains.kotlin.idea.inspections.KotlinInspectionSuppressor"/>
<localInspection implementationClass="org.jetbrains.kotlin.idea.intentions.ObjectLiteralToLambdaInspection"
displayName="Object literal can be converted to lambda"
groupPath="Kotlin"
+2
View File
@@ -1643,6 +1643,8 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
<category>Kotlin</category>
</intentionAction>
<lang.inspectionSuppressor language="kotlin" implementationClass="org.jetbrains.kotlin.idea.inspections.KotlinInspectionSuppressor"/>
<localInspection implementationClass="org.jetbrains.kotlin.idea.intentions.ObjectLiteralToLambdaInspection"
displayName="Object literal can be converted to lambda"
groupPath="Kotlin"
+2
View File
@@ -1642,6 +1642,8 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
<category>Kotlin</category>
</intentionAction>
<lang.inspectionSuppressor language="kotlin" implementationClass="org.jetbrains.kotlin.idea.inspections.KotlinInspectionSuppressor"/>
<localInspection implementationClass="org.jetbrains.kotlin.idea.intentions.ObjectLiteralToLambdaInspection"
displayName="Object literal can be converted to lambda"
groupPath="Kotlin"
+2
View File
@@ -1642,6 +1642,8 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
<category>Kotlin</category>
</intentionAction>
<lang.inspectionSuppressor language="kotlin" implementationClass="org.jetbrains.kotlin.idea.inspections.KotlinInspectionSuppressor"/>
<localInspection implementationClass="org.jetbrains.kotlin.idea.intentions.ObjectLiteralToLambdaInspection"
displayName="Object literal can be converted to lambda"
groupPath="Kotlin"
@@ -0,0 +1,8 @@
// "Typo: Change to..." "false"
// TOOL: com.intellij.spellchecker.inspections.SpellCheckingInspection
// ACTION: Add 'const' modifier
// ACTION: Convert property initializer to getter
// ACTION: To raw string literal
@Suppress("SpellCheckingInspection")
val str = "<caret>kjsghkjshtiurhuig"
@@ -0,0 +1,17 @@
// "Suppress 'SpellCheckingInspection' for val str" "true"
// TOOL: com.intellij.spellchecker.inspections.SpellCheckingInspection
// ACTION: Add 'const' modifier
// ACTION: Typo: Change to...
// ACTION: Edit inspection profile setting
// ACTION: Fix all 'Typo' problems in file
// ACTION: Run inspection on ...
// ACTION: Disable inspection
// ACTION: Save 'kjsghkjshtiurhuig' to project-level dictionary
// ACTION: Show property type hints
// ACTION: Edit intention settings
// ACTION: Convert property initializer to getter
// ACTION: Inject language or reference
// ACTION: To raw string literal
// ACTION: Suppress 'SpellCheckingInspection' for file suppressAvailable.kt
val str = "<caret>kjsghkjshtiurhuig"
@@ -0,0 +1,18 @@
// "Suppress 'SpellCheckingInspection' for val str" "true"
// TOOL: com.intellij.spellchecker.inspections.SpellCheckingInspection
// ACTION: Add 'const' modifier
// ACTION: Typo: Change to...
// ACTION: Edit inspection profile setting
// ACTION: Fix all 'Typo' problems in file
// ACTION: Run inspection on ...
// ACTION: Disable inspection
// ACTION: Save 'kjsghkjshtiurhuig' to project-level dictionary
// ACTION: Show property type hints
// ACTION: Edit intention settings
// ACTION: Convert property initializer to getter
// ACTION: Inject language or reference
// ACTION: To raw string literal
// ACTION: Suppress 'SpellCheckingInspection' for file suppressAvailable.kt
@Suppress("SpellCheckingInspection")
val str = "kjsghkjshtiurhuig"
@@ -3696,6 +3696,19 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
}
}
@TestMetadata("idea/testData/quickfix/suppress/external")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class External extends AbstractQuickFixMultiFileTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTestWithExtraFile, TargetBackend.ANY, testDataFilePath);
}
public void testAllFilesPresentInExternal() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/suppress/external"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true);
}
}
@TestMetadata("idea/testData/quickfix/suppress/forStatement")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -10296,6 +10296,29 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
}
}
@TestMetadata("idea/testData/quickfix/suppress/external")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class External extends AbstractQuickFixTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
}
public void testAllFilesPresentInExternal() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/suppress/external"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("suppressActive.kt")
public void testSuppressActive() throws Exception {
runTest("idea/testData/quickfix/suppress/external/suppressActive.kt");
}
@TestMetadata("suppressAvailable.kt")
public void testSuppressAvailable() throws Exception {
runTest("idea/testData/quickfix/suppress/external/suppressAvailable.kt");
}
}
@TestMetadata("idea/testData/quickfix/suppress/forStatement")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)