Search in sources :

Example 6 with Context

use of org.eclipse.ceylon.langtools.tools.javac.util.Context in project ceylon by eclipse.

the class Main method compile.

/**
 * Programmatic interface for main function.
 * @param args The command line parameters.
 */
@Override
public Result compile(String[] args) {
    Context context = new Context();
    // can't create it until Log
    CeyloncFileManager.preRegister(context);
    // has been set up
    CeylonLog.preRegister(context);
    Result result = compile(args, context);
    if (fileManager instanceof JavacFileManager) {
        // A fresh context was created above, so jfm must be a
        // JavacFileManager
        ((JavacFileManager) fileManager).close();
    }
    return result;
}
Also used : Context(org.eclipse.ceylon.langtools.tools.javac.util.Context) JavacFileManager(org.eclipse.ceylon.langtools.tools.javac.file.JavacFileManager) Result(org.eclipse.ceylon.langtools.tools.javac.main.Main.Result)

Example 7 with Context

use of org.eclipse.ceylon.langtools.tools.javac.util.Context in project ceylon by eclipse.

the class CeylonModuleRunner method compileAndRun.

private boolean compileAndRun(File srcDir, File resDir, File outRepo, String[] modules, String[] dependencies, String[] options, Set<String> removeAtRuntime, String[] modulesUsingCheckFunction, String[] modulesUsingCheckModule) throws Exception {
    // Compile all the .ceylon files into a .car
    Context context = new Context();
    final ErrorCollector listener = new ErrorCollector();
    // can't create it until Log
    CeyloncFileManager.preRegister(context);
    // has been set up
    CeylonLog.preRegister(context);
    context.put(DiagnosticListener.class, listener);
    org.eclipse.ceylon.compiler.java.launcher.Main compiler = new org.eclipse.ceylon.compiler.java.launcher.Main("ceylonc");
    List<String> args = new ArrayList<>();
    // args.add("-verbose:code");
    args.add("-g");
    args.add("-sysrep");
    args.add("../dist/dist/repo");
    args.add("-src");
    args.add(srcDir.getCanonicalPath());
    args.add("-res");
    args.add(resDir.getCanonicalPath());
    args.add("-out");
    args.add(outRepo.getAbsolutePath());
    for (String option : options) {
        args.add(option);
    }
    for (String module : modules) args.add(module);
    for (String module : dependencies) args.add(module);
    Result result = compiler.compile(args.toArray(new String[args.size()]), context);
    TreeSet<CompilerError> errors = listener.get(Kind.ERROR);
    if (!errors.isEmpty()) {
        List<Runner> errorRunners = new LinkedList<Runner>();
        for (final CompilerError compileError : errors) {
            createFailingTest(errorRunners, compileError.filename, new CompilationException(compileError.toString()));
        }
        for (Runner errorRunner : errorRunners) {
            children.put(errorRunner, errorRunner.getDescription());
        }
        // absolutely no point going on if we have errors
        return false;
    }
    // for invalid options we don't get errors from the listener
    if (!result.isOK()) {
        List<Runner> errorRunners = new LinkedList<Runner>();
        createFailingTest(errorRunners, "Invalid option?", new CompilationException("Invalid option? Check stdout."));
        for (Runner errorRunner : errorRunners) {
            children.put(errorRunner, errorRunner.getDescription());
        }
        // absolutely no point going on if we have errors
        return false;
    }
    // remove what we need for runtime
    for (String module : removeAtRuntime) {
        File moduleFolder = new File(outRepo, module.replace('.', File.separatorChar));
        FileUtil.delete(moduleFolder);
    }
    for (String module : modules) {
        postCompile(context, listener, module, srcDir, dependencies, removeAtRuntime, modulesUsingCheckFunction, modulesUsingCheckModule);
    }
    return true;
}
Also used : ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) Context(org.eclipse.ceylon.langtools.tools.javac.util.Context) Runner(org.junit.runner.Runner) ParentRunner(org.junit.runners.ParentRunner) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Result(org.eclipse.ceylon.langtools.tools.javac.main.Main.Result) File(java.io.File)

Example 8 with Context

use of org.eclipse.ceylon.langtools.tools.javac.util.Context in project ceylon by eclipse.

the class LanguageCompiler method getPhasedUnitsInstance.

/**
 * Get the PhasedUnits instance for this context.
 */
