Example usage for com.google.common.collect ImmutableSortedSet copyOf

List of usage examples for com.google.common.collect ImmutableSortedSet copyOf

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSortedSet copyOf.

Prototype

public static <E extends Comparable<? super E>> ImmutableSortedSet<E> copyOf(E[] elements) 

Source Link

Usage

From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java

/**
 * Output a chain of dereferences where some prefix should be treated as a single syntactic unit,
 * either because it looks like a type name or because there is only a single method invocation in
 * the chain./*from w ww .j a  va 2 s  .  c o  m*/
 *
 * @param items in the chain
 * @param needDot whether a leading dot is needed
 * @param prefixes the terminal indices of 'prefixes' of the expression that should be treated as
 *     a syntactic unit
 */
private void visitDotWithPrefix(List<ExpressionTree> items, boolean needDot, Collection<Integer> prefixes,
        FillMode prefixFillMode) {
    // Are there method invocations or field accesses after the prefix?
    boolean trailingDereferences = !prefixes.isEmpty() && getLast(prefixes) < items.size() - 1;

    builder.open(plusFour);
    for (int times = 0; times < prefixes.size(); times++) {
        builder.open(ZERO);
    }

    Deque<Integer> unconsumedPrefixes = new ArrayDeque<>(ImmutableSortedSet.copyOf(prefixes));
    BreakTag nameTag = genSym();
    for (int i = 0; i < items.size(); i++) {
        ExpressionTree e = items.get(i);
        if (needDot) {
            FillMode fillMode;
            if (!unconsumedPrefixes.isEmpty() && i <= unconsumedPrefixes.peekFirst()) {
                fillMode = prefixFillMode;
            } else {
                fillMode = FillMode.UNIFIED;
            }

            builder.breakOp(fillMode, "", ZERO, Optional.of(nameTag));
            token(".");
        }
        BreakTag tyargTag = genSym();
        dotExpressionUpToArgs(e, Optional.of(tyargTag));
        if (!unconsumedPrefixes.isEmpty() && i == unconsumedPrefixes.peekFirst()) {
            builder.close();
            unconsumedPrefixes.removeFirst();
        }

        Indent tyargIndent = Indent.If.make(tyargTag, plusFour, ZERO);
        Indent argsIndent = Indent.If.make(nameTag, plusFour, trailingDereferences ? plusFour : ZERO);
        dotExpressionArgsAndParen(e, tyargIndent, argsIndent);

        needDot = true;
    }

    builder.close();
}