Example usage for com.google.common.collect ImmutableList.Builder addAll

List of usage examples for com.google.common.collect ImmutableList.Builder addAll

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableList.Builder addAll.

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation).

Usage

From source file:com.google.errorprone.bugpatterns.inject.dagger.Util.java

/**
 * Returns a fix that changes a concrete class to an abstract class.
 *
 * <ul>//from  w  ww .j av  a2 s.c  o  m
 * <li>Removes {@code final} if it was there.
 * <li>Adds {@code abstract} if it wasn't there.
 * <li>Adds a private empty constructor if the class was {@code final} and had only a default
 *     constructor.
 * </ul>
 */
static SuggestedFix.Builder makeConcreteClassAbstract(ClassTree classTree, VisitorState state) {
    Set<Modifier> flags = EnumSet.noneOf(Modifier.class);
    flags.addAll(classTree.getModifiers().getFlags());
    boolean wasFinal = flags.remove(FINAL);
    boolean wasAbstract = !flags.add(ABSTRACT);

    if (classTree.getKind().equals(INTERFACE) || (!wasFinal && wasAbstract)) {
        return SuggestedFix.builder(); // no-op
    }

    ImmutableList.Builder<Object> modifiers = ImmutableList.builder();
    for (AnnotationTree annotation : classTree.getModifiers().getAnnotations()) {
        modifiers.add(state.getSourceForNode(annotation));
    }
    modifiers.addAll(flags);

    SuggestedFix.Builder makeAbstract = SuggestedFix.builder();
    if (((JCModifiers) classTree.getModifiers()).pos == -1) {
        makeAbstract.prefixWith(classTree, Joiner.on(' ').join(modifiers.build()));
    } else {
        makeAbstract.replace(classTree.getModifiers(), Joiner.on(' ').join(modifiers.build()));
    }
    if (wasFinal && HAS_GENERATED_CONSTRUCTOR.matches(classTree, state)) {
        makeAbstract.merge(addPrivateConstructor(classTree));
    }
    return makeAbstract;
}

From source file:com.spectralogic.ds3autogen.utils.Helper.java

/**
 * Adds an Argument to a list of Arguments
 * @param arguments List of Arguments//w  w  w  .  j  av a 2  s  .  c  om
 * @param argName Name of Argument being added
 * @param argType Type of Argument being added
 * @return List of arguments
 */
public static ImmutableList<Arguments> addArgument(final ImmutableList<Arguments> arguments,
        final String argName, final String argType) {
    final ImmutableList.Builder<Arguments> builder = ImmutableList.builder();
    if (hasContent(arguments)) {
        builder.addAll(arguments);
    }
    builder.add(new Arguments(argType, argName));
    return builder.build();
}

From source file:com.spectralogic.ds3autogen.utils.Helper.java

/**
 * Combines two lists of Arguments/*from w ww .j  av  a2s  . c  o  m*/
 * @param arguments List of Arguments
 * @param additionalArguments List of Arguments
 * @return Combined list of Arguments
 */
public static ImmutableList<Arguments> addArgument(final ImmutableList<Arguments> arguments,
        final ImmutableList<Arguments> additionalArguments) {
    final ImmutableList.Builder<Arguments> builder = ImmutableList.builder();
    if (hasContent(arguments)) {
        builder.addAll(arguments);
    }
    if (hasContent(additionalArguments)) {
        builder.addAll(additionalArguments);
    }
    return builder.build();
}

From source file:com.android.build.gradle.internal.transforms.ProGuardTransform.java

private static void handleQualifiedContent(@NonNull ClassPath classPath, @NonNull QualifiedContent content,
        @Nullable List<String> baseFilter) {
    List<String> filter = baseFilter;

    if (!content.getContentTypes().contains(DefaultContentType.CLASSES)) {
        // if the content is not meant to contain classes, we ignore them
        // in case they are present.
        ImmutableList.Builder<String> builder = ImmutableList.builder();
        if (filter != null) {
            builder.addAll(filter);
        }/* w ww. j av  a2 s  . c om*/
        builder.add("!**.class");
        filter = builder.build();
    } else if (!content.getContentTypes().contains(DefaultContentType.RESOURCES)) {
        // if the content is not meant to contain resources, we ignore them
        // in case they are present (by accepting only classes.)
        filter = ImmutableList.of("**.class");
    }

    inputJar(classPath, content.getFile(), filter);
}

From source file:com.google.idea.blaze.cpp.BlazeResolveConfigurationTemporaryBase.java

