test/tools/javac/annotations/typeAnnotations/TargetTypes.java

Wed, 23 Jan 2013 13:27:24 -0800

author
jjg
date
Wed, 23 Jan 2013 13:27:24 -0800
changeset 1521
71f35e4b93a5
child 1534
bec996065c45
permissions
-rw-r--r--

8006775: JSR 308: Compiler changes in JDK8
Reviewed-by: jjg
Contributed-by: mernst@cs.washington.edu, wmdietl@cs.washington.edu, mpapi@csail.mit.edu, mahmood@notnoop.com

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

mercurial