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

The following examples show how to use com.sun.tools.javac.util.ListBuffer#add() . 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
Source Project: java-n-IDE-for-Android   File: Paths.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Split a path into its elements. If emptyPathDefault is not null, all
 * empty elements in the path, including empty elements at either end of
 * the path, will be replaced with the value of emptyPathDefault.
 *
 * @param path             The path to be split
 * @param emptyPathDefault The value to substitute for empty path elements,
 *                         or null, to ignore empty path elements
 * @return The elements of the path
 */
private static Iterable<File> getPathEntries(String path, File emptyPathDefault) {
    ListBuffer<File> entries = new ListBuffer<File>();
    int start = 0;

    //System.out.println("SPARTACUS : getPathEntries "+path);

    while (start <= path.length()) {
        int sep = path.indexOf(File.pathSeparatorChar, start);
        if (sep == -1)
            sep = path.length();
        if (start < sep)
            entries.add(new File(path.substring(start, sep)));
        else if (emptyPathDefault != null)
            entries.add(emptyPathDefault);
        start = sep + 1;
    }
    return entries;
}
 
Example 2
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 3
@Override
public Iterable<JavaFileObject> list(Location location,
                                     String packageName,
                                     Set<Kind> kinds,
                                     boolean recurse)
    throws IOException
{
    // Acquire the list of files.
    Iterable<JavaFileObject> files = super.list(location, packageName, kinds, recurse);
    if (visibleSources.isEmpty()) {
        return files;
    }
    // Now filter!
    ListBuffer<JavaFileObject> filteredFiles = new ListBuffer<JavaFileObject>();
    for (JavaFileObject f : files) {
        URI uri = f.toUri();
        String t = uri.toString();
        if (t.startsWith("jar:")
            || t.endsWith(".class")
            || visibleSources.contains(uri))
        {
            filteredFiles.add(f);
        }
    }
    return filteredFiles;
}
 
Example 4
@Override @DefinedBy(Api.COMPILER)
public Iterable<JavaFileObject> list(Location location,
                                     String packageName,
                                     Set<Kind> kinds,
                                     boolean recurse) throws IOException {
    // TODO: Do this lazily by returning an iterable with a filtering Iterator
    // Acquire the list of files.
    Iterable<JavaFileObject> files = super.list(location, packageName, kinds, recurse);
    if (visibleSources.isEmpty()) {
        return locWrapMany(files, location);
    }
    // Now filter!
    ListBuffer<JavaFileObject> filteredFiles = new ListBuffer<>();
    for (JavaFileObject f : files) {
        URI uri = f.toUri();
        String t = uri.toString();
        if (t.startsWith("jar:")
            || t.endsWith(".class")
            || visibleSources.contains(uri)) {
            filteredFiles.add(f);
        }
    }

    return locWrapMany(filteredFiles, location);
}
 
Example 5
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 6
/** Restore the state of this inference context to the previous known checkpoint.
*  Consider that the number of saved undetermined variables can be different to the current
*  amount. This is because new captured variables could have been added.
*/
public void rollback(List<Type> saved_undet) {
    Assert.check(saved_undet != null);
    //restore bounds (note: we need to preserve the old instances)
    ListBuffer<Type> newUndetVars = new ListBuffer<>();
    ListBuffer<Type> newInferenceVars = new ListBuffer<>();
    while (saved_undet.nonEmpty() && undetvars.nonEmpty()) {
        UndetVar uv = (UndetVar)undetvars.head;
        UndetVar uv_saved = (UndetVar)saved_undet.head;
        if (uv.qtype == uv_saved.qtype) {
            uv_saved.dupTo(uv, types);
            undetvars = undetvars.tail;
            saved_undet = saved_undet.tail;
            newUndetVars.add(uv);
            newInferenceVars.add(uv.qtype);
        } else {
            undetvars = undetvars.tail;
        }
    }
    undetvars = newUndetVars.toList();
    inferencevars = newInferenceVars.toList();
}
 
Example 7
protected void entity(ListBuffer<DCTree> list) {
    newline = false;
    addPendingText(list, bp - 1);
    list.add(entity());
    if (textStart == -1) {
        textStart = bp;
        lastNonWhite = -1;
    }
}
 
Example 8
JCTree processSerialFields(Element sfNode) {
    String baseName = sfNode.getAttribute("basename");
    String[] fieldTypes = sfNode.getTextContent().split(",");

    ListBuffer<JCExpression> serialFields = new ListBuffer<>();
    HashMap<String, Integer> scope = new HashMap<>();

    for (String fType : fieldTypes) {
        String fieldName = baseName + getUniqIndex(scope, baseName);
        serialFields.add(
            make.NewClass(
                null,
                null,
                make.Type(getTypeByName("ObjectStreamField")),
                List.from(
                    new JCTree.JCExpression[] {
                        make.Literal(fieldName),
                        make.Ident(names.fromString(fType + ".class"))
                    }),
                null));
    }

    JCTree sfDecl = make.VarDef(
                        make.Modifiers(
                            Flags.PRIVATE | Flags.STATIC | Flags.FINAL),
                        names.fromString("serialPersistentFields"),
                        make.TypeArray(
                            make.Type(getTypeByName("ObjectStreamField"))),
                        make.NewArray(
                            null,
                            List.<JCExpression>nil(),
                            serialFields.toList()));

    return sfDecl;
}
 
