Search in sources :

Example 31 with ListBuffer

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

the class JavadocTool method parsePackageClasses.

/**
     * search all directories in path for subdirectory name. Add all
     * .java files found in such a directory to args.
     */
private void parsePackageClasses(String name, Iterable<JavaFileObject> files, ListBuffer<JCCompilationUnit> trees, List<String> excludedPackages) throws IOException {
    if (excludedPackages.contains(name)) {
        return;
    }
    boolean hasFiles = false;
    docenv.notice("main.Loading_source_files_for_package", name);
    if (files == null) {
        Location location = docenv.fileManager.hasLocation(StandardLocation.SOURCE_PATH) ? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH;
        ListBuffer<JavaFileObject> lb = new ListBuffer<JavaFileObject>();
        for (JavaFileObject fo : docenv.fileManager.list(location, name, EnumSet.of(JavaFileObject.Kind.SOURCE), false)) {
            String binaryName = docenv.fileManager.inferBinaryName(location, fo);
            String simpleName = getSimpleName(binaryName);
            if (isValidClassName(simpleName)) {
                lb.append(fo);
            }
        }
        files = lb.toList();
    }
    for (JavaFileObject fo : files) {
        // messager.notice("main.Loading_source_file", fn);
        trees.append(parse(fo));
        hasFiles = true;
    }
    if (!hasFiles) {
        messager.warning(null, "main.no_source_files_for_package", name.replace(File.separatorChar, '.'));
    }
}
Also used : JavaFileObject(javax.tools.JavaFileObject) ListBuffer(com.sun.tools.javac.util.ListBuffer) StandardLocation(javax.tools.StandardLocation) Location(javax.tools.JavaFileManager.Location)

Example 32 with ListBuffer

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

the class JavadocTool method getRootDocImpl.

public RootDocImpl getRootDocImpl(String doclocale, String encoding, ModifierFilter filter, List<String> javaNames, List<String[]> options, boolean breakiterator, List<String> subPackages, List<String> excludedPackages, boolean docClasses, boolean legacyDoclet, boolean quiet) throws IOException {
    docenv = DocEnv.instance(context);
    docenv.showAccess = filter;
    docenv.quiet = quiet;
    docenv.breakiterator = breakiterator;
    docenv.setLocale(doclocale);
    docenv.setEncoding(encoding);
    docenv.docClasses = docClasses;
    docenv.legacyDoclet = legacyDoclet;
    reader.sourceCompleter = docClasses ? null : this;
    ListBuffer<String> names = new ListBuffer<String>();
    ListBuffer<JCCompilationUnit> classTrees = new ListBuffer<JCCompilationUnit>();
    ListBuffer<JCCompilationUnit> packTrees = new ListBuffer<JCCompilationUnit>();
    try {
        StandardJavaFileManager fm = (StandardJavaFileManager) docenv.fileManager;
        for (List<String> it = javaNames; it.nonEmpty(); it = it.tail) {
            String name = it.head;
            if (!docClasses && name.endsWith(".java") && new File(name).exists()) {
                JavaFileObject fo = fm.getJavaFileObjects(name).iterator().next();
                docenv.notice("main.Loading_source_file", name);
                JCCompilationUnit tree = parse(fo);
                classTrees.append(tree);
            } else if (isValidPackageName(name)) {
                names = names.append(name);
            } else if (name.endsWith(".java")) {
                docenv.error(null, "main.file_not_found", name);
            } else {
                docenv.error(null, "main.illegal_package_name", name);
            }
        }
        if (!docClasses) {
            // Recursively search given subpackages.  If any packages
            //are found, add them to the list.
            Map<String, List<JavaFileObject>> packageFiles = searchSubPackages(subPackages, names, excludedPackages);
            // Parse the packages
            for (List<String> packs = names.toList(); packs.nonEmpty(); packs = packs.tail) {
                // Parse sources ostensibly belonging to package.
                String packageName = packs.head;
                parsePackageClasses(packageName, packageFiles.get(packageName), packTrees, excludedPackages);
            }
            if (messager.nerrors() != 0)
                return null;
            // Enter symbols for all files
            docenv.notice("main.Building_tree");
            enter.main(classTrees.toList().appendList(packTrees.toList()));
        }
    } catch (Abort ex) {
    }
    if (messager.nerrors() != 0)
        return null;
    if (docClasses)
        return new RootDocImpl(docenv, javaNames, options);
    else
        return new RootDocImpl(docenv, listClasses(classTrees.toList()), names.toList(), options);
}
Also used : JCCompilationUnit(com.sun.tools.javac.tree.JCTree.JCCompilationUnit) ListBuffer(com.sun.tools.javac.util.ListBuffer) JavaFileObject(javax.tools.JavaFileObject) Abort(com.sun.tools.javac.util.Abort) StandardJavaFileManager(javax.tools.StandardJavaFileManager) List(com.sun.tools.javac.util.List) File(java.io.File)

Example 33 with ListBuffer

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

the class ClassDocImpl method importedPackages.

