IDEA-121251 (stray annotation highlighted)

This commit is contained in:
Roman Shevchenko
2014-02-28 19:33:48 +01:00
parent b8e291a0cb
commit cfcc34be5f
3 changed files with 10 additions and 10 deletions
@@ -25,7 +25,6 @@ import com.intellij.psi.tree.TokenSet;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.CharTable;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.SmartList;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -55,18 +54,19 @@ public class JavaSharedImplUtil {
return type;
}
// collects annotations bound to C-style arrays
private static List<PsiAnnotation[]> collectAnnotations(PsiElement anchor, PsiAnnotation stopAt) {
List<PsiAnnotation[]> annotations = new SmartList<PsiAnnotation[]>();
List<PsiAnnotation[]> annotations = ContainerUtil.newSmartList();
List<PsiAnnotation> current = null;
boolean stop = false;
boolean found = (stopAt == null), stop = false;
for (PsiElement child = anchor.getNextSibling(); child != null; child = child.getNextSibling()) {
if (child instanceof PsiComment || child instanceof PsiWhiteSpace) continue;
if (child instanceof PsiAnnotation) {
if (current == null) current = new SmartList<PsiAnnotation>();
if (current == null) current = ContainerUtil.newSmartList();
current.add((PsiAnnotation)child);
if (child == stopAt) stop = true;
if (child == stopAt) found = stop = true;
continue;
}
@@ -80,8 +80,8 @@ public class JavaSharedImplUtil {
}
}
// stop == true means annotation is misplaced
return stop ? null : annotations;
// annotation is misplaced (either located before the anchor or has no following brackets)
return !found || stop ? null : annotations;
}
public static void normalizeBrackets(@NotNull PsiVariable variable) {
@@ -111,6 +111,7 @@ class Outer {
int @TA [] a @TA [] <error descr="Annotations are not allowed here">@TA</error> = (p != null ? p : mixedArrays);
return a;
}
void <error descr="Annotations are not allowed here">@TA</error> misplaced() { }
@TA Outer() { }
@@ -39,6 +39,8 @@ public class AnnotationsHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testInapplicable() { doTest(false); }
public void testDuplicateAttribute() { doTest(false); }
public void testDuplicateTarget() { doTest(false); }
public void testPingPongAnnotationTypesDependencies() { doTest(false);}
public void testClashMethods() { doTest(false);}
public void testInvalidPackageAnnotationTarget() { doTest(BASE_PATH + "/" + getTestName(true) + "/package-info.java", false, false); }
public void testPackageAnnotationNotInPackageInfo() { doTest(BASE_PATH + "/" + getTestName(true) + "/notPackageInfo.java", false, false); }
@@ -46,9 +48,6 @@ public class AnnotationsHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testTypeAnnotations() { doTest8(false); }
public void testRepeatable() { doTest8(false); }
public void testPingPongAnnotationTypesDependencies() { doTest(false);}
public void testClashMethods() { doTest(false);}
private void doTest(boolean checkWarnings) {
setLanguageLevel(LanguageLevel.JDK_1_7);
doTest(BASE_PATH + "/" + getTestName(true) + ".java", checkWarnings, false);