Spellchecker: fix generics support in type tokenizer (IDEA-54464, IDEA-54431), add test cases

This commit is contained in:
Ekaterina Shliakhovetskaja
2010-07-01 02:14:16 +04:00
parent 989d8306af
commit b318a99efe
7 changed files with 160 additions and 11 deletions
@@ -22,12 +22,13 @@ import com.intellij.spellchecker.inspections.CommentSplitter;
import com.intellij.spellchecker.inspections.SplitterFactory;
import com.intellij.spellchecker.tokenizer.Token;
import com.intellij.spellchecker.tokenizer.Tokenizer;
import com.intellij.util.containers.hash.HashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
/**
* Created by IntelliJ IDEA.
@@ -36,8 +37,13 @@ import java.util.List;
*/
public class DocCommentTokenizer extends Tokenizer<PsiDocComment> {
private final String[] excludedTags = new String[]{"author", "link"};
private static final Set<String> excludedTags = new HashSet<String>();
{
excludedTags.add("author");
excludedTags.add("see");
excludedTags.add("by");
excludedTags.add("link");
}
@Nullable
@Override
@@ -48,7 +54,7 @@ public class DocCommentTokenizer extends Tokenizer<PsiDocComment> {
for (PsiElement el : comment.getChildren()) {
if (el instanceof PsiDocTag) {
PsiDocTag tag = (PsiDocTag)el;
if (!Arrays.asList(excludedTags).contains(tag.getName())) {
if (!excludedTags.contains(tag.getName())) {
for (PsiElement data : tag.getDataElements()) {
result.add(new Token<PsiElement>(data, splitter));
}
@@ -22,8 +22,8 @@ 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.Tokenizer;
import com.intellij.spellchecker.tokenizer.SpellcheckingStrategy;
import com.intellij.spellchecker.tokenizer.Tokenizer;
import org.jetbrains.annotations.NotNull;
/**
@@ -17,6 +17,7 @@ package com.intellij.spellchecker;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiTypeElement;
@@ -49,6 +50,16 @@ public class PsiTypeTokenizer extends Tokenizer<PsiTypeElement> {
final boolean isInSource = (virtualFile != null) && fileIndex.isInContent(virtualFile);
return !isInSource ? null : new Token[]{new Token<PsiTypeElement>(element, element.getText(), true, SplitterFactory.getInstance().getIdentifierSplitter())};
return !isInSource
? null
: new Token[]{
new Token<PsiTypeElement>(element, element.getText(), true, 0, getRangeToCheck(element.getText(), psiClass.getName()),
SplitterFactory.getInstance().getIdentifierSplitter())};
}
@NotNull
private TextRange getRangeToCheck(@NotNull String text, @NotNull String name) {
final int i = text.indexOf(name);
return new TextRange(i, i + name.length());
}
}
@@ -15,9 +15,11 @@
*/
package com.intellij.spellchecker.tokenizer;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.spellchecker.inspections.CheckArea;
import com.intellij.spellchecker.inspections.Splitter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
@@ -25,18 +27,24 @@ import java.util.List;
public class Token<T extends PsiElement> {
private String text;
private String description;
private T element;
private boolean useRename;
private final String text;
private final String description;
private final boolean useRename;
private int offset;
private final T element;
private final Splitter splitter;
private TextRange range;
public Token(T element, String text, boolean useRename, Splitter splitter) {
this.element = element;
this.text = text;
this.useRename = useRename;
this.splitter = splitter;
this.offset = 0;
this.description = null;
}
public Token(T element, String text, boolean useRename, int offset, Splitter splitter) {
@@ -52,6 +60,11 @@ public class Token<T extends PsiElement> {
this(element, element.getText(), useRename, splitter);
}
public Token(T element, String text, boolean useRename, int offset, TextRange textRange, Splitter splitter) {
this(element, text, useRename, offset, splitter);
this.range = textRange;
}
public String getText() {
return text;
}
@@ -72,12 +85,21 @@ public class Token<T extends PsiElement> {
return offset;
}
@NotNull
public TextRange getRange() {
if (range==null){
range = new TextRange(0,(text!=null?text.length():0));
}
return range;
}
@Nullable
public List<CheckArea> getAreas() {
if (splitter == null || text == null) {
return null;
}
return splitter.split(text);
return splitter.split(text, getRange());
}
}
@@ -0,0 +1,37 @@
public class GenericTest {
/**
@see com.intellij.openapi
*/
public void a( GenTest<?> obj ) {
}
public void b( AnotherGenTest<?> obj ) {
}
public void c( Predicate<?> obj ) {
}
public void d( AnotherPredicate<?> obj ) {
}
public class GenTest<T> {
}
public class AnotherGenTest<T> {
}
public interface Predicate<T> {
}
public interface AnotherPredicate<T> {
}
}
@@ -0,0 +1,35 @@
public class Generic<TYPO descr="Typo: In word 'Testt'">Testt</TYPO> {
public void a( Gen<TYPO descr="Typo: In word 'Testt'">Testt</TYPO><?> obj ) {
}
public void b( AnotherGen<TYPO descr="Typo: In word 'Testt'">Testt</TYPO><?> obj ) {
}
public void c( <TYPO descr="Typo: In word 'Predicatte'">Predicatte</TYPO><?> obj ) {
}
public void d( Another<TYPO descr="Typo: In word 'Predicatte'">Predicatte</TYPO><?> obj ) {
}
public class Gen<TYPO descr="Typo: In word 'Testt'">Testt</TYPO><T> {
}
public class AnotherGen<TYPO descr="Typo: In word 'Testt'">Testt</TYPO><T> {
}
public interface <TYPO descr="Typo: In word 'Predicatte'">Predicatte</TYPO><T> {
}
public interface Another<TYPO descr="Typo: In word 'Predicatte'">Predicatte</TYPO><T> {
}
}
@@ -0,0 +1,38 @@
/*
* 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;
import com.intellij.spellchecker.inspections.SpellCheckerInspectionToolProvider;
/**
* Created by IntelliJ IDEA.
* User: Ekaterina Shliakhovetskaja
*/
public class JavaSpellcheckingTest extends SpellcheckerInspectionTestCase {
protected String getBasePath() {
return getSpellcheckerTestDataPath() + "/inspection/java";
}
public void testCorrectJava() throws Throwable {
doTest("GenericTest.java", SpellCheckerInspectionToolProvider.getInspectionTools());
}
public void testTypoInJava() throws Throwable {
doTest("GenericTestt.java", SpellCheckerInspectionToolProvider.getInspectionTools());
}
}