Skip to content
This repository was archived by the owner on Jan 13, 2026. It is now read-only.

Commit d72418a

Browse files
timtebeekclaude
andcommitted
refactor: Apply OpenRewrite best practices
Applied automated code improvements including: - Static imports for Collections and Collectors - Simplified equals expressions to avoid null checks - Organized and optimized import statements - Cleaned up unnecessary code patterns 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent a413e5d commit d72418a

18 files changed

Lines changed: 228 additions & 381 deletions

File tree

rewrite-python-remote/src/main/java/org/openrewrite/python/remote/Extensions.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,8 @@ protected ReceiverContext.DetailsReceiver<JLeftPadded> computeValue(Class<?> nod
163163
}
164164
return leftPadded;
165165
};
166-
} else {
167-
throw new IllegalArgumentException("Unsupported type: " + nodeType);
168166
}
167+
throw new IllegalArgumentException("Unsupported type: " + nodeType);
169168
}
170169
};
171170

@@ -230,9 +229,8 @@ protected ReceiverContext.DetailsReceiver<JRightPadded> computeValue(Class<?> no
230229
}
231230
return rightPadded;
232231
};
233-
} else {
234-
throw new IllegalArgumentException("Unsupported type: " + nodeType);
235232
}
233+
throw new IllegalArgumentException("Unsupported type: " + nodeType);
236234
}
237235
};
238236

rewrite-python-remote/src/main/java/org/openrewrite/python/remote/Python.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
package org.openrewrite.python.remote;
2424

2525
import com.fasterxml.jackson.core.type.TypeReference;
26-
import org.jspecify.annotations.Nullable;
27-
import org.openrewrite.*;
28-
import org.openrewrite.remote.model.*;
29-
import org.openrewrite.tree.*;
26+
import org.openrewrite.Checksum;
27+
import org.openrewrite.FileAttributes;
3028
import org.openrewrite.java.tree.*;
31-
import org.openrewrite.python.tree.*;
29+
import org.openrewrite.python.tree.Py;
30+
import org.openrewrite.remote.model.LstModel;
31+
import org.openrewrite.remote.model.LstProperty;
32+
import org.openrewrite.remote.model.LstType;
3233

3334
import java.util.List;
3435

rewrite-python-remote/src/main/java/org/openrewrite/python/remote/PythonReceiver.java

Lines changed: 105 additions & 214 deletions
Large diffs are not rendered by default.

rewrite-python-remote/src/main/java/org/openrewrite/python/remote/PythonSender.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@
2626
import org.jspecify.annotations.Nullable;
2727
import org.openrewrite.Cursor;
2828
import org.openrewrite.Tree;
29-
import org.openrewrite.python.PythonVisitor;
30-
import org.openrewrite.python.tree.*;
31-
import org.openrewrite.java.*;
3229
import org.openrewrite.java.tree.*;
30+
import org.openrewrite.python.PythonVisitor;
31+
import org.openrewrite.python.tree.Py;
3332
import org.openrewrite.remote.Sender;
3433
import org.openrewrite.remote.SenderContext;
3534

@@ -1208,8 +1207,4 @@ private static void sendSpace(Space space, SenderContext ctx) {
12081207
Extensions.sendSpace(space, ctx);
12091208
}
12101209

1211-
private static void sendComment(Comment comment, SenderContext ctx) {
1212-
Extensions.sendComment(comment, ctx);
1213-
}
1214-
12151210
}

rewrite-python-remote/src/main/java/org/openrewrite/python/remote/PythonValidator.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@
2323
package org.openrewrite.python.remote;
2424

2525
import org.jspecify.annotations.Nullable;
26-
import org.openrewrite.*;
26+
import org.openrewrite.Tree;
2727
import org.openrewrite.internal.ListUtils;
28-
import org.openrewrite.marker.Markers;
29-
import org.openrewrite.tree.*;
30-
import org.openrewrite.java.JavaVisitor;
3128
import org.openrewrite.java.tree.*;
3229
import org.openrewrite.python.PythonIsoVisitor;
33-
import org.openrewrite.python.tree.*;
30+
import org.openrewrite.python.tree.Py;
3431

