Example usage for com.google.common.collect ImmutableSet contains

List of usage examples for com.google.common.collect ImmutableSet contains

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSet contains.

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this set contains the specified element.

Usage

From source file:org.jetbrains.jet.plugin.quickfix.MigrateTuplesInProjectFix.java

private void replaceTupleComponentCalls(JetFile file, final BindingContext context) {
    for (JetDeclaration declaration : file.getDeclarations()) {
        declaration.acceptChildren(new JetVisitorVoid() {

            @Override//  w  w w .j  a v  a 2s . c  om
            public void visitSimpleNameExpression(JetSimpleNameExpression expression) {
                DeclarationDescriptor referenceTarget = context.get(BindingContext.REFERENCE_TARGET,
                        expression);
                if (referenceTarget == null)
                    return;

                DeclarationDescriptor containingDeclaration = referenceTarget.getContainingDeclaration();
                if (containingDeclaration == null)
                    return;

                ImmutableSet<ClassDescriptor> supportedTupleClasses = ImmutableSet
                        .of(KotlinBuiltIns.getInstance().getTuple(2), KotlinBuiltIns.getInstance().getTuple(3));
                //noinspection SuspiciousMethodCalls
                if (!supportedTupleClasses.contains(containingDeclaration))
                    return;

                ImmutableMap<String, String> supportedComponents = ImmutableMap.<String, String>builder()
                        .put("_1", "first").put("_2", "second").put("_3", "third").build();
                String newName = supportedComponents.get(expression.getReferencedName());
                if (newName == null)
                    return;

                expression.replace(JetPsiFactory.createExpression(expression.getProject(), newName));
            }

            @Override
            public void visitElement(PsiElement element) {
                element.acceptChildren(this);
            }
        });
    }
}

From source file:com.facebook.buck.thrift.ThriftCxxEnhancer.java

@VisibleForTesting
protected ImmutableSortedSet<String> getGeneratedSources(String thriftName, ImmutableList<String> services,
        ImmutableSet<String> options) {

    final String base = Files.getNameWithoutExtension(thriftName);
    final boolean bootstrap = options.contains("bootstrap");
    final boolean layouts = options.contains("frozen2");
    final boolean templates = cpp2 || options.contains("templates");
    final boolean perfhash = !cpp2 && options.contains("perfhash");
    final boolean separateProcessmap = cpp2 && options.contains("separate_processmap");
    final boolean fatal = cpp2 && options.contains("fatal");

    ImmutableSortedSet.Builder<String> sources = ImmutableSortedSet.naturalOrder();

    sources.add(base + "_constants.h");
    sources.add(base + "_constants.cpp");

    sources.add(base + "_types.h");
    sources.add(base + "_types.cpp");

    if (templates) {
        sources.add(base + "_types.tcc");
    }//from  w  ww  .ja v a  2s. c om

    if (layouts) {
        sources.add(base + "_layouts.h");
        sources.add(base + "_layouts.cpp");
    }

    if (!bootstrap && !cpp2) {
        sources.add(base + "_reflection.h");
        sources.add(base + "_reflection.cpp");
    }

    if (fatal) {
        final String[] suffixes = new String[] { "", "_enum", "_union", "_struct", "_constant", "_service",
                "_types", "_all" };

        for (String suffix : suffixes) {
            sources.add(base + "_fatal" + suffix + ".h");
            sources.add(base + "_fatal" + suffix + ".cpp");
        }
    }

    if (cpp2) {
        sources.add(base + "_types_custom_protocol.h");
    }

    for (String service : services) {

        sources.add(service + ".h");
        sources.add(service + ".cpp");

        if (cpp2) {
            sources.add(service + "_client.cpp");
            sources.add(service + "_custom_protocol.h");
        }

        if (separateProcessmap) {
            sources.add(service + "_processmap_binary.cpp");
            sources.add(service + "_processmap_compact.cpp");
        }

        if (templates) {
            sources.add(service + ".tcc");
        }

        if (perfhash) {
            sources.add(service + "_gperf.tcc");
        }

    }

    return sources.build();
}

From source file:com.facebook.buck.features.haskell.HaskellBinaryDescription.java

