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