Пример #1
0
 public ContextImpl(
     @NotNull JavaCompiler compiler,
     @NotNull DiagnosticOutputConsumer outConsumer,
     @NotNull OutputFileConsumer sink,
     CanceledStatus canceledStatus,
     boolean canUseOptimizedmanager) {
   myOutConsumer = outConsumer;
   myOutputFileSink = sink;
   myCanceledStatus = canceledStatus;
   StandardJavaFileManager stdManager = null;
   if (canUseOptimizedmanager) {
     final Class<StandardJavaFileManager> optimizedManagerClass =
         ClasspathBootstrap.getOptimizedFileManagerClass();
     if (optimizedManagerClass != null) {
       try {
         stdManager = optimizedManagerClass.newInstance();
       } catch (Throwable e) {
         if (SystemInfo.isWindows) {
           System.err.println(
               "Failed to load JPS optimized file manager for javac: " + e.getMessage());
         }
       }
     }
   }
   if (stdManager != null) {
     myStdManager = stdManager;
   } else {
     myStdManager = compiler.getStandardFileManager(outConsumer, Locale.US, null);
   }
 }
Пример #2
0
 public static void main(String... args) {
   try {
     JavaCompiler javac = javax.tools.ToolProvider.getSystemJavaCompiler();
     DiagnosticListener<JavaFileObject> dl =
         new DiagnosticListener<JavaFileObject>() {
           public void report(Diagnostic<? extends JavaFileObject> message) {
             throw new NullPointerException(SILLY_BILLY);
           }
         };
     StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null);
     Iterable<? extends JavaFileObject> files =
         fm.getJavaFileObjectsFromStrings(Arrays.asList("badfile.java"));
     javac.getTask(null, fm, dl, null, null, files).call();
   } catch (RuntimeException e) {
     Throwable cause = e.getCause();
     if (cause instanceof NullPointerException && cause.getMessage().equals(SILLY_BILLY)) return;
     throw new Error("unexpected exception caught: " + e);
   } catch (Throwable t) {
     throw new Error("unexpected exception caught: " + t);
   }
   throw new Error("no exception caught");
 }