Example #1
0
  public ResponseLinking copyWithFilteredResponses(final Predicate<Response> toKeepCondition) {
    final Set<Response> newIncompletes = Sets.filter(incompleteResponses(), toKeepCondition);
    final ImmutableSet.Builder<ResponseSet> newResponseSetsB = ImmutableSet.builder();
    final ImmutableBiMap.Builder<String, ResponseSet> responseSetsIdB = ImmutableBiMap.builder();
    // to account for ResponseSets merging due to lost annotation
    final Set<ResponseSet> alreadyAdded = Sets.newHashSet();
    for (final ResponseSet responseSet : responseSets()) {
      final ImmutableSet<Response> okResponses =
          FluentIterable.from(responseSet.asSet()).filter(toKeepCondition).toSet();
      if (!okResponses.isEmpty()) {
        final ResponseSet newResponseSet = ResponseSet.from(okResponses);
        if (alreadyAdded.contains(newResponseSet)) {
          continue;
        }
        alreadyAdded.add(newResponseSet);
        newResponseSetsB.add(newResponseSet);
        if (responseSetIds().isPresent()) {
          responseSetsIdB.put(responseSetIds().get().inverse().get(responseSet), newResponseSet);
        }
      }
    }

    final ImmutableSet<ResponseSet> newResponseSets = newResponseSetsB.build();
    final ResponseLinking.Builder ret =
        ResponseLinking.builder()
            .docID(docID())
            .responseSets(newResponseSets)
            .incompleteResponses(newIncompletes);
    if (responseSetIds().isPresent()) {
      ret.responseSetIds(responseSetsIdB.build());
    }
    return ret.build();
  }
            @Override
            public BiMap<String, Node> load(TreeModel treeModel) {
              ImmutableBiMap.Builder<String, Node> builder = new ImmutableBiMap.Builder<>();

              builder = collectNodes(treeModel.getNode(), new AtomicInteger(1), builder);

              return builder.build();
            }
Example #3
0
 public void testBuilder_orderEntriesByValue_usedTwiceFails() {
   ImmutableBiMap.Builder<String, Integer> builder =
       new Builder<String, Integer>().orderEntriesByValue(Ordering.natural());
   try {
     builder.orderEntriesByValue(Ordering.natural());
     fail("Expected IllegalStateException");
   } catch (IllegalStateException expected) {
   }
 }
Example #4
0
 public void testBuilder_orderEntriesByValueAfterExactSizeBuild() {
   ImmutableBiMap.Builder<String, Integer> builder =
       new ImmutableBiMap.Builder<String, Integer>(2).put("four", 4).put("one", 1);
   ImmutableMap<String, Integer> keyOrdered = builder.build();
   ImmutableMap<String, Integer> valueOrdered =
       builder.orderEntriesByValue(Ordering.natural()).build();
   assertMapEquals(keyOrdered, "four", 4, "one", 1);
   assertMapEquals(valueOrdered, "one", 1, "four", 4);
 }
Example #5
0
 public ImmutableBiMap<ModContainer, Object> buildModObjectList() {
   ImmutableBiMap.Builder<ModContainer, Object> builder =
       ImmutableBiMap.<ModContainer, Object>builder();
   for (ModContainer mc : activeModList) {
     if (!mc.isImmutable() && mc.getMod() != null) {
       builder.put(mc, mc.getMod());
     }
     if (mc.getMod() == null && !mc.isImmutable() && state != LoaderState.CONSTRUCTING) {
       FMLLog.severe(
           "There is a severe problem with %s - it appears not to have constructed correctly",
           mc.getModId());
       if (state != LoaderState.CONSTRUCTING) {
         this.errorOccurred(mc, new RuntimeException());
       }
     }
   }
   return builder.build();
 }
Example #6
0
  static {
    ImmutableBiMap.Builder<ChatColor, String> builder = ImmutableBiMap.builder();
    for (ChatColor style : ChatColor.values()) {
      if (!style.isFormat()) {
        continue;
      }

      String styleName;
      switch (style) {
        case MAGIC:
          styleName = "obfuscated";
          break;
        case UNDERLINE:
          styleName = "underlined";
          break;
        default:
          styleName = style.name().toLowerCase();
          break;
      }

      builder.put(style, styleName);
    }
    stylesToNames = builder.build();
  }
