langtools/test/tools/javac/T6358166.java
changeset 26264 a09fedde76be
parent 24897 655b72d7b96e
child 30730 d3ce7619db2c
equal deleted inserted replaced
26263:5ce1fe94b270 26264:a09fedde76be
    27  * @summary -verbose reports absurd times when annotation processing involved
    27  * @summary -verbose reports absurd times when annotation processing involved
    28  */
    28  */
    29 
    29 
    30 import java.io.*;
    30 import java.io.*;
    31 import java.util.*;
    31 import java.util.*;
       
    32 
    32 import javax.annotation.processing.*;
    33 import javax.annotation.processing.*;
    33 import javax.lang.model.element.*;
    34 import javax.lang.model.element.*;
    34 import javax.tools.*;
    35 import javax.tools.*;
    35 import com.sun.tools.javac.file.*;
    36 
    36 import com.sun.tools.javac.file.JavacFileManager; // disambiguate
    37 import com.sun.tools.javac.api.JavacTaskImpl;
       
    38 import com.sun.tools.javac.api.JavacTool;
       
    39 import com.sun.tools.javac.file.JavacFileManager;
    37 import com.sun.tools.javac.main.JavaCompiler;
    40 import com.sun.tools.javac.main.JavaCompiler;
    38 import com.sun.tools.javac.main.*;
       
    39 import com.sun.tools.javac.util.*;
    41 import com.sun.tools.javac.util.*;
    40 import com.sun.tools.javac.util.List; // disambiguate
    42 import com.sun.tools.javac.util.List; // disambiguate
    41 
    43 
    42 
    44 
    43 @SupportedAnnotationTypes("*")
    45 @SupportedAnnotationTypes("*")
    56     }
    58     }
    57 
    59 
    58     static void test(JavacFileManager fm, JavaFileObject f, String... args) throws Throwable {
    60     static void test(JavacFileManager fm, JavaFileObject f, String... args) throws Throwable {
    59         Context context = new Context();
    61         Context context = new Context();
    60 
    62 
    61         Main compilerMain = initCompilerMain(context, fm, args);
    63         JavacTool tool = JavacTool.create();
       
    64         JavacTaskImpl task = (JavacTaskImpl) tool.getTask(null, fm, null, Arrays.asList(args), null, List.of(f), context);
       
    65         task.call();
    62 
    66 
    63         JavaCompiler c = JavaCompiler.instance(context);
    67         JavaCompiler c = JavaCompiler.instance(context);
    64 
       
    65         c.compile(List.of(f));
       
    66 
       
    67         if (c.errorCount() != 0)
    68         if (c.errorCount() != 0)
    68             throw new AssertionError("compilation failed");
    69             throw new AssertionError("compilation failed");
    69 
    70 
    70         long msec = c.elapsed_msec;
    71         long msec = c.elapsed_msec;
    71         if (msec < 0 || msec > 5 * 60 * 1000) // allow test 5 mins to execute, should be more than enough!
    72         if (msec < 0 || msec > 5 * 60 * 1000) // allow test 5 mins to execute, should be more than enough!
    72             throw new AssertionError("elapsed time is suspect: " + msec);
    73             throw new AssertionError("elapsed time is suspect: " + msec);
    73     }
    74     }
    74 
    75 
    75     static Main initCompilerMain(Context context, JavacFileManager fm, String... args) {
       
    76         fm.setContext(context);
       
    77         context.put(JavaFileManager.class, fm);
       
    78 
       
    79         Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
       
    80         compilerMain.setOptions(Options.instance(context));
       
    81         compilerMain.filenames = new LinkedHashSet<File>();
       
    82         compilerMain.deferredFileManagerOptions = new LinkedHashMap<>();
       
    83         compilerMain.processArgs(args);
       
    84         fm.handleOptions(compilerMain.deferredFileManagerOptions);
       
    85         return compilerMain;
       
    86     }
       
    87 
       
    88     public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
    76     public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
    89         return true;
    77         return true;
    90     }
    78     }
    91 }
    79 }