Skip to content

Commit

Permalink
Remove Js.Binary since it already has a Js.JsBinary and we will renam…
Browse files Browse the repository at this point in the history
…e that to Js.Binary
  • Loading branch information
kunli2 committed Nov 27, 2023
1 parent 16edc5c commit f51e0dc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 138 deletions.
17 changes: 0 additions & 17 deletions src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,6 @@ public J visitArrowFunction(JS.ArrowFunction arrowFunction, PrintOutputCapture<P
return arrowFunction;
}

@Override
public J visitBinary(JS.Binary binary, PrintOutputCapture<P> 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> p) {
beforeSyntax(binding, JsSpace.Location.BINDING_PREFIX, p);
Expand Down Expand Up @@ -230,6 +212,9 @@ public J visitJsBinary(JS.JsBinary binary, PrintOutputCapture<P> p) {
case IdentityNotEquals:
keyword = "!==";
break;
case In:
keyword = "in";
break;
}

visitSpace(binary.getPadding().getOperator().getBefore(), JsSpace.Location.BINARY_PREFIX, p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ private J visitBinary(TSCNode node) {

Space opPrefix = whitespace();
JLeftPadded<J.Binary.Type> op = null;
JLeftPadded<JS.Binary.Type> jsOp = null;
JLeftPadded<JS.JsBinary.Type> jsOp = null;
TSCSyntaxKind opKind = node.getNodeProperty("operatorToken").syntaxKind();
switch (opKind) {
// Bitwise ops
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down
102 changes: 2 additions & 100 deletions src/main/java/org/openrewrite/javascript/tree/JS.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<JS.Binary.Padding> padding;

@With
@EqualsAndHashCode.Include
UUID id;

@With
Space prefix;

@With
Markers markers;

@With
Expression left;

JLeftPadded<JS.Binary.Type> operator;

public Binary(UUID id, Space prefix, Markers markers, Expression left, JLeftPadded<Type> 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 <P> J acceptJavaScript(JavaScriptVisitor<P> 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<JS.Binary.Type> getOperator() {
return t.operator;
}

public JS.Binary withOperator(JLeftPadded<JS.Binary.Type> 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
Expand Down Expand Up @@ -994,7 +895,8 @@ public CoordinateBuilder.Expression getCoordinates() {

public enum Type {
IdentityEquals,
IdentityNotEquals
IdentityNotEquals,
In
}

public JS.JsBinary.Padding getPadding() {
Expand Down

0 comments on commit f51e0dc

Please sign in to comment.