From 1675e45aee2608414e87e6083e2827cf6c50581f Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Mon, 2 Dec 2013 20:20:45 +0400 Subject: [PATCH] Enable basic spell check for Kotlin #KT-4272 Fixed --- idea/src/META-INF/plugin.xml | 2 + .../KotlinSpellcheckingStrategy.kt | 48 +++++++++++++++++++ idea/testData/checker/infos/Autocasts.kt | 2 +- idea/testData/checker/infos/Typos.kt | 10 ++++ .../checkers/AbstractJetPsiCheckerTest.java | 2 + .../checkers/JetPsiCheckerTestGenerated.java | 5 ++ 6 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 idea/src/org/jetbrains/jet/plugin/codeInsight/spellchecker/KotlinSpellcheckingStrategy.kt create mode 100644 idea/testData/checker/infos/Typos.kt diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 8d57176f284..67632c8d7e2 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -219,6 +219,8 @@ id="KotlinFunction" order="first"/> + + diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/spellchecker/KotlinSpellcheckingStrategy.kt b/idea/src/org/jetbrains/jet/plugin/codeInsight/spellchecker/KotlinSpellcheckingStrategy.kt new file mode 100644 index 00000000000..167667c77ae --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/spellchecker/KotlinSpellcheckingStrategy.kt @@ -0,0 +1,48 @@ +/* + * Copyright 2010-2013 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. + */ + +package org.jetbrains.jet.plugin + +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 + +class KotlinSpellcheckingStrategy: SuppressibleSpellcheckingStrategy() { + private val nameIdentifierTokenizer = PsiIdentifierOwnerTokenizer() + + [suppress("UNCHECKED_CAST")] + private val emptyTokenizer = SpellcheckingStrategy.EMPTY_TOKENIZER as Tokenizer + + override fun getTokenizer(element: PsiElement?): Tokenizer { + [suppress("UNCHECKED_CAST")] + return when { + element is PsiNameIdentifierOwner || element is PsiComment -> + super.getTokenizer(element) as Tokenizer + + 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/checker/infos/Autocasts.kt b/idea/testData/checker/infos/Autocasts.kt index e6d1c7269fa..c40a3aeb669 100644 --- a/idea/testData/checker/infos/Autocasts.kt +++ b/idea/testData/checker/infos/Autocasts.kt @@ -176,7 +176,7 @@ fun returnFunctionLiteral(a: Any?): Function0 = if (a is Int) { (): Int -> a } else { () -> 1 } -fun mergeAutocasts(a: Any?) { +fun mergeAutocasts(a: Any?) { if (a is String || a is Int) { a.compareTo("") a.toString() diff --git a/idea/testData/checker/infos/Typos.kt b/idea/testData/checker/infos/Typos.kt new file mode 100644 index 00000000000..f7e7a3bd65d --- /dev/null +++ b/idea/testData/checker/infos/Typos.kt @@ -0,0 +1,10 @@ +package kara.internal + +/* Test somthing */ +class MoreeFun { + fun wrte() { + val childen = 12 + val come = childen + wrte() + } +} diff --git a/idea/tests/org/jetbrains/jet/checkers/AbstractJetPsiCheckerTest.java b/idea/tests/org/jetbrains/jet/checkers/AbstractJetPsiCheckerTest.java index 11fe8d15994..32881565c88 100644 --- a/idea/tests/org/jetbrains/jet/checkers/AbstractJetPsiCheckerTest.java +++ b/idea/tests/org/jetbrains/jet/checkers/AbstractJetPsiCheckerTest.java @@ -18,6 +18,7 @@ package org.jetbrains.jet.checkers; import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase; import com.intellij.openapi.projectRoots.Sdk; +import com.intellij.spellchecker.inspections.SpellCheckingInspection; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.plugin.PluginTestCaseBase; import org.jetbrains.jet.plugin.highlighter.JetPsiChecker; @@ -29,6 +30,7 @@ public abstract class AbstractJetPsiCheckerTest extends LightDaemonAnalyzerTestC public void doTestWithInfos(@NotNull String filePath) throws Exception { try { + enableInspectionTool(new SpellCheckingInspection()); JetPsiChecker.setNamesHighlightingEnabled(false); doTest(filePath, true, true); } diff --git a/idea/tests/org/jetbrains/jet/checkers/JetPsiCheckerTestGenerated.java b/idea/tests/org/jetbrains/jet/checkers/JetPsiCheckerTestGenerated.java index baa8ea9cb62..4d85d6af55c 100644 --- a/idea/tests/org/jetbrains/jet/checkers/JetPsiCheckerTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/checkers/JetPsiCheckerTestGenerated.java @@ -442,6 +442,11 @@ public class JetPsiCheckerTestGenerated extends AbstractJetPsiCheckerTest { doTestWithInfos("idea/testData/checker/infos/PropertiesWithBackingFields.kt"); } + @TestMetadata("Typos.kt") + public void testTypos() throws Exception { + doTestWithInfos("idea/testData/checker/infos/Typos.kt"); + } + @TestMetadata("WrapIntoRef.kt") public void testWrapIntoRef() throws Exception { doTestWithInfos("idea/testData/checker/infos/WrapIntoRef.kt");