Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8273710: Remove redundant stream() call before forEach in jdk.jdeps

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -343,7 +343,7 @@ public int hashCode() {
public Graph<Node> moduleGraph() {
Graph.Builder<Node> builder = new Graph.Builder<>();

archives().stream()
archives()
.forEach(m -> {
Node u = new Node(m.getName(), Info.REQUIRES);
builder.addNode(u);
@@ -72,8 +72,7 @@ public Set<Edge<T>> edgesFrom(T u) {
*/
public Graph<T> reduce() {
Builder<T> builder = new Builder<>();
nodes.stream()
.forEach(u -> {
nodes.forEach(u -> {
builder.addNode(u);
edges.get(u).stream()
.filter(v -> !pathExists(u, v, false))
@@ -97,8 +96,7 @@ public Graph<T> reduce(Graph<T> g) {
}

Builder<T> builder = new Builder<>();
nodes.stream()
.forEach(u -> {
nodes.forEach(u -> {
builder.addNode(u);
// filter the edge if there exists a path from u to v in the given g
// or there exists another path from u to v in this graph
@@ -108,7 +106,7 @@ public Graph<T> reduce(Graph<T> g) {
});

// add the overlapped edges from this graph and the given g
g.edges().keySet().stream()
g.edges().keySet()
.forEach(u -> g.adjacentNodes(u).stream()
.filter(v -> isAdjacent(u, v))
.forEach(v -> builder.addEdge(u, v)));
@@ -147,7 +145,7 @@ public Graph<T> transpose() {
builder.addNodes(nodes);
// reverse edges
edges.keySet().forEach(u -> {
edges.get(u).stream()
edges.get(u)
.forEach(v -> builder.addEdge(v, u));
});
return builder.build();
@@ -214,8 +212,7 @@ private boolean pathExists(T u, T v, boolean includeAdjacent) {

public void printGraph(PrintWriter out) {
out.println("graph for " + nodes);
nodes.stream()
.forEach(u -> adjacentNodes(u).stream()
nodes.forEach(u -> adjacentNodes(u)
.forEach(v -> out.format(" %s -> %s%n", u, v)));
}

@@ -322,7 +319,7 @@ private void visit(T node, Set<T> visited, Set<T> done) {
return;
}
visited.add(node);
graph.edges().get(node).stream()
graph.edges().get(node)
.forEach(x -> visit(x, visited, done));
done.add(node);
result.addLast(node);
@@ -141,7 +141,7 @@ public Set<Deque<Archive>> inverseDependences() throws IOException {
targets().forEach(builder::addNode);

// transpose the module graph
configuration.getModules().values().stream()
configuration.getModules().values()
.forEach(m -> {
builder.addNode(m);
m.descriptor().requires().stream()
@@ -152,7 +152,7 @@ public Set<Deque<Archive>> inverseDependences() throws IOException {

// add the dependences from the analysis
Map<Archive, Set<Archive>> dependences = dependencyFinder.dependences();
dependences.entrySet().stream()
dependences.entrySet()
.forEach(e -> {
Archive u = e.getKey();
builder.addNode(u);
@@ -215,7 +215,7 @@ private Set<Deque<Archive>> findPaths(Graph<Archive> graph, Archive target) {
}

// push unvisited adjacent edges
unvisitedDeps.stream().forEach(deque::push);
unvisitedDeps.forEach(deque::push);


// when the adjacent edges of a node are visited, pop it from the path
@@ -397,8 +397,8 @@ private ModuleDescriptor dropHashes(ModuleDescriptor md) {
md.requires().forEach(builder::requires);
md.exports().forEach(builder::exports);
md.opens().forEach(builder::opens);
md.provides().stream().forEach(builder::provides);
md.uses().stream().forEach(builder::uses);
md.provides().forEach(builder::provides);
md.uses().forEach(builder::uses);
builder.packages(md.packages());
return builder.build();
}
@@ -771,7 +771,7 @@ boolean run(JdepsConfiguration config, JdepsWriter writer, Type type)
if (!options.nowarning) {
analyzer.archives()
.forEach(archive -> archive.reader()
.skippedEntries().stream()
.skippedEntries()
.forEach(name -> warning("warn.skipped.entry", name)));
}

@@ -796,7 +796,7 @@ boolean run(JdepsConfiguration config, JdepsWriter writer, Type type)
log.format("%-40s %s%n",
internalApiTitle.replaceAll(".", "-"),
replacementApiTitle.replaceAll(".", "-"));
jdkInternals.entrySet().stream()
jdkInternals.entrySet()
.forEach(e -> {
String key = e.getKey();
String[] lines = e.getValue().split("\\n");
@@ -1111,7 +1111,7 @@ private JdepsFilter dependencyFilter(JdepsConfiguration config) {

// --require
if (!options.requires.isEmpty()) {
options.requires.stream()
options.requires
.forEach(mn -> {
Module m = config.findModule(mn).get();
builder.requires(mn, m.packages());
@@ -223,10 +223,10 @@ public Module build() {
descriptor.packages().forEach(pn -> exports.put(pn, Collections.emptySet()));
descriptor.packages().forEach(pn -> opens.put(pn, Collections.emptySet()));
} else {
descriptor.exports().stream()
descriptor.exports()
.forEach(exp -> exports.computeIfAbsent(exp.source(), _k -> new HashSet<>())
.addAll(exp.targets()));
descriptor.opens().stream()
descriptor.opens()
.forEach(exp -> opens.computeIfAbsent(exp.source(), _k -> new HashSet<>())
.addAll(exp.targets()));
}
@@ -174,16 +174,14 @@ private ModuleDescriptor descriptor(Set<Module> requiresTransitive,
private Graph<Module> buildReducedGraph() {
ModuleGraphBuilder rpBuilder = new ModuleGraphBuilder(configuration);
rpBuilder.addModule(root);
requiresTransitive.stream()
.forEach(m -> rpBuilder.addEdge(root, m));
requiresTransitive.forEach(m -> rpBuilder.addEdge(root, m));

// requires transitive graph
Graph<Module> rbg = rpBuilder.build().reduce();

ModuleGraphBuilder gb = new ModuleGraphBuilder(configuration);
gb.addModule(root);
requires.stream()
.forEach(m -> gb.addEdge(root, m));
requires.forEach(m -> gb.addEdge(root, m));

// transitive reduction
Graph<Module> newGraph = gb.buildGraph().reduce(rbg);
@@ -310,7 +308,7 @@ private Map<String, Set<String>> unusedQualifiedExports() {
dependencyFinder.parse(mods.stream());

// adds to the qualified exports map if a module references it
mods.stream().forEach(m ->
mods.forEach(m ->
m.getDependencies()
.map(Dependency.Location::getPackageName)
.filter(qualifiedExports::containsKey)
@@ -147,7 +147,7 @@ public void genDotFile(Path path, String name,
*/
private Graph<String> gengraph(Configuration cf) {
Graph.Builder<String> builder = new Graph.Builder<>();
cf.modules().stream()
cf.modules()
.forEach(rm -> {
String mn = rm.name();
builder.addNode(mn);
@@ -406,7 +406,7 @@ public void printNode(PrintWriter out, ModuleDescriptor md, Set<String> edges) {
.collect(toSet());

String mn = md.name();
edges.stream().forEach(dn -> {
edges.forEach(dn -> {
String attr;
if (dn.equals("java.base")) {
attr = "color=\"" + attributes.requiresMandatedColor() + "\"";
@@ -113,7 +113,7 @@ public boolean run(int maxDepth, boolean ignoreMissingDeps) throws IOException {
.distinct()
.forEach(m -> {
if (internalPkgs.containsKey(m)) {
internalPkgs.get(m).stream()
internalPkgs.get(m)
.forEach(pn -> writer.format(" %s/%s%s", m, pn, separator));
} else {
writer.format(" %s%s", m, separator);
@@ -89,10 +89,10 @@ private Graph<Module> buildGraph(Map<Module, Set<Module>> edges) {
Graph.Builder<Module> builder = new Graph.Builder<>();
Set<Module> visited = new HashSet<>();
Deque<Module> deque = new LinkedList<>();
edges.entrySet().stream().forEach(e -> {
edges.entrySet().forEach(e -> {
Module m = e.getKey();
deque.add(m);
e.getValue().stream().forEach(v -> {
e.getValue().forEach(v -> {
deque.add(v);
builder.addEdge(m, v);
});