Skip to content
This repository was archived by the owner on Jan 13, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ protected ReceiverContext.DetailsReceiver<JLeftPadded> computeValue(Class<?> nod
return (leftPadded, type, ctx) -> {
if (leftPadded != null) {
leftPadded = leftPadded.withBefore(ctx.receiveNonNullNode(leftPadded.getBefore(), Extensions::receiveSpace));
leftPadded = leftPadded.withElement(ctx.receiveNonNullNode((Space) leftPadded.getElement(), Extensions::receiveSpace));
leftPadded = leftPadded.withElement(ctx.receiveNonNullNode((Space)leftPadded.getElement(), Extensions::receiveSpace));
leftPadded = leftPadded.withMarkers(ctx.receiveNonNullNode(leftPadded.getMarkers(), ctx::receiveMarkers));
} else {
leftPadded = new JLeftPadded<>(
Expand All @@ -163,9 +163,8 @@ protected ReceiverContext.DetailsReceiver<JLeftPadded> computeValue(Class<?> nod
}
return leftPadded;
};
} else {
throw new IllegalArgumentException("Unsupported type: " + nodeType);
}
throw new IllegalArgumentException("Unsupported type: " + nodeType);
}
};

Expand Down Expand Up @@ -218,7 +217,7 @@ protected ReceiverContext.DetailsReceiver<JRightPadded> computeValue(Class<?> no
if (nodeType == Space.class) {
return (rightPadded, type, ctx) -> {
if (rightPadded != null) {
rightPadded = rightPadded.withElement(ctx.receiveNonNullNode((Space) rightPadded.getElement(), Extensions::receiveSpace));
rightPadded = rightPadded.withElement(ctx.receiveNonNullNode((Space)rightPadded.getElement(), Extensions::receiveSpace));
rightPadded = rightPadded.withAfter(ctx.receiveNonNullNode(rightPadded.getAfter(), Extensions::receiveSpace));
rightPadded = rightPadded.withMarkers(ctx.receiveNonNullNode(rightPadded.getMarkers(), ctx::receiveMarkers));
} else {
Expand All @@ -230,9 +229,8 @@ protected ReceiverContext.DetailsReceiver<JRightPadded> computeValue(Class<?> no
}
return rightPadded;
};
} else {
throw new IllegalArgumentException("Unsupported type: " + nodeType);
}
throw new IllegalArgumentException("Unsupported type: " + nodeType);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,8 @@ public Space visitSpace(@Nullable Space space, PySpace.Location loc, P p) {
//noinspection ConstantValue
if (space == Space.EMPTY || space == Space.SINGLE_SPACE || space == null) {
return space;
} else if (space.getComments().isEmpty()) {
}
if (space.getComments().isEmpty()) {
return space;
}
return visitSpace(space, Space.Location.LANGUAGE_EXTENSION, p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ <T> JContainer<T> spaceBefore(JContainer<T> container, boolean spaceBefore) {

if (spaceBefore && notSingleSpace(container.getBefore().getWhitespace()) && doesNotContainNewLine(container.getBefore().getWhitespace())) {
return container.withBefore(container.getBefore().withWhitespace(" "));
} else if (!spaceBefore && onlySpacesAndNotEmpty(container.getBefore().getWhitespace()) && doesNotContainNewLine(container.getBefore().getWhitespace())) {
}
if (!spaceBefore && onlySpacesAndNotEmpty(container.getBefore().getWhitespace()) && doesNotContainNewLine(container.getBefore().getWhitespace())) {
return container.withBefore(container.getBefore().withWhitespace(""));
} else {
return container;
}
return container;
}

private static List<Comment> spaceLastCommentSuffix(List<Comment> comments, boolean spaceSuffix) {
Expand All @@ -105,11 +105,11 @@ private static List<Comment> spaceLastCommentSuffix(List<Comment> comments, bool
private static Comment spaceSuffix(Comment comment, boolean spaceSuffix) {
if (spaceSuffix && notSingleSpace(comment.getSuffix()) && doesNotContainNewLine(comment.getSuffix())) {
return comment.withSuffix(" ");
} else if (!spaceSuffix && onlySpacesAndNotEmpty(comment.getSuffix()) && doesNotContainNewLine(comment.getSuffix())) {
}
if (!spaceSuffix && onlySpacesAndNotEmpty(comment.getSuffix()) && doesNotContainNewLine(comment.getSuffix())) {
return comment.withSuffix("");
} else {
return comment;
}
return comment;
}

<T extends J> T spaceBefore(T j, boolean spaceBefore) {
Expand All @@ -119,11 +119,11 @@ <T extends J> T spaceBefore(T j, boolean spaceBefore) {

if (spaceBefore && notSingleSpace(j.getPrefix().getWhitespace()) && doesNotContainNewLine(j.getPrefix().getWhitespace())) {
return j.withPrefix(j.getPrefix().withWhitespace(" "));
} else if (!spaceBefore && onlySpacesAndNotEmpty(j.getPrefix().getWhitespace()) && doesNotContainNewLine(j.getPrefix().getWhitespace())) {
}
if (!spaceBefore && onlySpacesAndNotEmpty(j.getPrefix().getWhitespace()) && doesNotContainNewLine(j.getPrefix().getWhitespace())) {
return j.withPrefix(j.getPrefix().withWhitespace(""));
} else {
return j;
}
return j;
}

<T extends J> JRightPadded<T> spaceAfter(JRightPadded<T> container, boolean spaceAfter) {
Expand All @@ -135,11 +135,11 @@ <T extends J> JRightPadded<T> spaceAfter(JRightPadded<T> container, boolean spac

if (spaceAfter && notSingleSpace(container.getAfter().getWhitespace()) && doesNotContainNewLine(container.getAfter().getWhitespace())) {
return container.withAfter(container.getAfter().withWhitespace(" "));
} else if (!spaceAfter && onlySpacesAndNotEmpty(container.getAfter().getWhitespace()) && doesNotContainNewLine(container.getAfter().getWhitespace())) {
}
if (!spaceAfter && onlySpacesAndNotEmpty(container.getAfter().getWhitespace()) && doesNotContainNewLine(container.getAfter().getWhitespace())) {
return container.withAfter(container.getAfter().withWhitespace(""));
} else {
return container;
}
return container;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ public J visit(@Nullable Tree tree, PrintOutputCapture<P> p) {
if (!(tree instanceof Py)) {
// re-route printing to the Java printer
return delegate.visitNonNull(requireNonNull(tree), p);
} else {
//noinspection DataFlowIssue
return super.visit(tree, p);
}
//noinspection DataFlowIssue
return super.visit(tree, p);
}

@Override
Expand Down Expand Up @@ -704,10 +703,9 @@ public J visit(@Nullable Tree tree, PrintOutputCapture<P> p) {
if (tree instanceof Py) {
// re-route printing back up to Python printer
return PythonPrinter.this.visitNonNull(tree, p);
} else {
//noinspection DataFlowIssue
return super.visit(tree, p);
}
//noinspection DataFlowIssue
return super.visit(tree, p);
}

@Override
Expand Down
14 changes: 8 additions & 6 deletions rewrite-python/src/main/java/org/openrewrite/python/tree/Py.java
Original file line number Diff line number Diff line change
Expand Up @@ -749,9 +749,10 @@ public <P> J acceptPython(PythonVisitor<P> v, P p) {
@Override
public @Nullable JavaType getType() {
if (reference instanceof Expression) {
return ((Expression) reference).getType();
} else if (reference instanceof TypedTree) {
return ((TypedTree) reference).getType();
return ((Expression)reference).getType();
}
if (reference instanceof TypedTree) {
return ((TypedTree)reference).getType();
}
return null;
}
Expand All @@ -760,9 +761,10 @@ public <P> J acceptPython(PythonVisitor<P> v, P p) {
@Override
public ExpressionTypeTree withType(@Nullable JavaType type) {
if (reference instanceof Expression) {
return withReference(((Expression) reference).withType(type));
} else if (reference instanceof TypedTree) {
return withReference(((TypedTree) reference).withType(type));
return withReference(((Expression)reference).withType(type));
}
if (reference instanceof TypedTree) {
return withReference(((TypedTree)reference).withType(type));
}
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ public static final class SpaceBuilder {
private String finishWhitespace() {
if (whitespaceBuilder == null) {
return "";
} else {
String ws = whitespaceBuilder.toString();
whitespaceBuilder.setLength(0);
return ws;
}
String ws = whitespaceBuilder.toString();
whitespaceBuilder.setLength(0);
return ws;
}

private void finishComment() {
Expand Down Expand Up @@ -101,11 +100,10 @@ public static Space appendWhitespace(Space space, String whitespace) {
comment -> comment.withSuffix(comment.getSuffix() + whitespace)
)
);
} else {
return space.withWhitespace(
space.getWhitespace() + whitespace
);
}
return space.withWhitespace(
space.getWhitespace() + whitespace
);
}

public static Space appendComment(Space space, String commentWithHash) {
Expand Down
Loading