1 /*
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
32 int expected_tinvisibles = 0;
33 int expected_tvisibles = 0;
34 int expected_invisibles = 0;
35 int expected_visibles = 0;
36
37 //Makes debugging much easier. Set to 'false' for less output.
38 public Boolean verbose = true;
39 void println(String msg) { if (verbose) System.out.println(msg); }
40 void print(String msg) { if (verbose) System.out.print(msg); }
41
42 File writeTestFile(String fname, String source) throws IOException {
43 File f = new File(fname);
44 PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)));
45 out.println(source);
46 out.close();
47 return f;
48 }
49
50 File compile(File f) {
51 int rc = com.sun.tools.javac.Main.compile(new String[] {
52 "-source", "1.8", "-g", f.getPath() });
53 if (rc != 0)
54 throw new Error("compilation failed. rc=" + rc);
55 String path = f.getPath();
56 return new File(path.substring(0, path.length() - 5) + ".class");
57 }
58
59 ClassFile getClassFile(String name) throws IOException, ConstantPoolException {
60 URL url = getClass().getResource(name);
61 InputStream in = url.openStream();
62 try {
63 return ClassFile.read(in);
64 } finally {
65 in.close();
66 }
67 }
68
69 ClassFile getClassFile(URL url) throws IOException, ConstantPoolException {
70 InputStream in = url.openStream();
71 try {
72 return ClassFile.read(in);
|
1 /*
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
32 int expected_tinvisibles = 0;
33 int expected_tvisibles = 0;
34 int expected_invisibles = 0;
35 int expected_visibles = 0;
36
37 //Makes debugging much easier. Set to 'false' for less output.
38 public Boolean verbose = true;
39 void println(String msg) { if (verbose) System.out.println(msg); }
40 void print(String msg) { if (verbose) System.out.print(msg); }
41
42 File writeTestFile(String fname, String source) throws IOException {
43 File f = new File(fname);
44 PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)));
45 out.println(source);
46 out.close();
47 return f;
48 }
49
50 File compile(File f) {
51 int rc = com.sun.tools.javac.Main.compile(new String[] {
52 "-g", f.getPath() });
53 if (rc != 0)
54 throw new Error("compilation failed. rc=" + rc);
55 String path = f.getPath();
56 return new File(path.substring(0, path.length() - 5) + ".class");
57 }
58
59 ClassFile getClassFile(String name) throws IOException, ConstantPoolException {
60 URL url = getClass().getResource(name);
61 InputStream in = url.openStream();
62 try {
63 return ClassFile.read(in);
64 } finally {
65 in.close();
66 }
67 }
68
69 ClassFile getClassFile(URL url) throws IOException, ConstantPoolException {
70 InputStream in = url.openStream();
71 try {
72 return ClassFile.read(in);
|