langtools/test/tools/javap/typeAnnotations/ArrayClassLiterals2.java
author jjg
Tue, 02 Feb 2010 10:56:10 -0800
changeset 4873 cc4a679a96a2
child 5520 86e4b9a9da40
permissions -rw-r--r--
6918625: handle annotations on array class literals Reviewed-by: jjg, darcy Contributed-by: mali@csail.mit.edu, mernst@cs.washington.edu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4873
cc4a679a96a2 6918625: handle annotations on array class literals
jjg
parents:
diff changeset
     1
/*
cc4a679a96a2 6918625: handle annotations on array class literals
jjg
parents:
diff changeset
     2
 * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
cc4a679a96a2 6918625: handle annotations on array class literals
jjg
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
cc4a679a96a2 6918625: handle annotations on array class literals
jjg
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
cc4a679a96a2 6918625: handle annotations on array class literals
jjg
parents:
diff changeset
    21
 * have any questions.
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
}