Example #7
0
  public RuleNames(Grammar grammar, boolean installAdapter) {
    this.contextGrammar = grammar;
    Adapter adapter = new Adapter(this);
    if (installAdapter) {
      installAdapterIfMissing(adapter, grammar);
    }
    List<AbstractRule> allRules = GrammarUtil.allRules(grammar);
    ImmutableListMultimap.Builder<String, AbstractRule> simpleNameToRulesBuilder =
        ImmutableListMultimap.builder();
    ImmutableMap.Builder<String, AbstractRule> qualifiedNameToRuleBuilder = ImmutableMap.builder();
    ImmutableBiMap.Builder<String, AbstractRule> uniqueNameToRuleBuilder = ImmutableBiMap.builder();
    ImmutableBiMap.Builder<String, AbstractRule> antlrNameToRuleBuilder = ImmutableBiMap.builder();

    Map<String, AbstractRule> names = Maps.newHashMap();
    Set<String> usedAntlrNames = Sets.newHashSet();
    Set<String> usedUniqueNames = Sets.newHashSet();
    for (AbstractRule rule : allRules) {
      String name = rule.getName();
      simpleNameToRulesBuilder.put(name, rule);
      String qualifiedName = getQualifiedName(rule);
      qualifiedNameToRuleBuilder.put(qualifiedName, rule);
      String uniqueName = name;
      String antlrRuleName;
      if (names.containsKey(name)) {
        name = qualifiedName;
        uniqueName = getInheritedUniqueName(rule, usedUniqueNames);
        antlrRuleName = getInheritedAntlrRuleName(rule, usedAntlrNames);
      } else {
        antlrRuleName = getDefaultAntlrRuleName(rule);
      }
      names.put(name, rule);
      if (!usedUniqueNames.add(uniqueName)) {
        throw new IllegalStateException(uniqueName);
      }
      uniqueNameToRuleBuilder.put(uniqueName, rule);
      if (!usedAntlrNames.add(antlrRuleName)) {
        throw new IllegalStateException(antlrRuleName);
      }
      antlrNameToRuleBuilder.put(antlrRuleName, rule);
      if (installAdapter) {
        installAdapterIfMissing(adapter, rule);
      }
    }
    simpleNameToRules = simpleNameToRulesBuilder.build();
    qualifiedNameToRule = qualifiedNameToRuleBuilder.build();
    nameToRule = ImmutableBiMap.copyOf(names);
    uniqueNameToRule = uniqueNameToRuleBuilder.build();
    antlrNameToRule = antlrNameToRuleBuilder.build();
    this.allRules = ImmutableList.copyOf(allRules);
  }
Example #8
0
 private ImmutableBiMap<Path, Path> getAllPathsWork(Path workingDir) {
   ImmutableBiMap.Builder<Path, Path> builder = ImmutableBiMap.builder();
   builder.put(workingDir, compilationDirectory);
   builder.putAll(other);
   return builder.build();
 }
