From f51e0dc3a0b8bdebaa4e75f31c85dcdafe50880c Mon Sep 17 00:00:00 2001 From: Kun Li Date: Mon, 27 Nov 2023 13:30:50 -0800 Subject: [PATCH] Remove Js.Binary since it already has a Js.JsBinary and we will rename that to Js.Binary --- .../javascript/JavaScriptVisitor.java | 17 --- .../internal/JavaScriptPrinter.java | 21 +--- .../internal/TypeScriptParserVisitor.java | 6 +- .../org/openrewrite/javascript/tree/JS.java | 102 +----------------- 4 files changed, 8 insertions(+), 138 deletions(-) diff --git a/src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java b/src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java index c89d8ef5..11ab4dd7 100644 --- a/src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java +++ b/src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java @@ -108,23 +108,6 @@ public J visitArrowFunction(JS.ArrowFunction arrowFunction, P p) { return a; } - public J visitBinary(JS.Binary binary, P p) { - JS.Binary b = binary; - b = b.withPrefix(visitSpace(b.getPrefix(), Space.Location.BINARY_PREFIX, p)); - b = b.withMarkers(visitMarkers(b.getMarkers(), p)); - Expression temp = (Expression) visitExpression(b, p); - if (!(temp instanceof JS.Binary)) { - return temp; - } else { - b = (JS.Binary) temp; - } - b = b.withLeft(visitAndCast(b.getLeft(), p)); - b = b.getPadding().withOperator(visitLeftPadded(b.getPadding().getOperator(), JsLeftPadded.Location.BINARY_OPERATOR, p)); - b = b.withRight(visitAndCast(b.getRight(), p)); - b = b.withType(visitType(b.getType(), p)); - return b; - } - public J visitBinding(JS.ObjectBindingDeclarations.Binding binding, P p) { JS.ObjectBindingDeclarations.Binding b = binding; b = b.withPrefix(visitSpace(b.getPrefix(), JsSpace.Location.BINDING_PREFIX, p)); diff --git a/src/main/java/org/openrewrite/javascript/internal/JavaScriptPrinter.java b/src/main/java/org/openrewrite/javascript/internal/JavaScriptPrinter.java index 63b4109b..3c6b1f7b 100644 --- a/src/main/java/org/openrewrite/javascript/internal/JavaScriptPrinter.java +++ b/src/main/java/org/openrewrite/javascript/internal/JavaScriptPrinter.java @@ -101,24 +101,6 @@ public J visitArrowFunction(JS.ArrowFunction arrowFunction, PrintOutputCapture

p) { - beforeSyntax(binary, Space.Location.BINARY_PREFIX, p); - String keyword = ""; - switch (binary.getOperator()) { - case In: - keyword = "in"; - break; - } - visit(binary.getLeft(), p); - visitSpace(binary.getPadding().getOperator().getBefore(), Space.Location.BINARY_OPERATOR, p); - p.append(keyword); - - visit(binary.getRight(), p); - afterSyntax(binary, p); - return binary; - } - @Override public J visitBinding(JS.ObjectBindingDeclarations.Binding binding, PrintOutputCapture

p) { beforeSyntax(binding, JsSpace.Location.BINDING_PREFIX, p); @@ -230,6 +212,9 @@ public J visitJsBinary(JS.JsBinary binary, PrintOutputCapture

p) { case IdentityNotEquals: keyword = "!=="; break; + case In: + keyword = "in"; + break; } visitSpace(binary.getPadding().getOperator().getBefore(), JsSpace.Location.BINARY_PREFIX, p); diff --git a/src/main/java/org/openrewrite/javascript/internal/TypeScriptParserVisitor.java b/src/main/java/org/openrewrite/javascript/internal/TypeScriptParserVisitor.java index d0e61320..c6328756 100644 --- a/src/main/java/org/openrewrite/javascript/internal/TypeScriptParserVisitor.java +++ b/src/main/java/org/openrewrite/javascript/internal/TypeScriptParserVisitor.java @@ -297,7 +297,7 @@ private J visitBinary(TSCNode node) { Space opPrefix = whitespace(); JLeftPadded op = null; - JLeftPadded jsOp = null; + JLeftPadded jsOp = null; TSCSyntaxKind opKind = node.getNodeProperty("operatorToken").syntaxKind(); switch (opKind) { // Bitwise ops @@ -391,7 +391,7 @@ private J visitBinary(TSCNode node) { // TS/JS specific ops case InKeyword: consumeToken(TSCSyntaxKind.InKeyword); - jsOp = padLeft(opPrefix, JS.Binary.Type.In); + jsOp = padLeft(opPrefix, JS.JsBinary.Type.In); break; default: implementMe(node); @@ -400,7 +400,7 @@ private J visitBinary(TSCNode node) { Expression right = (Expression) visitNode(node.getNodeProperty("right")); if (jsOp != null) { - return new JS.Binary( + return new JS.JsBinary( randomId(), prefix, markers, diff --git a/src/main/java/org/openrewrite/javascript/tree/JS.java b/src/main/java/org/openrewrite/javascript/tree/JS.java index 49ec6cbd..cb14a7bf 100644 --- a/src/main/java/org/openrewrite/javascript/tree/JS.java +++ b/src/main/java/org/openrewrite/javascript/tree/JS.java @@ -403,105 +403,6 @@ public CoordinateBuilder.Statement getCoordinates() { } } - @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) - @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) - @AllArgsConstructor(access = AccessLevel.PRIVATE) - @Data - final class Binary implements JS, Expression, TypedTree { - - @Nullable - @NonFinal - transient WeakReference padding; - - @With - @EqualsAndHashCode.Include - UUID id; - - @With - Space prefix; - - @With - Markers markers; - - @With - Expression left; - - JLeftPadded operator; - - public Binary(UUID id, Space prefix, Markers markers, Expression left, JLeftPadded operator, Expression right, @Nullable JavaType type) { - this.id = id; - this.prefix = prefix; - this.markers = markers; - this.left = left; - this.operator = operator; - this.right = right; - this.type = type; - } - - public JS.Binary.Type getOperator() { - return operator.getElement(); - } - - public JS.Binary withOperator(JS.Binary.Type operator) { - return getPadding().withOperator(this.operator.withElement(operator)); - } - - @With - Expression right; - - @With - @Nullable - JavaType type; - - @Override - public

J acceptJavaScript(JavaScriptVisitor

v, P p) { - return v.visitBinary(this, p); - } - - @Transient - @Override - public CoordinateBuilder.Expression getCoordinates() { - return new CoordinateBuilder.Expression(this); - } - - public enum Type { - In, - } - - public JS.Binary.Padding getPadding() { - JS.Binary.Padding p; - if (this.padding == null) { - p = new JS.Binary.Padding(this); - this.padding = new WeakReference<>(p); - } else { - p = this.padding.get(); - if (p == null || p.t != this) { - p = new JS.Binary.Padding(this); - this.padding = new WeakReference<>(p); - } - } - return p; - } - - @RequiredArgsConstructor - public static class Padding { - private final JS.Binary t; - - public JLeftPadded getOperator() { - return t.operator; - } - - public JS.Binary withOperator(JLeftPadded operator) { - return t.operator == operator ? t : new JS.Binary(t.id, t.prefix, t.markers, t.left, operator, t.right, t.type); - } - } - - @Override - public String toString() { - return withPrefix(Space.EMPTY).printTrimmed(new JavaScriptPrinter<>()); - } - } - @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) @Data @@ -994,7 +895,8 @@ public CoordinateBuilder.Expression getCoordinates() { public enum Type { IdentityEquals, - IdentityNotEquals + IdentityNotEquals, + In } public JS.JsBinary.Padding getPadding() {