From 35e8e4d49a3f2ca7defbee97ea612b81800194ab Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 24 Feb 2015 19:41:53 +0100 Subject: [PATCH] Support spellchecking in Kotlin string literals; remove unused and unnecessary support for custom suppressions of spelling errors --- .../KotlinSpellcheckingStrategy.kt | 30 ++++++----- .../spelling/inspectionData/expected.xml | 50 +++++++++++++++++++ .../spelling/inspectionData/inspections.test | 1 + .../testData/inspections/spelling/spelling.kt | 8 +++ .../JetInspectionTestGenerated.java | 6 +++ 5 files changed, 79 insertions(+), 16 deletions(-) create mode 100644 idea/testData/inspections/spelling/inspectionData/expected.xml create mode 100644 idea/testData/inspections/spelling/inspectionData/inspections.test create mode 100644 idea/testData/inspections/spelling/spelling.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/spellchecker/KotlinSpellcheckingStrategy.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/spellchecker/KotlinSpellcheckingStrategy.kt index 070c11e293e..95086107a2a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/spellchecker/KotlinSpellcheckingStrategy.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/spellchecker/KotlinSpellcheckingStrategy.kt @@ -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 +class KotlinSpellcheckingStrategy: SpellcheckingStrategy() { + private val plainTextTokenizer = TokenizerBase(PlainTextSplitter.getInstance()) + private val emptyTokenizer = SpellcheckingStrategy.EMPTY_TOKENIZER override fun getTokenizer(element: PsiElement?): Tokenizer { [suppress("UNCHECKED_CAST")] return when { element is PsiNameIdentifierOwner || element is PsiComment -> - super.getTokenizer(element) as Tokenizer + 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.EMPTY_ARRAY } - diff --git a/idea/testData/inspections/spelling/inspectionData/expected.xml b/idea/testData/inspections/spelling/inspectionData/expected.xml new file mode 100644 index 00000000000..46e845103c2 --- /dev/null +++ b/idea/testData/inspections/spelling/inspectionData/expected.xml @@ -0,0 +1,50 @@ + + + spelling.kt + 1 + light_idea_test_case + + Typo + Typo: In word 'xyzzy' + + + spelling.kt + 2 + light_idea_test_case + + Typo + Typo: In word 'xyzzy' + + + spelling.kt + 3 + light_idea_test_case + + Typo + Typo: In word 'xyzzy' + + + spelling.kt + 4 + light_idea_test_case + + Typo + Typo: In word 'xyzzy' + + + spelling.kt + 5 + light_idea_test_case + + Typo + Typo: In word 'xyzzy' + + + spelling.kt + 7 + light_idea_test_case + + Typo + Typo: In word 'xyzzy' + + diff --git a/idea/testData/inspections/spelling/inspectionData/inspections.test b/idea/testData/inspections/spelling/inspectionData/inspections.test new file mode 100644 index 00000000000..7b9a63d95f8 --- /dev/null +++ b/idea/testData/inspections/spelling/inspectionData/inspections.test @@ -0,0 +1 @@ +// INSPECTION_CLASS: com.intellij.spellchecker.inspections.SpellCheckingInspection diff --git a/idea/testData/inspections/spelling/spelling.kt b/idea/testData/inspections/spelling/spelling.kt new file mode 100644 index 00000000000..6675ab05149 --- /dev/null +++ b/idea/testData/inspections/spelling/spelling.kt @@ -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""" +} diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/JetInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/JetInspectionTestGenerated.java index e2ed46fe7d9..7dc4536cc67 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/JetInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/JetInspectionTestGenerated.java @@ -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");