Skip to content

Commit

Permalink
Remove TypeReferencePrefix marker for now
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Sep 29, 2024
1 parent 5812aa9 commit 926abe1
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 69 deletions.
25 changes: 0 additions & 25 deletions src/main/java/org/openrewrite/javascript/format/SpacesVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
import org.openrewrite.internal.StringUtils;
import org.openrewrite.java.tree.*;
import org.openrewrite.javascript.JavaScriptIsoVisitor;
import org.openrewrite.javascript.markers.TypeReferencePrefix;
import org.openrewrite.javascript.style.SpacesStyle;
import org.openrewrite.marker.Markers;

import java.util.List;

Expand Down Expand Up @@ -147,18 +145,6 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, P
if (m.getReturnTypeExpression() != null) {
boolean useSpaceAfter = style.getOther().getAfterTypeReferenceColon();
m = m.withReturnTypeExpression(spaceBefore(m.getReturnTypeExpression(), useSpaceAfter));

TypeReferencePrefix typeReferencePrefix = m.getMarkers().findFirst(TypeReferencePrefix.class).orElse(null);
if (typeReferencePrefix != null) {
boolean useSpaceBefore = style.getOther().getBeforeTypeReferenceColon();
if (typeReferencePrefix.getPrefix().isEmpty() && useSpaceBefore) {
Markers markers = m.getMarkers().removeByType(TypeReferencePrefix.class);
m = m.withMarkers(markers.addIfAbsent(typeReferencePrefix.withPrefix(Space.format(" "))));
} else if (!typeReferencePrefix.getPrefix().isEmpty() && !useSpaceBefore) {
Markers markers = m.getMarkers().removeByType(TypeReferencePrefix.class);
m = m.withMarkers(markers.addIfAbsent(typeReferencePrefix.withPrefix(Space.EMPTY)));
}
}
}
m = m.getPadding().withParameters(
spaceBefore(m.getPadding().getParameters(), style.getBeforeParentheses().getFunctionDeclarationParentheses()));
Expand Down Expand Up @@ -280,20 +266,9 @@ public J.NewClass visitNewClass(J.NewClass newClass, P p) {
@Override
public J.VariableDeclarations visitVariableDeclarations(J.VariableDeclarations multiVariable, P p) {
J.VariableDeclarations m = super.visitVariableDeclarations(multiVariable, p);
TypeReferencePrefix typeReferencePrefix = m.getMarkers().findFirst(TypeReferencePrefix.class).orElse(null);
if (m.getTypeExpression() != null) {
boolean useSpaceAfter = style.getOther().getAfterPropertyNameValueSeparator();
m = m.withTypeExpression(spaceBefore(m.getTypeExpression(), useSpaceAfter));
if (typeReferencePrefix != null) {
boolean useSpaceBefore = style.getOther().getBeforePropertyNameValueSeparator();
if (typeReferencePrefix.getPrefix().isEmpty() && useSpaceBefore) {
Markers markers = m.getMarkers().removeByType(TypeReferencePrefix.class);
m = m.withMarkers(markers.addIfAbsent(typeReferencePrefix.withPrefix(Space.format(" "))));
} else if (!typeReferencePrefix.getPrefix().isEmpty() && !useSpaceBefore) {
Markers markers = m.getMarkers().removeByType(TypeReferencePrefix.class);
m = m.withMarkers(markers.addIfAbsent(typeReferencePrefix.withPrefix(Space.EMPTY)));
}
}
}
return m;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ public J visitArrowFunction(JS.ArrowFunction arrowFunction, PrintOutputCapture<P
}

if (arrowFunction.getReturnTypeExpression() != null) {
TypeReferencePrefix typeReferencePrefix = arrowFunction.getMarkers().findFirst(TypeReferencePrefix.class).orElse(null);
if (typeReferencePrefix != null) {
visitSpace(typeReferencePrefix.getPrefix(), Space.Location.LANGUAGE_EXTENSION, p);
p.append(":");
}
visit(arrowFunction.getReturnTypeExpression(), p);
}

Expand Down Expand Up @@ -558,11 +553,6 @@ public J visitMethodDeclaration(J.MethodDeclaration method, PrintOutputCapture<P

visitContainer("(", method.getPadding().getParameters(), JContainer.Location.METHOD_DECLARATION_PARAMETERS, ",", ")", p);
if (method.getReturnTypeExpression() != null) {
TypeReferencePrefix typeReferencePrefix = method.getMarkers().findFirst(TypeReferencePrefix.class).orElse(null);
if (typeReferencePrefix != null) {
visitSpace(typeReferencePrefix.getPrefix(), Space.Location.LANGUAGE_EXTENSION, p);
p.append(":");
}
visit(method.getReturnTypeExpression(), p);
}

Expand Down Expand Up @@ -724,8 +714,8 @@ public J visitVariableDeclarations(J.VariableDeclarations multiVariable, PrintOu
p.append(postFixOperator.getOperator().getValue());
}

visitSpace(variable.getAfter(), Space.Location.NAMED_VARIABLE_SUFFIX, p);
if (multiVariable.getTypeExpression() != null) {
multiVariable.getMarkers().findFirst(TypeReferencePrefix.class).ifPresent(typeReferencePrefix -> visitSpace(typeReferencePrefix.getPrefix(), Space.Location.LANGUAGE_EXTENSION, p));
p.append(":");
visit(multiVariable.getTypeExpression(), p);
}
Expand All @@ -735,7 +725,6 @@ public J visitVariableDeclarations(J.VariableDeclarations multiVariable, PrintOu
variable.getElement().getPadding().getInitializer(), JLeftPadded.Location.VARIABLE_INITIALIZER, p);
}

visitSpace(variable.getAfter(), Space.Location.NAMED_VARIABLE_SUFFIX, p);
afterSyntax(variable.getElement(), p);
if (i < variables.size() - 1) {
p.append(",");
Expand Down

This file was deleted.

0 comments on commit 926abe1

Please sign in to comment.