3532
import java.util.List;
3633
import java.util.Objects;

rewrite-python/src/main/java/org/openrewrite/python/PythonVisitor.java

Lines changed: 38 additions & 73 deletions
Large diffs are not rendered by default.

rewrite-python/src/main/java/org/openrewrite/python/format/PythonSpacesVisitor.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ <T> JContainer<T> spaceBefore(JContainer<T> container, boolean spaceBefore) {
9393

9494
if (spaceBefore && notSingleSpace(container.getBefore().getWhitespace()) && doesNotContainNewLine(container.getBefore().getWhitespace())) {
9595
return container.withBefore(container.getBefore().withWhitespace(" "));
96-
} else if (!spaceBefore && onlySpacesAndNotEmpty(container.getBefore().getWhitespace()) && doesNotContainNewLine(container.getBefore().getWhitespace())) {
96+
}
97+
if (!spaceBefore && onlySpacesAndNotEmpty(container.getBefore().getWhitespace()) && doesNotContainNewLine(container.getBefore().getWhitespace())) {
9798
return container.withBefore(container.getBefore().withWhitespace(""));
98-
} else {
99-
return container;
10099
}
100+
return container;
101101
}
102102

103103
private static List<Comment> spaceLastCommentSuffix(List<Comment> comments, boolean spaceSuffix) {
@@ -108,11 +108,11 @@ private static List<Comment> spaceLastCommentSuffix(List<Comment> comments, bool
108108
private static Comment spaceSuffix(Comment comment, boolean spaceSuffix) {
109109
if (spaceSuffix && notSingleSpace(comment.getSuffix()) && doesNotContainNewLine(comment.getSuffix())) {
110110
return comment.withSuffix(" ");
111-
} else if (!spaceSuffix && onlySpacesAndNotEmpty(comment.getSuffix()) && doesNotContainNewLine(comment.getSuffix())) {
111+
}
112+
if (!spaceSuffix && onlySpacesAndNotEmpty(comment.getSuffix()) && doesNotContainNewLine(comment.getSuffix())) {
112113
return comment.withSuffix("");
113-
} else {
114-
return comment;
115114
}
115+
return comment;
116116
}
117117

118118
<T extends J> T spaceBefore(T j, boolean spaceBefore) {
@@ -122,11 +122,11 @@ <T extends J> T spaceBefore(T j, boolean spaceBefore) {
122122

123123
if (spaceBefore && notSingleSpace(j.getPrefix().getWhitespace()) && doesNotContainNewLine(j.getPrefix().getWhitespace())) {
124124
return j.withPrefix(j.getPrefix().withWhitespace(" "));
125-
} else if (!spaceBefore && onlySpacesAndNotEmpty(j.getPrefix().getWhitespace()) && doesNotContainNewLine(j.getPrefix().getWhitespace())) {
125+
}
126+
if (!spaceBefore && onlySpacesAndNotEmpty(j.getPrefix().getWhitespace()) && doesNotContainNewLine(j.getPrefix().getWhitespace())) {
126127
return j.withPrefix(j.getPrefix().withWhitespace(""));
127-
} else {
128-
return j;
129128
}
129+
return j;
130130
}
131131

132132
<T extends J> JRightPadded<T> spaceAfter(JRightPadded<T> container, boolean spaceAfter) {
@@ -138,11 +138,11 @@ <T extends J> JRightPadded<T> spaceAfter(JRightPadded<T> container, boolean spac
138138

139139
if (spaceAfter && notSingleSpace(container.getAfter().getWhitespace()) && doesNotContainNewLine(container.getAfter().getWhitespace())) {
140140
return container.withAfter(container.getAfter().withWhitespace(" "));
141-
} else if (!spaceAfter && onlySpacesAndNotEmpty(container.getAfter().getWhitespace()) && doesNotContainNewLine(container.getAfter().getWhitespace())) {
141+
}
142+
if (!spaceAfter && onlySpacesAndNotEmpty(container.getAfter().getWhitespace()) && doesNotContainNewLine(container.getAfter().getWhitespace())) {
142143
return container.withAfter(container.getAfter().withWhitespace(""));
143-
} else {
144-
return container;
145144
}
145+
return container;
146146
}
147147

148148
/**

rewrite-python/src/main/java/org/openrewrite/python/internal/PythonPrinter.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ public J visit(@Nullable Tree tree, PrintOutputCapture<P> p) {
5050
if (!(tree instanceof Py)) {
5151
// re-route printing to the Java printer
5252
return delegate.visitNonNull(requireNonNull(tree), p);
53-
} else {
54-
//noinspection DataFlowIssue
55-
return super.visit(tree, p);
5653
}
54+
//noinspection DataFlowIssue
55+
return super.visit(tree, p);
5756
}
5857

5958
@Override
@@ -704,10 +703,9 @@ public J visit(@Nullable Tree tree, PrintOutputCapture<P> p) {
704703
if (tree instanceof Py) {
705704
// re-route printing back up to Python printer
706705
return PythonPrinter.this.visitNonNull(tree, p);
707-
} else {
708-
//noinspection DataFlowIssue
709-
return super.visit(tree, p);
710706
}
707+
//noinspection DataFlowIssue
708+
return super.visit(tree, p);
711709
}
712710

713711
@Override

rewrite-python/src/main/java/org/openrewrite/python/style/Autodetect.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ public SpacesStyle getStyle() {
193193
private static class FindSpaceVisitor extends PythonIsoVisitor<SpacesStatistics> {
194194

195195
private static boolean variableIsPartOfMethodHeader(Cursor cursor) {
196-
return cursor.getParentTreeCursor().getValue() instanceof J.VariableDeclarations
197-
&& cursor.getParentTreeCursor().getParentTreeCursor().getValue() instanceof J.MethodDeclaration;
196+
return cursor.getParentTreeCursor().getValue() instanceof J.VariableDeclarations &&
197+
cursor.getParentTreeCursor().getParentTreeCursor().getValue() instanceof J.MethodDeclaration;
198198
}
199199

200200
private static int hasSpace(@Nullable Space space) {

rewrite-python/src/main/java/org/openrewrite/python/tree/Py.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,12 @@ public Py.ForLoop withIterable(Expression iterable) {
375375

376376
JRightPadded<Statement> body;
377377

378+
@Override
378379
public Statement getBody() {
379380
return this.body.getElement();
380381
}
381382

383+
@Override
382384
public Py.ForLoop withBody(Statement body) {
383385
return this.getPadding().withBody(this.body.withElement(body));
384386
}
@@ -751,7 +753,8 @@ public <P> J acceptPython(PythonVisitor<P> v, P p) {
751753
public @Nullable JavaType getType() {
752754
if (reference instanceof Expression) {
753755
return ((Expression) reference).getType();
754-
} else if (reference instanceof TypedTree) {
756+
}
757+
if (reference instanceof TypedTree) {
755758
return ((TypedTree) reference).getType();
756759
}
757760
return null;
@@ -762,7 +765,8 @@ public <P> J acceptPython(PythonVisitor<P> v, P p) {
762765
public ExpressionTypeTree withType(@Nullable JavaType type) {
763766
if (reference instanceof Expression) {
764767
return withReference(((Expression) reference).withType(type));
765-
} else if (reference instanceof TypedTree) {
768+
}
769+
if (reference instanceof TypedTree) {
766770
return withReference(((TypedTree) reference).withType(type));
767771
}
768772
return this;

0 commit comments

Comments
 (0)