@Nullable
public static BlazeResolveConfiguration createConfigurationForTarget(Project project,
        WorkspacePathResolver workspacePathResolver, ImmutableMap<File, VirtualFile> headerRoots,
        TargetIdeInfo target, CToolchainIdeInfo toolchainIdeInfo, File compilerWrapper) {
    CIdeInfo cIdeInfo = target.cIdeInfo;
    if (cIdeInfo == null) {
        return null;
    }/*from   ww  w. ja  v a2 s .  com*/

    ImmutableSet.Builder<ExecutionRootPath> systemIncludesBuilder = ImmutableSet.builder();
    systemIncludesBuilder.addAll(cIdeInfo.transitiveSystemIncludeDirectories);
    systemIncludesBuilder.addAll(toolchainIdeInfo.builtInIncludeDirectories);
    systemIncludesBuilder.addAll(toolchainIdeInfo.unfilteredToolchainSystemIncludes);

    ImmutableSet.Builder<ExecutionRootPath> userIncludesBuilder = ImmutableSet.builder();
    userIncludesBuilder.addAll(cIdeInfo.transitiveIncludeDirectories);

    ImmutableSet.Builder<ExecutionRootPath> userQuoteIncludesBuilder = ImmutableSet.builder();
    userQuoteIncludesBuilder.addAll(cIdeInfo.transitiveQuoteIncludeDirectories);

    ImmutableList.Builder<String> cFlagsBuilder = ImmutableList.builder();
    cFlagsBuilder.addAll(toolchainIdeInfo.baseCompilerOptions);
    cFlagsBuilder.addAll(toolchainIdeInfo.cCompilerOptions);
    cFlagsBuilder.addAll(toolchainIdeInfo.unfilteredCompilerOptions);

    ImmutableList.Builder<String> cppFlagsBuilder = ImmutableList.builder();
    cppFlagsBuilder.addAll(toolchainIdeInfo.baseCompilerOptions);
    cppFlagsBuilder.addAll(toolchainIdeInfo.cppCompilerOptions);
    cppFlagsBuilder.addAll(toolchainIdeInfo.unfilteredCompilerOptions);

    ImmutableMap<String, String> features = ImmutableMap.of();

    return new BlazeResolveConfiguration(project, workspacePathResolver, headerRoots, target.key,
            systemIncludesBuilder.build(), systemIncludesBuilder.build(), userQuoteIncludesBuilder.build(),
            userIncludesBuilder.build(), userIncludesBuilder.build(), cIdeInfo.transitiveDefines, features,
            compilerWrapper, compilerWrapper, cFlagsBuilder.build(), cppFlagsBuilder.build());
}

From source file:com.facebook.swift.codec.metadata.ReflectionHelper.java

public static Iterable<Field> getAllDeclaredFields(Class<?> type) {
    ImmutableList.Builder<Field> fields = ImmutableList.builder();
    for (Class<?> clazz = type; (clazz != null) && !clazz.equals(Object.class); clazz = clazz.getSuperclass()) {
        fields.addAll(ImmutableList.copyOf(clazz.getDeclaredFields()));
    }/*  w  w w  .j  av  a 2  s  .c o  m*/
    return fields.build();
}

From source file:com.spotify.heroic.suggest.TagValuesSuggest.java

public static Collector<TagValuesSuggest, TagValuesSuggest> reduce(final OptionalLimit limit,
        final OptionalLimit groupLimit) {
    return groups -> {
        final ImmutableList.Builder<RequestError> errors = ImmutableList.builder();
        final Map<String, MidFlight> midflights = new HashMap<>();
        boolean limited1 = false;

        for (final TagValuesSuggest g : groups) {
            errors.addAll(g.getErrors());

            for (final Suggestion s : g.suggestions) {
                MidFlight m = midflights.get(s.key);

                if (m == null) {
                    m = new MidFlight();
                    midflights.put(s.key, m);
                }/*w  w w  .ja v a  2 s. c o  m*/

                m.values.addAll(s.values);
                m.limited = m.limited || s.limited;
            }

            limited1 = limited1 || g.limited;
        }

        final SortedSet<Suggestion> suggestions1 = new TreeSet<>();

        for (final Map.Entry<String, MidFlight> e : midflights.entrySet()) {
            final String key = e.getKey();
            final MidFlight m = e.getValue();

            final boolean sLimited = m.limited || groupLimit.isGreater(m.values.size());

            suggestions1.add(new Suggestion(key, groupLimit.limitSortedSet(m.values), sLimited));
        }

        return new TagValuesSuggest(errors.build(), limit.limitList(ImmutableList.copyOf(suggestions1)),
                limited1 || limit.isGreater(suggestions1.size()));
    };
}

From source file:com.facebook.presto.server.QueryExecutionResource.java

private static List<StageInfo> collectStages(StageInfo stage) {
    ImmutableList.Builder<StageInfo> result = ImmutableList.builder();
    result.add(stage);/*from  ww  w  .  j  a va 2 s  .  c  o m*/
    for (StageInfo child : stage.getSubStages()) {
        result.addAll(collectStages(child));
    }

    return result.build();
}

From source file:com.facebook.swift.codec.metadata.ReflectionHelper.java

public static Iterable<Method> getAllDeclaredMethods(Class<?> type) {
    ImmutableList.Builder<Method> methods = ImmutableList.builder();

    for (Class<?> clazz = type; (clazz != null) && !clazz.equals(Object.class); clazz = clazz.getSuperclass()) {
        methods.addAll(ImmutableList.copyOf(clazz.getDeclaredMethods()));
    }/*from www.  ja  v  a  2  s.c  om*/
    return methods.build();
}

From source file:com.spotify.heroic.aggregation.ChainInstance.java

private static List<AggregationInstance> flattenChain(final List<AggregationInstance> chain) {
    final ImmutableList.Builder<AggregationInstance> child = ImmutableList.builder();

    for (final AggregationInstance i : chain) {
        if (i instanceof ChainInstance) {
            child.addAll(flattenChain(ChainInstance.class.cast(i).getChain()));
        } else {/*from   www .  j a va 2  s  . c  o m*/
            child.add(i);
        }
    }

    return child.build();
}