From b1fd1cb4f11a8d1c9469d46f18615b55d6f128a9 Mon Sep 17 00:00:00 2001 From: traceyyoshima Date: Tue, 14 Nov 2023 18:06:14 -0700 Subject: [PATCH] Replaced uses of stream() with for loops. --- .../internal/TypeScriptParserVisitor.java | 103 +++++++++--------- 1 file changed, 54 insertions(+), 49 deletions(-) diff --git a/src/main/java/org/openrewrite/javascript/internal/TypeScriptParserVisitor.java b/src/main/java/org/openrewrite/javascript/internal/TypeScriptParserVisitor.java index 2c4a84bf..a5369d52 100644 --- a/src/main/java/org/openrewrite/javascript/internal/TypeScriptParserVisitor.java +++ b/src/main/java/org/openrewrite/javascript/internal/TypeScriptParserVisitor.java @@ -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; @@ -244,13 +243,13 @@ private J.NewArray visitArrayLiteralExpression(TSCNode node) { this::visitNode, true ); - List> 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> elements = new ArrayList<>(); + for (JRightPadded 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 apply = padRight(exp, jjRightPadded.getAfter(), jjRightPadded.getMarkers()); + elements.add(apply); + } JContainer arguments = JContainer.build(jContainer.getBefore(), elements, jContainer.getMarkers()); return new J.NewArray( @@ -555,13 +554,13 @@ private J.MethodInvocation visitCallExpression(TSCNode node) { true ); - List> 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> typeParams = new ArrayList<>(); + for (JRightPadded 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 apply = padRight(exp, jjRightPadded.getAfter(), jjRightPadded.getMarkers()); + typeParams.add(apply); + } typeParameters = JContainer.build(jContainer.getBefore(), typeParams, jContainer.getMarkers()); } @@ -575,13 +574,13 @@ private J.MethodInvocation visitCallExpression(TSCNode node) { this::visitNode, true ); - List> 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> elements = new ArrayList<>(); + for (JRightPadded 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 apply = padRight(exp, jjRightPadded.getAfter(), jjRightPadded.getMarkers()); + elements.add(apply); + } arguments = JContainer.build(jContainer.getBefore(), elements, jContainer.getMarkers()); } @@ -734,6 +733,11 @@ private J.ClassDeclaration visitClassDeclaration(TSCNode node) { private J visitCaseClause(TSCNode node) { TSCNode expression = node.getOptionalNodeProperty("expression"); List statements = node.getNodeListProperty("statements"); + List> list = new ArrayList<>(); + for (TSCNode it : statements) { + JRightPadded statementJRightPadded = maybeSemicolon((Statement) visitNode(it)); + list.add(statementJRightPadded); + } return new J.Case( randomId(), whitespace(), @@ -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 @@ -837,13 +839,13 @@ private J.Annotation visitDecorator(TSCNode node) { true ); - List> 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> elements = new ArrayList<>(); + for (JRightPadded 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 apply = padRight(exp, jjRightPadded.getAfter(), jjRightPadded.getMarkers()); + elements.add(apply); + } arguments = JContainer.build(jContainer.getBefore(), elements, jContainer.getMarkers()); } return new J.Annotation( @@ -857,6 +859,11 @@ private J.Annotation visitDecorator(TSCNode node) { private J visitDefaultClause(TSCNode node) { List statements = node.getNodeListProperty("statements"); + List> list = new ArrayList<>(); + for (TSCNode it : statements) { + JRightPadded statementJRightPadded = maybeSemicolon((Statement) visitNode(it)); + list.add(statementJRightPadded); + } return new J.Case( randomId(), whitespace(), @@ -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 @@ -1633,13 +1638,13 @@ private J.NewClass visitNewExpression(TSCNode node) { this::visitNode, true ); - List> 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> elements = new ArrayList<>(); + for (JRightPadded 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 apply = padRight(exp, jjRightPadded.getAfter(), jjRightPadded.getMarkers()); + elements.add(apply); + } JContainer arguments = JContainer.build(jContainer.getBefore(), elements, jContainer.getMarkers()); return new J.NewClass( randomId(), @@ -1684,13 +1689,13 @@ private J visitObjectLiteralExpression(TSCNode node) { if (jContainer.getElements().isEmpty()) { arguments = JContainer.empty(); } else { - List> 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> elements = new ArrayList<>(); + for (JRightPadded 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 apply = padRight(exp, jjRightPadded.getAfter(), jjRightPadded.getMarkers()); + elements.add(apply); + } arguments = JContainer.build(jContainer.getBefore(), elements, jContainer.getMarkers()); }