From 49a9fac92fd6e629dc3efa7e0e1629ac88a9d68d Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 23 Dec 2011 11:45:01 +0100 Subject: [PATCH] IDEA-79244 Spell checker gets confused by single quotes in stringy method name --- plugins/groovy/jetgroovy.iml | 1 + plugins/groovy/src/META-INF/plugin.xml | 2 + .../GroovySpellcheckingStrategy.java | 52 +++++++++++++++++++ .../groovy/lang/GroovySpellcheckerTest.groovy | 49 +++++++++++++++++ .../testData/inspection/groovy/Test.groovy | 2 - .../inspection/GroovyFileWithTypos.java | 34 ------------ .../SpellcheckerInspectionTestCase.java | 4 -- 7 files changed, 104 insertions(+), 40 deletions(-) create mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/GroovySpellcheckingStrategy.java create mode 100644 plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovySpellcheckerTest.groovy delete mode 100644 plugins/spellchecker/testData/inspection/groovy/Test.groovy delete mode 100644 plugins/spellchecker/testSrc/com/intellij/spellchecker/inspection/GroovyFileWithTypos.java diff --git a/plugins/groovy/jetgroovy.iml b/plugins/groovy/jetgroovy.iml index bcb38c12e2ff..79385a649ce6 100644 --- a/plugins/groovy/jetgroovy.iml +++ b/plugins/groovy/jetgroovy.iml @@ -30,6 +30,7 @@ + diff --git a/plugins/groovy/src/META-INF/plugin.xml b/plugins/groovy/src/META-INF/plugin.xml index fd3c5dc3a5c4..d7185b1b1557 100644 --- a/plugins/groovy/src/META-INF/plugin.xml +++ b/plugins/groovy/src/META-INF/plugin.xml @@ -146,6 +146,8 @@ + + diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/GroovySpellcheckingStrategy.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/GroovySpellcheckingStrategy.java new file mode 100644 index 000000000000..fc9c748bb6f3 --- /dev/null +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/GroovySpellcheckingStrategy.java @@ -0,0 +1,52 @@ +/* + * Copyright 2000-2011 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.plugins.groovy.codeInspection; + +import com.intellij.openapi.util.TextRange; +import com.intellij.psi.PsiElement; +import com.intellij.spellchecker.inspections.PlainTextSplitter; +import com.intellij.spellchecker.tokenizer.SpellcheckingStrategy; +import com.intellij.spellchecker.tokenizer.TokenConsumer; +import com.intellij.spellchecker.tokenizer.Tokenizer; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.groovy.lang.lexer.TokenSets; +import org.jetbrains.plugins.groovy.lang.psi.GrNamedElement; +import org.jetbrains.plugins.groovy.lang.resolve.GroovyStringLiteralManipulator; + +/** + * @author peter + */ +public class GroovySpellcheckingStrategy extends SpellcheckingStrategy { + @NotNull + @Override + public Tokenizer getTokenizer(PsiElement element) { + if (element instanceof GrNamedElement) { + final PsiElement name = ((GrNamedElement)element).getNameIdentifierGroovy(); + if (TokenSets.STRING_LITERAL_SET.contains(name.getNode().getElementType())) { + return new Tokenizer() { + @Override + public void tokenize(@NotNull GrNamedElement element, TokenConsumer consumer) { + String text = name.getText(); + TextRange range = GroovyStringLiteralManipulator.getLiteralRange(text); + consumer.consumeToken(name, text, false, 0, range, PlainTextSplitter.getInstance()); + } + }; + + } + } + return super.getTokenizer(element); + } +} diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovySpellcheckerTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovySpellcheckerTest.groovy new file mode 100644 index 000000000000..6af89920d7b7 --- /dev/null +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovySpellcheckerTest.groovy @@ -0,0 +1,49 @@ +/* + * Copyright 2000-2011 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.plugins.groovy.lang + +import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase +import com.intellij.spellchecker.inspections.SpellCheckingInspection + +/** + * @author peter + */ +class GroovySpellcheckerTest extends LightCodeInsightFixtureTestCase { + + public void testParameterName() { + myFixture.configureByText 'a.groovy', ''' +def test(int dddd) { +} +''' + checkTypos() + } + + private checkTypos() { + myFixture.enableInspections(new SpellCheckingInspection()) + myFixture.checkHighlighting(false, false, true) + } + + public void testLiteralMethodNames() { + myFixture.configureByText 'a.groovy', ''' +class SpockTest { + def "adds a 'play' extension"() { } + def "addds a 'play' extension"() { } +} +''' + checkTypos() + } + +} diff --git a/plugins/spellchecker/testData/inspection/groovy/Test.groovy b/plugins/spellchecker/testData/inspection/groovy/Test.groovy deleted file mode 100644 index 201b418f1772..000000000000 --- a/plugins/spellchecker/testData/inspection/groovy/Test.groovy +++ /dev/null @@ -1,2 +0,0 @@ -def test(int dddd) { -} diff --git a/plugins/spellchecker/testSrc/com/intellij/spellchecker/inspection/GroovyFileWithTypos.java b/plugins/spellchecker/testSrc/com/intellij/spellchecker/inspection/GroovyFileWithTypos.java deleted file mode 100644 index 15992c63f474..000000000000 --- a/plugins/spellchecker/testSrc/com/intellij/spellchecker/inspection/GroovyFileWithTypos.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2000-2009 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 com.intellij.spellchecker.inspection; - -/** - * Created by IntelliJ IDEA. - * User: Ekaterina Shliakhovetskaja - */ -public class GroovyFileWithTypos extends SpellcheckerInspectionTestCase { - - @Override - protected String getBasePath() { - return getSpellcheckerTestDataPath() + "/inspection/groovy"; - } - - public void testGroovy() throws Throwable { - doTest("Test.groovy", getInspectionTools()); - } - - -} \ No newline at end of file diff --git a/plugins/spellchecker/testSrc/com/intellij/spellchecker/inspection/SpellcheckerInspectionTestCase.java b/plugins/spellchecker/testSrc/com/intellij/spellchecker/inspection/SpellcheckerInspectionTestCase.java index 6189c4401f6e..73c8a066a0aa 100644 --- a/plugins/spellchecker/testSrc/com/intellij/spellchecker/inspection/SpellcheckerInspectionTestCase.java +++ b/plugins/spellchecker/testSrc/com/intellij/spellchecker/inspection/SpellcheckerInspectionTestCase.java @@ -16,13 +16,9 @@ package com.intellij.spellchecker.inspection; import com.intellij.codeInspection.LocalInspectionTool; -import com.intellij.openapi.application.PathManager; import com.intellij.openapi.application.PluginPathManager; -import com.intellij.openapi.util.io.FileUtil; - import com.intellij.spellchecker.inspections.SpellCheckingInspection; import com.intellij.testFramework.fixtures.CodeInsightFixtureTestCase; -import org.jetbrains.annotations.NonNls; public abstract class SpellcheckerInspectionTestCase extends CodeInsightFixtureTestCase { public static String getSpellcheckerTestDataPath() {