Skip to content

Commit

Permalink
Replaced uses of stream() with for loops.
Browse files Browse the repository at this point in the history
  • Loading branch information
traceyyoshima committed Nov 15, 2023
1 parent 16aceb3 commit b1fd1cb
Showing 1 changed file with 54 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.toList;
import static org.openrewrite.Tree.randomId;
import static org.openrewrite.java.tree.Space.EMPTY;

Expand Down Expand Up @@ -244,13 +243,13 @@ private J.NewArray visitArrayLiteralExpression(TSCNode node) {
this::visitNode,
true
);
List<JRightPadded<Expression>> elements = jContainer.getPadding().getElements().stream()
.map(it -> {
Expression exp = (!(it.getElement() instanceof Expression) && it.getElement() instanceof Statement) ?
new JS.StatementExpression(randomId(), (Statement) it.getElement()) : (Expression) it.getElement();
return padRight(exp, it.getAfter(), it.getMarkers());
})
.collect(toList());
List<JRightPadded<Expression>> elements = new ArrayList<>();
for (JRightPadded<J> jjRightPadded : jContainer.getPadding().getElements()) {
Expression exp = (!(jjRightPadded.getElement() instanceof Expression) && jjRightPadded.getElement() instanceof Statement) ?
new JS.StatementExpression(randomId(), (Statement) jjRightPadded.getElement()) : (Expression) jjRightPadded.getElement();
JRightPadded<Expression> apply = padRight(exp, jjRightPadded.getAfter(), jjRightPadded.getMarkers());
elements.add(apply);
}
JContainer<Expression> arguments = JContainer.build(jContainer.getBefore(), elements, jContainer.getMarkers());

return new J.NewArray(
Expand Down Expand Up @@ -555,13 +554,13 @@ private J.MethodInvocation visitCallExpression(TSCNode node) {
true
);

List<JRightPadded<Expression>> typeParams = jContainer.getPadding().getElements().stream()
.map(it -> {
Expression exp = (!(it.getElement() instanceof Expression) && it.getElement() instanceof Statement) ?
new JS.StatementExpression(randomId(), (Statement) it.getElement()) : (Expression) it.getElement();
return padRight(exp, it.getAfter(), it.getMarkers());
})
.collect(toList());
List<JRightPadded<Expression>> typeParams = new ArrayList<>();
for (JRightPadded<J> jjRightPadded : jContainer.getPadding().getElements()) {
Expression exp = (!(jjRightPadded.getElement() instanceof Expression) && jjRightPadded.getElement() instanceof Statement) ?
new JS.StatementExpression(randomId(), (Statement) jjRightPadded.getElement()) : (Expression) jjRightPadded.getElement();
JRightPadded<Expression> apply = padRight(exp, jjRightPadded.getAfter(), jjRightPadded.getMarkers());
typeParams.add(apply);
}
typeParameters = JContainer.build(jContainer.getBefore(), typeParams, jContainer.getMarkers());
}

Expand All @@ -575,13 +574,13 @@ private J.MethodInvocation visitCallExpression(TSCNode node) {
this::visitNode,
true
);
List<JRightPadded<Expression>> elements = jContainer.getPadding().getElements().stream()
.map(it -> {
Expression exp = (!(it.getElement() instanceof Expression) && it.getElement() instanceof Statement) ?
new JS.StatementExpression(randomId(), (Statement) it.getElement()) : (Expression) it.getElement();
return padRight(exp, it.getAfter(), it.getMarkers());
})
.collect(toList());
List<JRightPadded<Expression>> elements = new ArrayList<>();
for (JRightPadded<J> jjRightPadded : jContainer.getPadding().getElements()) {
Expression exp = (!(jjRightPadded.getElement() instanceof Expression) && jjRightPadded.getElement() instanceof Statement) ?
new JS.StatementExpression(randomId(), (Statement) jjRightPadded.getElement()) : (Expression) jjRightPadded.getElement();
JRightPadded<Expression> apply = padRight(exp, jjRightPadded.getAfter(), jjRightPadded.getMarkers());
elements.add(apply);
}
arguments = JContainer.build(jContainer.getBefore(), elements, jContainer.getMarkers());
}

