Skip to content

Commit 37bf21b

Browse files
refactor: OpenRewrite best practices (#8)
Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.recipes.OpenRewriteBestPractices?organizationId=T3BlblJld3JpdGU%3D Co-authored-by: Moderne <[email protected]>
1 parent 3c57997 commit 37bf21b

File tree

7 files changed

+41
-53
lines changed

7 files changed

+41
-53
lines changed

rewrite-csharp/src/main/java/org/openrewrite/csharp/CSharpIsoVisitor.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,8 @@
1515
*/
1616
package org.openrewrite.csharp;
1717

18-
import org.jspecify.annotations.Nullable;
19-
import org.openrewrite.*;
20-
import org.openrewrite.internal.ListUtils;
21-
import org.openrewrite.marker.Markers;
22-
import org.openrewrite.tree.*;
23-
import org.openrewrite.java.JavaVisitor;
24-
import org.openrewrite.java.tree.*;
2518
import org.openrewrite.csharp.tree.*;
26-
27-
import java.util.List;
19+
import org.openrewrite.java.tree.*;
2820

2921
public class CSharpIsoVisitor<P> extends CSharpVisitor<P>
3022
{

rewrite-csharp/src/main/java/org/openrewrite/csharp/CSharpPrinter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
*/
1616
package org.openrewrite.csharp;
1717

18+
import org.jspecify.annotations.Nullable;
1819
import org.openrewrite.Cursor;
1920
import org.openrewrite.PrintOutputCapture;
2021
import org.openrewrite.Tree;
2122
import org.openrewrite.csharp.marker.OmitBraces;
2223
import org.openrewrite.csharp.marker.SingleExpressionBlock;
2324
import org.openrewrite.csharp.tree.*;
24-
import org.openrewrite.internal.lang.Nullable;
2525
import org.openrewrite.java.JavaPrinter;
2626
import org.openrewrite.java.marker.CompactConstructor;
2727
import org.openrewrite.java.marker.Semicolon;
@@ -714,7 +714,7 @@ private void beforeSyntax(Cs cs, CsSpace.Location loc, PrintOutputCapture<P> p)
714714
beforeSyntax(cs.getPrefix(), cs.getMarkers(), loc, p);
715715
}
716716

717-
private void beforeSyntax(Space prefix, Markers markers, @Nullable CsSpace.Location loc, PrintOutputCapture<P> p) {
717+
private void beforeSyntax(Space prefix, Markers markers, CsSpace.@Nullable Location loc, PrintOutputCapture<P> p) {
718718
for (Marker marker : markers.getMarkers()) {
719719
p.append(p.getMarkerPrinter().beforePrefix(marker, new Cursor(getCursor(), marker), JAVA_MARKER_WRAPPER));
720720
}
@@ -727,7 +727,7 @@ private void beforeSyntax(Space prefix, Markers markers, @Nullable CsSpace.Locat
727727
}
728728
}
729729

730-
private void beforeSyntax(Space prefix, Markers markers, @Nullable Space.Location loc, PrintOutputCapture<P> p) {
730+
private void beforeSyntax(Space prefix, Markers markers, Space.@Nullable Location loc, PrintOutputCapture<P> p) {
731731
for (Marker marker : markers.getMarkers()) {
732732
p.append(p.getMarkerPrinter().beforePrefix(marker, new Cursor(getCursor(), marker), JAVA_MARKER_WRAPPER));
733733
}
@@ -749,4 +749,4 @@ private void afterSyntax(Markers markers, PrintOutputCapture<P> p) {
749749
p.append(p.getMarkerPrinter().afterSyntax(marker, new Cursor(getCursor(), marker), JAVA_MARKER_WRAPPER));
750750
}
751751
}
752-
}
752+
}

rewrite-csharp/src/main/java/org/openrewrite/csharp/CSharpVisitor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717

1818
import org.jspecify.annotations.Nullable;
1919
import org.openrewrite.*;
20+
import org.openrewrite.csharp.tree.*;
2021
import org.openrewrite.internal.ListUtils;
21-
import org.openrewrite.marker.Markers;
22-
import org.openrewrite.tree.*;
2322
import org.openrewrite.java.JavaVisitor;
2423
import org.openrewrite.java.tree.*;
25-
import org.openrewrite.csharp.tree.*;
24+
import org.openrewrite.marker.Markers;
25+
import org.openrewrite.tree.*;
2626

2727
import java.util.List;
2828

rewrite-csharp/src/main/java/org/openrewrite/csharp/marker/package-info.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
@NonNullApi
16+
@NullMarked
1717
@NonNullFields
1818
package org.openrewrite.csharp.marker;
1919

20-
import org.openrewrite.internal.lang.NonNullApi;
20+
import org.jspecify.annotations.NullMarked;
2121
import org.openrewrite.internal.lang.NonNullFields;

rewrite-csharp/src/main/java/org/openrewrite/csharp/package-info.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
@NonNullApi
16+
@NullMarked
1717
@NonNullFields
1818
package org.openrewrite.csharp;
1919

20-
import org.openrewrite.internal.lang.NonNullApi;
20+
import org.jspecify.annotations.NullMarked;
2121
import org.openrewrite.internal.lang.NonNullFields;

rewrite-csharp/src/main/java/org/openrewrite/csharp/tree/Cs.java

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
import lombok.*;
1919
import lombok.experimental.FieldDefaults;
2020
import lombok.experimental.NonFinal;
21+
import org.jspecify.annotations.Nullable;
2122
import org.openrewrite.*;
2223
import org.openrewrite.csharp.CSharpPrinter;
2324
import org.openrewrite.csharp.CSharpVisitor;
24-
import org.openrewrite.internal.lang.Nullable;
2525
import org.openrewrite.java.JavaPrinter;
2626
import org.openrewrite.java.internal.TypesInUse;
2727
import org.openrewrite.java.tree.*;
@@ -54,8 +54,7 @@ default <P> boolean isAcceptable(TreeVisitor<?, P> v, P p) {
5454
return v.isAdaptableTo(CSharpVisitor.class);
5555
}
5656

57-
@Nullable
58-
default <P> J acceptCSharp(CSharpVisitor<P> v, P p) {
57+
default <P> @Nullable J acceptCSharp(CSharpVisitor<P> v, P p) {
5958
return v.defaultValue(this, p);
6059
}
6160

@@ -121,11 +120,12 @@ public SourceFile withCharset(Charset charset) {
121120
return withCharsetName(charset.name());
122121
}
123122

124-
@Nullable
125-
public Package getPackageDeclaration() {
123+
@Override
124+
public @Nullable Package getPackageDeclaration() {
126125
return null;
127126
}
128127

128+
@Override
129129
public Cs.CompilationUnit withPackageDeclaration(Package packageDeclaration) {
130130
return this;
131131
}
@@ -164,15 +164,18 @@ public Cs.CompilationUnit withMembers(List<Statement> members) {
164164
return getPadding().withMembers(JRightPadded.withElements(this.members, members));
165165
}
166166

167+
@Override
167168
@Transient
168169
public List<Import> getImports() {
169170
return Collections.emptyList();
170171
}
171172

173+
@Override
172174
public Cs.CompilationUnit withImports(List<Import> imports) {
173175
return this;
174176
}
175177

178+
@Override
176179
@Transient
177180
public List<ClassDeclaration> getClasses() {
178181
return Collections.emptyList();
@@ -213,6 +216,7 @@ public TypesInUse getTypesInUse() {
213216
return cache;
214217
}
215218

219+
@Override
216220
public Padding getPadding() {
217221
Padding p;
218222
if (this.padding == null) {
@@ -378,8 +382,7 @@ public Padding getPadding() {
378382
public static class Padding {
379383
private final ArrayRankSpecifier t;
380384

381-
@Nullable
382-
public JContainer<Expression> getSizes() {
385+
public @Nullable JContainer<Expression> getSizes() {
383386
return t.sizes;
384387
}
385388

@@ -514,12 +517,12 @@ final class AttributeList implements Cs {
514517
@Nullable
515518
JRightPadded<Identifier> target;
516519

517-
@Nullable
518-
public J.Identifier getTarget() {
520+
521+
public J.@Nullable Identifier getTarget() {
519522
return target == null ? null : target.getElement();
520523
}
521524

522-
public AttributeList withTarget(@Nullable J.Identifier target) {
525+
public AttributeList withTarget(J.@Nullable Identifier target) {
523526
return getPadding().withTarget(JRightPadded.withElement(this.target, target));
524527
}
525528

@@ -1259,8 +1262,7 @@ public Interpolation withExpression(Expression expression) {
12591262
@Nullable
12601263
JRightPadded<Expression> alignment;
12611264

1262-
@Nullable
1263-
public Expression getAlignment() {
1265+
public @Nullable Expression getAlignment() {
12641266
return alignment != null ? alignment.getElement() : null;
12651267
}
12661268

@@ -1271,8 +1273,7 @@ public Interpolation withAlignment(@Nullable Expression alignment) {
12711273
@Nullable
12721274
JRightPadded<Expression> format;
12731275

1274-
@Nullable
1275-
public Expression getFormat() {
1276+
public @Nullable Expression getFormat() {
12761277
return format != null ? format.getElement() : null;
12771278
}
12781279

@@ -1328,17 +1329,15 @@ public Interpolation withExpression(JRightPadded<Expression> expression) {
13281329
return t.expression == expression ? t : new Interpolation(t.id, t.prefix, t.markers, expression, t.alignment, t.format);
13291330
}
13301331

1331-
@Nullable
1332-
public JRightPadded<Expression> getAlignment() {
1332+
public @Nullable JRightPadded<Expression> getAlignment() {
13331333
return t.alignment;
13341334
}
13351335

13361336
public Interpolation withAlignment(@Nullable JRightPadded<Expression> alignment) {
13371337
return t.alignment == alignment ? t : new Interpolation(t.id, t.prefix, t.markers, t.expression, alignment, t.format);
13381338
}
13391339

1340-
@Nullable
1341-
public JRightPadded<Expression> getFormat() {
1340+
public @Nullable JRightPadded<Expression> getFormat() {
13421341
return t.format;
13431342
}
13441343

@@ -1525,12 +1524,12 @@ public UsingDirective withUnsafe(boolean unsafe) {
15251524
@Nullable
15261525
JRightPadded<Identifier> alias;
15271526

1528-
@Nullable
1529-
public J.Identifier getAlias() {
1527+
1528+
public J.@Nullable Identifier getAlias() {
15301529
return alias != null ? alias.getElement() : null;
15311530
}
15321531

1533-
public UsingDirective withAlias(@Nullable J.Identifier alias) {
1532+
public UsingDirective withAlias(J.@Nullable Identifier alias) {
15341533
return getPadding().withAlias(JRightPadded.withElement(this.alias, alias));
15351534
}
15361535

@@ -1591,8 +1590,7 @@ public UsingDirective withUnsafe(JLeftPadded<Boolean> unsafe) {
15911590
return t.unsafe == unsafe ? t : new UsingDirective(t.id, t.prefix, t.markers, t.global, t.statik, unsafe, t.alias, t.namespaceOrType);
15921591
}
15931592

1594-
@Nullable
1595-
public JRightPadded<Identifier> getAlias() {
1593+
public @Nullable JRightPadded<Identifier> getAlias() {
15961594
return t.alias;
15971595
}
15981596

@@ -1657,25 +1655,25 @@ public CoordinateBuilder.Statement getCoordinates() {
16571655
return new CoordinateBuilder.Statement(this);
16581656
}
16591657

1658+
@Override
16601659
public JavaType getType() {
16611660
return typeExpression.getType();
16621661
}
16631662

1663+
@Override
16641664
public PropertyDeclaration withType(@Nullable JavaType type) {
16651665
return getPadding().withType(this.typeExpression.withType(type));
16661666
}
16671667

1668-
@Nullable
1669-
public NameTree getInterfaceSpecifier() {
1668+
public @Nullable NameTree getInterfaceSpecifier() {
16701669
return interfaceSpecifier!= null ? interfaceSpecifier.getElement() : null;
16711670
}
16721671

16731672
public PropertyDeclaration withInterfaceSpecifier(@Nullable NameTree interfaceSpecifier) {
16741673
return getPadding().withInterfaceSpecifier(JRightPadded.withElement(this.interfaceSpecifier, interfaceSpecifier));
16751674
}
16761675

1677-
@Nullable
1678-
public Expression getInitializer() {
1676+
public @Nullable Expression getInitializer() {
16791677
return initializer != null ? initializer.getElement() : null;
16801678
}
16811679

@@ -1711,8 +1709,7 @@ public TypeTree getType() {
17111709
return pd.typeExpression;
17121710
}
17131711

1714-
@Nullable
1715-
public JRightPadded<NameTree> getInterfaceSpecifier() {
1712+
public @Nullable JRightPadded<NameTree> getInterfaceSpecifier() {
17161713
return pd.interfaceSpecifier;
17171714
}
17181715

@@ -1742,8 +1739,7 @@ public PropertyDeclaration withType(TypeTree type) {
17421739
pd.initializer);
17431740
}
17441741

1745-
@Nullable
1746-
public JLeftPadded<Expression> getInitializer() {
1742+
public @Nullable JLeftPadded<Expression> getInitializer() {
17471743
return pd.initializer;
17481744
}
17491745

rewrite-csharp/src/main/java/org/openrewrite/csharp/tree/package-info.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
@NonNullApi
16+
@NullMarked
1717
@NonNullFields
1818
package org.openrewrite.csharp.tree;
1919

20-
import org.openrewrite.internal.lang.NonNullApi;
20+
import org.jspecify.annotations.NullMarked;
2121
import org.openrewrite.internal.lang.NonNullFields;

0 commit comments

Comments
 (0)