Java Code Examples for com.sun.tools.javac.util.ListBuffer#toList()

The following examples show how to use com.sun.tools.javac.util.ListBuffer#toList() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * 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();
}
 
Example 2
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();
}
 
Example 3
/**
 * 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();
}
 
Example 4
/**
 * 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();
}
 
Example 5
List<JCTree> parseParams(String s) throws ParseException {
    if (s.trim().isEmpty())
        return List.nil();

    JavacParser p = fac.newParser(s.replace("...", "[]"), false, false, false);
    ListBuffer<JCTree> paramTypes = new ListBuffer<JCTree>();
    paramTypes.add(p.parseType());

    if (p.token().kind == TokenKind.IDENTIFIER)
        p.nextToken();

    while (p.token().kind == TokenKind.COMMA) {
        p.nextToken();
        paramTypes.add(p.parseType());

        if (p.token().kind == TokenKind.IDENTIFIER)
            p.nextToken();
    }

    if (p.token().kind != TokenKind.EOF)
        throw new ParseException("dc.ref.unexpected.input");

    return paramTypes.toList();
}
 
Example 6
private static void testCopiedEndsWithList_nil() {
    ListBuffer<String> lb = new ListBuffer<>();

    lb.add("a");
    lb.add("b");
    lb.add("c");

    List<String> l1 = lb.toList();

    assertListEquals(l1, "a", "b", "c");
    assertEndsWithNil(l1);

    lb.add("d");

    List<String> l2 = lb.toList();
    assertListEquals(l2, "a", "b", "c", "d");
    assertEndsWithNil(l2);
    assertListEquals(l1, "a", "b", "c");
}
 
Example 7
static List<CastInfo> allCastInfo() {
    ListBuffer<CastInfo> buf = new ListBuffer<>();
    for (CastKind kind : CastKind.values()) {
        for (TypeKind b1 : TypeKind.values()) {
            if (kind.nbounds == 1) {
                buf.append(new CastInfo(kind, b1));
                continue;
            } else {
                for (TypeKind b2 : TypeKind.values()) {
                    if (kind.nbounds == 2) {
                        buf.append(new CastInfo(kind, b1, b2));
                        continue;
                    } else {
                        for (TypeKind b3 : TypeKind.values()) {
                            buf.append(new CastInfo(kind, b1, b2, b3));
                        }
                    }
                }
            }
        }
    }
    return buf.toList();
}
 
Example 8
Source Project: javaide   File: JCTree.java    License: GNU General Public License v3.0 5 votes vote down vote up
public List<JCImport> getImports() {
    ListBuffer<JCImport> imports = new ListBuffer<JCImport>();
    for (JCTree tree : defs) {
        int tag = tree.getTag();
        if (tag == IMPORT)
            imports.append((JCImport) tree);
        else if (tag != SKIP)
            break;
    }
    return imports.toList();
}
 
Example 9
/**
 * Initialize packages information.
 *
 * @param env the compilation environment
 * @param packages a list of package names (String)
 */
private void setPackages(DocEnv env, List<String> packages) {
    ListBuffer<PackageDocImpl> packlist = new ListBuffer<PackageDocImpl>();
    for (String name : packages) {
        PackageDocImpl pkg = env.lookupPackage(name);
        if (pkg != null) {
            pkg.isIncluded = true;
            packlist.append(pkg);
        } else {
            env.warning(null, "main.no_source_files_for_package", name);
        }
    }
    cmdLinePackages = packlist.toList();
}
 
Example 10
/**
 * Initialize packages information.
 *
 * @param env the compilation environment
 * @param packages a list of package names (String)
 */
private void setPackages(DocEnv env, List<String> packages) {
    ListBuffer<PackageDocImpl> packlist = new ListBuffer<PackageDocImpl>();
    for (String name : packages) {
        PackageDocImpl pkg = env.lookupPackage(name);
        if (pkg != null) {
            pkg.isIncluded = true;
            packlist.append(pkg);
        } else {
            env.warning(null, "main.no_source_files_for_package", name);
        }
    }
    cmdLinePackages = packlist.toList();
}
 
Example 11
List<Type> solveBasic(List<Type> varsToSolve, EnumSet<InferenceStep> steps) {
    ListBuffer<Type> solvedVars = new ListBuffer<>();
    for (Type t : varsToSolve.intersect(restvars())) {
        UndetVar uv = (UndetVar)asUndetVar(t);
        for (InferenceStep step : steps) {
            if (step.accepts(uv, this)) {
                uv.setInst(step.solve(uv, this));
                solvedVars.add(uv.qtype);
                break;
            }
        }
    }
    return solvedVars.toList();
}
 
Example 12
private List<Type> filterVars(Filter<UndetVar> fu) {
    ListBuffer<Type> res = new ListBuffer<>();
    for (Type t : undetvars) {
        UndetVar uv = (UndetVar)t;
        if (fu.accepts(uv)) {
            res.append(uv.qtype);
        }
    }
    return res.toList();
}
 
