List of usage examples for com.google.common.collect SortedSetMultimap putAll
boolean putAll(@Nullable K key, Iterable<? extends V> values);
From source file:org.terasology.documentation.ApiScraper.java
/** * @param args (ignored)/*from ww w . ja v a2s. c o m*/ * @throws Exception if the module environment cannot be loaded */ public static void main(String[] args) throws Exception { ModuleManager moduleManager = ModuleManagerFactory.create(); ModuleEnvironment environment = moduleManager.getEnvironment(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); SortedSetMultimap<String, String> sortedApi = Multimaps.newSortedSetMultimap(new HashMap<>(), TreeSet::new); for (Class<?> apiClass : environment.getTypesAnnotatedWith(API.class)) { //System.out.println("Processing: " + apiClass); boolean isPackage = apiClass.isSynthetic(); URL location; String category; String apiPackage = ""; if (isPackage) { apiPackage = apiClass.getPackage().getName(); location = classLoader.getResource(apiPackage.replace('.', '/')); } else { location = apiClass.getResource('/' + apiClass.getName().replace('.', '/') + ".class"); } if (location == null) { System.out.println("Failed to get a class/package location, skipping " + apiClass); continue; } switch (location.getProtocol()) { case "jar": // Find out what jar it came from and consider that the category String categoryFragment = location.getPath(); //System.out.println("category fragment as path: " + categoryFragment); int bang = categoryFragment.lastIndexOf("!"); int hyphen = categoryFragment.lastIndexOf("-", bang); int slash = categoryFragment.lastIndexOf("/", hyphen); category = categoryFragment.substring(slash + 1, hyphen); //System.out.println("category fragment pared down: " + category); if (isPackage) { //System.out.println("Jar-based Package: " + apiPackage + ", came from " + location); sortedApi.put(category, apiPackage + " (PACKAGE)"); } else { //System.out.println("Jar-based Class: " + apiClass + ", came from " + location); sortedApi.put(category, apiClass.getName() + (apiClass.isInterface() ? " (INTERFACE)" : " (CLASS)")); } break; case "file": // If file based we know it is local so organize it like that category = "terasology engine"; if (isPackage) { //System.out.println("Local Package: " + apiPackage + ", came from " + location); sortedApi.put(category, apiPackage + " (PACKAGE)"); } else { //System.out.println("Local Class: " + apiClass + ", came from " + location); sortedApi.put(category, apiClass.getName() + (apiClass.isInterface() ? " (INTERFACE)" : " (CLASS)")); } break; default: System.out.println("Unknown protocol for: " + apiClass + ", came from " + location); } } sortedApi.putAll("external", ExternalApiWhitelist.CLASSES.stream() .map(clazz -> clazz.getName() + " (CLASS)").collect(Collectors.toSet())); sortedApi.putAll("external", ExternalApiWhitelist.PACKAGES.stream().map(packagee -> packagee + " (PACKAGE)") .collect(Collectors.toSet())); System.out.println("# Modding API:\n"); for (String key : sortedApi.keySet()) { System.out.println("## " + key + "\n"); for (String value : sortedApi.get(key)) { System.out.println("* " + value); } System.out.println(""); } }
From source file:org.sosy_lab.cpachecker.cfa.postprocessing.global.CFACloner.java
public MutableCFA execute() { assert cfa.getLanguage() == Language.C; // copy content of old CFAs final SortedMap<String, FunctionEntryNode> functions = new TreeMap<>(cfa.getAllFunctions()); final SortedSetMultimap<String, CFANode> nodes = TreeMultimap.create(); for (final String function : cfa.getAllFunctionNames()) { if (cfa instanceof MutableCFA) { // it is more efficient to directly copy the nodes nodes.putAll(function, ((MutableCFA) cfa).getFunctionNodes(function)); } else {//www.j av a 2s . c om nodes.putAll(function, CFATraversal.dfs().collectNodesReachableFrom(cfa.getFunctionHead(function))); } } for (String functionName : cfa.getAllFunctionNames()) { if (cfa.getMainFunction().getFunctionName().equals(functionName)) { continue; // ignore main function } final FunctionEntryNode entryNode = cfa.getFunctionHead(functionName); for (int i = 1; i <= numberOfCopies; i++) { final String newFunctionName = getFunctionName(functionName, i); Preconditions.checkArgument(!cfa.getAllFunctionNames().contains(newFunctionName)); final Pair<FunctionEntryNode, Collection<CFANode>> newFunction = FunctionCloner.cloneCFA(entryNode, newFunctionName); functions.put(newFunctionName, newFunction.getFirst()); nodes.putAll(newFunctionName, newFunction.getSecond()); // get functioncalls from the CFA Preconditions.checkArgument(functions.containsKey(newFunctionName), "function %s not available", newFunctionName); final FunctionCallCollector visitor = new FunctionCallCollector(); CFATraversal.dfs().traverseOnce(functions.get(newFunctionName), visitor); final Collection<AStatementEdge> functionCalls = visitor.getFunctionCalls(); // redirect from caller to new (cloned) called function, // but only if the calling and the called function have equal clone-indices for (AStatementEdge statementEdge : functionCalls) { if (FunctionCallUnwinder.isFunctionCall(statementEdge, functions.keySet())) { final String calledFunctionName = FunctionCallUnwinder.getNameOfFunction(statementEdge); final String newCalledFunctionName = getFunctionName(calledFunctionName, i); FunctionCallUnwinder.replaceFunctionCall(statementEdge, newCalledFunctionName); } } } } return new MutableCFA(cfa.getMachineModel(), functions, nodes, cfa.getMainFunction(), cfa.getLanguage()); }
From source file:org.sosy_lab.cpachecker.cfa.postprocessing.global.FunctionCallUnwinder.java
public MutableCFA unwindRecursion() { assert cfa.getLanguage() == Language.C; // copy content of old CFAs final SortedMap<String, FunctionEntryNode> functions = new TreeMap<>(cfa.getAllFunctions()); final SortedSetMultimap<String, CFANode> nodes = TreeMultimap.create(); for (final String function : cfa.getAllFunctionNames()) { nodes.putAll(function, cfa.getFunctionNodes(function)); }/*from w ww . ja v a 2s . co m*/ final Multimap<String, String> reverseCallGraph = HashMultimap.create(); final Set<String> finished = new HashSet<>(); final Deque<String> waitlist = new ArrayDeque<>(); waitlist.add(cfa.getMainFunction().getFunctionName()); while (!waitlist.isEmpty()) { final String functionname = waitlist.pop(); if (!finished.add(functionname)) { continue; } // get CFA for functionname Preconditions.checkArgument(functions.containsKey(functionname), "function %s not available", functionname); FunctionEntryNode entryNode = functions.get(functionname); // get functioncalls from the CFA final FunctionCallCollector visitor = new FunctionCallCollector(); CFATraversal.dfs().traverseOnce(entryNode, visitor); final Collection<AStatementEdge> functionCalls = visitor.getFunctionCalls(); // unwind recursion for (AStatementEdge statementEdge : functionCalls) { if (!isFunctionCall(statementEdge, functions.keySet())) { continue; } final String calledFunction = getNameOfFunction(statementEdge); String newFunctionname = calledFunction; if (isCallStackSizeReached(calledFunction, reverseCallGraph)) { // ignore, we have "bounded" recursion unwinding } else { // further unwinding allowed while (isFatherOf(functionname, newFunctionname, reverseCallGraph)) { newFunctionname = incrementFunctionname(newFunctionname); } if (!calledFunction.equals(newFunctionname)) { // if we have found recursion and need a functioncall-replacement if (!functions.containsKey(newFunctionname)) { cloneFunction(calledFunction, newFunctionname, functions, nodes); } // redirect from caller to new (cloned) called function replaceFunctionCall(statementEdge, newFunctionname); } } waitlist.add(newFunctionname); reverseCallGraph.put(newFunctionname, functionname); } } return new MutableCFA(cfa.getMachineModel(), functions, nodes, cfa.getMainFunction(), cfa.getLanguage()); }
From source file:com.google.gerrit.server.git.GroupCollector.java
public SortedSetMultimap<ObjectId, String> getGroups() throws OrmException { done = true;/* www .ja v a2s .co m*/ SortedSetMultimap<ObjectId, String> result = MultimapBuilder.hashKeys(groups.keySet().size()) .treeSetValues().build(); for (Map.Entry<ObjectId, Collection<String>> e : groups.asMap().entrySet()) { ObjectId id = e.getKey(); result.putAll(id.copy(), resolveGroups(id, e.getValue())); } return result; }
From source file:org.sosy_lab.cpachecker.cfa.postprocessing.global.FunctionCallUnwinder.java
/** clones a function and adds it to the maps. */ private void cloneFunction(final String oldFunctionname, final String newFunctionname, final Map<String, FunctionEntryNode> functions, final SortedSetMultimap<String, CFANode> nodes) { Preconditions.checkArgument(!functions.containsKey(newFunctionname), "function exists, cloning is not allowed."); // clone//from w w w . j a va2s. com final FunctionEntryNode entryNode = functions.get(oldFunctionname); final Pair<FunctionEntryNode, Collection<CFANode>> newFunction = FunctionCloner.cloneCFA(entryNode, newFunctionname); // add new function to CFA functions.put(newFunctionname, newFunction.getFirst()); nodes.putAll(newFunctionname, newFunction.getSecond()); }
From source file:org.eigenbase.sql2rel.RelStructuredTypeFlattener.java
public void updateRelInMap(SortedSetMultimap<RelNode, Correlation> mapRefRelToCorVar) { for (RelNode rel : Lists.newArrayList(mapRefRelToCorVar.keySet())) { if (oldToNewRelMap.containsKey(rel)) { SortedSet<Correlation> corVarSet = mapRefRelToCorVar.removeAll(rel); mapRefRelToCorVar.putAll(oldToNewRelMap.get(rel), corVarSet); }// w w w . j ava2 s . c om } }
From source file:org.apache.calcite.sql2rel.RelStructuredTypeFlattener.java
public void updateRelInMap(SortedSetMultimap<RelNode, CorrelationId> mapRefRelToCorVar) { for (RelNode rel : Lists.newArrayList(mapRefRelToCorVar.keySet())) { if (oldToNewRelMap.containsKey(rel)) { SortedSet<CorrelationId> corVarSet = mapRefRelToCorVar.removeAll(rel); mapRefRelToCorVar.putAll(oldToNewRelMap.get(rel), corVarSet); }/* ww w.j a va 2 s .c o m*/ } }
From source file:com.google.idea.blaze.android.rendering.BlazeRenderErrorContributor.java
/** * Blaze doesn't resolve class dependencies from resources until building the final * android_binary, so we could end up with resources that ultimately build correctly, but fail to * find their class dependencies during rendering in the layout editor. *//*from w ww . j a va 2 s . c o m*/ private void reportResourceTargetShouldDependOnClassTarget(TargetIdeInfo target, TargetMap targetMap, ArtifactLocationDecoder decoder) { Collection<String> missingClasses = logger.getMissingClasses(); if (missingClasses == null || missingClasses.isEmpty()) { return; } // Sorted entries for deterministic error message. SortedSetMultimap<String, TargetKey> missingClassToTargetMap = TreeMultimap.create(); SourceToTargetMap sourceToTargetMap = SourceToTargetMap.getInstance(project); ImmutableCollection transitiveDependencies = TransitiveDependencyMap.getInstance(project) .getTransitiveDependencies(target.key); for (String missingClass : missingClasses) { File sourceFile = getSourceFileForClass(missingClass); if (sourceFile == null) { continue; } ImmutableCollection<TargetKey> sourceTargets = sourceToTargetMap.getRulesForSourceFile(sourceFile); if (sourceTargets.stream().noneMatch(sourceTarget -> sourceTarget.equals(target.key) || transitiveDependencies.contains(sourceTarget))) { missingClassToTargetMap.putAll(missingClass, sourceTargets); } } if (missingClassToTargetMap.isEmpty()) { return; } HtmlBuilder builder = new HtmlBuilder(); addTargetLink(builder, target, decoder).add(" contains resource files that reference these classes:") .beginList(); for (String missingClass : missingClassToTargetMap.keySet()) { builder.listItem().addLink(missingClass, getLinkManager().createOpenClassUrl(missingClass)) .add(" from "); for (TargetKey targetKey : missingClassToTargetMap.get(missingClass)) { addTargetLink(builder, targetMap.get(targetKey), decoder).add(" "); } } builder.endList().add("Please fix your dependencies so that "); addTargetLink(builder, target, decoder).add(" correctly depends on these classes, ") .addLink("then ", "sync the project", " ", getLinkManager().createSyncProjectUrl()) .addLink("and ", "refresh the layout", ".", getLinkManager().createRefreshRenderUrl()).newline() .newline() .addBold("NOTE: blaze can still build with the incorrect dependencies " + "due to the way it handles resources, " + "but the layout editor needs them to be correct."); addIssue().setSeverity(HighlightSeverity.ERROR, HIGH_PRIORITY + 1) // Reported above missing classes. .setSummary("Missing class dependencies").setHtmlContent(builder).build(); }