List of usage examples for com.google.common.collect FluentIterable append
@Beta @CheckReturnValue public final FluentIterable<E> append(E... elements)
From source file:com.google.gerrit.server.change.ActionJson.java
private Map<String, ActionInfo> toActionMap(ChangeControl ctl, List<ActionVisitor> visitors, ChangeInfo changeInfo) {//from w w w . j ava2s . c o m Map<String, ActionInfo> out = new LinkedHashMap<>(); if (!ctl.getUser().isIdentifiedUser()) { return out; } Provider<CurrentUser> userProvider = Providers.of(ctl.getUser()); FluentIterable<UiAction.Description> descs = UiActions.from(changeViews, changeResourceFactory.create(ctl), userProvider); // The followup action is a client-side only operation that does not // have a server side handler. It must be manually registered into the // resulting action map. if (ctl.getChange().getStatus().isOpen()) { UiAction.Description descr = new UiAction.Description(); PrivateInternals_UiActionDescription.setId(descr, "followup"); PrivateInternals_UiActionDescription.setMethod(descr, "POST"); descr.setTitle("Create follow-up change"); descr.setLabel("Follow-Up"); descs = descs.append(descr); } ACTION: for (UiAction.Description d : descs) { ActionInfo actionInfo = new ActionInfo(d); for (ActionVisitor visitor : visitors) { if (!visitor.visit(d.getId(), actionInfo, changeInfo)) { continue ACTION; } } out.put(d.getId(), actionInfo); } return out; }
From source file:com.facebook.buck.apple.WorkspaceAndProjectGenerator.java
private void writeWorkspaceSchemes(String workspaceName, Path outputDirectory, ImmutableMap<String, XcodeWorkspaceConfigDescription.Arg> schemeConfigs, ImmutableSetMultimap<String, Optional<TargetNode<?>>> schemeNameToSrcTargetNode, ImmutableSetMultimap<String, TargetNode<?>> buildForTestNodes, ImmutableSetMultimap<String, TargetNode<AppleTestDescription.Arg>> ungroupedTests, ImmutableMap<PBXTarget, Path> targetToProjectPathMap, Iterable<PBXTarget> synthesizedCombinedTestTargets, Function<TargetNode<?>, Collection<PBXTarget>> targetNodeToPBXTargetTransformer, Function<BuildTarget, PBXTarget> buildTargetToPBXTargetTransformer) throws IOException { for (Map.Entry<String, XcodeWorkspaceConfigDescription.Arg> schemeConfigEntry : schemeConfigs.entrySet()) { String schemeName = schemeConfigEntry.getKey(); boolean isMainScheme = schemeName.equals(workspaceName); XcodeWorkspaceConfigDescription.Arg schemeConfigArg = schemeConfigEntry.getValue(); Iterable<PBXTarget> orderedBuildTargets = FluentIterable .from(ImmutableSet.copyOf(Optional.presentInstances(schemeNameToSrcTargetNode.get(schemeName)))) .transformAndConcat(targetNodeToPBXTargetTransformer).toSet(); FluentIterable<PBXTarget> orderedBuildTestTargets = FluentIterable .from(buildForTestNodes.get(schemeName)).transformAndConcat(targetNodeToPBXTargetTransformer); if (isMainScheme) { orderedBuildTestTargets = orderedBuildTestTargets.append(synthesizedCombinedTestTargets); }//from w w w. j ava2 s .c o m FluentIterable<PBXTarget> orderedRunTestTargets = FluentIterable.from(ungroupedTests.get(schemeName)) .transformAndConcat(targetNodeToPBXTargetTransformer); if (isMainScheme) { orderedRunTestTargets = orderedRunTestTargets.append(synthesizedCombinedTestTargets); } Optional<String> runnablePath; Optional<BuildTarget> targetToBuildWithBuck = getTargetToBuildWithBuck(); if (buildWithBuck && targetToBuildWithBuck.isPresent()) { Optional<String> productName = getProductName(schemeNameToSrcTargetNode.get(schemeName), targetToBuildWithBuck); String binaryName = AppleBundle.getBinaryName(targetToBuildWithBuck.get(), productName); runnablePath = Optional.of(projectFilesystem.resolve( ProjectGenerator.getScratchPathForAppBundle(targetToBuildWithBuck.get(), binaryName)) .toString()); } else { runnablePath = Optional.absent(); } Optional<String> remoteRunnablePath; if (schemeConfigArg.isRemoteRunnable.or(false)) { // XXX TODO(bhamiltoncx): Figure out the actual name of the binary to launch remoteRunnablePath = Optional.of("/" + workspaceName); } else { remoteRunnablePath = Optional.absent(); } SchemeGenerator schemeGenerator = new SchemeGenerator(projectFilesystem, schemeConfigArg.srcTarget.transform(buildTargetToPBXTargetTransformer), orderedBuildTargets, orderedBuildTestTargets, orderedRunTestTargets, schemeName, combinedProject ? outputDirectory : outputDirectory.resolve(workspaceName + ".xcworkspace"), buildWithBuck, parallelizeBuild, runnablePath, remoteRunnablePath, XcodeWorkspaceConfigDescription.getActionConfigNamesFromArg(workspaceArguments), targetToProjectPathMap); schemeGenerator.writeScheme(); schemeGenerators.put(schemeName, schemeGenerator); } }
From source file:com.facebook.buck.apple.AppleBundleDescription.java
/** * Propagate the bundle's platform, debug symbol and strip flavors to its dependents * which are other bundles (e.g. extensions) *//* ww w. j a va 2 s. co m*/ @Override public ImmutableSet<BuildTarget> findDepsForTargetFromConstructorArgs(BuildTarget buildTarget, CellPathResolver cellRoots, AppleBundleDescription.Arg constructorArg) { if (!cxxPlatformFlavorDomain.containsAnyOf(buildTarget.getFlavors())) { buildTarget = BuildTarget.builder(buildTarget) .addAllFlavors(ImmutableSet.of(defaultCxxPlatform.getFlavor())).build(); } Optional<MultiarchFileInfo> fatBinaryInfo = MultiarchFileInfos.create(appleCxxPlatformsFlavorDomain, buildTarget); CxxPlatform cxxPlatform; if (fatBinaryInfo.isPresent()) { AppleCxxPlatform appleCxxPlatform = fatBinaryInfo.get().getRepresentativePlatform(); cxxPlatform = appleCxxPlatform.getCxxPlatform(); } else { cxxPlatform = ApplePlatforms.getCxxPlatformForBuildTarget(cxxPlatformFlavorDomain, defaultCxxPlatform, buildTarget); } String platformName = cxxPlatform.getFlavor().getName(); final Flavor actualWatchFlavor; if (ApplePlatform.isSimulator(platformName)) { actualWatchFlavor = WATCH_SIMULATOR_FLAVOR; } else if (platformName.startsWith(ApplePlatform.IPHONEOS.getName()) || platformName.startsWith(ApplePlatform.WATCHOS.getName())) { actualWatchFlavor = WATCH_OS_FLAVOR; } else { actualWatchFlavor = ImmutableFlavor.of(platformName); } FluentIterable<BuildTarget> depsExcludingBinary = FluentIterable.from(constructorArg.deps) .filter(Predicates.not(constructorArg.binary::equals)); // Propagate platform flavors. Need special handling for watch to map the pseudo-flavor // watch to the actual watch platform (simulator or device) so can't use // BuildTargets.propagateFlavorsInDomainIfNotPresent() { FluentIterable<BuildTarget> targetsWithPlatformFlavors = depsExcludingBinary .filter(BuildTargets.containsFlavors(cxxPlatformFlavorDomain)); FluentIterable<BuildTarget> targetsWithoutPlatformFlavors = depsExcludingBinary .filter(Predicates.not(BuildTargets.containsFlavors(cxxPlatformFlavorDomain))); FluentIterable<BuildTarget> watchTargets = targetsWithoutPlatformFlavors .filter(BuildTargets.containsFlavor(WATCH)).transform(input -> BuildTarget .builder(input.withoutFlavors(WATCH)).addFlavors(actualWatchFlavor).build()); targetsWithoutPlatformFlavors = targetsWithoutPlatformFlavors .filter(Predicates.not(BuildTargets.containsFlavor(WATCH))); // Gather all the deps now that we've added platform flavors to everything. depsExcludingBinary = targetsWithPlatformFlavors.append(watchTargets) .append(BuildTargets.propagateFlavorDomains(buildTarget, ImmutableSet.of(cxxPlatformFlavorDomain), targetsWithoutPlatformFlavors)); } // Propagate some flavors depsExcludingBinary = BuildTargets.propagateFlavorsInDomainIfNotPresent(StripStyle.FLAVOR_DOMAIN, buildTarget, depsExcludingBinary); depsExcludingBinary = BuildTargets.propagateFlavorsInDomainIfNotPresent(AppleDebugFormat.FLAVOR_DOMAIN, buildTarget, depsExcludingBinary); depsExcludingBinary = BuildTargets.propagateFlavorsInDomainIfNotPresent(LinkerMapMode.FLAVOR_DOMAIN, buildTarget, depsExcludingBinary); return ImmutableSet.copyOf(depsExcludingBinary); }
From source file:org.sosy_lab.cpachecker.util.cwriter.PathToCWithLoopsTranslator.java
/** * Recreates the code of one (or more nested) loops with gotos. * @param pCFAEdge the edge into the loop * @param currentBlock the current block * @param loopsAfter the loops which we are in after the edge * @return the complete c-code for the recreated loop *///from w w w.ja v a 2 s . co m private Pair<String, CFAEdge> recreateLoop(CFAEdge pCFAEdge, BasicBlock currentBlock, List<Loop> loopsAfter) { // clear all necessary things resetLoopAndIfMaps(); CFAEdge lastEdge = null; // start actual loop recreation StringBuilder wholeLoopString = new StringBuilder(); // we go into a loop thus we have to uproll it right now, and add all // handled edges to the handledEdges list, so they wont occur twice in the // generated c code // this should be already handled by the handledEdges check at the beginning // of the processEdge method assert loopsAfter.get(loopsAfter.size() - 1).getIncomingEdges().contains(pCFAEdge); Loop loop = loopsAfter.get(loopsAfter.size() - 1); // create necessary mappings String labelStayInLoop = createFreshLabelForLoop(pCFAEdge, loop); // uproll loop and write code wholeLoopString.append(labelStayInLoop).append(": ;\n"); Deque<CFAEdge> edgesToHandle = new ArrayDeque<>(); edgesToHandle.offer(pCFAEdge); Deque<Loop> loopStack = new ArrayDeque<>(); loopStack.push(loop); Deque<CFAEdge> ifStack = new ArrayDeque<>(); Deque<CFAEdge> outOfLoopEdgesStack = new ArrayDeque<>(); while ((!edgesToHandle.isEmpty() || !outOfLoopEdgesStack.isEmpty() || !ifStack.isEmpty())) { // all nodes from the current loop handled, so we can go on to the // next one if (edgesToHandle.isEmpty()) { // at first we need to handle ifs if (!ifStack.isEmpty()) { edgesToHandle.offer(ifStack.pop()); wholeLoopString.append("goto ").append(ifOutLabels.get(edgesToHandle.peek())).append(";\n") .append(ifElseLabels.get(edgesToHandle.peek())).append(": ;\n"); } else { edgesToHandle.offer(outOfLoopEdgesStack.pop()); Loop oldLoop = loopStack.pop(); wholeLoopString.append("goto ").append(loopInLabels.get(oldLoop)).append(";\n") .append(loopOutLabels.get(oldLoop)).append(": ;\n"); } } CFANode currentEdgePredecessor = edgesToHandle.peek().getPredecessor(); handleIfOutLabels(wholeLoopString, currentEdgePredecessor); // only continue if we didn't already visit this edge if (handledEdges.contains(edgesToHandle.peek())) { edgesToHandle.pop(); continue; } CFAEdge currentEdge = edgesToHandle.pop(); handledEdges.add(currentEdge); FluentIterable<CFAEdge> leaving = CFAUtils.leavingEdges(currentEdge.getSuccessor()) .filter(not(instanceOf(FunctionCallEdge.class))); // there was a function call, we need to replace it with the correct successor // as we are sure that there is only one, this is safe, we also don't // need to update loops here if (leaving.isEmpty()) { CFAEdge realLeavingEdge = currentEdge.getSuccessor().getLeavingEdge(0); CFAEdge leavingSummaryEdge = currentEdge.getSuccessor().getLeavingSummaryEdge(); wholeLoopString.append(processSimpleWithLoop(realLeavingEdge, currentBlock, "")); handledFunctions.add(((CFunctionEntryNode) realLeavingEdge.getSuccessor()).getFunctionName()); leaving = leaving.append(leavingSummaryEdge); // no function call just and ordinary statement, add it as it is // to the loopString } else if (leaving.size() == 1) { wholeLoopString.append(processSimpleWithLoop(leaving.get(0), currentBlock, "")); } // only one successor, to handle // we need to check the loops so that we know if we need // to update the loopStack, or only the handledEdges if (leaving.size() == 1) { CFAEdge onlyEdge = leaving.get(0); // this is an edge from inside the loop back to the loop if (loopToHead.get(loopStack.peek()) == onlyEdge.getSuccessor() && !loopStack.peek().getIncomingEdges().contains(onlyEdge)) { handledEdges.add(onlyEdge); handleIfOutLabels(wholeLoopString, onlyEdge.getPredecessor()); } else { edgesToHandle.offer(onlyEdge); updateLoopStack(wholeLoopString, loopStack, onlyEdge); } // more sucessors, we have to add some gotos } else { // there can be at most two leaving edges assert leaving.size() == 2 : leaving.toString(); CFAEdge leaving1 = leaving.get(0); CFAEdge leaving2 = leaving.get(1); // outgoing edges have to be handled first, this way // we can create the goto easier ImmutableSet<CFAEdge> outOfCurrentLoop = loopStack.peek().getOutgoingEdges(); boolean isOutOfLoopContained = false; CFAEdge leavingLoopEdge = null; if (outOfCurrentLoop.contains(leaving1)) { handleOutOfLoopEdge(currentBlock, wholeLoopString, edgesToHandle, loopStack, leaving1, leaving2); leavingLoopEdge = leaving1; isOutOfLoopContained = true; } else if (outOfCurrentLoop.contains(leaving2)) { handleOutOfLoopEdge(currentBlock, wholeLoopString, edgesToHandle, loopStack, leaving2, leaving1); leavingLoopEdge = leaving2; isOutOfLoopContained = true; } if (isOutOfLoopContained) { // we are alredy in the outermost loop that should be handled // if we have an edge which is leaving this loop we just need // to create a goto if (loopStack.size() == 1) { lastEdge = leavingLoopEdge; handledEdges.add(leavingLoopEdge); // deeper loopstack, potentially the same code as above // we do only need to handle the successor of the outOfLoopEdge, too } else { outOfLoopEdgesStack.push(leavingLoopEdge); } // end this loop iteration here continue; } // now comes the case where both edges stay in the loop, this means // this is a "simple" if statement // we need to find the merging point of both branches, such that we // know where the gotos and labels have to go if (!handledEdges.contains(leaving1)) { wholeLoopString.append(processSimpleWithLoop(leaving1, currentBlock, createFreshLabelForIf(leaving2, findEndOfBranches(singletonList(loopToHead.get(loopStack.peek())), currentEdgePredecessor, leaving1.getSuccessor(), leaving2.getSuccessor())))); edgesToHandle.push(leaving1); ifStack.push(leaving2); } } } wholeLoopString.append("goto ").append(loopInLabels.get(loop)).append(";\n").append(loopOutLabels.get(loop)) .append(": ;\n"); // assert ifOutLabelEnd.isEmpty() && loopStack.isEmpty(); return Pair.of(wholeLoopString.toString(), lastEdge); }
From source file:org.sosy_lab.cpachecker.core.counterexample.AssumptionToEdgeAllocator.java
private @Nullable AExpressionStatement buildEquationExpressionStatement(CBinaryExpressionBuilder pBuilder, CExpression pLeftSide, CExpression pRightSide) { CExpression leftSide = pLeftSide;//from ww w.jav a 2s .c o m CExpression rightSide = pRightSide; final CType leftType = leftSide.getExpressionType().getCanonicalType(); final CType rightType = rightSide.getExpressionType().getCanonicalType(); if (leftType instanceof CVoidType && rightType instanceof CVoidType) { return null; } boolean equalTypes = leftType.equals(rightType); FluentIterable<Class<? extends CType>> acceptedTypes = FluentIterable .from(Collections.<Class<? extends CType>>singleton(CSimpleType.class)); if (includeConstantsForPointers) { acceptedTypes = acceptedTypes.append(Arrays.asList(CArrayType.class, CPointerType.class)); } boolean leftIsAccepted = equalTypes || acceptedTypes.anyMatch(new Predicate<Class<? extends CType>>() { @Override public boolean apply(Class<? extends CType> pArg0) { return pArg0.isAssignableFrom(leftType.getClass()); } }); boolean rightIsAccepted = equalTypes || acceptedTypes.anyMatch(new Predicate<Class<? extends CType>>() { @Override public boolean apply(Class<? extends CType> pArg0) { return pArg0.isAssignableFrom(rightType.getClass()); } }); if (!includeConstantsForPointers && (!leftIsAccepted || !rightIsAccepted)) { return null; } if (leftType instanceof CSimpleType && !rightIsAccepted) { rightSide = new CCastExpression(rightSide.getFileLocation(), leftType, rightSide); } else if (!leftIsAccepted && rightType instanceof CSimpleType) { leftSide = new CCastExpression(leftSide.getFileLocation(), rightType, leftSide); } CBinaryExpression assumption = pBuilder.buildBinaryExpressionUnchecked(leftSide, rightSide, CBinaryExpression.BinaryOperator.EQUALS); return new CExpressionStatement(assumption.getFileLocation(), assumption); }