Skip to content

Commit

Permalink
refactor: Move @Nullable method annotations to the return type
Browse files Browse the repository at this point in the history
jkschneider and TeamModerne committed Jul 16, 2024

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent cd87965 commit 052dbf0
Showing 18 changed files with 62 additions and 124 deletions.
3 changes: 1 addition & 2 deletions src/main/java/org/openrewrite/kotlin/Assertions.java
Original file line number Diff line number Diff line change
@@ -68,8 +68,7 @@ static void customizeExecutionContext(ExecutionContext ctx) {
// The idea is to differentiate adjacent spaces by whitespace count so that if any adjacent spaces are swapped or unhandled well by the parser, it can be detected.
// Just change from `before` to `adjustSpaces(before)` below in the `kotlin()` method to test locally
@SuppressWarnings("IfStatementWithIdenticalBranches")
@Nullable
private static String adjustSpaces(@Nullable String input) {
private static @Nullable String adjustSpaces(@Nullable String input) {
if (input == null) {
return null;
}
3 changes: 1 addition & 2 deletions src/main/java/org/openrewrite/kotlin/FindKotlinSources.java
Original file line number Diff line number Diff line change
@@ -65,8 +65,7 @@ public Tree visit(@Nullable Tree tree, ExecutionContext ctx) {
return tree;
}

@Nullable
private KotlinSourceFile.SourceFileType getSourceFileType(SourceFile sourceFile) {
private @Nullable KotlinSourceFile.SourceFileType getSourceFileType(SourceFile sourceFile) {
KotlinSourceFile.SourceFileType sourceFileType = null;
if (sourceFile instanceof K.CompilationUnit) {
sourceFileType = KotlinSourceFile.SourceFileType.Kotlin;
3 changes: 1 addition & 2 deletions src/main/java/org/openrewrite/kotlin/KotlinParser.java
Original file line number Diff line number Diff line change
@@ -321,8 +321,7 @@ public Builder languageLevel(KotlinLanguageLevel languageLevel) {
return this;
}

@Nullable
private Collection<Path> resolvedClasspath() {
private @Nullable Collection<Path> resolvedClasspath() {
if (artifactNames != null && !artifactNames.isEmpty()) {
classpath = JavaParser.dependenciesFromClasspath(artifactNames.toArray(new String[0]));
artifactNames = null;
Original file line number Diff line number Diff line change
@@ -422,9 +422,8 @@ private static int getNewLineCount(String whitespace) {
return newLineCount;
}

@Nullable
@Override
public J postVisit(J tree, P p) {
public @Nullable J postVisit(J tree, P p) {
if (stopAfter != null && stopAfter.isScope(tree)) {
getCursor().putMessageOnFirstEnclosing(JavaSourceFile.class, "stop", true);
}
Original file line number Diff line number Diff line change
@@ -327,18 +327,16 @@ public J.VariableDeclarations visitVariableDeclarations(J.VariableDeclarations m
return v;
}

@Nullable
@Override
public J postVisit(J tree, P p) {
public @Nullable J postVisit(J tree, P p) {
if (stopAfter != null && stopAfter.isScope(tree)) {
getCursor().putMessageOnFirstEnclosing(JavaSourceFile.class, "stop", true);
}
return super.postVisit(tree, p);
}

@Nullable
@Override
public J visit(@Nullable Tree tree, P p) {
public @Nullable J visit(@Nullable Tree tree, P p) {
if (getCursor().getNearestMessage("stop") != null) {
return (J) tree;
}
Original file line number Diff line number Diff line change
@@ -175,18 +175,16 @@ public Javadoc visitLineBreak(Javadoc.LineBreak lineBreak, Integer integer) {
.withComments(comments));
}

@Nullable
@Override
public J postVisit(J tree, P p) {
public @Nullable J postVisit(J tree, P p) {
if (stopAfter != null && stopAfter.isScope(tree)) {
getCursor().putMessageOnFirstEnclosing(JavaSourceFile.class, "stop", true);
}
return super.postVisit(tree, p);
}

@Nullable
@Override
public J visit(@Nullable Tree tree, P p) {
public @Nullable J visit(@Nullable Tree tree, P p) {
if (getCursor().getNearestMessage("stop") != null) {
return (J) tree;
}
Original file line number Diff line number Diff line change
@@ -91,9 +91,8 @@ public J postVisit(J tree, P p) {
return tree;
}

@Nullable
@Override
public J visit(@Nullable Tree tree, P p) {
public @Nullable J visit(@Nullable Tree tree, P p) {
if (getCursor().getNearestMessage("stop") != null) {
return (J) tree;
}
Original file line number Diff line number Diff line change
@@ -124,18 +124,16 @@ private String normalize(String text, boolean isComment) {
return text;
}

@Nullable
@Override
public J postVisit(J tree, P p) {
public @Nullable J postVisit(J tree, P p) {
if (stopAfter != null && stopAfter.isScope(tree)) {
getCursor().putMessageOnFirstEnclosing(JavaSourceFile.class, "stop", true);
}
return super.postVisit(tree, p);
}

@Nullable
@Override
public J visit(@Nullable Tree tree, P p) {
public @Nullable J visit(@Nullable Tree tree, P p) {
if (getCursor().getNearestMessage("stop") != null) {
return (J) tree;
}
Original file line number Diff line number Diff line change
@@ -73,18 +73,16 @@ public Space visitSpace(Space space, Space.Location loc, P p) {
return s;
}

@Nullable
@Override
public J postVisit(J tree, P p) {
public @Nullable J postVisit(J tree, P p) {
if (stopAfter != null && stopAfter.isScope(tree)) {
getCursor().putMessageOnFirstEnclosing(JavaSourceFile.class, "stop", true);
}
return super.postVisit(tree, p);
}

@Nullable
@Override
public J visit(@Nullable Tree tree, P p) {
public @Nullable J visit(@Nullable Tree tree, P p) {
if (getCursor().getNearestMessage("stop") != null) {
return (J) tree;
}
Original file line number Diff line number Diff line change
@@ -1163,7 +1163,7 @@ public J.EnumValue visitEnumValue(J.EnumValue _enum, P p) {
return e;
}

// @Override
// @Override
// public J.TypeParameter visitTypeParameter(J.TypeParameter typeParam, P p) {
// J.TypeParameter tp = super.visitTypeParameter(typeParam, p);
// if (tp.getPadding().getBounds() != null) {
@@ -1188,18 +1188,16 @@ public J.EnumValue visitEnumValue(J.EnumValue _enum, P p) {
// return tp;
// }

@Nullable
@Override
public J postVisit(J tree, P p) {
public @Nullable J postVisit(J tree, P p) {
if (stopAfter != null && stopAfter.isScope(tree)) {
getCursor().getRoot().putMessage("stop", true);
}
return super.postVisit(tree, p);
}

@Nullable
@Override
public J visit(@Nullable Tree tree, P p) {
public @Nullable J visit(@Nullable Tree tree, P p) {
if (getCursor().getNearestMessage("stop") != null) {
return (J) tree;
}
Original file line number Diff line number Diff line change
@@ -53,8 +53,7 @@ public TabsAndIndentsVisitor(TabsAndIndentsStyle style, WrappingAndBracesStyle w
}

@Override
@Nullable
public J visit(@Nullable Tree tree, P p, Cursor parent) {
public @Nullable J visit(@Nullable Tree tree, P p, Cursor parent) {
setCursor(parent);
for (Cursor c = parent; c != null; c = c.getParent()) {
Object v = c.getValue();
@@ -85,11 +84,9 @@ public J visit(@Nullable Tree tree, P p, Cursor parent) {
return visit(tree, p);
}


@SuppressWarnings("StatementWithEmptyBody")
@Override
@Nullable
public J preVisit(@Nullable J tree, P p) {
public @Nullable J preVisit(@Nullable J tree, P p) {
if (tree instanceof JavaSourceFile ||
tree instanceof J.Package ||
tree instanceof J.Import ||
@@ -698,18 +695,16 @@ private int forInitColumn() {
throw new IllegalStateException("For loops must have a control section");
}

@Nullable
@Override
public J postVisit(J tree, P p) {
public @Nullable J postVisit(J tree, P p) {
if (stopAfter != null && stopAfter.isScope(tree)) {
getCursor().putMessageOnFirstEnclosing(JavaSourceFile.class, "stop", true);
}
return super.postVisit(tree, p);
}

@Nullable
@Override
public J visit(@Nullable Tree tree, P p) {
public @Nullable J visit(@Nullable Tree tree, P p) {
if (tree instanceof J && tree.getMarkers().findFirst(Implicit.class).isPresent()) {
return (J) tree;
} else if (getCursor().getNearestMessage("stop") != null) {
Original file line number Diff line number Diff line change
@@ -259,18 +259,16 @@ private List<J.Modifier> withNewline(List<J.Modifier> modifiers) {
return modifiers;
}

@Nullable
@Override
public J postVisit(J tree, P p) {
public @Nullable J postVisit(J tree, P p) {
if (stopAfter != null && stopAfter.isScope(tree)) {
getCursor().putMessageOnFirstEnclosing(JavaSourceFile.class, "stop", true);
}
return super.postVisit(tree, p);
}

@Nullable
@Override
public J visit(@Nullable Tree tree, P p) {
public @Nullable J visit(@Nullable Tree tree, P p) {
if (getCursor().getNearestMessage("stop") != null) {
return (J) tree;
}
Loading

0 comments on commit 052dbf0

Please sign in to comment.