Skip to content
This repository was archived by the owner on May 12, 2025. It is now read-only.

Commit 1f52198

Browse files
refactor: Annotate methods which may return null with @Nullable (#615)
Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.staticanalysis.AnnotateNullableMethods?organizationId=T3BlblJld3JpdGU%3D Co-authored-by: Moderne <team@moderne.io>
1 parent 39af1ee commit 1f52198

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

src/main/java/org/openrewrite/kotlin/KotlinVisitor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ public <J2 extends J> JContainer<J2> visitContainer(JContainer<J2> container, P
411411
return super.visitContainer(container, JContainer.Location.LANGUAGE_EXTENSION, p);
412412
}
413413

414-
public <J2 extends J> JContainer<J2> visitContainer(@Nullable JContainer<J2> container,
414+
public <J2 extends J> @Nullable JContainer<J2> visitContainer(@Nullable JContainer<J2> container,
415415
KContainer.Location loc, P p) {
416416
if (container == null) {
417417
//noinspection ConstantConditions
@@ -429,7 +429,7 @@ public <J2 extends J> JContainer<J2> visitContainer(@Nullable JContainer<J2> con
429429
JContainer.build(before, js, container.getMarkers());
430430
}
431431

432-
public <T> JLeftPadded<T> visitLeftPadded(@Nullable JLeftPadded<T> left, KLeftPadded.Location loc, P p) {
432+
public <T> @Nullable JLeftPadded<T> visitLeftPadded(@Nullable JLeftPadded<T> left, KLeftPadded.Location loc, P p) {
433433
if (left == null) {
434434
//noinspection ConstantConditions
435435
return null;
@@ -458,7 +458,7 @@ public <T> JLeftPadded<T> visitLeftPadded(@Nullable JLeftPadded<T> left, KLeftPa
458458
return (before == left.getBefore() && t == left.getElement()) ? left : new JLeftPadded<>(before, t, left.getMarkers());
459459
}
460460

461-
public <T> JRightPadded<T> visitRightPadded(@Nullable JRightPadded<T> right, KRightPadded.Location loc, P p) {
461+
public <T> @Nullable JRightPadded<T> visitRightPadded(@Nullable JRightPadded<T> right, KRightPadded.Location loc, P p) {
462462
if (right == null) {
463463
//noinspection ConstantConditions
464464
return null;

src/main/java/org/openrewrite/kotlin/format/TabsAndIndentsVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public <T> JLeftPadded<T> visitLeftPadded(@Nullable JLeftPadded<T> left, JLeftPa
248248
}
249249

250250
@Override
251-
public <T> JRightPadded<T> visitRightPadded(@Nullable JRightPadded<T> right, JRightPadded.Location loc, P p) {
251+
public <T> @Nullable JRightPadded<T> visitRightPadded(@Nullable JRightPadded<T> right, JRightPadded.Location loc, P p) {
252252
if (right == null) {
253253
//noinspection ConstantConditions
254254
return null;

src/main/java/org/openrewrite/kotlin/internal/PsiTreePrinter.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,17 @@ public static class TreePrinterContext {
123123
int depth;
124124
}
125125

126-
public static String printFirFile(FirFile file) {
126+
public static @Nullable String printFirFile(FirFile file) {
127127
StringBuilder sb = new StringBuilder();
128128
List<StringBuilder> lines = new ArrayList<>();
129129
sb.append("------------").append("\n");
130130
sb.append("FirFile:").append("\n\n");
131131

132132
TreePrinterContext context = new TreePrinterContext(lines, 1);
133133
new FirDefaultVisitor<Void, TreePrinterContext>() {
134+
134135
@Override
135-
public Void visitElement(FirElement firElement, TreePrinterContext ctx) {
136+
public @Nullable Void visitElement(FirElement firElement, TreePrinterContext ctx) {
136137
StringBuilder line = new StringBuilder();
137138
line.append(leftPadding(ctx.getDepth()))
138139
.append(printFirElement(firElement));
@@ -153,17 +154,18 @@ public Void visitElement(FirElement firElement, TreePrinterContext ctx) {
153154
return null;
154155
}
155156
}.visitFile(file, context);
156-
sb.append(java.lang.String.join("\n", lines));
157+
sb.append(String.join("\n", lines));
157158
return sb.toString();
158159
}
159160

160-
public static String printFirTree(FirElement firElement) {
161+
public static @Nullable String printFirTree(FirElement firElement) {
161162
StringBuilder sb = new StringBuilder();
162163
List<StringBuilder> lines = new ArrayList<>();
163164
TreePrinterContext context = new TreePrinterContext(lines, 1);
164165
new FirDefaultVisitor<Void, TreePrinterContext>() {
166+
165167
@Override
166-
public Void visitElement(FirElement fir, TreePrinterContext ctx) {
168+
public @Nullable Void visitElement(FirElement fir, TreePrinterContext ctx) {
167169
StringBuilder line = new StringBuilder();
168170
line.append(leftPadding(ctx.getDepth()))
169171
.append(printFirElement(fir));
@@ -184,7 +186,7 @@ public Void visitElement(FirElement fir, TreePrinterContext ctx) {
184186
return null;
185187
}
186188
}.visitElement(firElement, context);
187-
sb.append(java.lang.String.join("\n", lines));
189+
sb.append(String.join("\n", lines));
188190
return sb.toString();
189191
}
190192

0 commit comments

Comments
 (0)