Skip to content

Commit fe551f1

Browse files
committed
remove the last use of createCollection
1 parent 85d6bfe commit fe551f1

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

javascript/extractor/src/com/semmle/js/extractor/CFGExtractor.java

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -934,22 +934,13 @@ private Node visitWithSuccessors(Node nd, Collection<Node> successors) {
934934
}
935935

936936
/**
937-
* Creates an `Collection<Node>` from the one-or-more nodes contained in `nodes`.
938-
* `nodes` is either `null`, a `Node`, or a `Collection<Node>`.
939-
*/
940-
@SuppressWarnings("unchecked")
941-
private Collection<Node> createCollection(Object nodes) { // TODO: Delete usages.
942-
if (nodes == null) return Collections.<Node>emptySet();
943-
if (nodes instanceof Node) return Collections.<Node>singleton((Node) nodes);
944-
return (Collection<Node>) nodes;
945-
}
946-
947-
/**
948-
* Creates an `Collection<Node>` that iterates the nodes in reverse order from the one-or-more nodes contained in `nodes`.
937+
* Creates a new collection that contains the same elements, but is reversed.
938+
*
939+
* @return The reversed collection.
949940
*/
950-
private Collection<Node> createReversedCollection(final Object nodes) {
951-
List<Node> list = new ArrayList<>();
952-
createCollection(nodes).forEach(list::add);
941+
private <T> Collection<T> reverse(Collection<T> col) {
942+
List<T> list = new ArrayList<>();
943+
col.forEach(list::add);
953944
Collections.reverse(list);
954945
return list;
955946
}
@@ -961,15 +952,27 @@ private Collection<Node> createReversedCollection(final Object nodes) {
961952
*
962953
* @return The earliest non-null (collection of) node from `nodes`.
963954
*/
964-
private Collection<Node> visitSequence(Object... nodes) {
965-
Object fst = nodes[nodes.length - 1];
966-
for (int i = nodes.length - 2; i >= 0; --i) {
967-
for (Node node : createReversedCollection(nodes[i])) {
968-
Node ffst = visitWithSuccessors(node, createCollection(fst));
969-
if (ffst != null) fst = ffst;
955+
@SuppressWarnings("unchecked")
956+
private Collection<Node> visitSequence(Object... rawNodes) {
957+
List<Collection<Node>> nodes = new ArrayList<>();
958+
for (Object node : rawNodes) {
959+
if (node == null) {
960+
nodes.add(Collections.<Node>emptySet());
961+
} else if (node instanceof Node) {
962+
nodes.add(Collections.<Node>singleton((Node) node));
963+
} else {
964+
nodes.add((Collection<Node>)node);
965+
}
966+
}
967+
968+
Collection<Node> fst = nodes.get(nodes.size() - 1);
969+
for (int i = nodes.size() - 2; i >= 0; --i) {
970+
for (Node node : reverse(nodes.get(i))) {
971+
Node ffst = visitWithSuccessors(node, fst);
972+
if (ffst != null) fst = Collections.<Node>singleton(ffst);
970973
}
971974
}
972-
return createCollection(fst);
975+
return fst;
973976
}
974977

975978
@Override

0 commit comments

Comments
 (0)