Skip to content

Commit 965dd97

Browse files
committed
Clean up and clarification
1 parent f9b50da commit 965dd97

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

src/main/java/org/jenkinsci/plugins/workflow/graph/StandardGraphLookupView.java

+11-16
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
/**
1919
* Provides overall insight into the structure of a flow graph... but with limited visibility so we can change implementation.
20-
* Designed to work entirely on the basis of the {@link FlowNode#id} rather than the {@link FlowNode}s themselves.
20+
* Designed to work entirely on the basis of the {@link FlowNode#getId()} rather than the {@link FlowNode}s themselves.
2121
*/
2222
@SuppressFBWarnings(value = "ES_COMPARING_STRINGS_WITH_EQ", justification = "Can can use instance identity when comparing to a final constant")
2323
@Restricted(NoExternalUse.class)
@@ -40,10 +40,11 @@ public void clearCache() {
4040
@Override
4141
public void onNewHead(@Nonnull FlowNode newHead) {
4242
if (newHead instanceof BlockEndNode) {
43-
blockStartToEnd.put(((BlockEndNode)newHead).getStartNode().getId(), newHead.getId());
44-
String overallEnclosing = nearestEnclosingBlock.get(((BlockEndNode) newHead).getStartNode().getId());
45-
if (overallEnclosing != null) {
46-
nearestEnclosingBlock.put(newHead.getId(), overallEnclosing);
43+
String startNodeId = ((BlockEndNode)newHead).getStartNode().getId();
44+
blockStartToEnd.put(startNodeId, newHead.getId());
45+
String enclosingId = nearestEnclosingBlock.get(startNodeId);
46+
if (enclosingId != null) {
47+
nearestEnclosingBlock.put(newHead.getId(), enclosingId);
4748
}
4849
} else {
4950
if (newHead instanceof BlockStartNode) {
@@ -168,11 +169,9 @@ public BlockEndNode getEndNode(@Nonnull final BlockStartNode startNode) {
168169
throw new RuntimeException(ioe);
169170
}
170171
} else {
171-
BlockEndNode node = bruteForceScanForEnd(startNode);
172-
if (node != null) {
173-
blockStartToEnd.put(startNode.getId(), node.getId());
174-
}
175-
return node;
172+
// returns the end node or null
173+
// if this returns end node, it also adds start and end to blockStartToEnd
174+
return bruteForceScanForEnd(startNode);
176175
}
177176
}
178177

@@ -192,12 +191,8 @@ public BlockStartNode findEnclosingBlockStart(@Nonnull FlowNode node) {
192191
}
193192
}
194193

195-
BlockStartNode enclosing = bruteForceScanForEnclosingBlock(node);
196-
if (enclosing != null) {
197-
nearestEnclosingBlock.put(node.getId(), enclosing.getId());
198-
return enclosing;
199-
}
200-
return null;
194+
// when scan completes, enclosing is in the cache if it exists
195+
return bruteForceScanForEnclosingBlock(node);
201196
}
202197

203198
@Override

0 commit comments

Comments
 (0)