Example #9
0
  @VisibleForTesting
  static AppleCxxPlatform buildWithExecutableChecker(
      AppleSdk targetSdk,
      String minVersion,
      String targetArchitecture,
      AppleSdkPaths sdkPaths,
      BuckConfig buckConfig,
      ExecutableFinder executableFinder) {

    ImmutableList.Builder<Path> toolSearchPathsBuilder = ImmutableList.builder();
    // Search for tools from most specific to least specific.
    toolSearchPathsBuilder
        .add(sdkPaths.getSdkPath().resolve(USR_BIN))
        .add(sdkPaths.getSdkPath().resolve("Developer").resolve(USR_BIN))
        .add(sdkPaths.getPlatformPath().resolve("Developer").resolve(USR_BIN));
    for (Path toolchainPath : sdkPaths.getToolchainPaths()) {
      toolSearchPathsBuilder.add(toolchainPath.resolve(USR_BIN));
    }
    if (sdkPaths.getDeveloperPath().isPresent()) {
      toolSearchPathsBuilder.add(sdkPaths.getDeveloperPath().get().resolve(USR_BIN));
      toolSearchPathsBuilder.add(sdkPaths.getDeveloperPath().get().resolve("Tools"));
    }
    ImmutableList<Path> toolSearchPaths = toolSearchPathsBuilder.build();

    // TODO(user): Add more and better cflags.
    ImmutableList.Builder<String> cflagsBuilder = ImmutableList.builder();
    cflagsBuilder.add("-isysroot", sdkPaths.getSdkPath().toString());
    cflagsBuilder.add("-arch", targetArchitecture);
    switch (targetSdk.getApplePlatform().getName()) {
      case ApplePlatform.Name.IPHONEOS:
        cflagsBuilder.add("-mios-version-min=" + minVersion);
        break;
      case ApplePlatform.Name.IPHONESIMULATOR:
        cflagsBuilder.add("-mios-simulator-version-min=" + minVersion);
        break;
      default:
        // For Mac builds, -mmacosx-version-min=<version>.
        cflagsBuilder.add(
            "-m" + targetSdk.getApplePlatform().getName() + "-version-min=" + minVersion);
        break;
    }

    ImmutableList<String> ldflags = ImmutableList.of("-sdk_version", targetSdk.getVersion());

    ImmutableList.Builder<String> versionsBuilder = ImmutableList.builder();
    versionsBuilder.add(targetSdk.getVersion());
    for (AppleToolchain toolchain : targetSdk.getToolchains()) {
      versionsBuilder.add(toolchain.getVersion());
    }
    String version = Joiner.on(':').join(versionsBuilder.build());

    Tool clangPath =
        new VersionedTool(
            getToolPath("clang", toolSearchPaths, executableFinder),
            ImmutableList.<String>of(),
            "apple-clang",
            version);

    Tool clangXxPath =
        new VersionedTool(
            getToolPath("clang++", toolSearchPaths, executableFinder),
            ImmutableList.<String>of(),
            "apple-clang++",
            version);

    Tool ar =
        new VersionedTool(
            getToolPath("ar", toolSearchPaths, executableFinder),
            ImmutableList.<String>of(),
            "apple-ar",
            version);

    Tool actool =
        new VersionedTool(
            getToolPath("actool", toolSearchPaths, executableFinder),
            ImmutableList.<String>of(),
            "apple-actool",
            version);

    Tool ibtool =
        new VersionedTool(
            getToolPath("ibtool", toolSearchPaths, executableFinder),
            ImmutableList.<String>of(),
            "apple-ibtool",
            version);

    Tool xctest =
        new VersionedTool(
            getToolPath("xctest", toolSearchPaths, executableFinder),
            ImmutableList.<String>of(),
            "apple-xctest",
            version);

    Optional<Tool> otest = getOptionalTool("otest", toolSearchPaths, executableFinder, version);

    Tool dsymutil =
        new VersionedTool(
            getToolPath("dsymutil", toolSearchPaths, executableFinder),
            ImmutableList.<String>of(),
            "apple-dsymutil",
            version);

    CxxBuckConfig config = new CxxBuckConfig(buckConfig);

    ImmutableFlavor targetFlavor =
        ImmutableFlavor.of(
            ImmutableFlavor.replaceInvalidCharacters(
                targetSdk.getName() + "-" + targetArchitecture));

    ImmutableBiMap.Builder<Path, Path> sanitizerPaths = ImmutableBiMap.builder();
    sanitizerPaths.put(sdkPaths.getSdkPath(), Paths.get("APPLE_SDKROOT"));
    sanitizerPaths.put(sdkPaths.getPlatformPath(), Paths.get("APPLE_PLATFORM_DIR"));
    if (sdkPaths.getDeveloperPath().isPresent()) {
      sanitizerPaths.put(sdkPaths.getDeveloperPath().get(), Paths.get("APPLE_DEVELOPER_DIR"));
    }

    DebugPathSanitizer debugPathSanitizer =
        new DebugPathSanitizer(250, File.separatorChar, Paths.get("."), sanitizerPaths.build());

    ImmutableList<String> cflags = cflagsBuilder.build();

    CxxPlatform cxxPlatform =
        CxxPlatforms.build(
            targetFlavor,
            Platform.MACOS,
            config,
            clangPath,
            clangPath,
            new ClangCompiler(clangPath),
            new ClangCompiler(clangXxPath),
            clangPath,
            clangXxPath,
            clangXxPath,
            Optional.of(CxxPlatform.LinkerType.DARWIN),
            clangXxPath,
            ldflags,
            new BsdArchiver(ar),
            cflags,
            ImmutableList.<String>of(),
            getOptionalTool("lex", toolSearchPaths, executableFinder, version),
            getOptionalTool("yacc", toolSearchPaths, executableFinder, version),
            Optional.of(debugPathSanitizer));

    return AppleCxxPlatform.builder()
        .setCxxPlatform(cxxPlatform)
        .setAppleSdk(targetSdk)
        .setAppleSdkPaths(sdkPaths)
        .setActool(actool)
        .setIbtool(ibtool)
        .setXctest(xctest)
        .setOtest(otest)
        .setDsymutil(dsymutil)
        .build();
  }