Search in sources :

Example 1 with Main

use of org.eclipse.ceylon.langtools.tools.javac.main.Main in project ceylon by eclipse.

the class JavacTool method getTask.

public JavacTask getTask(Writer out, JavaFileManager fileManager, DiagnosticListener<? super JavaFileObject> diagnosticListener, Iterable<String> options, Iterable<String> classes, Iterable<? extends JavaFileObject> compilationUnits, Context context) {
    try {
        ClientCodeWrapper ccw = ClientCodeWrapper.instance(context);
        if (options != null)
            for (String option : options) // null check
            option.getClass();
        if (classes != null) {
            for (String cls : classes) if (// implicit null check
            !SourceVersion.isName(cls))
                throw new IllegalArgumentException("Not a valid class name: " + cls);
        }
        if (compilationUnits != null) {
            // implicit null check
            compilationUnits = ccw.wrapJavaFileObjects(compilationUnits);
            for (JavaFileObject cu : compilationUnits) {
                if (cu.getKind() != JavaFileObject.Kind.SOURCE) {
                    String kindMsg = "Compilation unit is not of SOURCE kind: " + "\"" + cu.getName() + "\"";
                    throw new IllegalArgumentException(kindMsg);
                }
            }
        }
        if (diagnosticListener != null)
            context.put(DiagnosticListener.class, ccw.wrap(diagnosticListener));
        if (out == null)
            context.put(Log.outKey, new PrintWriter(System.err, true));
        else
            context.put(Log.outKey, new PrintWriter(out, true));
        if (fileManager == null)
            fileManager = getStandardFileManager(diagnosticListener, null, null);
        fileManager = ccw.wrap(fileManager);
        context.put(JavaFileManager.class, fileManager);
        processOptions(context, fileManager, options);
        Main compiler = new Main("javacTask", context.get(Log.outKey));
        return new JavacTaskImpl(compiler, options, context, classes, compilationUnits);
    } catch (ClientCodeException ex) {
        throw new RuntimeException(ex.getCause());
    }
}
Also used : ClientCodeException(org.eclipse.ceylon.langtools.tools.javac.util.ClientCodeException) Main(org.eclipse.ceylon.langtools.tools.javac.main.Main) PrintWriter(java.io.PrintWriter)

Aggregations

PrintWriter (java.io.PrintWriter)1 Main (org.eclipse.ceylon.langtools.tools.javac.main.Main)1 ClientCodeException (org.eclipse.ceylon.langtools.tools.javac.util.ClientCodeException)1