/**
     * Get the list of packages declared as imported.
     * These are called "type-import-on-demand declarations" in the JLS.
     * This method is deprecated in the ClassDoc interface.
     *
     * @return an array of PackageDocImpl representing the imported packages.
     *
     * ###NOTE: the syntax supports importing all inner classes from a class as well.
     * @deprecated  Import declarations are implementation details that
     *          should not be exposed here.  In addition, this method's
     *          return type does not allow for all type-import-on-demand
     *          declarations to be returned.
     */
@Deprecated
public PackageDoc[] importedPackages() {
    // information is not available for binary classfiles
    if (tsym.sourcefile == null)
        return new PackageDoc[0];
    ListBuffer<PackageDocImpl> importedPackages = new ListBuffer<PackageDocImpl>();
    //### Add the implicit "import java.lang.*" to the result
    Names names = tsym.name.table.names;
    importedPackages.append(env.getPackageDoc(env.reader.enterPackage(names.java_lang)));
    Env<AttrContext> compenv = env.enter.getEnv(tsym);
    if (compenv == null)
        return new PackageDocImpl[0];
    for (JCTree t : compenv.toplevel.defs) {
        if (t.getTag() == JCTree.IMPORT) {
            JCTree imp = ((JCImport) t).qualid;
            if (TreeInfo.name(imp) == names.asterisk) {
                JCFieldAccess sel = (JCFieldAccess) imp;
                Symbol s = sel.selected.type.tsym;
                PackageDocImpl pdoc = env.getPackageDoc(s.packge());
                if (!importedPackages.contains(pdoc))
                    importedPackages.append(pdoc);
            }
        }
    }
    return importedPackages.toArray(new PackageDocImpl[importedPackages.length()]);
}
Also used : Names(com.sun.tools.javac.util.Names) JCImport(com.sun.tools.javac.tree.JCTree.JCImport) JCFieldAccess(com.sun.tools.javac.tree.JCTree.JCFieldAccess) Symbol(com.sun.tools.javac.code.Symbol) ListBuffer(com.sun.tools.javac.util.ListBuffer) JCTree(com.sun.tools.javac.tree.JCTree) AttrContext(com.sun.tools.javac.comp.AttrContext)

Example 34 with ListBuffer

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

the class PackageDocImpl method getClasses.

/**
     * Return a list of all classes contained in this package, including
     * member classes of those classes, and their member classes, etc.
     */
private List<ClassDocImpl> getClasses(boolean filtered) {
    if (allClasses != null && !filtered) {
        return allClasses;
    }
    if (allClassesFiltered != null && filtered) {
        return allClassesFiltered;
    }
    ListBuffer<ClassDocImpl> classes = new ListBuffer<ClassDocImpl>();
    for (Scope.Entry e = sym.members().elems; e != null; e = e.sibling) {
        if (e.sym != null) {
            ClassSymbol s = (ClassSymbol) e.sym;
            ClassDocImpl c = env.getClassDoc(s);
            if (c != null && !c.isSynthetic())
                c.addAllClasses(classes, filtered);
        }
    }
    if (filtered)
        return allClassesFiltered = classes.toList();
    else
        return allClasses = classes.toList();
}
Also used : Scope(com.sun.tools.javac.code.Scope) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) ListBuffer(com.sun.tools.javac.util.ListBuffer)

Example 35 with ListBuffer

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

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(com.sun.tools.javac.file.RelativePath.RelativeDirectory) JavaFileObject(javax.tools.JavaFileObject) ListBuffer(com.sun.tools.javac.util.ListBuffer) RelativeFile(com.sun.tools.javac.file.RelativePath.RelativeFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Aggregations

ListBuffer (com.sun.tools.javac.util.ListBuffer)88 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)54 JCStatement (com.sun.tools.javac.tree.JCTree.JCStatement)25 JCVariableDecl (com.sun.tools.javac.tree.JCTree.JCVariableDecl)25 JCTree (com.sun.tools.javac.tree.JCTree)22 JCTypeParameter (com.sun.tools.javac.tree.JCTree.JCTypeParameter)22 Name (com.sun.tools.javac.util.Name)19 JavacNode (lombok.javac.JavacNode)18 JCAnnotation (com.sun.tools.javac.tree.JCTree.JCAnnotation)17 JCBlock (com.sun.tools.javac.tree.JCTree.JCBlock)17 JavacTreeMaker (lombok.javac.JavacTreeMaker)17 JCMethodDecl (com.sun.tools.javac.tree.JCTree.JCMethodDecl)14 Type (com.redhat.ceylon.model.typechecker.model.Type)12 JCClassDecl (com.sun.tools.javac.tree.JCTree.JCClassDecl)12 JCModifiers (com.sun.tools.javac.tree.JCTree.JCModifiers)11 JCPrimitiveTypeTree (com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree)8 List (com.sun.tools.javac.util.List)7 ArrayList (java.util.ArrayList)7 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)6 ModelUtil.appliedType (com.redhat.ceylon.model.typechecker.model.ModelUtil.appliedType)6