Support spellchecking in Kotlin string literals; remove unused and unnecessary support for custom suppressions of spelling errors
This commit is contained in:
+14
-16
@@ -16,33 +16,31 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea
|
||||
|
||||
import com.intellij.spellchecker.tokenizer.SuppressibleSpellcheckingStrategy
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.spellchecker.tokenizer.Tokenizer
|
||||
import com.intellij.spellchecker.tokenizer.SpellcheckingStrategy
|
||||
import com.intellij.codeInspection.SuppressQuickFix
|
||||
import com.intellij.spellchecker.tokenizer.PsiIdentifierOwnerTokenizer
|
||||
import com.intellij.psi.PsiNameIdentifierOwner
|
||||
import com.intellij.psi.PsiComment
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiNameIdentifierOwner
|
||||
import com.intellij.spellchecker.inspections.PlainTextSplitter
|
||||
import com.intellij.spellchecker.tokenizer.SpellcheckingStrategy
|
||||
import com.intellij.spellchecker.tokenizer.SuppressibleSpellcheckingStrategy
|
||||
import com.intellij.spellchecker.tokenizer.Tokenizer
|
||||
import com.intellij.spellchecker.tokenizer.TokenizerBase
|
||||
import org.jetbrains.kotlin.psi.JetLiteralStringTemplateEntry
|
||||
|
||||
class KotlinSpellcheckingStrategy: SuppressibleSpellcheckingStrategy() {
|
||||
private val nameIdentifierTokenizer = PsiIdentifierOwnerTokenizer()
|
||||
|
||||
[suppress("UNCHECKED_CAST")]
|
||||
private val emptyTokenizer = SpellcheckingStrategy.EMPTY_TOKENIZER as Tokenizer<out PsiElement?>
|
||||
class KotlinSpellcheckingStrategy: SpellcheckingStrategy() {
|
||||
private val plainTextTokenizer = TokenizerBase<JetLiteralStringTemplateEntry>(PlainTextSplitter.getInstance())
|
||||
private val emptyTokenizer = SpellcheckingStrategy.EMPTY_TOKENIZER
|
||||
|
||||
override fun getTokenizer(element: PsiElement?): Tokenizer<out PsiElement?> {
|
||||
[suppress("UNCHECKED_CAST")]
|
||||
return when {
|
||||
element is PsiNameIdentifierOwner || element is PsiComment ->
|
||||
super.getTokenizer(element) as Tokenizer<out PsiElement?>
|
||||
super.getTokenizer(element)
|
||||
|
||||
element is JetLiteralStringTemplateEntry -> plainTextTokenizer
|
||||
|
||||
else ->
|
||||
emptyTokenizer
|
||||
}
|
||||
}
|
||||
|
||||
public override fun isSuppressedFor(element : PsiElement, name : String) : Boolean = false
|
||||
public override fun getSuppressActions(element : PsiElement, name : String) : Array<SuppressQuickFix> = SuppressQuickFix.EMPTY_ARRAY
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<problems>
|
||||
<problem>
|
||||
<file>spelling.kt</file>
|
||||
<line>1</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/spelling.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Typo</problem_class>
|
||||
<description>Typo: In word 'xyzzy'</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>spelling.kt</file>
|
||||
<line>2</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/spelling.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Typo</problem_class>
|
||||
<description>Typo: In word 'xyzzy'</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>spelling.kt</file>
|
||||
<line>3</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/spelling.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Typo</problem_class>
|
||||
<description>Typo: In word 'xyzzy'</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>spelling.kt</file>
|
||||
<line>4</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/spelling.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Typo</problem_class>
|
||||
<description>Typo: In word 'xyzzy'</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>spelling.kt</file>
|
||||
<line>5</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/spelling.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Typo</problem_class>
|
||||
<description>Typo: In word 'xyzzy'</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>spelling.kt</file>
|
||||
<line>7</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/spelling.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Typo</problem_class>
|
||||
<description>Typo: In word 'xyzzy'</description>
|
||||
</problem>
|
||||
</problems>
|
||||
@@ -0,0 +1 @@
|
||||
// INSPECTION_CLASS: com.intellij.spellchecker.inspections.SpellCheckingInspection
|
||||
@@ -0,0 +1,8 @@
|
||||
fun xyzzy(): String {
|
||||
// this one is about xyzzy
|
||||
val s = "xyzzy ${xyzzy()} \n good\tbad\n"
|
||||
/* xyzzy in a block comment */
|
||||
/** xyzzy in a documentation comment */
|
||||
fun bar() {}
|
||||
return """xyzzy in a triple quoted string"""
|
||||
}
|
||||
@@ -81,6 +81,12 @@ public class JetInspectionTestGenerated extends AbstractJetInspectionTest {
|
||||
JetTestUtils.assertAllTestsPresentInSingleGeneratedClass(this.getClass(), new File("idea/testData/inspections"), Pattern.compile("^(inspections\\.test)$"));
|
||||
}
|
||||
|
||||
@TestMetadata("spelling/inspectionData/inspections.test")
|
||||
public void testSpelling_inspectionData_Inspections_test() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/inspections/spelling/inspectionData/inspections.test");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("unusedSymbol/class/inspectionData/inspections.test")
|
||||
public void testUnusedSymbol_class_inspectionData_Inspections_test() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/inspections/unusedSymbol/class/inspectionData/inspections.test");
|
||||
|
||||
Reference in New Issue
Block a user