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

Thu, 31 Aug 2017 15:17:03 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:17:03 +0800
changeset 2525
2eb010b6cb22
parent 2227
998b10c43157
parent 0
959103a6100f
permissions
-rw-r--r--

merge

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

mercurial