test/langtools/tools/javac/annotations/typeAnnotations/classfile/ClassfileTestHelper.java
changeset 59285 7799a51dbe30
parent 47216 71c04702a3d5
equal deleted inserted replaced
59284:88502b1cf76f 59285:7799a51dbe30
     1 /*
     1 /*
     2  * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    25 import java.io.*;
    25 import java.io.*;
    26 import java.net.URL;
    26 import java.net.URL;
    27 import java.util.List;
    27 import java.util.List;
    28 
    28 
    29 import com.sun.tools.classfile.*;
    29 import com.sun.tools.classfile.*;
       
    30 import java.util.ArrayList;
    30 
    31 
    31 public class ClassfileTestHelper {
    32 public class ClassfileTestHelper {
    32     int expected_tinvisibles = 0;
    33     int expected_tinvisibles = 0;
    33     int expected_tvisibles = 0;
    34     int expected_tvisibles = 0;
    34     int expected_invisibles = 0;
    35     int expected_invisibles = 0;
    35     int expected_visibles = 0;
    36     int expected_visibles = 0;
       
    37     List<String> extraOptions = List.of();
    36 
    38 
    37     //Makes debugging much easier. Set to 'false' for less output.
    39     //Makes debugging much easier. Set to 'false' for less output.
    38     public Boolean verbose = true;
    40     public Boolean verbose = true;
    39     void println(String msg) { if (verbose) System.err.println(msg); }
    41     void println(String msg) { if (verbose) System.err.println(msg); }
    40     void print(String msg) { if (verbose) System.err.print(msg); }
    42     void print(String msg) { if (verbose) System.err.print(msg); }
    46         out.close();
    48         out.close();
    47         return f;
    49         return f;
    48     }
    50     }
    49 
    51 
    50     File compile(File f) {
    52     File compile(File f) {
    51         int rc = com.sun.tools.javac.Main.compile(new String[] {
    53         List<String> options = new ArrayList<>(List.of("-g", f.getPath()));
    52                 "-g", f.getPath() });
    54         options.addAll(extraOptions);
       
    55         int rc = com.sun.tools.javac.Main.compile(options.toArray(new String[0]));
    53         if (rc != 0)
    56         if (rc != 0)
    54             throw new Error("compilation failed. rc=" + rc);
    57             throw new Error("compilation failed. rc=" + rc);
    55         String path = f.getPath();
    58         String path = f.getPath();
    56         return new File(path.substring(0, path.length() - 5) + ".class");
    59         return new File(path.substring(0, path.length() - 5) + ".class");
    57     }
    60     }