test/tools/javac/annotations/typeAnnotations/classfile/ClassfileTestHelper.java

Print this page




  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  */
  23 
  24 import java.lang.annotation.*;
  25 import java.io.*;
  26 import java.net.URL;
  27 import java.util.List;
  28 
  29 import com.sun.tools.classfile.*;
  30 
  31 public class ClassfileTestHelper {
  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);




  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  */
  23 
  24 import java.lang.annotation.*;
  25 import java.io.*;
  26 import java.net.URL;
  27 import java.util.List;
  28 
  29 import com.sun.tools.classfile.*;
  30 
  31 public class ClassfileTestHelper {
  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.err.println(msg); }
  40     void print(String msg) { if (verbose) System.err.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);