TargetTypes.java revision 3233:b5d08bc0d224
1/* 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24package pkg; 25 26import java.lang.annotation.*; 27import static java.lang.annotation.ElementType.*; 28import static java.lang.annotation.RetentionPolicy.*; 29 30import java.util.*; 31import java.io.*; 32 33/* 34 * @summary compiler accepts all values 35 * @author Mahmood Ali 36 * @author Yuri Gaevsky 37 */ 38 39@Target(TYPE_USE) 40@Retention(RetentionPolicy.RUNTIME) 41@interface A {} 42 43@Target(TYPE_USE) 44@Retention(RetentionPolicy.RUNTIME) 45@Documented 46@interface DA {} 47 48@Target(TYPE_PARAMETER) 49@Retention(RetentionPolicy.RUNTIME) 50@Documented 51@interface DTPA {} 52 53/** typecast */ 54class T0x00 { 55 void m0x00(Long l1) { 56 Object l2 = (@A @DA Long) l1; 57 } 58} 59 60/** typecast generic/array */ 61class T0x01<T> { 62 void m0x01(List<T> list) { 63 List<T> l = (List<@A @DA T>) list; 64 } 65} 66 67/** instanceof */ 68class T0x02 { 69 boolean m0x02(String s) { 70 return (s instanceof @A @DA String); 71 } 72} 73 74/** type test (instanceof) generic/array */ 75class T0x03<T> { 76 void m0x03(T typeObj, Object obj) { 77 boolean ok = obj instanceof String @A @DA []; 78 } 79} 80 81/** object creation (new) */ 82class T0x04 { 83 void m0x04() { 84 new @A @DA ArrayList<String>(); 85 } 86} 87 88/** object creation (new) generic/array */ 89class T0x05<T> { 90 void m0x05() { 91 new ArrayList<@A @DA T>(); 92 } 93} 94 95/** method receiver */ 96class T0x06 { 97 void m0x06(@A @DA T0x06 this) {} 98} 99 100/** local variable */ 101class T0x08 { 102 void m0x08() { 103 @A @DA String s = null; 104 } 105} 106 107/** local variable generic/array */ 108class T0x09<T> { 109 void g() { 110 List<@A @DA String> l = null; 111 } 112 113 void a() { 114 String @A @DA [] as = null; 115 } 116} 117 118/** method return type generic/array */ 119class T0x0B { 120 Class<@A @DA Object> m0x0B() { return null; } 121} 122 123/** method parameter generic/array */ 124class T0x0D { 125 void m0x0D(HashMap<@A @DA Object, List<@A @DA List<@A @DA Class>>> s1) {} 126} 127 128/** field generic/array */ 129class T0x0F { 130 HashMap<@A @DA Object, @A @DA Object> c1; 131} 132 133/** class type parameter bound */ 134class T0x10<T extends @A @DA Cloneable> { 135} 136 137class T0x10A<T extends @A @DA Object> { 138} 139 140/** class type parameter bound generic/array */ 141class T0x11<T extends List<@A @DA T>> { 142} 143 144/** method type parameter bound */ 145class T0x12<T> { 146 <T extends @A @DA Cloneable> void m0x12() {} 147} 148 149/** method type parameter bound generic/array */ 150class T0x13 { 151 static <T extends Comparable<@A @DA T>> T m0x13() { 152 return null; 153 } 154} 155 156/** class extends/implements */ 157class T0x14 extends @A @DA Thread implements @A @DA Serializable, @A @DA Cloneable { 158} 159 160/** class extends/implements generic/array */ 161class T0x15<T> extends ArrayList<@A @DA T> { 162} 163 164/** exception type in throws */ 165class T0x16 { 166 void m0x16() throws @A @DA Exception {} 167} 168 169/** type argument in constructor call */ 170class T0x18<T> { 171 <T> T0x18() {} 172 173 void m() { 174 new <@A @DA Integer> T0x18(); 175 } 176} 177 178/** type argument in constructor call generic/array */ 179class T0x19 { 180 <T> T0x19() {} 181 182 void g() { 183 new <List<@A @DA String>> T0x19(); 184 } 185} 186 187/** type argument in method call */ 188class T0x1A<T,U> { 189 public static <T, U> T m() { return null; } 190 static void m0x1A() { 191 T0x1A.<@A @DA Integer, @A @DA Short>m(); 192 } 193} 194 195/** type argument in method call generic/array */ 196class T0x1B<T> { 197 void m0x1B() { 198 Collections.<T @A @DA []>emptyList(); 199 } 200} 201 202/** wildcard bound */ 203class T0x1C { 204 void m0x1C(List<? extends @A @DA String> lst) {} 205} 206 207/** wildcard bound generic/array */ 208class T0x1D<T> { 209 void m0x1D(List<? extends @A @DA List<int[]>> lst) {} 210} 211 212/** method type parameter */ 213class T0x20 { 214 <@A @DA T> void m0x20() {} 215} 216 217class T0x20A { 218 <@A @DTPA T> void m0x20A() {} 219} 220 221class T0x20B { 222 <T> void m0x20B(@A @DA T p) {} 223} 224 225/** class type parameter */ 226class T0x22<@A @DA T> { 227} 228 229class T0x22A<@A @DTPA T> { 230} 231 232class T0x22B<T> { 233 @A @DA T f; 234} 235