langtools/test/tools/javac/MethodParameters.java
author jjg
Sat, 29 Dec 2012 17:33:17 -0800
changeset 15031 c4fad55a5681
child 15036 b60e18ab9dd7
permissions -rw-r--r--
8004727: Add compiler support for parameter reflection Reviewed-by: jjg Contributed-by: eric.mccorkle@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15031
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
     1
/*
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
     4
 *
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
     8
 *
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    13
 * accompanied this code).
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    14
 *
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    18
 *
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    21
 * questions.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    22
 */
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    23
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    24
/*
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    25
 * @test
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    26
 * @summary javac should generate method parameters correctly.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    27
 */
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    28
// key: opt.arg.parameters
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    29
import com.sun.tools.classfile.*;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    30
import com.sun.tools.javac.file.JavacFileManager;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    31
import com.sun.tools.javac.main.Main;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    32
import com.sun.tools.javac.util.Context;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    33
import com.sun.tools.javac.util.Name;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    34
import com.sun.tools.javac.util.Names;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    35
import java.io.*;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    36
import javax.lang.model.element.*;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    37
import java.util.*;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    38
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    39
public class MethodParameters {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    40
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    41
    static final String Foo_name = "Foo";
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    42
    static final String Foo_contents =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    43
        "public class Foo {\n" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    44
        "  Foo() {}\n" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    45
        "  void foo0() {}\n" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    46
        "  void foo2(int j, int k) {}\n" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    47
        "}";
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    48
    static final String Bar_name = "Bar";
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    49
    static final String Bar_contents =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    50
        "public class Bar {\n" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    51
        "  Bar(int i) {}" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    52
        "  Foo foo() { return new Foo(); }\n" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    53
        "}";
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    54
    static final String Baz_name = "Baz";
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    55
    static final String Baz_contents =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    56
        "public class Baz {\n" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    57
        "  int baz;" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    58
        "  Baz(int i) {}" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    59
        "}";
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    60
    static final String Qux_name = "Qux";
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    61
    static final String Qux_contents =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    62
        "public class Qux extends Baz {\n" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    63
        "  Qux(int i) { super(i); }" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    64
        "}";
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    65
    static final File classesdir = new File("methodparameters");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    66
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    67
    public static void main(String... args) throws Exception {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    68
        new MethodParameters().run();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    69
    }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    70
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    71
    void run() throws Exception {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    72
        classesdir.mkdir();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    73
        final File Foo_java =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    74
            writeFile(classesdir, Foo_name + ".java", Foo_contents);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    75
        final File Bar_java =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    76
            writeFile(classesdir, Bar_name + ".java", Bar_contents);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    77
        final File Baz_java =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    78
            writeFile(classesdir, Baz_name + ".java", Baz_contents);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    79
        System.err.println("Test compile with -parameter");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    80
        compile("-parameters", "-d", classesdir.getPath(), Foo_java.getPath());
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    81
        // First test: make sure javac doesn't choke to death on
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    82
        // MethodParameter attributes
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    83
        System.err.println("Test compile with classfile containing MethodParameter attributes");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    84
        compile("-parameters", "-d", classesdir.getPath(),
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    85
                "-cp", classesdir.getPath(), Bar_java.getPath());
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    86
        System.err.println("Examine class foo");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    87
        checkFoo();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    88
        checkBar();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    89
        System.err.println("Test debug information conflict");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    90
        compile("-g", "-parameters", "-d", classesdir.getPath(),
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    91
                "-cp", classesdir.getPath(), Baz_java.getPath());
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    92
        System.err.println("Introducing debug information conflict");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    93
        Baz_java.delete();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    94
        modifyBaz(false);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    95
        System.err.println("Checking language model");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    96
        inspectBaz();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    97
        System.err.println("Permuting attributes");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    98
        modifyBaz(true);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    99
        System.err.println("Checking language model");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   100
        inspectBaz();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   101
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   102
        if(0 != errors)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   103
            throw new Exception("MethodParameters test failed with " +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   104
                                errors + " errors");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   105
    }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   106
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   107
    void inspectBaz() throws Exception {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   108
        final File Qux_java =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   109
            writeFile(classesdir, Qux_name + ".java", Qux_contents);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   110
        final String[] args = { "-XDsave-parameter-names", "-d",
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   111
                                classesdir.getPath(),
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   112
                                "-cp", classesdir.getPath(),
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   113
                                Qux_java.getPath() };
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   114
        final StringWriter sw = new StringWriter();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   115
        final PrintWriter pw = new PrintWriter(sw);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   116
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   117
        // We need to be able to crack open javac and look at its data
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   118
        // structures.  We'll rig up a compiler instance, but keep its
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   119
        // Context, thus allowing us to get at the ClassReader.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   120
        Context context = new Context();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   121
        Main comp =  new Main("javac", pw);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   122
        JavacFileManager.preRegister(context);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   123
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   124
        // Compile Qux, which uses Baz.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   125
        comp.compile(args, context);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   126
        pw.close();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   127
        final String out = sw.toString();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   128
        if (out.length() > 0)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   129
            System.err.println(out);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   130
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   131
        // Now get the class reader, construct a name for Baz, and load it.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   132
        com.sun.tools.javac.jvm.ClassReader cr =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   133
            com.sun.tools.javac.jvm.ClassReader.instance(context);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   134
        Name name = Names.instance(context).fromString(Baz_name);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   135
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   136
        // Now walk down the language model and check the name of the
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   137
        // parameter.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   138
        final Element baz = cr.loadClass(name);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   139
        for (Element e : baz.getEnclosedElements()) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   140
            if (e instanceof ExecutableElement) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   141
                final ExecutableElement ee = (ExecutableElement) e;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   142
                final List<? extends VariableElement> params =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   143
                    ee.getParameters();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   144
                if (1 != params.size())
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   145
                    throw new Exception("Classfile Baz badly formed: wrong number of methods");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   146
                final VariableElement param = params.get(0);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   147
                if (!param.getSimpleName().contentEquals("baz")) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   148
                    errors++;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   149
                    System.err.println("javac did not correctly resolve the metadata conflict, parameter's name reads as " + param.getSimpleName());
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   150
                } else
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   151
                    System.err.println("javac did correctly resolve the metadata conflict");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   152
            }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   153
        }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   154
    }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   155
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   156
    void modifyBaz(boolean flip) throws Exception {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   157
        final File Baz_class = new File(classesdir, Baz_name + ".class");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   158
        final ClassFile baz = ClassFile.read(Baz_class);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   159
        final int ind = baz.constant_pool.getUTF8Index("baz");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   160
        MethodParameters_attribute mpattr = null;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   161
        int mpind = 0;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   162
        Code_attribute cattr = null;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   163
        int cind = 0;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   164
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   165
        // Find the indexes of the MethodParameters and the Code attributes
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   166
        if (baz.methods.length != 1)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   167
            throw new Exception("Classfile Baz badly formed: wrong number of methods");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   168
        if (!baz.methods[0].getName(baz.constant_pool).equals("<init>"))
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   169
            throw new Exception("Classfile Baz badly formed: method has name " +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   170
                                baz.methods[0].getName(baz.constant_pool));
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   171
        for (int i = 0; i < baz.methods[0].attributes.attrs.length; i++) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   172
            if (baz.methods[0].attributes.attrs[i] instanceof
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   173
                MethodParameters_attribute) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   174
                mpattr = (MethodParameters_attribute)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   175
                    baz.methods[0].attributes.attrs[i];
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   176
                mpind = i;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   177
            } else if (baz.methods[0].attributes.attrs[i] instanceof
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   178
                       Code_attribute) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   179
                cattr = (Code_attribute) baz.methods[0].attributes.attrs[i];
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   180
                cind = i;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   181
            }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   182
        }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   183
        if (null == mpattr)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   184
            throw new Exception("Classfile Baz badly formed: no method parameters info");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   185
        if (null == cattr)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   186
            throw new Exception("Classfile Baz badly formed: no local variable table");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   187
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   188
        int flags = mpattr.method_parameter_table[0].flags;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   189
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   190
        // Alter the MethodParameters attribute, changing the name of
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   191
        // the parameter from i to baz.  This requires Black Magic...
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   192
        //
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   193
        // The (well-designed) classfile library (correctly) does not
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   194
        // allow us to mess around with the attribute data structures,
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   195
        // or arbitrarily generate new ones.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   196
        //
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   197
        // Instead, we install a new subclass of Attribute that
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   198
        // hijacks the Visitor pattern and outputs the sequence of
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   199
        // bytes that we want.  This only works in this particular
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   200
        // instance, because we know we'll only every see one kind of
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   201
        // visitor.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   202
        //
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   203
        // If anyone ever changes the makeup of the Baz class, or
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   204
        // tries to install some kind of visitor that gets run prior
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   205
        // to serialization, this will break.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   206
        baz.methods[0].attributes.attrs[mpind] =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   207
            new Attribute(mpattr.attribute_name_index,
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   208
                          mpattr.attribute_length) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   209
                public <R, D> R accept(Visitor<R, D> visitor, D data) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   210
                    if (data instanceof ByteArrayOutputStream) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   211
                        ByteArrayOutputStream out =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   212
                            (ByteArrayOutputStream) data;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   213
                        out.write(1);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   214
                        out.write((ind >> 8) & 0xff);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   215
                        out.write(ind & 0xff);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   216
                        out.write((flags >> 24) & 0xff);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   217
                        out.write((flags >> 16) & 0xff);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   218
                        out.write((flags >> 8) & 0xff);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   219
                        out.write(flags & 0xff);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   220
                    } else
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   221
                        throw new RuntimeException("Output stream is of type " + data.getClass() + ", which is not handled by this test.  Update the test and it should work.");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   222
                    return null;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   223
                }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   224
            };
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   225
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   226
        // Flip the code and method attributes.  This is for checking
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   227
        // that order doesn't matter.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   228
        if (flip) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   229
            baz.methods[0].attributes.attrs[mpind] = cattr;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   230
            baz.methods[0].attributes.attrs[cind] = mpattr;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   231
        }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   232
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   233
        new ClassWriter().write(baz, Baz_class);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   234
    }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   235
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   236
    // Run a bunch of structural tests on foo to make sure it looks right.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   237
    void checkFoo() throws Exception {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   238
        final File Foo_class = new File(classesdir, Foo_name + ".class");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   239
        final ClassFile foo = ClassFile.read(Foo_class);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   240
        for (int i = 0; i < foo.methods.length; i++) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   241
            System.err.println("Examine method Foo." + foo.methods[i].getName(foo.constant_pool));
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   242
            if (foo.methods[i].getName(foo.constant_pool).equals("foo2")) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   243
                for (int j = 0; j < foo.methods[i].attributes.attrs.length; j++)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   244
                    if (foo.methods[i].attributes.attrs[j] instanceof
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   245
                        MethodParameters_attribute) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   246
                        MethodParameters_attribute mp =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   247
                            (MethodParameters_attribute)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   248
                            foo.methods[i].attributes.attrs[j];
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   249
                        System.err.println("Foo.foo2 should have 2 parameters: j and k");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   250
                        if (2 != mp.method_parameter_table_length)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   251
                            error("expected 2 method parameter entries in foo2, got " +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   252
                                  mp.method_parameter_table_length);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   253
                        else if (!foo.constant_pool.getUTF8Value(mp.method_parameter_table[0].name_index).equals("j"))
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   254
                            error("expected first parameter to foo2 to be \"j\", got \"" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   255
                                  foo.constant_pool.getUTF8Value(mp.method_parameter_table[0].name_index) +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   256
                                  "\" instead");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   257
                        else if  (!foo.constant_pool.getUTF8Value(mp.method_parameter_table[1].name_index).equals("k"))
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   258
                            error("expected first parameter to foo2 to be \"k\", got \"" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   259
                                  foo.constant_pool.getUTF8Value(mp.method_parameter_table[1].name_index) +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   260
                                  "\" instead");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   261
                    }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   262
            }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   263
            else if (foo.methods[i].getName(foo.constant_pool).equals("<init>")) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   264
                for (int j = 0; j < foo.methods[i].attributes.attrs.length; j++) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   265
                    if (foo.methods[i].attributes.attrs[j] instanceof
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   266
                        MethodParameters_attribute)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   267
                        error("Zero-argument constructor shouldn't have MethodParameters");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   268
                }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   269
            }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   270
            else if (foo.methods[i].getName(foo.constant_pool).equals("foo0")) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   271
                for (int j = 0; j < foo.methods[i].attributes.attrs.length; j++)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   272
                    if (foo.methods[i].attributes.attrs[j] instanceof
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   273
                        MethodParameters_attribute)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   274
                        error("Zero-argument method shouldn't have MethodParameters");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   275
            }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   276
            else
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   277
                error("Unknown method " + foo.methods[i].getName(foo.constant_pool) + " showed up in class Foo");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   278
        }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   279
    }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   280
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   281
    // Run a bunch of structural tests on Bar to make sure it looks right.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   282
    void checkBar() throws Exception {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   283
        final File Bar_class = new File(classesdir, Bar_name + ".class");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   284
        final ClassFile bar = ClassFile.read(Bar_class);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   285
        for (int i = 0; i < bar.methods.length; i++) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   286
            System.err.println("Examine method Bar." + bar.methods[i].getName(bar.constant_pool));
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   287
            if (bar.methods[i].getName(bar.constant_pool).equals("<init>")) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   288
                for (int j = 0; j < bar.methods[i].attributes.attrs.length; j++)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   289
                    if (bar.methods[i].attributes.attrs[j] instanceof
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   290
                        MethodParameters_attribute) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   291
                        MethodParameters_attribute mp =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   292
                            (MethodParameters_attribute)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   293
                            bar.methods[i].attributes.attrs[j];
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   294
                        System.err.println("Bar constructor should have 1 parameter: i");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   295
                        if (1 != mp.method_parameter_table_length)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   296
                            error("expected 1 method parameter entries in constructor, got " +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   297
                                  mp.method_parameter_table_length);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   298
                        else if (!bar.constant_pool.getUTF8Value(mp.method_parameter_table[0].name_index).equals("i"))
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   299
                            error("expected first parameter to foo2 to be \"i\", got \"" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   300
                                  bar.constant_pool.getUTF8Value(mp.method_parameter_table[0].name_index) +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   301
                                  "\" instead");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   302
                    }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   303
            }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   304
            else if (bar.methods[i].getName(bar.constant_pool).equals("foo")) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   305
                for (int j = 0; j < bar.methods[i].attributes.attrs.length; j++) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   306
                    if (bar.methods[i].attributes.attrs[j] instanceof
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   307
                        MethodParameters_attribute)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   308
                        error("Zero-argument constructor shouldn't have MethodParameters");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   309
                }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   310
            }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   311
        }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   312
    }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   313
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   314
    String compile(String... args) throws Exception {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   315
        System.err.println("compile: " + Arrays.asList(args));
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   316
        StringWriter sw = new StringWriter();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   317
        PrintWriter pw = new PrintWriter(sw);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   318
        int rc = com.sun.tools.javac.Main.compile(args, pw);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   319
        pw.close();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   320
        String out = sw.toString();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   321
        if (out.length() > 0)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   322
            System.err.println(out);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   323
        if (rc != 0)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   324
            error("compilation failed, rc=" + rc);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   325
        return out;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   326
    }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   327
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   328
    File writeFile(File dir, String path, String body) throws IOException {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   329
        File f = new File(dir, path);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   330
        f.getParentFile().mkdirs();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   331
        FileWriter out = new FileWriter(f);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   332
        out.write(body);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   333
        out.close();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   334
        return f;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   335
    }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   336
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   337
    void error(String msg) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   338
        System.err.println("Error: " + msg);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   339
        errors++;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   340
    }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   341
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   342
    int errors;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   343
}