Wildcards.java revision 2933:49d207bf704d
150397Sobrien/* 252284Sobrien * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved. 350397Sobrien * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 450397Sobrien * 550397Sobrien * This code is free software; you can redistribute it and/or modify it 650397Sobrien * under the terms of the GNU General Public License version 2 only, as 750397Sobrien * published by the Free Software Foundation. 850397Sobrien * 950397Sobrien * This code is distributed in the hope that it will be useful, but WITHOUT 1050397Sobrien * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1150397Sobrien * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1250397Sobrien * version 2 for more details (a copy is included in the LICENSE file that 1350397Sobrien * accompanied this code). 1450397Sobrien * 1550397Sobrien * You should have received a copy of the GNU General Public License version 1650397Sobrien * 2 along with this work; if not, write to the Free Software Foundation, 1750397Sobrien * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1850397Sobrien * 1950397Sobrien * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2050397Sobrien * or visit www.oracle.com if you need additional information or have any 2150397Sobrien * questions. 2250397Sobrien */ 2350397Sobrien 2450397Sobrienimport java.lang.annotation.*; 2550397Sobrienimport java.io.*; 2650397Sobrienimport java.net.URL; 2750397Sobrienimport java.util.List; 2850397Sobrien 2950397Sobrienimport com.sun.tools.classfile.*; 3050397Sobrien 3150397Sobrien/* 3252284Sobrien * @test Wildcards 3352284Sobrien * @bug 6843077 8006775 3450397Sobrien * @summary test that annotations target wildcards get emitted to classfile 3550397Sobrien * @modules jdk.compiler/com.sun.tools.classfile 3650397Sobrien */ 3750397Sobrienpublic class Wildcards extends ClassfileTestHelper { 3850397Sobrien public static void main(String[] args) throws Exception { 3950397Sobrien new Wildcards().run(); 4050397Sobrien } 4150397Sobrien 4250397Sobrien public void run() throws Exception { 4350397Sobrien expected_tinvisibles = 3; 4450397Sobrien expected_tvisibles = 0; 4550397Sobrien 4650397Sobrien ClassFile cf = getClassFile("Wildcards$Test.class"); 4750397Sobrien test(cf); 4850397Sobrien for (Field f : cf.fields) { 4950397Sobrien test(cf, f); 5050397Sobrien } 5150397Sobrien for (Method m: cf.methods) { 5250397Sobrien test(cf, m,false); 5350397Sobrien } 5450397Sobrien 5550397Sobrien countAnnotations(); 5650397Sobrien 5750397Sobrien if (errors > 0) 5850397Sobrien throw new Exception(errors + " errors found"); 5950397Sobrien System.out.println("PASSED"); 6050397Sobrien } 6152284Sobrien 6250397Sobrien /*********************** Test class *************************/ 6352284Sobrien static class Test { 6450397Sobrien @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) 6550397Sobrien @interface A {} 6652284Sobrien 6750397Sobrien List<? extends @A Number> f; 6850397Sobrien 6950397Sobrien List<? extends @A Object> test(List<? extends @A Number> p) { 7050397Sobrien List<? extends @A Object> l; // not counted... gets optimized away 7150397Sobrien return null; 7252284Sobrien } 7352284Sobrien } 7450397Sobrien} 7552284Sobrien