diff --git a/src/main/java/org/openrewrite/javascript/format/SpacesVisitor.java b/src/main/java/org/openrewrite/javascript/format/SpacesVisitor.java index 9403a550..72c54527 100644 --- a/src/main/java/org/openrewrite/javascript/format/SpacesVisitor.java +++ b/src/main/java/org/openrewrite/javascript/format/SpacesVisitor.java @@ -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; @@ -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())); @@ -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; } diff --git a/src/main/java/org/openrewrite/javascript/internal/JavaScriptPrinter.java b/src/main/java/org/openrewrite/javascript/internal/JavaScriptPrinter.java index b3c26ac8..cf4bbbef 100644 --- a/src/main/java/org/openrewrite/javascript/internal/JavaScriptPrinter.java +++ b/src/main/java/org/openrewrite/javascript/internal/JavaScriptPrinter.java @@ -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); } @@ -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); } @@ -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); } @@ -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(","); diff --git a/src/main/java/org/openrewrite/javascript/markers/TypeReferencePrefix.java b/src/main/java/org/openrewrite/javascript/markers/TypeReferencePrefix.java deleted file mode 100644 index e6e23a95..00000000 --- a/src/main/java/org/openrewrite/javascript/markers/TypeReferencePrefix.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2022 the original author or authors. - * <p> - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * <p> - * https://www.apache.org/licenses/LICENSE-2.0 - * <p> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.openrewrite.javascript.markers; - -import lombok.Value; -import lombok.With; -import org.openrewrite.Incubating; -import org.openrewrite.java.tree.Space; -import org.openrewrite.marker.Marker; - -import java.util.UUID; - -@Incubating(since = "0.0") -@Value -@With -public class TypeReferencePrefix implements Marker { - UUID id; - Space prefix; -}