Annotation applicability highlighting reworked

This commit is contained in:
Roman Shevchenko
2013-03-13 10:23:19 +01:00
parent bb11ce13c7
commit 2ab88505d2
21 changed files with 545 additions and 352 deletions
@@ -5,4 +5,4 @@ import java.lang.annotation.*;
@Expose @interface Expose {}
@Target({ElementType.FIELD})
@<error descr="'@Expose1' not applicable to annotation type">Expose1</error>@interface Expose1 {}
<error descr="'@Expose1' not applicable to annotation type">@Expose1</error>@interface Expose1 {}
@@ -1 +1 @@
@<error descr="'@SuppressWarnings' not applicable to package">SuppressWarnings</error>("all") package annotations.invalidPackageAnnotationTarget;
<error descr="'@SuppressWarnings' not applicable to package">@SuppressWarnings("all")</error> package annotations.invalidPackageAnnotationTarget;
@@ -1,33 +1,141 @@
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
import java.lang.annotation.*;
import java.io.*;
import java.util.*;
import java.io.<error descr="Annotations are not allowed here">@SuppressWarnings</error> Reader;
import <error descr="Annotations are not allowed here">@SuppressWarnings</error> java.io.Writer;
import static java.lang.annotation.ElementType.*;
@Target({ElementType.TYPE_USE/*, ElementType.TYPE*/})
@interface TA {
}
/*@Target({CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, PARAMETER, TYPE})*/ @interface A { }
@Target({TYPE_USE}) @interface TA { }
@Target({TYPE_PARAMETER}) @interface TPA { }
@<error descr="'@TA' not applicable to type">TA</error>
class X0<@<error descr="'@TA' not applicable to type parameter">TA</error> T> {
@TA
protected
void f() @<error descr="'@TA' not applicable to parameter">TA</error> {
@TA String p=new @TA String();
@A @TA <error descr="'@TPA' not applicable to type">@TPA</error>
class Outer {
private Map<@TA String, @TA List<@TA <error descr="'@A' not applicable to type use">@A</error> String>> m;
if (this instanceof @TA Object) return;
String o = p;
List<@TA String> l;
Class c = @TA String.class;
interface I { void m(int i); }
private I i = (@TA <error descr="'@Override' not applicable to parameter">@Override</error> final int k) -> { };
<error descr="'void' type may not be annotated">@TA</error> <T> void m(T t) { }
<error descr="'void' type may not be annotated">@TA</error> void test1() {
this.<@TA <error descr="'@TPA' not applicable to type use">@TPA</error> String>m("...");
}
class FF<F extends @TA String> { }
Collection<? super @TA String> cs;
interface BI<T> { }
class BII<T> implements @TA BI<@TA T> { }
class BIII extends @TA BII<Object> { }
void tm() throws @TA RuntimeException { }
class Middle {
class Inner {
void test() {
@TA Inner v1;
@TA Middle.@TA Inner v2;
@TA Outer.@TA Middle.@TA Inner v3;
@TA Outer v4;
@TA Outer.@TA Middle v5;
@TA Outer.@TA Middle.@TA Inner v6;
List<@TA Outer.@TA Middle.@TA Inner> l;
}
}
}
@TA int @TA[] methodf() throws @TA Exception {
boolean a = this instanceof @TA X0;
X0<@<error descr="Duplicate annotation">TA</error> @<error descr="Duplicate annotation">TA</error> X0> c = new @TA X0<@TA X0>();
Object o = (@TA Object) c;
@TA X0.field = null;
return null;
static class StaticMiddle {
static class StaticInner {
void test() {
@TA StaticInner v1;
<error descr="Static member qualifying type may not be annotated">@TA</error> StaticMiddle.@TA StaticInner v2;
<error descr="Static member qualifying type may not be annotated">@TA</error> Outer.<error descr="Static member qualifying type may not be annotated">@TA</error> StaticMiddle.@TA StaticInner v3;
List<@TA Outer.<error descr="Static member qualifying type may not be annotated">@TA</error> StaticMiddle.@TA StaticInner> l;
}
}
}
@TA() int @TA[] p;
static @TA Object field;
@TA List<String> disambiguateBetweenBinaryExpr;
{
new @TA Object();
new @TA ArrayList<String>();
ArrayList<String> var = new <String> @TA ArrayList();
new @TA Outer().new @TA Middle();
@A Map.@TA Entry e1;
@A <error descr="Static member qualifying type may not be annotated">@TA</error> Map.@TA Entry e2;
@A java.<error descr="Annotation not applicable to this kind of reference">@TA</error> util.Map.@TA Entry e3;
@A List<java.<error descr="Annotation not applicable to this kind of reference">@TA</error> lang.@TA String> l1;
Object obj = "str";
@TA String str = (@TA String)obj;
boolean b = str instanceof @TA String;
<error descr="Annotations are not allowed here">@TA</error> tm();
try (@TA Reader r = new @TA FileReader("/dev/zero"); @TA Writer w = new @TA FileWriter("/dev/null")) { }
catch (@TA IllegalArgumentException | @TA IOException e) { }
@A @TA <error descr="Cannot resolve symbol 'Unknown'">Unknown</error>.@TA Unknown uu;
Class<?> c1 = <error descr="Class literal type may not be annotated">@TA</error> String.class;
Class<?> c2 = int <error descr="Class literal type may not be annotated">@TA</error> [].class;
}
interface IntFunction<T> { int apply(T t); }
interface Sorter<T> { void sort(T[] a, Comparator<? super T> c); }
void m1(IntFunction<Date> f) { }
void m2(IntFunction<List<String>> f) { }
void m3(Sorter<Integer> s) { }
void lambdas() {
m1(@TA Date::getDay);
m1(<error descr="Annotations are not allowed here">@TA</error> java.util.@TA Date::getDay);
m2(List<@TA String>::size);
m3(Arrays::<@TA Integer>sort);
Comparator<Object> cmp = (@TA Object x, @TA Object y) -> { System.out.println("x=" + x + " y=" + y); return 0; };
}
void m(List<@TA ? extends Comparable<Object>> p) { }
void arrays(String @TA ... docs) {
//todo[r.sh]
//@TA String @TA [] @TA [] docs1 = new @TA String @TA [2] @TA [2];
}
@TA Outer() { }
class MyClass<@TA @TPA T> { }
interface MyInterface<@TA @TPA E> { }
static class Super {
protected int aField;
int getField() { return aField; }
}
static class This extends Super {
void superField() {
Outer.<error descr="Annotations are not allowed here">@TA</error> This.super.aField = 0;
IntFunction<Super> f = Outer.<error descr="Annotations are not allowed here">@TA</error> This.super::getField;
}
}
//todo[r.sh]
/*public String toString(@TA C this) { return ""; }
public boolean equals(@TA C this, @TA C other) { return false; }
C(@TA C this, boolean b) { }
class Outer {
class Middle {
class Inner {
void innerMethod(@TA Outer.@TA Middle.@TA Inner this) { }
}
}
}*/
List<@<error descr="Duplicate annotation">TA</error> @<error descr="Duplicate annotation">TA</error> String> c = null;
}
@@ -15,14 +15,14 @@ abstract class C {
void notWrong() { }
}
class B extends <error descr="Annotations are not allowed here">@Deprecated</error> Object { }
class B extends <error descr="Type annotations are not supported at this language level">@Deprecated</error> Object { }
enum E {
@Anno E1
}
interface I {
@<error descr="Duplicate annotation">Anno</error> public @<error descr="Duplicate annotation">Anno</error> Collection<<error descr="Annotations are not allowed here">@Anno</error> String> method(@<error descr="Duplicate annotation">Anno</error> @<error descr="Duplicate annotation">Anno</error> Object o);
@<error descr="Duplicate annotation">Anno</error> public @<error descr="Duplicate annotation">Anno</error> Collection<<error descr="Type annotations are not supported at this language level">@Anno</error> String> method(@<error descr="Duplicate annotation">Anno</error> @<error descr="Duplicate annotation">Anno</error> Object o);
}
@interface Caller {