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