List of usage examples for com.google.common.collect ImmutableSet.Builder add
boolean add(E e);
From source file:com.google.devtools.build.lib.rules.cpp.CcCommon.java
/** * Creates the feature configuration for a given rule. * * @param ruleContext the context of the rule we want the feature configuration for. * @param ruleSpecificRequestedFeatures features that will be requested, and thus be always * enabled if the toolchain supports them. * @param ruleSpecificUnsupportedFeatures features that are not supported in the current context. * @param sourceCategory the source category for this build. * @return the feature configuration for the given {@code ruleContext}. *//*from ww w. jav a 2 s . c o m*/ public static FeatureConfiguration configureFeatures(RuleContext ruleContext, Set<String> ruleSpecificRequestedFeatures, Set<String> ruleSpecificUnsupportedFeatures, SourceCategory sourceCategory, CcToolchainProvider toolchain) { ImmutableSet.Builder<String> unsupportedFeaturesBuilder = ImmutableSet.builder(); unsupportedFeaturesBuilder.addAll(ruleSpecificUnsupportedFeatures); if (!toolchain.supportsHeaderParsing()) { // TODO(bazel-team): Remove once supports_header_parsing has been removed from the // cc_toolchain rule. unsupportedFeaturesBuilder.add(CppRuleClasses.PARSE_HEADERS); unsupportedFeaturesBuilder.add(CppRuleClasses.PREPROCESS_HEADERS); } if (toolchain.getCppCompilationContext().getCppModuleMap() == null) { unsupportedFeaturesBuilder.add(CppRuleClasses.MODULE_MAPS); } Set<String> unsupportedFeatures = unsupportedFeaturesBuilder.build(); ImmutableSet.Builder<String> requestedFeatures = ImmutableSet.builder(); for (String feature : Iterables.concat(ImmutableSet.of(toolchain.getCompilationMode().toString()), ImmutableSet.of(getHostOrNonHostFeature(ruleContext)), DEFAULT_FEATURES, ruleContext.getFeatures())) { if (!unsupportedFeatures.contains(feature)) { requestedFeatures.add(feature); } } requestedFeatures.addAll(ruleSpecificRequestedFeatures); requestedFeatures.addAll(sourceCategory.getActionConfigSet()); FeatureConfiguration configuration = toolchain.getFeatures() .getFeatureConfiguration(requestedFeatures.build()); for (String feature : unsupportedFeatures) { if (configuration.isEnabled(feature)) { ruleContext.ruleError("The C++ toolchain '" + ruleContext.getPrerequisite(":cc_toolchain", Mode.TARGET).getLabel() + "' unconditionally implies feature '" + feature + "', which is unsupported by this rule. " + "This is most likely a misconfiguration in the C++ toolchain."); } } return configuration; }
From source file:google.registry.testing.AppEngineRule.java
/** Read a datastore index file, and parse the indexes into individual strings. */ private static Set<String> getIndexXmlStrings(String indexFile) { ImmutableSet.Builder<String> builder = new ImmutableSet.Builder<>(); try {//from w w w . j av a 2s . co m // To normalize the indexes, we are going to pass them through JSON and then rewrite the xml. JSONObject datastoreIndexes = new JSONObject(); Object indexes = toJSONObject(indexFile).get("datastore-indexes"); if (indexes instanceof JSONObject) { datastoreIndexes = (JSONObject) indexes; } for (JSONObject index : getJsonAsArray(datastoreIndexes.opt("datastore-index"))) { builder.add(getIndexXmlString(index)); } } catch (JSONException e) { throw new RuntimeException(e); } return builder.build(); }
From source file:com.spotify.heroic.metric.QueryResult.java
/** * Collect result parts into a complete result. * * @param range The range which the result represents. * @return A complete QueryResult./*from w w w.java2 s . c om*/ */ public static Collector<QueryResultPart, QueryResult> collectParts(final QueryTrace.Identifier what, final DateRange range, final AggregationCombiner combiner, final OptionalLimit groupLimit) { final QueryTrace.NamedWatch w = QueryTrace.watch(what); return parts -> { final List<List<ShardedResultGroup>> all = new ArrayList<>(); final List<RequestError> errors = new ArrayList<>(); final ImmutableList.Builder<QueryTrace> queryTraces = ImmutableList.builder(); final ImmutableSet.Builder<ResultLimit> limits = ImmutableSet.builder(); long preAggregationSampleSize = 0; for (final QueryResultPart part : parts) { errors.addAll(part.getErrors()); queryTraces.add(part.getQueryTrace()); limits.addAll(part.getLimits().getLimits()); preAggregationSampleSize += part.getPreAggregationSampleSize(); if (part.isEmpty()) { continue; } all.add(part.getGroups()); } final List<ShardedResultGroup> groups = combiner.combine(all); final QueryTrace trace = w.end(queryTraces.build()); if (groupLimit.isGreaterOrEqual(groups.size())) { limits.add(ResultLimit.GROUP); } return new QueryResult(range, groupLimit.limitList(groups), errors, trace, new ResultLimits(limits.build()), preAggregationSampleSize, Optional.empty()); }; }
From source file:com.saharw.objectpool.common.MoreTypes.java
public static ImmutableSet<TypeElement> asTypeElements(Iterable<? extends TypeMirror> mirrors) { checkNotNull(mirrors);//w w w. j a v a2 s . c o m ImmutableSet.Builder<TypeElement> builder = ImmutableSet.builder(); for (TypeMirror mirror : mirrors) { builder.add(asTypeElement(mirror)); } return builder.build(); }
From source file:com.google.devtools.build.lib.skyframe.SkylarkImportLookupFunction.java
/** * Computes the set of {@link Label}s corresponding to a set of Skylark {@link LoadStatement}s. * * @param imports a collection of Skylark {@link LoadStatement}s * @param containingFileLabel the {@link Label} of the file containing the load statements * @return an {@link ImmutableMap} which maps a {@link String} used in the load statement to its * corresponding {@Label}. Returns {@code null} if any Skyframe dependencies are unavailable. * @throws SkylarkImportFailedException if no package can be found that contains the loaded file */// w w w . j a v a 2s. c o m @Nullable static ImmutableMap<String, Label> findLabelsForLoadStatements(ImmutableCollection<SkylarkImport> imports, Label containingFileLabel, Environment env) throws SkylarkImportFailedException, InterruptedException { Preconditions.checkArgument(!containingFileLabel.getPackageIdentifier().getRepository().isDefault()); Map<String, Label> outputMap = Maps.newHashMapWithExpectedSize(imports.size()); // Filter relative vs. absolute paths. ImmutableSet.Builder<PathFragment> absoluteImportsToLookup = new ImmutableSet.Builder<>(); // We maintain a multimap from path fragments to their correspond import strings, to cover the // (unlikely) case where two distinct import strings generate the same path fragment. ImmutableMultimap.Builder<PathFragment, String> pathToImports = new ImmutableMultimap.Builder<>(); for (SkylarkImport imp : imports) { if (imp.hasAbsolutePath()) { absoluteImportsToLookup.add(imp.getAbsolutePath()); pathToImports.put(imp.getAbsolutePath(), imp.getImportString()); } else { outputMap.put(imp.getImportString(), imp.getLabel(containingFileLabel)); } } // Look up labels for absolute paths. ImmutableMap<PathFragment, Label> absoluteLabels = labelsForAbsoluteImports(absoluteImportsToLookup.build(), env); if (absoluteLabels == null) { return null; } for (Entry<PathFragment, Label> entry : absoluteLabels.entrySet()) { PathFragment currPath = entry.getKey(); Label currLabel = entry.getValue(); for (String importString : pathToImports.build().get(currPath)) { outputMap.put(importString, currLabel); } } ImmutableMap<String, Label> immutableOutputMap = ImmutableMap.copyOf(outputMap); return immutableOutputMap; }
From source file:com.google.errorprone.bugpatterns.threadsafety.ImmutableChecker.java
/** * Gets the set of in-scope immutable type parameters from the containerOf specs * on {@code @Immutable} annotations.//from w w w . j av a2s . co m * * <p>Usually only the immediately enclosing declaration is searched, but it's * possible to have cases like: * * <pre> * @Immutable(containerOf="T") class C<T> { * class Inner extends ImmutableCollection<T> {} * } * </pre> */ private static ImmutableSet<String> immutableTypeParametersInScope(Symbol sym) { if (sym == null) { return ImmutableSet.of(); } ImmutableSet.Builder<String> result = ImmutableSet.builder(); OUTER: for (Symbol s = sym; s.owner != null; s = s.owner) { switch (s.getKind()) { case INSTANCE_INIT: continue; case PACKAGE: break OUTER; default: break; } ImmutableAnnotationInfo annotation = getImmutableAnnotation(s); if (annotation == null) { continue; } for (TypeVariableSymbol typaram : s.getTypeParameters()) { String name = typaram.getSimpleName().toString(); if (annotation.containerOf().contains(name)) { result.add(name); } } if (s.isStatic()) { break; } } return result.build(); }
From source file:com.facebook.buck.apple.AppleBuildRules.java
public static ImmutableSet<TargetNode<?, ?>> getRecursiveTargetNodeDependenciesOfTypes( final TargetGraph targetGraph, final Optional<AppleDependenciesCache> cache, final RecursiveDependenciesMode mode, final TargetNode<?, ?> targetNode, final Optional<ImmutableSet<Class<? extends Description<?>>>> descriptionClasses) { LOG.verbose("Getting recursive dependencies of node %s, mode %s, including only types %s\n", targetNode, mode, descriptionClasses);/*from www . ja va 2 s .c om*/ GraphTraversable<TargetNode<?, ?>> graphTraversable = node -> { if (!isXcodeTargetDescription(node.getDescription()) || SwiftLibraryDescription.isSwiftTarget(node.getBuildTarget())) { return Collections.emptyIterator(); } LOG.verbose("Finding children of node: %s", node); ImmutableSortedSet<TargetNode<?, ?>> defaultDeps; ImmutableSortedSet<TargetNode<?, ?>> exportedDeps; if (!cache.isPresent()) { ImmutableSortedSet.Builder<TargetNode<?, ?>> defaultDepsBuilder = ImmutableSortedSet.naturalOrder(); ImmutableSortedSet.Builder<TargetNode<?, ?>> exportedDepsBuilder = ImmutableSortedSet .naturalOrder(); addDirectAndExportedDeps(targetGraph, node, defaultDepsBuilder, exportedDepsBuilder); defaultDeps = defaultDepsBuilder.build(); exportedDeps = exportedDepsBuilder.build(); } else { defaultDeps = cache.get().getDefaultDeps(node); exportedDeps = cache.get().getExportedDeps(node); } if (node.getDescription() instanceof AppleBundleDescription) { AppleBundleDescription.Arg arg = (AppleBundleDescription.Arg) node.getConstructorArg(); ImmutableSortedSet.Builder<TargetNode<?, ?>> editedDeps = ImmutableSortedSet.naturalOrder(); ImmutableSortedSet.Builder<TargetNode<?, ?>> editedExportedDeps = ImmutableSortedSet.naturalOrder(); for (TargetNode<?, ?> rule : defaultDeps) { if (!rule.getBuildTarget().equals(arg.binary)) { editedDeps.add(rule); } else { addDirectAndExportedDeps(targetGraph, targetGraph.get(arg.binary), editedDeps, editedExportedDeps); } } ImmutableSortedSet<TargetNode<?, ?>> newDefaultDeps = editedDeps.build(); ImmutableSortedSet<TargetNode<?, ?>> newExportedDeps = editedExportedDeps.build(); LOG.verbose("Transformed deps for bundle %s: %s -> %s, exported deps %s -> %s", node, defaultDeps, newDefaultDeps, exportedDeps, newExportedDeps); defaultDeps = newDefaultDeps; exportedDeps = newExportedDeps; } LOG.verbose("Default deps for node %s mode %s: %s", node, mode, defaultDeps); if (!exportedDeps.isEmpty()) { LOG.verbose("Exported deps for node %s mode %s: %s", node, mode, exportedDeps); } ImmutableSortedSet<TargetNode<?, ?>> deps = ImmutableSortedSet.of(); if (node != targetNode) { switch (mode) { case LINKING: boolean nodeIsAppleLibrary = node.getDescription() instanceof AppleLibraryDescription; boolean nodeIsCxxLibrary = node.getDescription() instanceof CxxLibraryDescription; if (nodeIsAppleLibrary || nodeIsCxxLibrary) { if (AppleLibraryDescription.isSharedLibraryTarget(node.getBuildTarget())) { deps = exportedDeps; } else { deps = defaultDeps; } } else if (RECURSIVE_DEPENDENCIES_STOP_AT_DESCRIPTION_CLASSES .contains(node.getDescription().getClass())) { deps = exportedDeps; } else { deps = defaultDeps; } break; case COPYING: if (RECURSIVE_DEPENDENCIES_STOP_AT_DESCRIPTION_CLASSES .contains(node.getDescription().getClass())) { deps = exportedDeps; } else { deps = defaultDeps; } break; case BUILDING: deps = defaultDeps; break; } } else { deps = defaultDeps; } LOG.verbose("Walking children of node %s: %s", node, deps); return deps.iterator(); }; final ImmutableSet.Builder<TargetNode<?, ?>> filteredRules = ImmutableSet.builder(); AcyclicDepthFirstPostOrderTraversal<TargetNode<?, ?>> traversal = new AcyclicDepthFirstPostOrderTraversal<>( graphTraversable); try { for (TargetNode<?, ?> node : traversal.traverse(ImmutableList.of(targetNode))) { if (node != targetNode && (!descriptionClasses.isPresent() || descriptionClasses.get().contains(node.getDescription().getClass()))) { filteredRules.add(node); } } } catch (AcyclicDepthFirstPostOrderTraversal.CycleException e) { // actual load failures and cycle exceptions should have been caught at an earlier stage throw new RuntimeException(e); } ImmutableSet<TargetNode<?, ?>> result = filteredRules.build(); LOG.verbose("Got recursive dependencies of node %s mode %s types %s: %s\n", targetNode, mode, descriptionClasses, result); return result; }
From source file:org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableScan.java
private static Pair<ImmutableList<Integer>, ImmutableSet<Integer>> buildColIndxsFrmReloptHT( RelOptHiveTable relOptHTable, RelDataType scanRowType) { RelDataType relOptHtRowtype = relOptHTable.getRowType(); ImmutableList<Integer> neededColIndxsFrmReloptHT; Builder<Integer> neededColIndxsFrmReloptHTBldr = new ImmutableList.Builder<Integer>(); ImmutableSet<Integer> viurtualOrPartColIndxsInTS; ImmutableSet.Builder<Integer> viurtualOrPartColIndxsInTSBldr = new ImmutableSet.Builder<Integer>(); Map<String, Integer> colNameToPosInReloptHT = HiveCalciteUtil .getRowColNameIndxMap(relOptHtRowtype.getFieldList()); List<String> colNamesInScanRowType = scanRowType.getFieldNames(); int partOrVirtualColStartPosInrelOptHtRowtype = relOptHTable.getNonPartColumns().size(); int tmp;//from w ww . java2 s. c o m for (int i = 0; i < colNamesInScanRowType.size(); i++) { tmp = colNameToPosInReloptHT.get(colNamesInScanRowType.get(i)); neededColIndxsFrmReloptHTBldr.add(tmp); if (tmp >= partOrVirtualColStartPosInrelOptHtRowtype) { viurtualOrPartColIndxsInTSBldr.add(i); } } neededColIndxsFrmReloptHT = neededColIndxsFrmReloptHTBldr.build(); viurtualOrPartColIndxsInTS = viurtualOrPartColIndxsInTSBldr.build(); return new Pair<ImmutableList<Integer>, ImmutableSet<Integer>>(neededColIndxsFrmReloptHT, viurtualOrPartColIndxsInTS); }
From source file:com.google.devtools.build.lib.analysis.constraints.ConstraintSemantics.java
/** * Finds the given environment in the given set and returns the default environments for its * group./*from ww w . j a v a2s.c o m*/ */ private static Collection<EnvironmentWithGroup> getDefaults(Label env, EnvironmentCollection allEnvironments) { EnvironmentGroup group = null; for (EnvironmentGroup candidateGroup : allEnvironments.getGroups()) { if (candidateGroup.getDefaults().contains(env)) { group = candidateGroup; break; } } Verify.verifyNotNull(group); ImmutableSet.Builder<EnvironmentWithGroup> builder = ImmutableSet.builder(); for (Label defaultEnv : group.getDefaults()) { builder.add(EnvironmentWithGroup.create(defaultEnv, group)); } return builder.build(); }
From source file:com.android.build.gradle.model.NdkComponentModelPlugin.java
public static void configureScopeForNdk(VariantScope scope) { VariantConfiguration config = scope.getVariantConfiguration(); ImmutableSet.Builder<File> builder = ImmutableSet.builder(); for (Abi abi : NdkHandler.getAbiList()) { scope.addNdkDebuggableLibraryFolders(abi, new File(scope.getGlobalScope().getBuildDir(), NdkNamingScheme.getDebugLibraryDirectoryName( config.getBuildType().getName(), config.getFlavorName(), abi.getName()))); // Return the parent directory of the binaries' output. // If output directory is "/path/to/lib/platformName". We want to return // "/path/to/lib". builder.add(new File(scope.getGlobalScope().getBuildDir(), NdkNamingScheme .getOutputDirectoryName(config.getBuildType().getName(), config.getFlavorName(), abi.getName())) .getParentFile()); }//from www . ja v a 2 s. c o m scope.setNdkSoFolder(builder.build()); }