From 926abe149b49728a00341d0ff7ca4a3720daba5d Mon Sep 17 00:00:00 2001 From: Knut Wannheden Date: Sun, 29 Sep 2024 21:57:03 +0200 Subject: [PATCH] Remove `TypeReferencePrefix` marker for now --- .../javascript/format/SpacesVisitor.java | 25 --------------- .../internal/JavaScriptPrinter.java | 13 +------- .../markers/TypeReferencePrefix.java | 32 ------------------- 3 files changed, 1 insertion(+), 69 deletions(-) delete mode 100644 src/main/java/org/openrewrite/javascript/markers/TypeReferencePrefix.java 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

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. - *

- * 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 - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * 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; -}