test/tools/javap/typeAnnotations/ArrayClassLiterals2.java

Tue, 25 May 2010 15:54:51 -0700

author
ohair
date
Tue, 25 May 2010 15:54:51 -0700
changeset 554
9d9f26857129
parent 485
b0a68258360a
permissions
-rw-r--r--

6943119: Rebrand source copyright notices
Reviewed-by: darcy

jjg@485 1 /*
ohair@554 2 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
jjg@485 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@485 4 *
jjg@485 5 * This code is free software; you can redistribute it and/or modify it
jjg@485 6 * under the terms of the GNU General Public License version 2 only, as
jjg@485 7 * published by the Free Software Foundation.
jjg@485 8 *
jjg@485 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@485 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@485 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@485 12 * version 2 for more details (a copy is included in the LICENSE file that
jjg@485 13 * accompanied this code).
jjg@485 14 *
jjg@485 15 * You should have received a copy of the GNU General Public License version
jjg@485 16 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@485 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@485 18 *
ohair@554 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 20 * or visit www.oracle.com if you need additional information or have any
ohair@554 21 * questions.
jjg@485 22 */
jjg@485 23
jjg@485 24 /*
jjg@485 25 * @test
jjg@485 26 * @bug 6918625
jjg@485 27 * @summary javap dumps type information of array class literals
jjg@485 28 */
jjg@485 29
jjg@485 30 import java.io.*;
jjg@485 31
jjg@485 32 public class ArrayClassLiterals2 {
jjg@485 33 public static void main(String[] args) throws Exception {
jjg@485 34 new ArrayClassLiterals2().run();
jjg@485 35 }
jjg@485 36
jjg@485 37 public void run() throws IOException {
jjg@485 38 File classFile = new File(System.getProperty("test.classes"), "ArrayClassLiterals2$Test.class");
jjg@485 39
jjg@485 40 verify(classFile,
jjg@485 41 "RuntimeInvisibleTypeAnnotations:",
jjg@485 42 "CLASS_LITERAL_GENERIC_OR_ARRAY"
jjg@485 43 );
jjg@485 44
jjg@485 45 if (errors > 0)
jjg@485 46 throw new Error(errors + " found.");
jjg@485 47 }
jjg@485 48
jjg@485 49 String javap(File f) {
jjg@485 50 StringWriter sw = new StringWriter();
jjg@485 51 PrintWriter out = new PrintWriter(sw);
jjg@485 52 int rc = com.sun.tools.javap.Main.run(new String[] { "-v", f.getPath() }, out);
jjg@485 53 if (rc != 0)
jjg@485 54 throw new Error("javap failed. rc=" + rc);
jjg@485 55 out.close();
jjg@485 56 return sw.toString();
jjg@485 57 }
jjg@485 58
jjg@485 59 void verify(File classFile, String... expects) {
jjg@485 60 String output = javap(classFile);
jjg@485 61 for (String expect: expects) {
jjg@485 62 if (output.indexOf(expect)< 0)
jjg@485 63 error(expect + " not found");
jjg@485 64 }
jjg@485 65 }
jjg@485 66
jjg@485 67 void error(String msg) {
jjg@485 68 System.err.println(msg);
jjg@485 69 errors++;
jjg@485 70 }
jjg@485 71
jjg@485 72 int errors;
jjg@485 73
jjg@485 74
jjg@485 75 /*********************** Test class *************************/
jjg@485 76 static class Test {
jjg@485 77 @interface A { }
jjg@485 78 void test() {
jjg@485 79 Object a = @A String @A [] @A [].class;
jjg@485 80 }
jjg@485 81 }
jjg@485 82 }

mercurial