Skip to content

Commit

Permalink
refactor: Annotate methods which may return null with @Nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsdebruin and TeamModerne committed Oct 28, 2024
1 parent 39af1ee commit 93da08a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/openrewrite/kotlin/KotlinVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public <J2 extends J> JContainer<J2> visitContainer(JContainer<J2> container, P
return super.visitContainer(container, JContainer.Location.LANGUAGE_EXTENSION, p);
}

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

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

public <T> JRightPadded<T> visitRightPadded(@Nullable JRightPadded<T> right, KRightPadded.Location loc, P p) {
public <T> @Nullable JRightPadded<T> visitRightPadded(@Nullable JRightPadded<T> right, KRightPadded.Location loc, P p) {
if (right == null) {
//noinspection ConstantConditions
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public <T> JLeftPadded<T> visitLeftPadded(@Nullable JLeftPadded<T> left, JLeftPa
}

@Override
public <T> JRightPadded<T> visitRightPadded(@Nullable JRightPadded<T> right, JRightPadded.Location loc, P p) {
public <T> @Nullable JRightPadded<T> visitRightPadded(@Nullable JRightPadded<T> right, JRightPadded.Location loc, P p) {
if (right == null) {
//noinspection ConstantConditions
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,17 @@ public static class TreePrinterContext {
int depth;
}

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

TreePrinterContext context = new TreePrinterContext(lines, 1);
new FirDefaultVisitor<Void, TreePrinterContext>() {

@Override
public Void visitElement(FirElement firElement, TreePrinterContext ctx) {
public @Nullable Void visitElement(FirElement firElement, TreePrinterContext ctx) {
StringBuilder line = new StringBuilder();
line.append(leftPadding(ctx.getDepth()))
.append(printFirElement(firElement));
Expand All @@ -153,17 +154,18 @@ public Void visitElement(FirElement firElement, TreePrinterContext ctx) {
return null;
}
}.visitFile(file, context);
sb.append(java.lang.String.join("\n", lines));
sb.append(String.join("\n", lines));
return sb.toString();
}

public static String printFirTree(FirElement firElement) {
public static @Nullable String printFirTree(FirElement firElement) {
StringBuilder sb = new StringBuilder();
List<StringBuilder> lines = new ArrayList<>();
TreePrinterContext context = new TreePrinterContext(lines, 1);
new FirDefaultVisitor<Void, TreePrinterContext>() {

@Override
public Void visitElement(FirElement fir, TreePrinterContext ctx) {
public @Nullable Void visitElement(FirElement fir, TreePrinterContext ctx) {
StringBuilder line = new StringBuilder();
line.append(leftPadding(ctx.getDepth()))
.append(printFirElement(fir));
Expand All @@ -184,7 +186,7 @@ public Void visitElement(FirElement fir, TreePrinterContext ctx) {
return null;
}
}.visitElement(firElement, context);
sb.append(java.lang.String.join("\n", lines));
sb.append(String.join("\n", lines));
return sb.toString();
}

Expand Down

0 comments on commit 93da08a

Please sign in to comment.