project coin: @SafeVarargs applicability

This commit is contained in:
anna
2011-02-16 09:48:35 +01:00
parent d0939934ff
commit 898f2cc1bc
5 changed files with 119 additions and 0 deletions
@@ -0,0 +1,47 @@
import java.util.List;
@<error descr="'@SafeVarargs' not applicable to type">SafeVarargs</error>
public class SafeVarargsTests {
//fixed arity
<error descr="@SafeVarargs is not allowed on methods with fixed arity">@SafeVarargs</error>
public void testNonVarargs1(){}
<error descr="@SafeVarargs is not allowed on methods with fixed arity">@SafeVarargs</error>
public void testNonVarargs2(int <warning descr="Parameter 'i' is never used">i</warning>){}
<error descr="@SafeVarargs is not allowed on methods with fixed arity">@SafeVarargs</error>
public <T> void testNonVarargs3(T <warning descr="Parameter 't' is never used">t</warning>){}
//non static/non final
<error descr="@SafeVarargs is not allowed on non-final instance methods">@SafeVarargs</error>
public void testNonVarargs4(int... <warning descr="Parameter 'i' is never used">i</warning>){}
//reassigned
@SafeVarargs
public final <T> void testT(T[] tt, T... t) {
<warning descr="@SafeVarargs do not suppress potentially unsafe operations">t</warning> = tt;
System.out.println(t[0]);
}
//incorrect types
@SafeVarargs
public final void testString(<warning descr="@SafeVarargs is not applicable for reifiable types">String...</warning> <warning descr="Parameter 'str' is never used">str</warning>){
}
@SafeVarargs
public final void testStringArray(<warning descr="@SafeVarargs is not applicable for reifiable types">String[]...</warning> <warning descr="Parameter 'str' is never used">str</warning>){
}
@SafeVarargs
public static void testUnbound(<warning descr="@SafeVarargs is not applicable for reifiable types">List<?>...</warning> <warning descr="Parameter 't' is never used">t</warning>){}
//correct usages
@SafeVarargs
public static <T> void foo(T... <warning descr="Parameter 't' is never used">t</warning>){}
@SafeVarargs
public static <T> void foo1(List<T>... <warning descr="Parameter 't' is never used">t</warning>){}
@SafeVarargs
public static <T> void foo2(List<? extends T>... <warning descr="Parameter 't' is never used">t</warning>){}
}