@Override
public boolean hasFlavors(ImmutableSet<Flavor> flavors) {
    if (getHaskellPlatformsProvider().getHaskellPlatforms().containsAnyOf(flavors)) {
        return true;
    }// w  ww.  j  a  v  a  2  s  .  co m

    for (Type type : Type.values()) {
        if (flavors.contains(type.getFlavor())) {
            return true;
        }
    }

    return false;
}

From source file:com.facebook.buck.java.intellij.AbstractIjModule.java

@Value.Check
protected void checkDependencyConsistency() {
    ImmutableSet<BuildTarget> buildTargets = FluentIterable.from(getTargets()).transform(TargetNode.TO_TARGET)
            .toSet();/*from w  ww . j  av  a 2 s . c  o m*/

    for (Map.Entry<BuildTarget, IjModuleGraph.DependencyType> entry : getDependencies().entrySet()) {
        BuildTarget depBuildTarget = entry.getKey();
        IjModuleGraph.DependencyType dependencyType = entry.getValue();
        boolean isSelfDependency = buildTargets.contains(depBuildTarget);

        if (dependencyType.equals(IjModuleGraph.DependencyType.COMPILED_SHADOW)) {
            Preconditions.checkArgument(isSelfDependency,
                    "Target %s is a COMPILED_SHADOW dependency of module %s and therefore should be part"
                            + "of its target set.",
                    depBuildTarget, getName());
        } else {
            Preconditions.checkArgument(!isSelfDependency,
                    "Target %s is a regular dependency of module %s and therefore should not be part of "
                            + "its target set.",
                    depBuildTarget, getName());
        }
    }
}

From source file:com.facebook.buck.ide.intellij.AbstractIjModule.java

@Value.Check
protected void checkDependencyConsistency() {
    ImmutableSet<BuildTarget> buildTargets = getTargets().stream().map(TargetNode::getBuildTarget)
            .collect(MoreCollectors.toImmutableSet());

    for (Map.Entry<BuildTarget, DependencyType> entry : getDependencies().entrySet()) {
        BuildTarget depBuildTarget = entry.getKey();
        DependencyType dependencyType = entry.getValue();
        boolean isSelfDependency = buildTargets.contains(depBuildTarget);

        if (dependencyType.equals(DependencyType.COMPILED_SHADOW)) {
            Preconditions.checkArgument(isSelfDependency,
                    "Target %s is a COMPILED_SHADOW dependency of module %s and therefore should be part"
                            + "of its target set.",
                    depBuildTarget, getName());
        } else {/*from  w  ww.j  a v a 2 s . c  o m*/
            Preconditions.checkArgument(!isSelfDependency,
                    "Target %s is a regular dependency of module %s and therefore should not be part of "
                            + "its target set.",
                    depBuildTarget, getName());
        }
    }
}

From source file:com.facebook.buck.jvm.java.intellij.AbstractIjModule.java

@Value.Check
protected void checkDependencyConsistency() {
    ImmutableSet<BuildTarget> buildTargets = getTargets().stream().map(HasBuildTarget::getBuildTarget)
            .collect(MoreCollectors.toImmutableSet());

    for (Map.Entry<BuildTarget, DependencyType> entry : getDependencies().entrySet()) {
        BuildTarget depBuildTarget = entry.getKey();
        DependencyType dependencyType = entry.getValue();
        boolean isSelfDependency = buildTargets.contains(depBuildTarget);

        if (dependencyType.equals(DependencyType.COMPILED_SHADOW)) {
            Preconditions.checkArgument(isSelfDependency,
                    "Target %s is a COMPILED_SHADOW dependency of module %s and therefore should be part"
                            + "of its target set.",
                    depBuildTarget, getName());
        } else {//from  www  . j a v a 2 s.com
            Preconditions.checkArgument(!isSelfDependency,
                    "Target %s is a regular dependency of module %s and therefore should not be part of "
                            + "its target set.",
                    depBuildTarget, getName());
        }
    }
}

From source file:com.facebook.buck.rules.keys.DefaultRuleKeyCache.java

/**
 * Invalidate all inputs *not* from the given {@link ProjectFilesystem}s and their transitive
 * dependents.//from   w  w  w  .j  av a2  s  .  co m
 */