Example 13
/**
 * Initialize classes information. Those classes are input from
 * command line.
 *
 * @param env the compilation environment
 * @param classes a list of ClassDeclaration
 */
private void setClasses(DocEnv env, List<JCClassDecl> classes) {
    ListBuffer<ClassDocImpl> result = new ListBuffer<ClassDocImpl>();
    for (JCClassDecl def : classes) {
        //### Do we want modifier check here?
        if (env.shouldDocument(def.sym)) {
            ClassDocImpl cd = env.getClassDoc(def.sym);
            if (cd != null) {
                cd.isIncluded = true;
                result.append(cd);
            } //else System.out.println(" (classdoc is null)");//DEBUG
        } //else System.out.println(" (env.shouldDocument() returned false)");//DEBUG
    }
    cmdLineClasses = result.toList();
}
 
Example 14
/**
 * Initialize classes information. Those classes are input from
 * command line.
 *
 * @param env the compilation environment
 * @param classes a list of ClassDeclaration
 */
private void setClasses(DocEnv env, List<JCClassDecl> classes) {
    ListBuffer<ClassDocImpl> result = new ListBuffer<ClassDocImpl>();
    for (JCClassDecl def : classes) {
        //### Do we want modifier check here?
        if (env.shouldDocument(def.sym)) {
            ClassDocImpl cd = env.getClassDoc(def.sym);
            if (cd != null) {
                cd.isIncluded = true;
                result.append(cd);
            } //else System.out.println(" (classdoc is null)");//DEBUG
        } //else System.out.println(" (env.shouldDocument() returned false)");//DEBUG
    }
    cmdLineClasses = result.toList();
}
 
Example 15
/**
 * Constructor used when reading class files.
 *
 * @param env the documentation environment, state for this javadoc run
 * @param classes list of class names specified on the commandline
 * @param options list of options
 */
public RootDocImpl(DocEnv env, List<String> classes, List<String[]> options) {
    super(env, null);
    this.options = options;
    cmdLinePackages = List.nil();
    ListBuffer<ClassDocImpl> classList = new ListBuffer<ClassDocImpl>();
    for (String className : classes) {
        ClassDocImpl c = env.loadClass(className);
        if (c == null)
            env.error(null, "javadoc.class_not_found", className);
        else
            classList = classList.append(c);
    }
    cmdLineClasses = classList.toList();
}
 
Example 16
Source Project: javaide   File: TreeCopier.java    License: GNU General Public License v3.0 5 votes vote down vote up
public <T extends JCTree> List<T> copy(List<T> trees, P p) {
    if (trees == null)
        return null;
    ListBuffer<T> lb = new ListBuffer<T>();
    for (T tree: trees)
        lb.append(copy(tree, p));
    return lb.toList();
}
 