public static PhasedUnits getPhasedUnitsInstance(final Context context) {
    PhasedUnits phasedUnits = context.get(phasedUnitsKey);
    if (phasedUnits == null) {
        org.eclipse.ceylon.compiler.typechecker.context.Context ceylonContext = getCeylonContextInstance(context);
        phasedUnits = new PhasedUnits(ceylonContext, new ModuleManagerFactory() {

            @Override
            public ModuleManager createModuleManager(org.eclipse.ceylon.compiler.typechecker.context.Context ceylonContext) {
                CompilerDelegate phasedUnitsManager = getCompilerDelegate(context);
                return phasedUnitsManager.getModuleManager();
            }

            @Override
            public ModuleSourceMapper createModuleManagerUtil(org.eclipse.ceylon.compiler.typechecker.context.Context ceylonContext, ModuleManager moduleManager) {
                CompilerDelegate phasedUnitsManager = getCompilerDelegate(context);
                return phasedUnitsManager.getModuleSourceMapper();
            }
        });
        context.put(phasedUnitsKey, phasedUnits);
    }
    return phasedUnits;
}
Also used : ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) AttrContext(org.eclipse.ceylon.langtools.tools.javac.comp.AttrContext) Context(org.eclipse.ceylon.langtools.tools.javac.util.Context) PhasedUnits(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits) ModuleManagerFactory(org.eclipse.ceylon.compiler.typechecker.util.ModuleManagerFactory) ModuleManager(org.eclipse.ceylon.model.typechecker.util.ModuleManager)

Example 9 with Context

use of org.eclipse.ceylon.langtools.tools.javac.util.Context in project ceylon by eclipse.

the class CeyloncTool method getTask.

public CeyloncTaskImpl getTask(Writer out, JavaFileManager fileManager, DiagnosticListener<? super JavaFileObject> diagnosticListener, Iterable<String> options, Iterable<String> classes, Iterable<? extends JavaFileObject> compilationUnits) {
    // final String kindMsg = "All compilation units must be of SOURCE kind";
    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) && // FIX for ceylon because default is not a valid name for Java
        !"default".equals(cls))
            throw new IllegalArgumentException("Not a valid class name: " + cls);
    }
    if (fileManager == null)
        fileManager = getStandardFileManager(out, diagnosticListener, null, null);
    Context context = ((CeyloncFileManager) fileManager).getContext();
    if (diagnosticListener != null && context.get(DiagnosticListener.class) == null)
        context.put(DiagnosticListener.class, diagnosticListener);
    context.put(JavaFileManager.class, fileManager);
    JavacTool.processOptions(context, fileManager, options);
    Main compiler = new Main("ceyloncTask", context.get(Log.outKey));
    return new CeyloncTaskImpl(compiler, options, context, classes, compilationUnits);
}
Also used : Context(org.eclipse.ceylon.langtools.tools.javac.util.Context) DiagnosticListener(org.eclipse.ceylon.javax.tools.DiagnosticListener) Main(org.eclipse.ceylon.compiler.java.launcher.Main)

Example 10 with Context

use of org.eclipse.ceylon.langtools.tools.javac.util.Context in project ceylon by eclipse.

the class JavacTask method instance.

/**
 * Get the {@code JavacTask} for a {@code ProcessingEnvironment}.
 * If the compiler is being invoked using a
 * {@link org.eclipse.ceylon.javax.tools.JavaCompiler.CompilationTask CompilationTask},
 * then that task will be returned.
 * @param processingEnvironment the processing environment
 * @return the {@code JavacTask} for a {@code ProcessingEnvironment}
 * @since 1.8
 */
public static JavacTask instance(ProcessingEnvironment processingEnvironment) {
    if (!processingEnvironment.getClass().getName().equals("org.eclipse.ceylon.langtools.tools.javac.processing.JavacProcessingEnvironment"))
        throw new IllegalArgumentException();
    Context c = ((JavacProcessingEnvironment) processingEnvironment).getContext();
    JavacTask t = c.get(JavacTask.class);
    return (t != null) ? t : new BasicJavacTask(c, true);
}
Also used : Context(org.eclipse.ceylon.langtools.tools.javac.util.Context) BasicJavacTask(org.eclipse.ceylon.langtools.tools.javac.api.BasicJavacTask) JavacProcessingEnvironment(org.eclipse.ceylon.langtools.tools.javac.processing.JavacProcessingEnvironment) BasicJavacTask(org.eclipse.ceylon.langtools.tools.javac.api.BasicJavacTask)

Aggregations

Context (org.eclipse.ceylon.langtools.tools.javac.util.Context)11 File (java.io.File)2 PrintWriter (java.io.PrintWriter)2 ArrayList (java.util.ArrayList)2 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)2 Main (org.eclipse.ceylon.compiler.java.launcher.Main)2 RuntimeModelLoader (org.eclipse.ceylon.compiler.java.runtime.model.RuntimeModelLoader)2 RuntimeModuleManager (org.eclipse.ceylon.compiler.java.runtime.model.RuntimeModuleManager)2 PhasedUnits (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits)2 DiagnosticListener (org.eclipse.ceylon.javax.tools.DiagnosticListener)2 TaskEvent (org.eclipse.ceylon.langtools.source.util.TaskEvent)2 TaskListener (org.eclipse.ceylon.langtools.source.util.TaskListener)2 JavacTaskImpl (org.eclipse.ceylon.langtools.tools.javac.api.JavacTaskImpl)2 JavacFileManager (org.eclipse.ceylon.langtools.tools.javac.file.JavacFileManager)2 Result (org.eclipse.ceylon.langtools.tools.javac.main.Main.Result)2 Modules (org.eclipse.ceylon.model.typechecker.model.Modules)2 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1