langtools/test/tools/javac/MethodParametersTest.java
author sogoel
Thu, 05 Jun 2014 10:57:10 -0700
changeset 24797 850ebd4d80a7
parent 24604 7f68545b5128
child 30730 d3ce7619db2c
permissions -rw-r--r--
8044072: Group 2: create .out files for OverrideChecks tests in tools/javac dir Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15031
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
     1
/*
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 16307
diff changeset
     2
 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
15031
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
15036
b60e18ab9dd7 8005647: langtools/test/tools/javap/MethodParameters.java fails on windows
jjh
parents: 15031
diff changeset
    26
 * @bug 8004727
15031
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    27
 * @summary javac should generate method parameters correctly.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    28
 */
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    29
// key: opt.arg.parameters
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    30
import com.sun.tools.classfile.*;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    31
import com.sun.tools.javac.file.JavacFileManager;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    32
import com.sun.tools.javac.main.Main;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    33
import com.sun.tools.javac.util.Context;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    34
import com.sun.tools.javac.util.Name;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    35
import com.sun.tools.javac.util.Names;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    36
import java.io.*;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    37
import javax.lang.model.element.*;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    38
import java.util.*;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    39
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents: 15036
diff changeset
    40
public class MethodParametersTest {
15031
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    41
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    42
    static final String Foo_name = "Foo";
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    43
    static final String Foo_contents =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    44
        "public class Foo {\n" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    45
        "  Foo() {}\n" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    46
        "  void foo0() {}\n" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    47
        "  void foo2(int j, int k) {}\n" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    48
        "}";
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    49
    static final String Bar_name = "Bar";
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    50
    static final String Bar_contents =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    51
        "public class Bar {\n" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    52
        "  Bar(int i) {}" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    53
        "  Foo foo() { return new Foo(); }\n" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    54
        "}";
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    55
    static final String Baz_name = "Baz";
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    56
    static final String Baz_contents =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    57
        "public class Baz {\n" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    58
        "  int baz;" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    59
        "  Baz(int i) {}" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    60
        "}";
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    61
    static final String Qux_name = "Qux";
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    62
    static final String Qux_contents =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    63
        "public class Qux extends Baz {\n" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    64
        "  Qux(int i) { super(i); }" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    65
        "}";
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    66
    static final File classesdir = new File("methodparameters");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    67
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    68
    public static void main(String... args) throws Exception {
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents: 15036
diff changeset
    69
        new MethodParametersTest().run();
15031
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
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    72
    void run() throws Exception {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    73
        classesdir.mkdir();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    74
        final File Foo_java =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    75
            writeFile(classesdir, Foo_name + ".java", Foo_contents);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    76
        final File Bar_java =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    77
            writeFile(classesdir, Bar_name + ".java", Bar_contents);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    78
        final File Baz_java =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    79
            writeFile(classesdir, Baz_name + ".java", Baz_contents);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    80
        System.err.println("Test compile with -parameter");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    81
        compile("-parameters", "-d", classesdir.getPath(), Foo_java.getPath());
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    82
        // First test: make sure javac doesn't choke to death on
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    83
        // MethodParameter attributes
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    84
        System.err.println("Test compile with classfile containing MethodParameter attributes");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    85
        compile("-parameters", "-d", classesdir.getPath(),
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    86
                "-cp", classesdir.getPath(), Bar_java.getPath());
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    87
        System.err.println("Examine class foo");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    88
        checkFoo();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    89
        checkBar();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    90
        System.err.println("Test debug information conflict");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    91
        compile("-g", "-parameters", "-d", classesdir.getPath(),
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    92
                "-cp", classesdir.getPath(), Baz_java.getPath());
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    93
        System.err.println("Introducing debug information conflict");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    94
        Baz_java.delete();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    95
        modifyBaz(false);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    96
        System.err.println("Checking language model");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    97
        inspectBaz();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    98
        System.err.println("Permuting attributes");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
    99
        modifyBaz(true);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   100
        System.err.println("Checking language model");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   101
        inspectBaz();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   102
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   103
        if(0 != errors)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   104
            throw new Exception("MethodParameters test failed with " +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   105
                                errors + " errors");
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
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   108
    void inspectBaz() throws Exception {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   109
        final File Qux_java =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   110
            writeFile(classesdir, Qux_name + ".java", Qux_contents);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   111
        final String[] args = { "-XDsave-parameter-names", "-d",
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   112
                                classesdir.getPath(),
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   113
                                "-cp", classesdir.getPath(),
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   114
                                Qux_java.getPath() };
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   115
        final StringWriter sw = new StringWriter();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   116
        final PrintWriter pw = new PrintWriter(sw);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   117
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   118
        // 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
   119
        // structures.  We'll rig up a compiler instance, but keep its
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   120
        // Context, thus allowing us to get at the ClassReader.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   121
        Context context = new Context();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   122
        Main comp =  new Main("javac", pw);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   123
        JavacFileManager.preRegister(context);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   124
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   125
        // Compile Qux, which uses Baz.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   126
        comp.compile(args, context);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   127
        pw.close();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   128
        final String out = sw.toString();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   129
        if (out.length() > 0)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   130
            System.err.println(out);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   131
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 16307
diff changeset
   132
        // Now get the class finder, construct a name for Baz, and load it.
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 16307
diff changeset
   133
        com.sun.tools.javac.code.ClassFinder cf =
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 16307
diff changeset
   134
            com.sun.tools.javac.code.ClassFinder.instance(context);
15031
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   135
        Name name = Names.instance(context).fromString(Baz_name);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   136
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   137
        // Now walk down the language model and check the name of the
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   138
        // parameter.
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 16307
diff changeset
   139
        final Element baz = cf.loadClass(name);
15031
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   140
        for (Element e : baz.getEnclosedElements()) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   141
            if (e instanceof ExecutableElement) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   142
                final ExecutableElement ee = (ExecutableElement) e;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   143
                final List<? extends VariableElement> params =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   144
                    ee.getParameters();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   145
                if (1 != params.size())
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   146
                    throw new Exception("Classfile Baz badly formed: wrong number of methods");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   147
                final VariableElement param = params.get(0);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   148
                if (!param.getSimpleName().contentEquals("baz")) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   149
                    errors++;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   150
                    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
   151
                } else
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   152
                    System.err.println("javac did correctly resolve the metadata conflict");
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
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   157
    void modifyBaz(boolean flip) throws Exception {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   158
        final File Baz_class = new File(classesdir, Baz_name + ".class");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   159
        final ClassFile baz = ClassFile.read(Baz_class);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   160
        final int ind = baz.constant_pool.getUTF8Index("baz");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   161
        MethodParameters_attribute mpattr = null;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   162
        int mpind = 0;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   163
        Code_attribute cattr = null;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   164
        int cind = 0;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   165
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   166
        // Find the indexes of the MethodParameters and the Code attributes
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   167
        if (baz.methods.length != 1)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   168
            throw new Exception("Classfile Baz badly formed: wrong number of methods");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   169
        if (!baz.methods[0].getName(baz.constant_pool).equals("<init>"))
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   170
            throw new Exception("Classfile Baz badly formed: method has name " +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   171
                                baz.methods[0].getName(baz.constant_pool));
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   172
        for (int i = 0; i < baz.methods[0].attributes.attrs.length; i++) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   173
            if (baz.methods[0].attributes.attrs[i] instanceof
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   174
                MethodParameters_attribute) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   175
                mpattr = (MethodParameters_attribute)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   176
                    baz.methods[0].attributes.attrs[i];
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   177
                mpind = i;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   178
            } else if (baz.methods[0].attributes.attrs[i] instanceof
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   179
                       Code_attribute) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   180
                cattr = (Code_attribute) baz.methods[0].attributes.attrs[i];
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   181
                cind = i;
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
        }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   184
        if (null == mpattr)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   185
            throw new Exception("Classfile Baz badly formed: no method parameters info");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   186
        if (null == cattr)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   187
            throw new Exception("Classfile Baz badly formed: no local variable table");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   188
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   189
        int flags = mpattr.method_parameter_table[0].flags;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   190
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   191
        // Alter the MethodParameters attribute, changing the name of
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   192
        // the parameter from i to baz.  This requires Black Magic...
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   193
        //
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   194
        // The (well-designed) classfile library (correctly) does not
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   195
        // allow us to mess around with the attribute data structures,
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   196
        // or arbitrarily generate new ones.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   197
        //
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   198
        // Instead, we install a new subclass of Attribute that
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   199
        // hijacks the Visitor pattern and outputs the sequence of
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   200
        // bytes that we want.  This only works in this particular
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   201
        // instance, because we know we'll only every see one kind of
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   202
        // visitor.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   203
        //
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   204
        // If anyone ever changes the makeup of the Baz class, or
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   205
        // tries to install some kind of visitor that gets run prior
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   206
        // to serialization, this will break.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   207
        baz.methods[0].attributes.attrs[mpind] =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   208
            new Attribute(mpattr.attribute_name_index,
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   209
                          mpattr.attribute_length) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   210
                public <R, D> R accept(Visitor<R, D> visitor, D data) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   211
                    if (data instanceof ByteArrayOutputStream) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   212
                        ByteArrayOutputStream out =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   213
                            (ByteArrayOutputStream) data;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   214
                        out.write(1);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   215
                        out.write((ind >> 8) & 0xff);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   216
                        out.write(ind & 0xff);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   217
                        out.write((flags >> 24) & 0xff);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   218
                        out.write((flags >> 16) & 0xff);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   219
                        out.write((flags >> 8) & 0xff);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   220
                        out.write(flags & 0xff);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   221
                    } else
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   222
                        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
   223
                    return null;
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
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   227
        // Flip the code and method attributes.  This is for checking
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   228
        // that order doesn't matter.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   229
        if (flip) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   230
            baz.methods[0].attributes.attrs[mpind] = cattr;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   231
            baz.methods[0].attributes.attrs[cind] = mpattr;
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
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   234
        new ClassWriter().write(baz, Baz_class);
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
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   237
    // 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
   238
    void checkFoo() throws Exception {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   239
        final File Foo_class = new File(classesdir, Foo_name + ".class");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   240
        final ClassFile foo = ClassFile.read(Foo_class);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   241
        for (int i = 0; i < foo.methods.length; i++) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   242
            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
   243
            if (foo.methods[i].getName(foo.constant_pool).equals("foo2")) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   244
                for (int j = 0; j < foo.methods[i].attributes.attrs.length; j++)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   245
                    if (foo.methods[i].attributes.attrs[j] instanceof
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   246
                        MethodParameters_attribute) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   247
                        MethodParameters_attribute mp =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   248
                            (MethodParameters_attribute)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   249
                            foo.methods[i].attributes.attrs[j];
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   250
                        System.err.println("Foo.foo2 should have 2 parameters: j and k");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   251
                        if (2 != mp.method_parameter_table_length)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   252
                            error("expected 2 method parameter entries in foo2, got " +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   253
                                  mp.method_parameter_table_length);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   254
                        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
   255
                            error("expected first parameter to foo2 to be \"j\", got \"" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   256
                                  foo.constant_pool.getUTF8Value(mp.method_parameter_table[0].name_index) +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   257
                                  "\" instead");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   258
                        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
   259
                            error("expected first parameter to foo2 to be \"k\", got \"" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   260
                                  foo.constant_pool.getUTF8Value(mp.method_parameter_table[1].name_index) +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   261
                                  "\" instead");
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
            }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   264
            else if (foo.methods[i].getName(foo.constant_pool).equals("<init>")) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   265
                for (int j = 0; j < foo.methods[i].attributes.attrs.length; j++) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   266
                    if (foo.methods[i].attributes.attrs[j] instanceof
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   267
                        MethodParameters_attribute)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   268
                        error("Zero-argument constructor shouldn't have MethodParameters");
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
            }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   271
            else if (foo.methods[i].getName(foo.constant_pool).equals("foo0")) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   272
                for (int j = 0; j < foo.methods[i].attributes.attrs.length; j++)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   273
                    if (foo.methods[i].attributes.attrs[j] instanceof
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   274
                        MethodParameters_attribute)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   275
                        error("Zero-argument method shouldn't have MethodParameters");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   276
            }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   277
            else
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   278
                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
   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
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   282
    // 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
   283
    void checkBar() throws Exception {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   284
        final File Bar_class = new File(classesdir, Bar_name + ".class");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   285
        final ClassFile bar = ClassFile.read(Bar_class);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   286
        for (int i = 0; i < bar.methods.length; i++) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   287
            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
   288
            if (bar.methods[i].getName(bar.constant_pool).equals("<init>")) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   289
                for (int j = 0; j < bar.methods[i].attributes.attrs.length; j++)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   290
                    if (bar.methods[i].attributes.attrs[j] instanceof
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   291
                        MethodParameters_attribute) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   292
                        MethodParameters_attribute mp =
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   293
                            (MethodParameters_attribute)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   294
                            bar.methods[i].attributes.attrs[j];
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   295
                        System.err.println("Bar constructor should have 1 parameter: i");
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   296
                        if (1 != mp.method_parameter_table_length)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   297
                            error("expected 1 method parameter entries in constructor, got " +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   298
                                  mp.method_parameter_table_length);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   299
                        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
   300
                            error("expected first parameter to foo2 to be \"i\", got \"" +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   301
                                  bar.constant_pool.getUTF8Value(mp.method_parameter_table[0].name_index) +
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   302
                                  "\" instead");
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
            }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   305
            else if (bar.methods[i].getName(bar.constant_pool).equals("foo")) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   306
                for (int j = 0; j < bar.methods[i].attributes.attrs.length; j++) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   307
                    if (bar.methods[i].attributes.attrs[j] instanceof
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   308
                        MethodParameters_attribute)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   309
                        error("Zero-argument constructor shouldn't have MethodParameters");
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
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   315
    String compile(String... args) throws Exception {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   316
        System.err.println("compile: " + Arrays.asList(args));
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   317
        StringWriter sw = new StringWriter();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   318
        PrintWriter pw = new PrintWriter(sw);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   319
        int rc = com.sun.tools.javac.Main.compile(args, pw);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   320
        pw.close();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   321
        String out = sw.toString();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   322
        if (out.length() > 0)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   323
            System.err.println(out);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   324
        if (rc != 0)
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   325
            error("compilation failed, rc=" + rc);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   326
        return out;
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
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   329
    File writeFile(File dir, String path, String body) throws IOException {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   330
        File f = new File(dir, path);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   331
        f.getParentFile().mkdirs();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   332
        FileWriter out = new FileWriter(f);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   333
        out.write(body);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   334
        out.close();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   335
        return f;
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
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   338
    void error(String msg) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   339
        System.err.println("Error: " + msg);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   340
        errors++;
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
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   343
    int errors;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents:
diff changeset
   344
}