Search in sources :

Example 36 with JavaFileObject

use of org.eclipse.ceylon.javax.tools.JavaFileObject in project ceylon by eclipse.

the class Todo method removeByFile.

private void removeByFile(Env<AttrContext> env) {
    JavaFileObject file = env.toplevel.sourcefile;
    FileQueue fq = fileMap.get(file);
    if (fq == null)
        return;
    if (fq.fileContents.remove(env)) {
        if (fq.isEmpty()) {
            fileMap.remove(file);
            contentsByFile.remove(fq);
        }
    }
}
Also used : JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject)

Example 37 with JavaFileObject

use of org.eclipse.ceylon.javax.tools.JavaFileObject in project ceylon by eclipse.

the class Enter method visitTopLevel.

@Override
public void visitTopLevel(JCCompilationUnit tree) {
    JavaFileObject prev = log.useSource(tree.sourcefile);
    boolean addEnv = false;
    boolean isPkgInfo = tree.sourcefile.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE);
    if (tree.pid != null) {
        tree.packge = reader.enterPackage(TreeInfo.fullName(tree.pid));
        if (tree.packageAnnotations.nonEmpty() || pkginfoOpt == PkgInfo.ALWAYS) {
            if (isPkgInfo) {
                addEnv = true;
            } else if (tree.packageAnnotations.nonEmpty()) {
                log.error(tree.packageAnnotations.head.pos(), "pkg.annotations.sb.in.package-info.java");
            }
        }
    } else {
        tree.packge = syms.unnamedPackage;
    }
    // Find all classes in package.
    tree.packge.complete();
    Env<AttrContext> topEnv = topLevelEnv(tree);
    // Save environment of package-info.java file.
    if (isPkgInfo) {
        Env<AttrContext> env0 = typeEnvs.get(tree.packge);
        if (env0 == null) {
            typeEnvs.put(tree.packge, topEnv);
        } else {
            JCCompilationUnit tree0 = env0.toplevel;
            if (!fileManager.isSameFile(tree.sourcefile, tree0.sourcefile)) {
                log.warning(tree.pid != null ? tree.pid.pos() : null, "pkg-info.already.seen", tree.packge);
                if (addEnv || (tree0.packageAnnotations.isEmpty())) {
                    typeEnvs.put(tree.packge, topEnv);
                }
            }
        }
        for (Symbol q = tree.packge; q != null && q.kind == PCK; q = q.owner) q.flags_field |= EXISTS;
        Name name = names.package_info;
        ClassSymbol c = reader.enterClass(name, tree.packge);
        c.flatname = names.fromString(tree.packge + "." + name);
        c.sourcefile = tree.sourcefile;
        c.completer = null;
        c.members_field = new Scope(c);
        tree.packge.package_info = c;
    }
    classEnter(tree.defs, topEnv);
    if (addEnv) {
        todo.append(topEnv);
    }
    log.useSource(prev);
    result = null;
}
Also used : JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) Scope(org.eclipse.ceylon.langtools.tools.javac.code.Scope) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Example 38 with JavaFileObject

use of org.eclipse.ceylon.javax.tools.JavaFileObject in project ceylon by eclipse.

the class Attr method attribExprToTree.

public Env<AttrContext> attribExprToTree(JCTree expr, Env<AttrContext> env, JCTree tree) {
    breakTree = tree;
    JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
    try {
        attribExpr(expr, env);
    } catch (BreakAttr b) {
        return b.env;
    } catch (AssertionError ae) {
        if (ae.getCause() instanceof BreakAttr) {
            return ((BreakAttr) (ae.getCause())).env;
        } else {
            throw ae;
        }
    } finally {
        breakTree = null;
        log.useSource(prev);
    }
    return env;
}
Also used : JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject)

Example 39 with JavaFileObject

use of org.eclipse.ceylon.javax.tools.JavaFileObject in project ceylon by eclipse.

the class JavacFileManager method list.

public Iterable<JavaFileObject> list(Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse) throws IOException {
    // validatePackageName(packageName);
    nullCheck(packageName);
    nullCheck(kinds);
    Iterable<? extends File> path = getLocation(location);
    if (path == null)
        return List.nil();
    RelativeDirectory subdirectory = RelativeDirectory.forPackage(packageName);
    ListBuffer<JavaFileObject> results = new ListBuffer<JavaFileObject>();
    for (File directory : path) listContainer(directory, subdirectory, kinds, recurse, results);
    return results.toList();
}
Also used : RelativeDirectory(org.eclipse.ceylon.langtools.tools.javac.file.RelativePath.RelativeDirectory) JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) ListBuffer(org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer) RelativeFile(org.eclipse.ceylon.langtools.tools.javac.file.RelativePath.RelativeFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 40 with JavaFileObject

use of org.eclipse.ceylon.javax.tools.JavaFileObject in project ceylon by eclipse.

the class JavacFileManager method listDirectory.

/**
 * Insert all files in subdirectory subdirectory of directory directory
 * which match fileKinds into resultList
 */
private void listDirectory(File directory, RelativeDirectory subdirectory, Set<JavaFileObject.Kind> fileKinds, boolean recurse, ListBuffer<JavaFileObject> resultList) {
    File d = subdirectory.getFile(directory);
    if (!caseMapCheck(d, subdirectory))
        return;
    File[] files = d.listFiles();
    if (files == null)
        return;
    if (sortFiles != null)
        Arrays.sort(files, sortFiles);
    for (File f : files) {
        String fname = f.getName();
        if (f.isDirectory()) {
            if (recurse && isValidDirectory(fname)) {
                listDirectory(directory, new RelativeDirectory(subdirectory, fname), fileKinds, recurse, resultList);
            }
        } else {
            if (isValidFile(fname, fileKinds)) {
                JavaFileObject fe = new RegularFileObject(this, fname, new File(d, fname));
                resultList.append(fe);
            }
        }
    }
}
Also used : RelativeDirectory(org.eclipse.ceylon.langtools.tools.javac.file.RelativePath.RelativeDirectory) JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) RelativeFile(org.eclipse.ceylon.langtools.tools.javac.file.RelativePath.RelativeFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Aggregations

JavaFileObject (org.eclipse.ceylon.javax.tools.JavaFileObject)53 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)9 File (java.io.File)8 IOException (java.io.IOException)8 HashSet (java.util.HashSet)8 CeylonFileObject (org.eclipse.ceylon.compiler.java.codegen.CeylonFileObject)5 TaskEvent (org.eclipse.ceylon.langtools.source.util.TaskEvent)5 Symbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol)5 Type (org.eclipse.ceylon.langtools.tools.javac.code.Type)5 InputStream (java.io.InputStream)4 ListBuffer (org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer)4 LinkedHashSet (java.util.LinkedHashSet)3 VirtualFile (org.eclipse.ceylon.compiler.typechecker.io.VirtualFile)3 JavacFileManager (org.eclipse.ceylon.langtools.tools.javac.file.JavacFileManager)3 JCCompilationUnit (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit)3 FileInputStream (java.io.FileInputStream)2 OutputStream (java.io.OutputStream)2 PrintWriter (java.io.PrintWriter)2 ByteBuffer (java.nio.ByteBuffer)2 CharBuffer (java.nio.CharBuffer)2