Example 17
static List<CastInfo> allCastInfo() {
    ListBuffer<CastInfo> buf = new ListBuffer<>();
    for (CastKind kind : CastKind.values()) {
        for (ClassKind clazz : ClassKind.values()) {
            if (kind == CastKind.INTERFACE && clazz != ClassKind.OBJECT) {
                continue;
            } else if (kind.interfaceBounds == 0) {
                buf.append(new CastInfo(kind, clazz));
                continue;
            } else {
                for (InterfaceKind intf1 : InterfaceKind.values()) {
                    if (kind.interfaceBounds == 1) {
                        buf.append(new CastInfo(kind, clazz, intf1));
                        continue;
                    } else {
                        for (InterfaceKind intf2 : InterfaceKind.values()) {
                            if (kind.interfaceBounds == 2) {
                                buf.append(
                                        new CastInfo(kind, clazz, intf1, intf2));
                                continue;
                            } else {
                                for (InterfaceKind intf3 : InterfaceKind.values()) {
                                    buf.append(
                                            new CastInfo(kind, clazz, intf1,
                                                         intf2, intf3));
                                    continue;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return buf.toList();
}
 
Example 18
/**
 * Read general text content of an inline tag, including HTML entities and elements.
 * Matching pairs of { } are skipped; the text is terminated by the first
 * unmatched }. It is an error if the beginning of the next tag is detected.
 */
@SuppressWarnings("fallthrough")
protected List<DCTree> inlineContent() {
    ListBuffer<DCTree> trees = new ListBuffer<DCTree>();

    skipWhitespace();
    int pos = bp;
    int depth = 1;
    textStart = -1;

    loop:
    while (bp < buflen) {

        switch (ch) {
            case '\n': case '\r': case '\f':
                newline = true;
                // fall through

            case ' ': case '\t':
                nextChar();
                break;

            case '&':
                entity(trees);
                break;

            case '<':
                newline = false;
                addPendingText(trees, bp - 1);
                trees.add(html());
                break;

            case '{':
                newline = false;
                depth++;
                nextChar();
                break;

            case '}':
                newline = false;
                if (--depth == 0) {
                    addPendingText(trees, bp - 1);
                    nextChar();
                    return trees.toList();
                }
                nextChar();
                break;

            case '@':
                if (newline)
                    break loop;
                // fallthrough

            default:
                if (textStart == -1)
                    textStart = bp;
                nextChar();
                break;
        }
    }

    return List.<DCTree>of(erroneous("dc.unterminated.inline.tag", pos));
}
 
Example 19
@Override
public void visitProvides(JCProvides tree) {
    Type st = attr.attribType(tree.serviceName, env, syms.objectType);
    ClassSymbol service = (ClassSymbol) st.tsym;
    if (allProvides.containsKey(service)) {
        log.error(tree.serviceName.pos(), Errors.RepeatedProvidesForService(service));
    }
    ListBuffer<ClassSymbol> impls = new ListBuffer<>();
    for (JCExpression implName : tree.implNames) {
        Type it;
        boolean prevVisitingServiceImplementation = env.info.visitingServiceImplementation;
        try {
            env.info.visitingServiceImplementation = true;
            it = attr.attribType(implName, env, syms.objectType);
        } finally {
            env.info.visitingServiceImplementation = prevVisitingServiceImplementation;
        }
        ClassSymbol impl = (ClassSymbol) it.tsym;
        if ((impl.flags_field & PUBLIC) == 0) {
            log.error(implName.pos(), Errors.NotDefPublic(impl, impl.location()));
        }
        //find provider factory:
        MethodSymbol factory = factoryMethod(impl);
        if (factory != null) {
            Type returnType = factory.type.getReturnType();
            if (!types.isSubtype(returnType, st)) {
                log.error(implName.pos(), Errors.ServiceImplementationProviderReturnMustBeSubtypeOfServiceInterface);
            }
        } else {
            if (!types.isSubtype(it, st)) {
                log.error(implName.pos(), Errors.ServiceImplementationMustBeSubtypeOfServiceInterface);
            } else if ((impl.flags() & ABSTRACT) != 0) {
                log.error(implName.pos(), Errors.ServiceImplementationIsAbstract(impl));
            } else if (impl.isInner()) {
                log.error(implName.pos(), Errors.ServiceImplementationIsInner(impl));
            } else {
                MethodSymbol constr = noArgsConstructor(impl);
                if (constr == null) {
                    log.error(implName.pos(), Errors.ServiceImplementationDoesntHaveANoArgsConstructor(impl));
                } else if ((constr.flags() & PUBLIC) == 0) {
                    log.error(implName.pos(), Errors.ServiceImplementationNoArgsConstructorNotPublic(impl));
                }
            }
        }
        if (it.hasTag(CLASS)) {
            if (Maps.computeIfAbsent(allProvides,service, s -> new HashSet<>()).add(impl)) {
                impls.append(impl);
            } else {
                log.error(implName.pos(), Errors.DuplicateProvides(service, impl));
            }
        }
    }
    if (st.hasTag(CLASS) && !impls.isEmpty()) {
        Directive.ProvidesDirective d = new Directive.ProvidesDirective(service, impls.toList());
        msym.provides = msym.provides.prepend(d);
        msym.directives = msym.directives.prepend(d);
        directiveToTreeMap.put(d, tree);
    }
}
 
Example 20
protected void attribSuperTypes(Env<AttrContext> env, Env<AttrContext> baseEnv) {
    JCClassDecl tree = env.enclClass;
    ClassSymbol sym = tree.sym;
    ClassType ct = (ClassType)sym.type;
    // Determine supertype.
    Type supertype;
    JCExpression extending;

    if (tree.extending != null) {
        extending = clearTypeParams(tree.extending);
        supertype = attr.attribBase(extending, baseEnv, true, false, true);
    } else {
        extending = null;
        supertype = ((tree.mods.flags & Flags.ENUM) != 0)
        ? attr.attribBase(enumBase(tree.pos, sym), baseEnv,
                          true, false, false)
        : (sym.fullname == names.java_lang_Object)
        ? Type.noType
        : syms.objectType;
    }
    ct.supertype_field = modelMissingTypes(baseEnv, supertype, extending, false);

    // Determine interfaces.
    ListBuffer<Type> interfaces = new ListBuffer<>();
    ListBuffer<Type> all_interfaces = null; // lazy init
    List<JCExpression> interfaceTrees = tree.implementing;
    for (JCExpression iface : interfaceTrees) {
        iface = clearTypeParams(iface);
        Type it = attr.attribBase(iface, baseEnv, false, true, true);
        if (it.hasTag(CLASS)) {
            interfaces.append(it);
            if (all_interfaces != null) all_interfaces.append(it);
        } else {
            if (all_interfaces == null)
                all_interfaces = new ListBuffer<Type>().appendList(interfaces);
            all_interfaces.append(modelMissingTypes(baseEnv, it, iface, true));
        }
    }

    if ((sym.flags_field & ANNOTATION) != 0) {
        ct.interfaces_field = List.of(syms.annotationType);
        ct.all_interfaces_field = ct.interfaces_field;
    }  else {
        ct.interfaces_field = interfaces.toList();
        ct.all_interfaces_field = (all_interfaces == null)
                ? ct.interfaces_field : all_interfaces.toList();
    }
}