Search in sources :

Example 26 with Context

use of com.sun.tools.javac.util.Context in project ceylon-compiler by ceylon.

the class ImplementationCacheTest method main.

public static void main(String[] args) throws IOException {
    List<? extends JavaFileObject> files = Arrays.asList(new SourceFile());
    JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    JavacTask ct = (JavacTask) tool.getTask(null, null, null, null, null, files);
    Context ctx = new Context();
    JavacFileManager.preRegister(ctx);
    checkImplementationCache(ct.analyze(), Types.instance(ctx));
}
Also used : Context(com.sun.tools.javac.util.Context) JavaCompiler(javax.tools.JavaCompiler) JavacTask(com.sun.source.util.JavacTask)

Example 27 with Context

use of com.sun.tools.javac.util.Context in project ceylon-compiler by ceylon.

the class CeylonModuleRunner method compileAndRun.

private void 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);
    com.redhat.ceylon.compiler.java.launcher.Main compiler = new com.redhat.ceylon.compiler.java.launcher.Main("ceylonc");
    List<String> args = new ArrayList<>();
    //            args.add("-verbose:code");
    args.add("-g");
    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);
    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());
        }
    }
    // 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);
    }
}
Also used : Context(com.sun.tools.javac.util.Context) ArtifactContext(com.redhat.ceylon.cmr.api.ArtifactContext) Runner(org.junit.runner.Runner) ParentRunner(org.junit.runners.ParentRunner) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Main(com.redhat.ceylon.compiler.java.runtime.Main) File(java.io.File)

Example 28 with Context

use of com.sun.tools.javac.util.Context in project ceylon-compiler by ceylon.

the class ModelLoaderTests method verifyRuntimeClassLoading.

protected void verifyRuntimeClassLoading(RunnableTest test) {
    RepositoryManager repoManager = CeylonUtils.repoManager().buildManager();
    VFS vfs = new VFS();
    com.redhat.ceylon.compiler.typechecker.context.Context context = new com.redhat.ceylon.compiler.typechecker.context.Context(repoManager, vfs);
    RuntimeModuleManager moduleManager = new RuntimeModuleManager();
    context.setModules(new Modules());
    moduleManager.initCoreModules(new Modules());
    moduleManager.loadModule(AbstractModelLoader.CEYLON_LANGUAGE, Versions.CEYLON_VERSION_NUMBER, repoManager.getArtifactResult("ceylon.language", Versions.CEYLON_VERSION_NUMBER), getClass().getClassLoader());
    RuntimeModelLoader modelLoader = moduleManager.getModelLoader();
    modelLoader.setupWithNoStandardModules();
    modelLoader.loadStandardModules();
    test.test(modelLoader);
}
Also used : Context(com.sun.tools.javac.util.Context) VFS(com.redhat.ceylon.compiler.typechecker.io.VFS) RuntimeModuleManager(com.redhat.ceylon.compiler.java.runtime.model.RuntimeModuleManager) Modules(com.redhat.ceylon.model.typechecker.model.Modules) RuntimeModelLoader(com.redhat.ceylon.compiler.java.runtime.model.RuntimeModelLoader) RepositoryManager(com.redhat.ceylon.cmr.api.RepositoryManager)

Example 29 with Context

use of com.sun.tools.javac.util.Context in project ceylon-compiler by ceylon.

the class TestSymtabItems method run.

void run() throws Exception {
    Context c = new Context();
    JavacFileManager.preRegister(c);
    Symtab syms = Symtab.instance(c);
    JavacTypes types = JavacTypes.instance(c);
    // will init ClassReader.sourceCompleter
    JavaCompiler.instance(c);
    for (Field f : Symtab.class.getDeclaredFields()) {
        // during API evolution
        if (f.getName().toLowerCase().contains("methodhandle"))
            continue;
        Class<?> ft = f.getType();
        if (TypeMirror.class.isAssignableFrom(ft))
            print(f.getName(), (TypeMirror) f.get(syms), types);
        else if (Element.class.isAssignableFrom(ft))
            print(f.getName(), (Element) f.get(syms));
    }
    if (errors > 0)
        throw new Exception(errors + " errors occurred");
}
Also used : Context(com.sun.tools.javac.util.Context) Symtab(com.sun.tools.javac.code.Symtab) JavacTypes(com.sun.tools.javac.model.JavacTypes) Field(java.lang.reflect.Field) TypeMirror(javax.lang.model.type.TypeMirror) PackageElement(javax.lang.model.element.PackageElement) ExecutableElement(javax.lang.model.element.ExecutableElement) VariableElement(javax.lang.model.element.VariableElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) TypeParameterElement(javax.lang.model.element.TypeParameterElement) UnknownTypeException(javax.lang.model.type.UnknownTypeException) UnknownElementException(javax.lang.model.element.UnknownElementException)

Example 30 with Context

use of com.sun.tools.javac.util.Context in project ceylon-compiler by ceylon.

the class MakeLiteralTest method run.

void run() throws Exception {
    Context context = new Context();
    JavacFileManager.preRegister(context);
    Symtab syms = Symtab.instance(context);
    maker = TreeMaker.instance(context);
    types = Types.instance(context);
    test("abc", CLASS, syms.stringType, "abc");
    test(Boolean.FALSE, BOOLEAN, syms.booleanType, Integer.valueOf(0));
    test(Boolean.TRUE, BOOLEAN, syms.booleanType, Integer.valueOf(1));
    test(Byte.valueOf((byte) 1), BYTE, syms.byteType, Byte.valueOf((byte) 1));
    test(Character.valueOf('a'), CHAR, syms.charType, Integer.valueOf('a'));
    test(Double.valueOf(1d), DOUBLE, syms.doubleType, Double.valueOf(1d));
    test(Float.valueOf(1f), FLOAT, syms.floatType, Float.valueOf(1f));
    test(Integer.valueOf(1), INT, syms.intType, Integer.valueOf(1));
    test(Long.valueOf(1), LONG, syms.longType, Long.valueOf(1));
    test(Short.valueOf((short) 1), SHORT, syms.shortType, Short.valueOf((short) 1));
    if (errors > 0)
        throw new Exception(errors + " errors found");
}
Also used : Context(com.sun.tools.javac.util.Context) Symtab(com.sun.tools.javac.code.Symtab)

Aggregations

Context (com.sun.tools.javac.util.Context)65 JavacFileManager (com.sun.tools.javac.file.JavacFileManager)19 Test (org.junit.Test)9 Options (com.sun.tools.javac.util.Options)8 IOException (java.io.IOException)8 PrintWriter (java.io.PrintWriter)8 JavaFileObject (javax.tools.JavaFileObject)7 ListBuffer (com.sun.tools.javac.util.ListBuffer)6 JavacTask (com.sun.source.util.JavacTask)5 JavacProcessingEnvironment (com.sun.tools.javac.processing.JavacProcessingEnvironment)5 JCCompilationUnit (com.sun.tools.javac.tree.JCTree.JCCompilationUnit)5 JavaFileManager (javax.tools.JavaFileManager)5 OutputStreamWriter (java.io.OutputStreamWriter)4 Path (java.nio.file.Path)4 DiagnosticListener (javax.tools.DiagnosticListener)4 ImmutableList (com.google.common.collect.ImmutableList)3 JavacTaskImpl (com.sun.tools.javac.api.JavacTaskImpl)3 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)3 JCVariableDecl (com.sun.tools.javac.tree.JCTree.JCVariableDecl)3 StringWriter (java.io.StringWriter)3