Example 9
private List<Comment> getComments(Comment.CommentStyle style) {
    if (comments == null) {
        return List.nil();
    } else {
        ListBuffer<Comment> buf = new ListBuffer<>();
        for (Comment c : comments) {
            if (c.getStyle() == style) {
                buf.add(c);
            }
        }
        return buf.toList();
    }
}
 
Example 10
protected void addPendingText(ListBuffer<DCTree> list, int textEnd) {
    if (textStart != -1) {
        if (textStart <= textEnd) {
            list.add(m.at(textStart).Text(newString(textStart, textEnd + 1)));
        }
        textStart = -1;
    }
}
 
Example 11
/**
 * Save the state of this inference context
 */
public List<Type> save() {
    ListBuffer<Type> buf = new ListBuffer<>();
    for (Type t : undetvars) {
        buf.add(((UndetVar)t).dup(infer.types));
    }
    return buf.toList();
}
 
Example 12
/**
 * Save the state of this inference context
 */
public List<Type> save() {
    ListBuffer<Type> buf = new ListBuffer<>();
    for (Type t : undetvars) {
        buf.add(((UndetVar)t).dup(infer.types));
    }
    return buf.toList();
}
 
Example 13
protected void entity(ListBuffer<DCTree> list) {
    newline = false;
    addPendingText(list, bp - 1);
    list.add(entity());
    if (textStart == -1) {
        textStart = bp;
        lastNonWhite = -1;
    }
}
 
Example 14
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 15
Source Project: hottub   File: Tokens.java    License: GNU General Public License v2.0 5 votes vote down vote up
private List<Comment> getComments(Comment.CommentStyle style) {
    if (comments == null) {
        return List.nil();
    } else {
        ListBuffer<Comment> buf = new ListBuffer<>();
        for (Comment c : comments) {
            if (c.getStyle() == style) {
                buf.add(c);
            }
        }
        return buf.toList();
    }
}
 
Example 16
/**
 * Read block content, consisting of text, html and inline tags.
 * Terminated by the end of input, or the beginning of the next block tag:
 * i.e. @ as the first non-whitespace character on a line.
 */
@SuppressWarnings("fallthrough")
protected List<DCTree> blockContent() {
    ListBuffer<DCTree> trees = new ListBuffer<DCTree>();
    textStart = -1;

    loop:
    while (bp < buflen) {
        switch (ch) {
            case '\n': case '\r': case '\f':
                newline = true;
                // fallthrough

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

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

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

            case '>':
                newline = false;
                addPendingText(trees, bp - 1);
                trees.add(m.at(bp).Erroneous(newString(bp, bp+1), diagSource, "dc.bad.gt"));
                nextChar();
                if (textStart == -1) {
                    textStart = bp;
                    lastNonWhite = -1;
                }
                break;

            case '{':
                inlineTag(trees);
                break;

            case '@':
                if (newline) {
                    addPendingText(trees, lastNonWhite);
                    break loop;
                }
                // fallthrough

            default:
                newline = false;
                if (textStart == -1)
                    textStart = bp;
                lastNonWhite = bp;
                nextChar();
        }
    }

    if (lastNonWhite != -1)
        addPendingText(trees, lastNonWhite);

    return trees.toList();
}
 
Example 17
/**
 * Read block content, consisting of text, html and inline tags.
 * Terminated by the end of input, or the beginning of the next block tag:
 * i.e. @ as the first non-whitespace character on a line.
 */
@SuppressWarnings("fallthrough")
protected List<DCTree> blockContent() {
    ListBuffer<DCTree> trees = new ListBuffer<>();
    textStart = -1;

    loop:
    while (bp < buflen) {
        switch (ch) {
            case '\n': case '\r': case '\f':
                newline = true;
                // fallthrough

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

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

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

            case '>':
                newline = false;
                addPendingText(trees, bp - 1);
                trees.add(m.at(bp).newErroneousTree(newString(bp, bp + 1), diagSource, "dc.bad.gt"));
                nextChar();
                if (textStart == -1) {
                    textStart = bp;
                    lastNonWhite = -1;
                }
                break;

            case '{':
                inlineTag(trees);
                break;

            case '@':
                if (newline) {
                    addPendingText(trees, lastNonWhite);
                    break loop;
                }
                // fallthrough

            default:
                newline = false;
                if (textStart == -1)
                    textStart = bp;
                lastNonWhite = bp;
                nextChar();
        }
    }

    if (lastNonWhite != -1)
        addPendingText(trees, lastNonWhite);

    return trees.toList();
}
 