@Override
public void invalidateAllExceptFilesystems(ImmutableSet<ProjectFilesystem> filesystems,
        CacheStatsTracker statsTracker) {
    if (filesystems.isEmpty()) {
        invalidateAll(statsTracker);
    } else {
        invalidateInputs(inputsIndex.keySet().stream()
                .filter(input -> !filesystems.contains(input.getFilesystem())).collect(Collectors.toList()),
                statsTracker);
    }
}

From source file:com.arpnetworking.metrics.mad.Aggregator.java

private ImmutableSet<Statistic> computeDependentStatistics(final ImmutableSet<Statistic> statistics) {
    final ImmutableSet.Builder<Statistic> builder = ImmutableSet.builder();
    for (final Statistic statistic : statistics) {
        statistic.getDependencies().stream().filter(dependency -> !statistics.contains(dependency))
                .forEach(builder::add);/*from   ww w.  ja  v a 2 s  .c om*/
    }
    return builder.build();
}

From source file:com.facebook.buck.cxx.CxxBinaryDescription.java

@SuppressWarnings("PMD.PrematureDeclaration")
@Override//from   w ww  .j a v  a  2  s  .co m
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params,
        BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {

    // We explicitly remove some flavors below from params to make sure rule
    // has the same output regardless if we will strip or not.
    Optional<StripStyle> flavoredStripStyle = StripStyle.FLAVOR_DOMAIN.getValue(params.getBuildTarget());
    Optional<LinkerMapMode> flavoredLinkerMapMode = LinkerMapMode.FLAVOR_DOMAIN
            .getValue(params.getBuildTarget());
    params = CxxStrip.removeStripStyleFlavorInParams(params, flavoredStripStyle);
    params = LinkerMapMode.removeLinkerMapModeFlavorInParams(params, flavoredLinkerMapMode);

    // Extract the platform from the flavor, falling back to the default platform if none are
    // found.
    ImmutableSet<Flavor> flavors = ImmutableSet.copyOf(params.getBuildTarget().getFlavors());
    CxxPlatform cxxPlatform = cxxPlatforms.getValue(flavors).orElse(defaultCxxPlatform);
    if (flavors.contains(CxxDescriptionEnhancer.HEADER_SYMLINK_TREE_FLAVOR)) {
        flavors = ImmutableSet.copyOf(
                Sets.difference(flavors, ImmutableSet.of(CxxDescriptionEnhancer.HEADER_SYMLINK_TREE_FLAVOR)));
        BuildTarget target = BuildTarget.builder(params.getBuildTarget().getUnflavoredBuildTarget())
                .addAllFlavors(flavors).build();
        BuildRuleParams typeParams = params.copyWithChanges(target, params.getDeclaredDeps(),
                params.getExtraDeps());

        return createHeaderSymlinkTreeBuildRule(typeParams, resolver, cxxPlatform, args);
    }

    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);

    if (flavors.contains(CxxCompilationDatabase.COMPILATION_DATABASE)) {
        BuildRuleParams paramsWithoutFlavor = params.withoutFlavor(CxxCompilationDatabase.COMPILATION_DATABASE);
        CxxLinkAndCompileRules cxxLinkAndCompileRules = CxxDescriptionEnhancer
                .createBuildRulesForCxxBinaryDescriptionArg(paramsWithoutFlavor, resolver, cxxBuckConfig,
                        cxxPlatform, args, flavoredStripStyle, flavoredLinkerMapMode);
        return CxxCompilationDatabase.createCompilationDatabase(params, pathResolver,
                cxxLinkAndCompileRules.compileRules);
    }

    if (flavors.contains(CxxCompilationDatabase.UBER_COMPILATION_DATABASE)) {
        return CxxDescriptionEnhancer
                .createUberCompilationDatabase(cxxPlatforms.getValue(flavors).isPresent() ? params
                        : params.withFlavor(defaultCxxPlatform.getFlavor()), resolver);
    }

    if (flavors.contains(CxxInferEnhancer.InferFlavors.INFER.get())) {
        return CxxInferEnhancer.requireInferAnalyzeAndReportBuildRuleForCxxDescriptionArg(params, resolver,
                pathResolver, cxxBuckConfig, cxxPlatform, args, inferBuckConfig,
                new CxxInferSourceFilter(inferBuckConfig));
    }

    if (flavors.contains(CxxInferEnhancer.InferFlavors.INFER_ANALYZE.get())) {
        return CxxInferEnhancer.requireInferAnalyzeBuildRuleForCxxDescriptionArg(params, resolver, pathResolver,
                cxxBuckConfig, cxxPlatform, args, inferBuckConfig, new CxxInferSourceFilter(inferBuckConfig));
    }

    if (flavors.contains(CxxInferEnhancer.InferFlavors.INFER_CAPTURE_ALL.get())) {
        return CxxInferEnhancer.requireAllTransitiveCaptureBuildRules(params, resolver, cxxBuckConfig,
                cxxPlatform, inferBuckConfig, new CxxInferSourceFilter(inferBuckConfig), args);
    }

    if (flavors.contains(CxxInferEnhancer.InferFlavors.INFER_CAPTURE_ONLY.get())) {
        return CxxInferEnhancer.requireInferCaptureAggregatorBuildRuleForCxxDescriptionArg(params, resolver,
                pathResolver, cxxBuckConfig, cxxPlatform, args, inferBuckConfig,
                new CxxInferSourceFilter(inferBuckConfig));
    }

    if (flavors.contains(CxxDescriptionEnhancer.SANDBOX_TREE_FLAVOR)) {
        return CxxDescriptionEnhancer.createSandboxTreeBuildRule(resolver, args, cxxPlatform, params);
    }

    CxxLinkAndCompileRules cxxLinkAndCompileRules = CxxDescriptionEnhancer
            .createBuildRulesForCxxBinaryDescriptionArg(params, resolver, cxxBuckConfig, cxxPlatform, args,
                    flavoredStripStyle, flavoredLinkerMapMode);

    // Return a CxxBinary rule as our representative in the action graph, rather than the CxxLink
    // rule above for a couple reasons:
    //  1) CxxBinary extends BinaryBuildRule whereas CxxLink does not, so the former can be used
    //     as executables for genrules.
    //  2) In some cases, users add dependencies from some rules onto other binary rules, typically
    //     if the binary is executed by some test or library code at test time.  These target graph
    //     deps should *not* become build time dependencies on the CxxLink step, otherwise we'd
    //     have to wait for the dependency binary to link before we could link the dependent binary.
    //     By using another BuildRule, we can keep the original target graph dependency tree while
    //     preventing it from affecting link parallelism.

    params = CxxStrip.restoreStripStyleFlavorInParams(params, flavoredStripStyle);
    params = LinkerMapMode.restoreLinkerMapModeFlavorInParams(params, flavoredLinkerMapMode);
    CxxBinary cxxBinary = new CxxBinary(
            params.appendExtraDeps(cxxLinkAndCompileRules.executable.getDeps(ruleFinder)), resolver,
            pathResolver, ruleFinder, cxxLinkAndCompileRules.getBinaryRule(), cxxLinkAndCompileRules.executable,
            args.frameworks, args.tests, params.getBuildTarget().withoutFlavors(cxxPlatforms.getFlavors()));
    resolver.addToIndex(cxxBinary);
    return cxxBinary;
}

From source file:com.facebook.buck.apple.toolchain.AbstractProvisioningProfileMetadata.java

public ImmutableMap<String, NSObject> getMergeableEntitlements() {
    ImmutableSet<String> includedKeys = ImmutableSet.of("application-identifier", "beta-reports-active",
            "get-task-allow", "com.apple.developer.aps-environment", "com.apple.developer.team-identifier");

    ImmutableMap<String, NSObject> allEntitlements = getEntitlements();
    ImmutableMap.Builder<String, NSObject> filteredEntitlementsBuilder = ImmutableMap.builder();
    for (String key : allEntitlements.keySet()) {
        if (includedKeys.contains(key)) {
            filteredEntitlementsBuilder.put(key, allEntitlements.get(key));
        }/* w w  w.  j  a v a  2  s.com*/
    }
    return filteredEntitlementsBuilder.build();
}