| 1 |
package assuper; |
| 2 |
|
| 3 |
import java.lang.ref.WeakReference; |
| 4 |
import java.lang.reflect.Field; |
| 5 |
import java.util.Date; |
| 6 |
import java.util.List; |
| 7 |
import org.checkerframework.dataflow.qual.Pure; |
| 8 |
|
| 9 |
// This class has code that used to cause AsSuper to crash |
| 10 |
@SuppressWarnings("") |
| 11 |
class AsSuperTest { |
| 12 |
// TODO: Value Checker crashes on this |
| 13 |
/* void primitiveNarrowing() { |
| 14 |
Byte b = 100; |
| 15 |
Character c = 100; |
| 16 |
Short s = 100; |
| 17 |
|
| 18 |
byte bb = 100; |
| 19 |
char cc = 100; |
| 20 |
short ss = 100; |
| 21 |
} |
| 22 |
*/ |
| 23 |
|
| 24 |
// test anonymous classes |
| 25 |
private void testAnonymous() { |
| 26 |
new Object() { |
| 27 |
public boolean equals(Object o) { |
| 28 |
return true; |
| 29 |
} |
| 30 |
}.equals(null); |
| 31 |
|
| 32 |
Date d = new Date() {}; |
| 33 |
} |
| 34 |
|
| 35 |
private void apply(Field field) { |
| 36 |
Class<?> type = field.getType(); |
| 37 |
type.getSuperclass().getName().equals("java.lang.Enum"); |
| 38 |
} |
| 39 |
|
| 40 |
void arrayAsMethodReceiver(Object[] array) { |
| 41 |
array.clone(); |
| 42 |
} |
| 43 |
|
| 44 |
<T> T lowerBoundedWildcard(java.util.List<? super Iterable<?>> l) { |
| 45 |
lowerBoundedWildcard(new java.util.ArrayList<Object>()); |
| 46 |
throw new Error(); |
| 47 |
} |
| 48 |
|
| 49 |
// Test super() and this() |
| 50 |
class Inner { |
| 51 |
public Inner() { |
| 52 |
super(); |
| 53 |
} |
| 54 |
|
| 55 |
public Inner(int i) { |
| 56 |
this(); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
public static <T extends Interface<? super T>> void foo2(T a, T b) { |
| 61 |
a.compareTo(b); |
| 62 |
} |
| 63 |
|
| 64 |
public static <T extends Object & Interface<? super T>> void foo(T a, T b) { |
| 65 |
a.compareTo(b); |
| 66 |
} |
| 67 |
|
| 68 |
interface Interface<F> { |
| 69 |
void compareTo(F t); |
| 70 |
} |
| 71 |
|
| 72 |
public void m1(Class<?> c) { |
| 73 |
Class<? extends I2> x = c.asSubclass(I2.class); |
| 74 |
new WeakReference<Class<? extends I2>>(c.asSubclass(I2.class)); |
| 75 |
} |
| 76 |
|
| 77 |
interface I2 {} |
| 78 |
|
| 79 |
@Pure |
| 80 |
void bar() { |
| 81 |
bar(); |
| 82 |
} |
| 83 |
|
| 84 |
public static <Z> void copy(List<? super Z> dest, List<? extends Z> src) { |
| 85 |
dest.set(0, src.get(0)); |
| 86 |
} |
| 87 |
|
| 88 |
public static <F, E extends F> void copy2(List<? super F> dest, List<E> src) { |
| 89 |
dest.set(0, src.get(0)); |
| 90 |
} |
| 91 |
} |