mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-98245 (spellchecker suppression for Java)
This commit is contained in:
+15
-7
@@ -49,8 +49,12 @@ import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.intellij.util.ObjectUtils.notNull;
|
||||
|
||||
public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase {
|
||||
@NonNls private static final String BEFORE_PREFIX = "before";
|
||||
@NonNls private static final String AFTER_PREFIX = "after";
|
||||
|
||||
private static QuickFixTestCase myWrapper;
|
||||
|
||||
protected boolean shouldBeAvailableAfterExecution() {
|
||||
@@ -62,10 +66,11 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase
|
||||
}
|
||||
|
||||
private static void doTestFor(final String testName, final QuickFixTestCase quickFixTestCase) {
|
||||
final String relativePath = quickFixTestCase.getBasePath() + "/" + BEFORE_PREFIX + testName;
|
||||
final String relativePath = notNull(quickFixTestCase.getBasePath(), "") + "/" + BEFORE_PREFIX + testName;
|
||||
final String testFullPath = quickFixTestCase.getTestDataPath().replace(File.separatorChar, '/') + relativePath;
|
||||
final File testFile = new File(testFullPath);
|
||||
CommandProcessor.getInstance().executeCommand(quickFixTestCase.getProject(), new Runnable() {
|
||||
@SuppressWarnings({"AssignmentToStaticFieldFromInstanceMethod", "CallToPrintStackTrace"})
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@@ -118,6 +123,7 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase
|
||||
}
|
||||
|
||||
// "quick fix action text to perform" "should be available"
|
||||
assert comment != null : commenter;
|
||||
Pattern pattern = Pattern.compile("^" + comment.replace("*", "\\*") + actionPattern, Pattern.DOTALL);
|
||||
Matcher matcher = pattern.matcher(contents);
|
||||
assertTrue("No comment found in "+file.getVirtualFile(), matcher.matches());
|
||||
@@ -126,10 +132,11 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase
|
||||
return Pair.create(text, actionShouldBeAvailable);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"HardCodedStringLiteral"})
|
||||
public static void doAction(final String text, final boolean actionShouldBeAvailable, final String testFullPath, final String testName,
|
||||
QuickFixTestCase quickFix)
|
||||
throws Exception {
|
||||
public static void doAction(String text,
|
||||
boolean actionShouldBeAvailable,
|
||||
String testFullPath,
|
||||
String testName,
|
||||
QuickFixTestCase quickFix) throws Exception {
|
||||
IntentionAction action = quickFix.findActionWithText(text);
|
||||
if (action == null) {
|
||||
if (actionShouldBeAvailable) {
|
||||
@@ -139,7 +146,8 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase
|
||||
texts.add(intentionAction.getText());
|
||||
}
|
||||
Collection<HighlightInfo> infos = quickFix.doHighlighting();
|
||||
fail("Action with text '" + text + "' is not available in test " + testFullPath+"\nAvailable actions ("+texts.size()+"): "+texts+"\n"+actions+"\nInfos:"+infos);
|
||||
fail("Action with text '" + text + "' is not available in test " + testFullPath + "\n" +
|
||||
"Available actions (" + texts.size() + "): " + texts + "\n" + actions + "\nInfos:" + infos);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -155,7 +163,7 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase
|
||||
fail("Action '" + text + "' is still available after its invocation in test " + testFullPath);
|
||||
}
|
||||
}
|
||||
final String expectedFilePath = quickFix.getBasePath() + "/after" + testName;
|
||||
String expectedFilePath = notNull(quickFix.getBasePath(), "") + "/" + AFTER_PREFIX + testName;
|
||||
quickFix.checkResultByFile("In file :" + expectedFilePath, expectedFilePath, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-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.
|
||||
@@ -15,22 +15,22 @@
|
||||
*/
|
||||
package com.intellij.spellchecker;
|
||||
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInspection.SuppressIntentionAction;
|
||||
import com.intellij.codeInspection.SuppressManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiLiteralExpression;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiNamedElement;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import com.intellij.spellchecker.tokenizer.SpellcheckingStrategy;
|
||||
import com.intellij.spellchecker.tokenizer.SuppressibleSpellcheckingStrategy;
|
||||
import com.intellij.spellchecker.tokenizer.Tokenizer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
*
|
||||
* @author shkate@jetbrains.com
|
||||
*/
|
||||
public class JavaSpellcheckingStrategy extends SpellcheckingStrategy {
|
||||
public class JavaSpellcheckingStrategy extends SuppressibleSpellcheckingStrategy {
|
||||
private final MethodNameTokenizerJava myMethodNameTokenizer = new MethodNameTokenizerJava();
|
||||
private final DocCommentTokenizer myDocCommentTokenizer = new DocCommentTokenizer();
|
||||
private final LiteralExpressionTokenizer myLiteralExpressionTokenizer = new LiteralExpressionTokenizer();
|
||||
@@ -39,15 +39,32 @@ public class JavaSpellcheckingStrategy extends SpellcheckingStrategy {
|
||||
@NotNull
|
||||
@Override
|
||||
public Tokenizer getTokenizer(PsiElement element) {
|
||||
if (element instanceof PsiMethod) return myMethodNameTokenizer;
|
||||
if (element instanceof PsiDocComment) return myDocCommentTokenizer;
|
||||
if (element instanceof PsiMethod) {
|
||||
return myMethodNameTokenizer;
|
||||
}
|
||||
if (element instanceof PsiDocComment) {
|
||||
return myDocCommentTokenizer;
|
||||
}
|
||||
if (element instanceof PsiLiteralExpression) {
|
||||
if (SuppressManager.isSuppressedInspectionName((PsiLiteralExpression)element)){
|
||||
if (SuppressManager.isSuppressedInspectionName((PsiLiteralExpression)element)) {
|
||||
return EMPTY_TOKENIZER;
|
||||
}
|
||||
return myLiteralExpressionTokenizer;
|
||||
}
|
||||
if (element instanceof PsiNamedElement) return myNamedElementTokenizer;
|
||||
if (element instanceof PsiNamedElement) {
|
||||
return myNamedElementTokenizer;
|
||||
}
|
||||
|
||||
return super.getTokenizer(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuppressedFor(@NotNull PsiElement element, @NotNull String name) {
|
||||
return SuppressManager.getInstance().isSuppressedFor(element, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuppressIntentionAction[] getSuppressActions(@NotNull PsiElement element, @NotNull String name) {
|
||||
return SuppressManager.getInstance().createSuppressActions(HighlightDisplayKey.find(name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
class BaddName1 {
|
||||
int baddField;
|
||||
void baddMethod() { }
|
||||
}
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
class BaddName2 {
|
||||
int baddField;
|
||||
void baddMethod() { }
|
||||
}
|
||||
|
||||
class GoodName {
|
||||
@SuppressWarnings("SpellCheckingInspection") int baddField;
|
||||
@SuppressWarnings("SpellCheckingInspection") void baddMethod() { }
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Suppress for class" "true"
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
class BaddName {
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Suppress for statement with comment" "true"
|
||||
class C {
|
||||
{
|
||||
//noinspection SpellCheckingInspection
|
||||
String s = "tyypoo";
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
// "Suppress for class" "true"
|
||||
class <caret>BaddName {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// "Suppress for statement with comment" "true"
|
||||
class C {
|
||||
{
|
||||
String s = "<caret>tyypoo";
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
+1
@@ -31,6 +31,7 @@ public class JavaSpellcheckerInspectionTest extends LightCodeInsightFixtureTestC
|
||||
public void testDocComment() { doTest(); }
|
||||
public void testStringLiteral() { doTest(); }
|
||||
public void testStringLiteralEscaping() { doTest(); }
|
||||
public void testSuppressions() { doTest(); }
|
||||
|
||||
private void doTest() {
|
||||
myFixture.enableInspections(SpellcheckerInspectionTestCase.getInspectionTools());
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2000-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 com.intellij.spellchecker.inspection;
|
||||
|
||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixTestCase;
|
||||
import com.intellij.openapi.application.PluginPathManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class JavaSpellcheckerSuppressionTest extends LightQuickFixTestCase {
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return PluginPathManager.getPluginHomePath("java-i18n") + "/testData/suppression";
|
||||
}
|
||||
|
||||
public void testClassName() { doTest(); }
|
||||
public void testStringLiteral() { doTest(); }
|
||||
|
||||
private void doTest() {
|
||||
enableInspectionTools(SpellcheckerInspectionTestCase.getInspectionTools());
|
||||
doSingleTest(getTestName(false) + ".java");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user