Example 18
private List<ModuleSymbol> scanModulePath(ModuleSymbol toFind) {
    ListBuffer<ModuleSymbol> results = new ListBuffer<>();
    Map<Name, Location> namesInSet = new HashMap<>();
    boolean multiModuleMode = fileManager.hasLocation(StandardLocation.MODULE_SOURCE_PATH);
    while (moduleLocationIterator.hasNext()) {
        Set<Location> locns = (moduleLocationIterator.next());
        namesInSet.clear();
        for (Location l: locns) {
            try {
                Name n = names.fromString(fileManager.inferModuleName(l));
                if (namesInSet.put(n, l) == null) {
                    ModuleSymbol msym = syms.enterModule(n);
                    if (msym.sourceLocation != null || msym.classLocation != null) {
                        // module has already been found, so ignore this instance
                        continue;
                    }
                    if (fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH) &&
                        msym.patchLocation == null) {
                        msym.patchLocation =
                                fileManager.getLocationForModule(StandardLocation.PATCH_MODULE_PATH,
                                                                 msym.name.toString());
                        if (msym.patchLocation != null &&
                            multiModuleMode &&
                            fileManager.hasLocation(StandardLocation.CLASS_OUTPUT)) {
                            msym.patchOutputLocation =
                                    fileManager.getLocationForModule(StandardLocation.CLASS_OUTPUT,
                                                                     msym.name.toString());
                        }
                    }
                    if (moduleLocationIterator.outer == StandardLocation.MODULE_SOURCE_PATH) {
                        msym.sourceLocation = l;
                        if (fileManager.hasLocation(StandardLocation.CLASS_OUTPUT)) {
                            msym.classLocation =
                                    fileManager.getLocationForModule(StandardLocation.CLASS_OUTPUT,
                                                                     msym.name.toString());
                        }
                    } else {
                        msym.classLocation = l;
                    }
                    if (moduleLocationIterator.outer == StandardLocation.SYSTEM_MODULES ||
                        moduleLocationIterator.outer == StandardLocation.UPGRADE_MODULE_PATH) {
                        msym.flags_field |= Flags.SYSTEM_MODULE;
                    }
                    if (toFind == null ||
                        (toFind == msym && (msym.sourceLocation != null || msym.classLocation != null))) {
                        // Note: cannot return msym directly, because we must finish
                        // processing this set first
                        results.add(msym);
                    }
                } else {
                    log.error(Errors.DuplicateModuleOnPath(
                            getDescription(moduleLocationIterator.outer), n));
                }
            } catch (IOException e) {
                // skip location for now?  log error?
            }
        }
        if (toFind != null && results.nonEmpty())
            return results.toList();
    }

    return results.toList();
}
 
Example 19
/**
 * Read a series of HTML attributes, terminated by {@literal > }.
 * Each attribute is of the form {@literal identifier[=value] }.
 * "value" may be unquoted, single-quoted, or double-quoted.
 */
protected List<DCTree> htmlAttrs() {
    ListBuffer<DCTree> attrs = new ListBuffer<>();
    skipWhitespace();

    loop:
    while (isIdentifierStart(ch)) {
        int namePos = bp;
        Name name = readAttributeName();
        skipWhitespace();
        List<DCTree> value = null;
        ValueKind vkind = ValueKind.EMPTY;
        if (ch == '=') {
            ListBuffer<DCTree> v = new ListBuffer<>();
            nextChar();
            skipWhitespace();
            if (ch == '\'' || ch == '"') {
                vkind = (ch == '\'') ? ValueKind.SINGLE : ValueKind.DOUBLE;
                char quote = ch;
                nextChar();
                textStart = bp;
                while (bp < buflen && ch != quote) {
                    if (newline && ch == '@') {
                        attrs.add(erroneous("dc.unterminated.string", namePos));
                        // No point trying to read more.
                        // In fact, all attrs get discarded by the caller
                        // and superseded by a malformed.html node because
                        // the html tag itself is not terminated correctly.
                        break loop;
                    }
                    attrValueChar(v);
                }
                addPendingText(v, bp - 1);
                nextChar();
            } else {
                vkind = ValueKind.UNQUOTED;
                textStart = bp;
                while (bp < buflen && !isUnquotedAttrValueTerminator(ch)) {
                    attrValueChar(v);
                }
                addPendingText(v, bp - 1);
            }
            skipWhitespace();
            value = v.toList();
        }
        DCAttribute attr = m.at(namePos).newAttributeTree(name, vkind, value);
        attrs.add(attr);
    }

    return attrs.toList();
}
 
Example 20
/**
 * 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));
}