IDEA-79244 Spell checker gets confused by single quotes in stringy method name

This commit is contained in:
peter
2011-12-23 12:32:37 +01:00
parent cd6470f2fc
commit 49a9fac92f
7 changed files with 104 additions and 40 deletions
+1
View File
@@ -30,6 +30,7 @@
<orderEntry type="module" module-name="IntelliLang-java" scope="TEST" />
<orderEntry type="module" module-name="IntelliLang-xml" scope="TEST" />
<orderEntry type="module" module-name="jps-builders" />
<orderEntry type="module" module-name="spellchecker" />
</component>
</module>
+2
View File
@@ -146,6 +146,8 @@
<projectService serviceInterface="org.jetbrains.plugins.groovy.gant.GantSettings" serviceImplementation="org.jetbrains.plugins.groovy.gant.GantSettings"/>
<spellchecker.support language="Groovy" implementationClass="org.jetbrains.plugins.groovy.codeInspection.GroovySpellcheckingStrategy"/>
<colorSettingsPage implementation="org.jetbrains.plugins.groovy.highlighter.GroovyColorsAndFontsPage"/>
<framework.type implementation="org.jetbrains.plugins.groovy.config.GroovyFrameworkType"/>
<renameHandler implementation="org.jetbrains.plugins.groovy.refactoring.rename.PropertyRenameHandler"/>
@@ -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<GrNamedElement>() {
@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);
}
}
@@ -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 <TYPO descr="Typo: In word 'dddd'">dddd</TYPO>) {
}
'''
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 "<TYPO descr="Typo: In word 'addds'">addds</TYPO> a 'play' extension"() { }
}
'''
checkTypos()
}
}
@@ -1,2 +0,0 @@
def test(int <TYPO descr="Typo: In word 'dddd'">dddd</TYPO>) {
}
@@ -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());
}
}
@@ -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() {