Expand Down Expand Up @@ -734,6 +733,11 @@ private J.ClassDeclaration visitClassDeclaration(TSCNode node) {
private J visitCaseClause(TSCNode node) {
TSCNode expression = node.getOptionalNodeProperty("expression");
List<TSCNode> statements = node.getNodeListProperty("statements");
List<JRightPadded<Statement>> list = new ArrayList<>();
for (TSCNode it : statements) {
JRightPadded<Statement> statementJRightPadded = maybeSemicolon((Statement) visitNode(it));
list.add(statementJRightPadded);
}
return new J.Case(
randomId(),
whitespace(),
Expand All @@ -747,9 +751,7 @@ private J visitCaseClause(TSCNode node) {
),
JContainer.build(
sourceBefore(TSCSyntaxKind.ColonToken),
statements.stream()
.map(it -> maybeSemicolon((Statement) visitNode(it)))
.collect(toList()),
list,
Markers.EMPTY
),
null
Expand Down Expand Up @@ -837,13 +839,13 @@ private J.Annotation visitDecorator(TSCNode node) {
true
);

List<JRightPadded<Expression>> elements = jContainer.getPadding().getElements().stream()
.map(it -> {
Expression exp = (!(it.getElement() instanceof Expression) && it.getElement() instanceof Statement) ?
new JS.StatementExpression(randomId(), (Statement) it.getElement()) : (Expression) it.getElement();
return padRight(exp, it.getAfter(), it.getMarkers());
})
.collect(toList());
List<JRightPadded<Expression>> elements = new ArrayList<>();
for (JRightPadded<J> jjRightPadded : jContainer.getPadding().getElements()) {
Expression exp = (!(jjRightPadded.getElement() instanceof Expression) && jjRightPadded.getElement() instanceof Statement) ?
new JS.StatementExpression(randomId(), (Statement) jjRightPadded.getElement()) : (Expression) jjRightPadded.getElement();
JRightPadded<Expression> apply = padRight(exp, jjRightPadded.getAfter(), jjRightPadded.getMarkers());
elements.add(apply);
}
arguments = JContainer.build(jContainer.getBefore(), elements, jContainer.getMarkers());
}
return new J.Annotation(
Expand All @@ -857,6 +859,11 @@ private J.Annotation visitDecorator(TSCNode node) {

private J visitDefaultClause(TSCNode node) {
List<TSCNode> statements = node.getNodeListProperty("statements");
List<JRightPadded<Statement>> list = new ArrayList<>();
for (TSCNode it : statements) {
JRightPadded<Statement> statementJRightPadded = maybeSemicolon((Statement) visitNode(it));
list.add(statementJRightPadded);
}
return new J.Case(
randomId(),
whitespace(),
Expand All @@ -870,9 +877,7 @@ private J visitDefaultClause(TSCNode node) {
),
JContainer.build(
sourceBefore(TSCSyntaxKind.ColonToken),
statements.stream()
.map(it -> maybeSemicolon((Statement) visitNode(it)))
.collect(toList()),
list,
Markers.EMPTY
),
null
Expand Down Expand Up @@ -1633,13 +1638,13 @@ private J.NewClass visitNewExpression(TSCNode node) {
this::visitNode,
true
);
List<JRightPadded<Expression>> elements = jContainer.getPadding().getElements().stream()
.map(it -> {
Expression exp = (!(it.getElement() instanceof Expression) && it.getElement() instanceof Statement) ?
new JS.StatementExpression(randomId(), (Statement) it.getElement()) : (Expression) it.getElement();
return padRight(exp, it.getAfter(), it.getMarkers());
})
.collect(toList());
List<JRightPadded<Expression>> elements = new ArrayList<>();
for (JRightPadded<J> jjRightPadded : jContainer.getPadding().getElements()) {
Expression exp = (!(jjRightPadded.getElement() instanceof Expression) && jjRightPadded.getElement() instanceof Statement) ?
new JS.StatementExpression(randomId(), (Statement) jjRightPadded.getElement()) : (Expression) jjRightPadded.getElement();
JRightPadded<Expression> apply = padRight(exp, jjRightPadded.getAfter(), jjRightPadded.getMarkers());
elements.add(apply);
}
JContainer<Expression> arguments = JContainer.build(jContainer.getBefore(), elements, jContainer.getMarkers());
return new J.NewClass(
randomId(),
Expand Down Expand Up @@ -1684,13 +1689,13 @@ private J visitObjectLiteralExpression(TSCNode node) {
if (jContainer.getElements().isEmpty()) {
arguments = JContainer.empty();
} else {
List<JRightPadded<Expression>> elements = jContainer.getPadding().getElements().stream()
.map(it -> {
Expression exp = (!(it.getElement() instanceof Expression) && it.getElement() instanceof Statement) ?
new JS.StatementExpression(randomId(), (Statement) it.getElement()) : (Expression) it.getElement();
return padRight(exp, it.getAfter(), it.getMarkers());
})
.collect(toList());
List<JRightPadded<Expression>> elements = new ArrayList<>();
for (JRightPadded<J> jjRightPadded : jContainer.getPadding().getElements()) {
Expression exp = (!(jjRightPadded.getElement() instanceof Expression) && jjRightPadded.getElement() instanceof Statement) ?
new JS.StatementExpression(randomId(), (Statement) jjRightPadded.getElement()) : (Expression) jjRightPadded.getElement();
JRightPadded<Expression> apply = padRight(exp, jjRightPadded.getAfter(), jjRightPadded.getMarkers());
elements.add(apply);
}
arguments = JContainer.build(jContainer.getBefore(), elements, jContainer.getMarkers());
}

Expand Down

0 comments on commit b1fd1cb

Please sign in to comment.