From ad91222a2869e7baba013394c80ea349822397e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Schn=C3=A9ider?= Date: Tue, 16 Jul 2024 22:28:19 +0000 Subject: [PATCH] refactor: Move `@Nullable` method annotations to the return type Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.staticanalysis.NullableOnMethodReturnType?organizationId=T3BlblJld3JpdGU%3D Co-authored-by: Moderne --- .../src/main/java/org/openrewrite/Cursor.java | 21 +-- .../org/openrewrite/DeleteSourceFiles.java | 4 +- .../org/openrewrite/ExecutionContext.java | 4 +- .../java/org/openrewrite/FileAttributes.java | 3 +- .../java/org/openrewrite/FindSourceFiles.java | 4 +- .../openrewrite/InMemoryExecutionContext.java | 6 +- .../src/main/java/org/openrewrite/Recipe.java | 3 +- .../main/java/org/openrewrite/RecipeRun.java | 6 +- .../main/java/org/openrewrite/RenameFile.java | 4 +- .../src/main/java/org/openrewrite/Result.java | 3 +- .../org/openrewrite/SetFilePermissions.java | 4 +- .../main/java/org/openrewrite/SourceFile.java | 3 +- .../src/main/java/org/openrewrite/Tree.java | 6 +- .../java/org/openrewrite/TreeVisitor.java | 21 +-- .../main/java/org/openrewrite/Validated.java | 9 +- .../org/openrewrite/config/CategoryTree.java | 15 +- .../config/YamlResourceLoader.java | 3 +- .../internal/InMemoryLargeSourceSet.java | 3 +- .../org/openrewrite/internal/ListUtils.java | 3 +- .../internal/RecipeIntrospectionUtils.java | 3 +- .../openrewrite/internal/ReflectionUtils.java | 6 +- .../org/openrewrite/marker/GitProvenance.java | 36 ++-- .../java/org/openrewrite/marker/Markup.java | 6 +- .../marker/OperatingSystemProvenance.java | 3 +- .../marker/ci/BuildEnvironment.java | 4 +- .../remote/LocalRemoteArtifactCache.java | 6 +- .../java/org/openrewrite/remote/Remote.java | 3 +- .../remote/RemoteArtifactCache.java | 3 +- .../scheduling/RecipeRunCycle.java | 3 +- .../scheduling/WatchableExecutionContext.java | 6 +- .../org/openrewrite/semver/CaretRange.java | 3 +- .../org/openrewrite/style/NamedStyles.java | 6 +- .../org/openrewrite/table/RecipeRunStats.java | 3 +- .../openrewrite/trait/SimpleTraitMatcher.java | 3 +- .../tree/ParsingExecutionContextView.java | 3 +- .../org/openrewrite/PreconditionsTest.java | 12 +- .../gradle/DependencyUseStringNotation.java | 6 +- .../gradle/DependencyVersionSelector.java | 9 +- .../UpgradeTransitiveDependencyVersion.java | 3 +- .../marker/GradleDependencyConfiguration.java | 6 +- .../gradle/marker/GradleProject.java | 3 +- .../gradle/marker/GradleSettings.java | 3 +- .../plugins/AddDevelocityGradlePlugin.java | 3 +- .../MigrateGradleEnterpriseToDevelocity.java | 6 +- .../DependencyStringNotationConverter.java | 6 +- .../gradle/util/GradleWrapper.java | 3 +- .../org/openrewrite/groovy/GroovyParser.java | 3 +- .../openrewrite/groovy/GroovyTypeMapping.java | 15 +- .../format/MinimumViableSpacingVisitor.java | 6 +- ...renthesesForLastArgumentLambdaVisitor.java | 6 +- .../java/org/openrewrite/groovy/tree/G.java | 12 +- .../org/openrewrite/hcl/JsonPathMatcher.java | 12 +- .../openrewrite/hcl/RandomizeIdVisitor.java | 4 +- .../hcl/format/AttributeSpaceVisitor.java | 6 +- .../hcl/format/BlankLinesVisitor.java | 6 +- .../hcl/format/BracketsVisitor.java | 7 +- .../openrewrite/hcl/format/SpacesVisitor.java | 6 +- .../hcl/format/TabsAndIndentsVisitor.java | 12 +- .../hcl/internal/HclParserVisitor.java | 3 +- .../hcl/internal/template/Substitutions.java | 6 +- .../java/org/openrewrite/hcl/tree/Hcl.java | 21 +-- .../openrewrite/hcl/tree/HclContainer.java | 3 +- .../openrewrite/hcl/tree/HclCoordinates.java | 3 +- .../openrewrite/hcl/tree/HclLeftPadded.java | 3 +- .../openrewrite/hcl/tree/HclRightPadded.java | 3 +- .../ReloadableJava11JavadocVisitor.java | 6 +- .../ReloadableJava11ParserVisitor.java | 9 +- .../isolated/ReloadableJava11TypeMapping.java | 18 +- .../ReloadableJava17JavadocVisitor.java | 6 +- .../ReloadableJava17ParserVisitor.java | 9 +- .../isolated/ReloadableJava17TypeMapping.java | 18 +- .../ReloadableJava21JavadocVisitor.java | 6 +- .../ReloadableJava21ParserVisitor.java | 9 +- .../isolated/ReloadableJava21TypeMapping.java | 18 +- .../java/ReloadableJava8JavadocVisitor.java | 6 +- .../java/ReloadableJava8ParserVisitor.java | 9 +- .../java/ReloadableJava8TypeMapping.java | 18 +- .../java/search/IsOrIsNotLikelyTestTest.java | 4 +- .../java/AddOrUpdateAnnotationAttribute.java | 3 +- .../org/openrewrite/java/ChangePackage.java | 6 +- .../java/org/openrewrite/java/ChangeType.java | 13 +- .../org/openrewrite/java/InvertCondition.java | 3 +- .../org/openrewrite/java/JavaTypeVisitor.java | 6 +- .../java/JavaUnrestrictedClassLoader.java | 6 +- .../org/openrewrite/java/JavaVisitor.java | 12 +- .../org/openrewrite/java/JavadocVisitor.java | 3 +- .../org/openrewrite/java/MethodMatcher.java | 6 +- .../openrewrite/java/RandomizeIdVisitor.java | 4 +- .../org/openrewrite/java/RenameVariable.java | 9 +- .../ReplaceStringLiteralWithConstant.java | 6 +- .../java/format/BlankLinesVisitor.java | 3 +- .../format/MinimumViableSpacingVisitor.java | 6 +- .../java/format/NormalizeFormatVisitor.java | 6 +- .../format/NormalizeLineBreaksVisitor.java | 3 +- .../format/NormalizeTabsOrSpacesVisitor.java | 6 +- .../RemoveTrailingWhitespaceVisitor.java | 6 +- .../java/format/SpacesVisitor.java | 6 +- .../java/format/TabsAndIndentsVisitor.java | 12 +- .../java/format/WrappingAndBracesVisitor.java | 6 +- .../internal/JavaReflectionTypeMapping.java | 3 +- .../java/internal/JavaTypeCache.java | 3 +- .../template/AnnotationTemplateGenerator.java | 4 +- .../BlockStatementTemplateGenerator.java | 9 +- .../internal/template/PatternVariables.java | 6 +- .../java/internal/template/Substitutions.java | 6 +- .../java/marker/JavaSourceSet.java | 3 +- .../java/search/SemanticallyEqual.java | 3 +- .../java/style/CheckstyleConfigLoader.java | 50 ++--- .../java/trait/VariableAccess.java | 6 +- .../org/openrewrite/java/tree/Expression.java | 3 +- .../java/org/openrewrite/java/tree/J.java | 171 ++++++------------ .../org/openrewrite/java/tree/JContainer.java | 3 +- .../openrewrite/java/tree/JLeftPadded.java | 3 +- .../openrewrite/java/tree/JRightPadded.java | 3 +- .../java/tree/JavaCoordinates.java | 3 +- .../org/openrewrite/java/tree/JavaType.java | 30 +-- .../org/openrewrite/java/tree/Javadoc.java | 12 +- .../org/openrewrite/java/tree/MethodCall.java | 3 +- .../org/openrewrite/java/tree/TypeUtils.java | 18 +- .../org/openrewrite/json/JsonPathMatcher.java | 12 +- .../json/internal/JsonParserVisitor.java | 3 +- .../java/org/openrewrite/json/tree/Json.java | 3 +- .../maven/AddDevelocityMavenExtension.java | 3 +- .../maven/AddManagedDependency.java | 6 +- .../maven/MavenExecutionContextView.java | 9 +- .../org/openrewrite/maven/MavenSettings.java | 24 +-- .../org/openrewrite/maven/MavenVisitor.java | 24 +-- .../maven/RemoveDuplicateDependencies.java | 6 +- .../RemoveRedundantDependencyVersions.java | 3 +- .../openrewrite/maven/UpdateMavenModel.java | 3 +- .../maven/UpgradeDependencyVersion.java | 12 +- .../maven/cache/CompositeMavenPomCache.java | 12 +- .../maven/cache/InMemoryMavenPomCache.java | 12 +- .../maven/cache/LocalMavenArtifactCache.java | 6 +- .../maven/cache/MavenArtifactCache.java | 12 +- .../ReadOnlyLocalMavenArtifactCache.java | 6 +- .../maven/cache/RocksdbMavenPomCache.java | 12 +- .../maven/internal/MavenPomDownloader.java | 21 +-- .../openrewrite/maven/internal/RawPom.java | 6 +- .../maven/internal/VersionRequirement.java | 9 +- .../openrewrite/maven/tree/Dependency.java | 6 +- .../tree/GraphvizResolutionEventListener.java | 3 +- .../maven/tree/ManagedDependency.java | 6 +- .../maven/tree/MavenRepository.java | 3 +- .../maven/tree/MavenResolutionResult.java | 6 +- .../org/openrewrite/maven/tree/Plugin.java | 6 +- .../java/org/openrewrite/maven/tree/Pom.java | 6 +- .../maven/tree/ResolvedDependency.java | 9 +- .../maven/tree/ResolvedManagedDependency.java | 3 +- .../openrewrite/maven/tree/ResolvedPom.java | 15 +- .../org/openrewrite/maven/tree/Scope.java | 8 +- .../utilities/MavenArtifactDownloader.java | 3 +- .../properties/ChangePropertyValue.java | 4 +- .../properties/PropertiesParser.java | 3 +- .../properties/PropertiesVisitor.java | 3 +- .../properties/tree/Properties.java | 3 +- .../protobuf/internal/ProtoParserVisitor.java | 6 +- .../org/openrewrite/protobuf/tree/Proto.java | 39 ++-- .../protobuf/tree/ProtoContainer.java | 3 +- .../protobuf/tree/ProtoLeftPadded.java | 3 +- .../org/openrewrite/test/RewriteTest.java | 3 +- .../org/openrewrite/xml/XPathMatcher.java | 3 +- .../xml/format/LineBreaksVisitor.java | 6 +- .../format/MinimumViableSpacingVisitor.java | 6 +- .../xml/format/NormalizeFormatVisitor.java | 6 +- .../format/NormalizeLineBreaksVisitor.java | 7 +- .../format/NormalizeTabsOrSpacesVisitor.java | 6 +- .../RemoveTrailingWhitespaceVisitor.java | 6 +- .../xml/format/TabsAndIndentsVisitor.java | 6 +- .../xml/internal/XmlParserVisitor.java | 3 +- .../org/openrewrite/xml/search/FindTags.java | 3 +- .../java/org/openrewrite/xml/tree/Xml.java | 3 +- .../openrewrite/yaml/ChangePropertyValue.java | 4 +- .../org/openrewrite/yaml/JsonPathMatcher.java | 12 +- .../java/org/openrewrite/yaml/MergeYaml.java | 3 +- .../yaml/format/AutoFormatVisitor.java | 6 +- .../yaml/format/IndentsVisitor.java | 12 +- .../format/MinimumViableSpacingVisitor.java | 6 +- .../yaml/format/NormalizeFormatVisitor.java | 6 +- .../format/NormalizeLineBreaksVisitor.java | 6 +- .../java/org/openrewrite/yaml/tree/Yaml.java | 3 +- 181 files changed, 506 insertions(+), 980 deletions(-) diff --git a/rewrite-core/src/main/java/org/openrewrite/Cursor.java b/rewrite-core/src/main/java/org/openrewrite/Cursor.java index 4a110e14079..6dbfb6bec7c 100644 --- a/rewrite-core/src/main/java/org/openrewrite/Cursor.java +++ b/rewrite-core/src/main/java/org/openrewrite/Cursor.java @@ -160,8 +160,7 @@ public Object next() { } } - @Nullable - public T firstEnclosing(Class tClass) { + public @Nullable T firstEnclosing(Class tClass) { CursorIterator iter = new CursorIterator(this); while (iter.hasNext()) { Object value = iter.next(); @@ -214,8 +213,7 @@ public Cursor dropParentWhile(Predicate valuePredicate) { return cursor; } - @Nullable - public Cursor getParent(int levels) { + public @Nullable Cursor getParent(int levels) { Cursor cursor = this; for (int i = 0; i < levels && cursor != null; i++) { cursor = cursor.parent; @@ -223,8 +221,7 @@ public Cursor getParent(int levels) { return cursor; } - @Nullable - public Cursor getParent() { + public @Nullable Cursor getParent() { return getParent(1); } @@ -292,8 +289,7 @@ public T computeMessageIfAbsent(String key, Function ma * @param The expected value of the message. * @return The closest message matching the provided key in the cursor stack, or null if none. */ - @Nullable - public T getNearestMessage(String key) { + public @Nullable T getNearestMessage(String key) { @SuppressWarnings("unchecked") T t = messages == null ? null : (T) messages.get(key); return t == null && parent != null ? parent.getNearestMessage(key) : t; } @@ -316,8 +312,7 @@ public T getNearestMessage(String key, T defaultValue) { * @param The expected value of the message. * @return The closest message matching the provided key in the cursor stack, or null if none. */ - @Nullable - public T pollNearestMessage(String key) { + public @Nullable T pollNearestMessage(String key) { @SuppressWarnings("unchecked") T t = messages == null ? null : (T) messages.remove(key); return t == null && parent != null ? parent.pollNearestMessage(key) : t; } @@ -329,8 +324,7 @@ public T pollNearestMessage(String key) { * @param The expected value of the message. * @return The message matching the provided key, or null if none. */ - @Nullable - public T getMessage(String key) { + public @Nullable T getMessage(String key) { //noinspection unchecked return messages == null ? null : (T) messages.get(key); } @@ -347,8 +341,7 @@ public T getMessage(String key, T defaultValue) { * @param The expected value of the message. * @return The message matching the provided key, or null if none. */ - @Nullable - public T pollMessage(String key) { + public @Nullable T pollMessage(String key) { //noinspection unchecked return messages == null ? null : (T) messages.remove(key); } diff --git a/rewrite-core/src/main/java/org/openrewrite/DeleteSourceFiles.java b/rewrite-core/src/main/java/org/openrewrite/DeleteSourceFiles.java index 10ce9d27018..a836522ef6e 100644 --- a/rewrite-core/src/main/java/org/openrewrite/DeleteSourceFiles.java +++ b/rewrite-core/src/main/java/org/openrewrite/DeleteSourceFiles.java @@ -44,9 +44,9 @@ public String getDescription() { @Override public TreeVisitor getVisitor() { return new TreeVisitor() { - @Nullable + @Override - public Tree visit(@Nullable Tree tree, ExecutionContext ctx) { + public @Nullable Tree visit(@Nullable Tree tree, ExecutionContext ctx) { if (tree instanceof SourceFile) { SourceFile sourceFile = (SourceFile) tree; Path sourcePath = sourceFile.getSourcePath(); diff --git a/rewrite-core/src/main/java/org/openrewrite/ExecutionContext.java b/rewrite-core/src/main/java/org/openrewrite/ExecutionContext.java index 284b9ae6efd..c3823e4acb1 100644 --- a/rewrite-core/src/main/java/org/openrewrite/ExecutionContext.java +++ b/rewrite-core/src/main/java/org/openrewrite/ExecutionContext.java @@ -51,7 +51,7 @@ default Set getObservers() { void putMessage(String key, @Nullable Object value); - @Nullable T getMessage(String key); + @Nullable T getMessage(String key); default T computeMessage(String key, V value, Supplier defaultValue, BiFunction remappingFunction) { T oldMessage = getMessage(key); @@ -83,7 +83,7 @@ default T getMessage(String key, @Nullable T defaultValue) { return t == null ? defaultValue : t; } - @Nullable T pollMessage(String key); + @Nullable T pollMessage(String key); @SuppressWarnings("unused") default T pollMessage(String key, T defaultValue) { diff --git a/rewrite-core/src/main/java/org/openrewrite/FileAttributes.java b/rewrite-core/src/main/java/org/openrewrite/FileAttributes.java index cc0b7854b38..cfa5fd09de8 100644 --- a/rewrite-core/src/main/java/org/openrewrite/FileAttributes.java +++ b/rewrite-core/src/main/java/org/openrewrite/FileAttributes.java @@ -46,8 +46,7 @@ public class FileAttributes { long size; - @Nullable - public static FileAttributes fromPath(Path path) { + public static @Nullable FileAttributes fromPath(Path path) { if (Files.exists(path)) { try { BasicFileAttributes basicFileAttributes = Files.readAttributes(path, BasicFileAttributes.class); diff --git a/rewrite-core/src/main/java/org/openrewrite/FindSourceFiles.java b/rewrite-core/src/main/java/org/openrewrite/FindSourceFiles.java index 82a040bc9d8..74faa8e09f8 100644 --- a/rewrite-core/src/main/java/org/openrewrite/FindSourceFiles.java +++ b/rewrite-core/src/main/java/org/openrewrite/FindSourceFiles.java @@ -50,9 +50,9 @@ public String getDescription() { @Override public TreeVisitor getVisitor() { return new TreeVisitor() { - @Nullable + @Override - public Tree visit(@Nullable Tree tree, ExecutionContext ctx) { + public @Nullable Tree visit(@Nullable Tree tree, ExecutionContext ctx) { if (tree instanceof SourceFile) { SourceFile sourceFile = (SourceFile) tree; Path sourcePath = sourceFile.getSourcePath(); diff --git a/rewrite-core/src/main/java/org/openrewrite/InMemoryExecutionContext.java b/rewrite-core/src/main/java/org/openrewrite/InMemoryExecutionContext.java index 49efd7381ff..edf5a76d60c 100644 --- a/rewrite-core/src/main/java/org/openrewrite/InMemoryExecutionContext.java +++ b/rewrite-core/src/main/java/org/openrewrite/InMemoryExecutionContext.java @@ -60,15 +60,13 @@ public void putMessage(String key, @Nullable Object value) { } @Override - @Nullable - public T getMessage(String key) { + public @Nullable T getMessage(String key) { //noinspection unchecked return (T) messages.get(key); } @Override - @Nullable - public T pollMessage(String key) { + public @Nullable T pollMessage(String key) { //noinspection unchecked return (T) messages.remove(key); } diff --git a/rewrite-core/src/main/java/org/openrewrite/Recipe.java b/rewrite-core/src/main/java/org/openrewrite/Recipe.java index d1993685dd1..19832599c33 100644 --- a/rewrite-core/src/main/java/org/openrewrite/Recipe.java +++ b/rewrite-core/src/main/java/org/openrewrite/Recipe.java @@ -198,8 +198,7 @@ public Set getTags() { /** * @return An estimated effort were a developer to fix manually instead of using this recipe. */ - @Nullable - public Duration getEstimatedEffortPerOccurrence() { + public @Nullable Duration getEstimatedEffortPerOccurrence() { return Duration.ofMinutes(5); } diff --git a/rewrite-core/src/main/java/org/openrewrite/RecipeRun.java b/rewrite-core/src/main/java/org/openrewrite/RecipeRun.java index 7a43ffe2881..675a925fcc8 100644 --- a/rewrite-core/src/main/java/org/openrewrite/RecipeRun.java +++ b/rewrite-core/src/main/java/org/openrewrite/RecipeRun.java @@ -42,8 +42,7 @@ public class RecipeRun { @With Map, List> dataTables; - @Nullable - public DataTable getDataTable(String name) { + public @Nullable DataTable getDataTable(String name) { for (DataTable dataTable : dataTables.keySet()) { if (dataTable.getName().equals(name)) { return dataTable; @@ -52,8 +51,7 @@ public DataTable getDataTable(String name) { return null; } - @Nullable - public List getDataTableRows(String name) { + public @Nullable List getDataTableRows(String name) { for (Map.Entry, List> dataTableAndRows : dataTables.entrySet()) { if (dataTableAndRows.getKey().getName().equals(name)) { //noinspection unchecked diff --git a/rewrite-core/src/main/java/org/openrewrite/RenameFile.java b/rewrite-core/src/main/java/org/openrewrite/RenameFile.java index acb84e9f55c..4669895faed 100644 --- a/rewrite-core/src/main/java/org/openrewrite/RenameFile.java +++ b/rewrite-core/src/main/java/org/openrewrite/RenameFile.java @@ -48,9 +48,9 @@ public String getDescription() { @Override public TreeVisitor getVisitor() { return new TreeVisitor() { - @Nullable + @Override - public Tree visit(@Nullable Tree tree, ExecutionContext ctx) { + public @Nullable Tree visit(@Nullable Tree tree, ExecutionContext ctx) { if (tree instanceof SourceFile) { SourceFile sourceFile = (SourceFile) tree; Path sourcePath = sourceFile.getSourcePath(); diff --git a/rewrite-core/src/main/java/org/openrewrite/Result.java b/rewrite-core/src/main/java/org/openrewrite/Result.java index d868280b954..319b0c782c5 100755 --- a/rewrite-core/src/main/java/org/openrewrite/Result.java +++ b/rewrite-core/src/main/java/org/openrewrite/Result.java @@ -230,8 +230,7 @@ public String diff(@Nullable Path relativeTo, @Nullable PrintOutputCapture.Marke } } - @Nullable - public static String diff(String before, String after, Path path) { + public static @Nullable String diff(String before, String after, Path path) { String diff = null; try (InMemoryDiffEntry diffEntry = new InMemoryDiffEntry( path, diff --git a/rewrite-core/src/main/java/org/openrewrite/SetFilePermissions.java b/rewrite-core/src/main/java/org/openrewrite/SetFilePermissions.java index c302deadde5..3a45862dd66 100644 --- a/rewrite-core/src/main/java/org/openrewrite/SetFilePermissions.java +++ b/rewrite-core/src/main/java/org/openrewrite/SetFilePermissions.java @@ -55,9 +55,9 @@ public String getDescription() { @Override public TreeVisitor getVisitor() { return new TreeVisitor() { - @Nullable + @Override - public Tree visit(@Nullable Tree tree, ExecutionContext ctx) { + public @Nullable Tree visit(@Nullable Tree tree, ExecutionContext ctx) { if (tree instanceof SourceFile) { SourceFile sourceFile = (SourceFile) tree; Path sourcePath = sourceFile.getSourcePath(); diff --git a/rewrite-core/src/main/java/org/openrewrite/SourceFile.java b/rewrite-core/src/main/java/org/openrewrite/SourceFile.java index 038052eb8ff..f367b58db6f 100644 --- a/rewrite-core/src/main/java/org/openrewrite/SourceFile.java +++ b/rewrite-core/src/main/java/org/openrewrite/SourceFile.java @@ -70,8 +70,7 @@ default boolean printEqualsInput(Parser.Input input, ExecutionContext ctx) { T withFileAttributes(@Nullable FileAttributes fileAttributes); - @Nullable - default S getStyle(Class style) { + default @Nullable S getStyle(Class style) { return NamedStyles.merge(style, getMarkers().findAll(NamedStyles.class)); } diff --git a/rewrite-core/src/main/java/org/openrewrite/Tree.java b/rewrite-core/src/main/java/org/openrewrite/Tree.java index 2015ae8c4b7..ab5a22b7b3f 100644 --- a/rewrite-core/src/main/java/org/openrewrite/Tree.java +++ b/rewrite-core/src/main/java/org/openrewrite/Tree.java @@ -65,8 +65,7 @@ static UUID randomId() { * @param

visit context type * @return visitor result */ - @Nullable - default R accept(TreeVisitor v, P p) { + default @Nullable R accept(TreeVisitor v, P p) { return v.defaultValue(this, p); } @@ -123,8 +122,7 @@ default T2 cast() { return (T2) this; } - @Nullable - default T2 safeCast() { + default @Nullable T2 safeCast() { try { return cast(); } catch (ClassCastException ignored) { diff --git a/rewrite-core/src/main/java/org/openrewrite/TreeVisitor.java b/rewrite-core/src/main/java/org/openrewrite/TreeVisitor.java index 59c1beb8b9e..5618f45993a 100644 --- a/rewrite-core/src/main/java/org/openrewrite/TreeVisitor.java +++ b/rewrite-core/src/main/java/org/openrewrite/TreeVisitor.java @@ -85,8 +85,7 @@ public void setCursor(@Nullable Cursor cursor) { /** * @return Describes the language type that this visitor applies to, e.g. java, xml, properties. */ - @Nullable - public String getLanguage() { + public @Nullable String getLanguage() { return null; } @@ -135,18 +134,15 @@ public final Cursor updateCursor(T currentValue) { return cursor; } - @Nullable - public T preVisit(T tree, P p) { + public @Nullable T preVisit(T tree, P p) { return defaultValue(tree, p); } - @Nullable - public T postVisit(T tree, P p) { + public @Nullable T postVisit(T tree, P p) { return defaultValue(tree, p); } - @Nullable - public T visit(@Nullable Tree tree, P p, Cursor parent) { + public @Nullable T visit(@Nullable Tree tree, P p, Cursor parent) { this.cursor = parent; return visit(tree, p); } @@ -221,8 +217,7 @@ public P reduce(Tree tree, P p, Cursor parent) { return p; } - @Nullable - public T visit(@Nullable Tree tree, P p) { + public @Nullable T visit(@Nullable Tree tree, P p) { if (tree == null) { return defaultValue(null, p); } @@ -305,8 +300,7 @@ public void visit(@Nullable List nodes, P p) { } @SuppressWarnings("unused") - @Nullable - public T defaultValue(@Nullable Tree tree, P p) { + public @Nullable T defaultValue(@Nullable Tree tree, P p) { //noinspection unchecked return (T) tree; } @@ -318,8 +312,7 @@ protected final T2 visitAndCast(T2 t, P p, BiFunction T2 visitAndCast(@Nullable Tree tree, P p) { + protected final @Nullable T2 visitAndCast(@Nullable Tree tree, P p) { //noinspection unchecked return (T2) visit(tree, p); } diff --git a/rewrite-core/src/main/java/org/openrewrite/Validated.java b/rewrite-core/src/main/java/org/openrewrite/Validated.java index ab420cff96f..15394b13b19 100644 --- a/rewrite-core/src/main/java/org/openrewrite/Validated.java +++ b/rewrite-core/src/main/java/org/openrewrite/Validated.java @@ -230,8 +230,7 @@ public String getProperty() { } @Override - @Nullable - public T getValue() { + public @Nullable T getValue() { return value; } @@ -285,13 +284,11 @@ public String getProperty() { return property; } - @Nullable - public Object getInvalidValue() { + public @Nullable Object getInvalidValue() { return value; } - @Nullable - public Throwable getException() { + public @Nullable Throwable getException() { return exception; } diff --git a/rewrite-core/src/main/java/org/openrewrite/config/CategoryTree.java b/rewrite-core/src/main/java/org/openrewrite/config/CategoryTree.java index c591e9345f4..d8e0aa7c5e9 100644 --- a/rewrite-core/src/main/java/org/openrewrite/config/CategoryTree.java +++ b/rewrite-core/src/main/java/org/openrewrite/config/CategoryTree.java @@ -164,8 +164,7 @@ public Integer getRecipeCount() { return sum; } - @Nullable - public CategoryTree getCategory(String subcategory) { + public @Nullable CategoryTree getCategory(String subcategory) { String packageName = getDescriptor().getPackageName(); synchronized (lock) { String[] split = subcategory.split("\\.", 2); @@ -188,8 +187,7 @@ public CategoryTree getCategory(String subcategory) { return null; } - @Nullable - public CategoryTree getCategory(String... subcategories) { + public @Nullable CategoryTree getCategory(String... subcategories) { CategoryTree acc = this; for (String subcategory : subcategories) { if (acc == null) { @@ -219,8 +217,7 @@ public CategoryTree getCategoryOrThrow(String... subcategories) { return acc; } - @Nullable - public RecipeDescriptor getRecipe(String id) { + public @Nullable RecipeDescriptor getRecipe(String id) { if (id.contains(".")) { String[] split = id.split("\\.", 2); CategoryTree subcategory = getCategory(split[0]); @@ -236,8 +233,7 @@ public RecipeDescriptor getRecipe(String id) { return null; } - @Nullable - public G getRecipeGroup(String id) { + public @Nullable G getRecipeGroup(String id) { if (id.contains(".")) { String[] split = id.split("\\.", 2); CategoryTree subcategory = getCategory(split[0]); @@ -414,8 +410,7 @@ public Collection> getCategories(boolean omitCategoryRoots, } } - @Nullable - private CategoryTree maybeAddCore(CategoryDescriptor parent) { + private @Nullable CategoryTree maybeAddCore(CategoryDescriptor parent) { if (recipesByGroup.isEmpty()) { return null; } diff --git a/rewrite-core/src/main/java/org/openrewrite/config/YamlResourceLoader.java b/rewrite-core/src/main/java/org/openrewrite/config/YamlResourceLoader.java index f2b5a1cb0dc..5813ae9f3d3 100644 --- a/rewrite-core/src/main/java/org/openrewrite/config/YamlResourceLoader.java +++ b/rewrite-core/src/main/java/org/openrewrite/config/YamlResourceLoader.java @@ -87,8 +87,7 @@ private enum ResourceType { this.spec = spec; } - @Nullable - public static ResourceType fromSpec(@Nullable String spec) { + public static @Nullable ResourceType fromSpec(@Nullable String spec) { return Arrays.stream(values()) .filter(type -> type.getSpec().equals(spec)) .findAny() diff --git a/rewrite-core/src/main/java/org/openrewrite/internal/InMemoryLargeSourceSet.java b/rewrite-core/src/main/java/org/openrewrite/internal/InMemoryLargeSourceSet.java index 742f3e3ba09..07dea5eee39 100644 --- a/rewrite-core/src/main/java/org/openrewrite/internal/InMemoryLargeSourceSet.java +++ b/rewrite-core/src/main/java/org/openrewrite/internal/InMemoryLargeSourceSet.java @@ -128,9 +128,8 @@ public Changeset getChangeset() { return new InMemoryChangeset(changes); } - @Nullable @Override - public SourceFile getBefore(Path sourcePath) { + public @Nullable SourceFile getBefore(Path sourcePath) { List sourceFiles = getInitialState().ls; for (SourceFile s : sourceFiles) { if (s.getSourcePath().equals(sourcePath)) { diff --git a/rewrite-core/src/main/java/org/openrewrite/internal/ListUtils.java b/rewrite-core/src/main/java/org/openrewrite/internal/ListUtils.java index 9e9f9543816..e8a47c4d6b6 100644 --- a/rewrite-core/src/main/java/org/openrewrite/internal/ListUtils.java +++ b/rewrite-core/src/main/java/org/openrewrite/internal/ListUtils.java @@ -319,8 +319,7 @@ public static List insertAll(@Nullable List ls, int index, @Nullable L return newLs; } - @Nullable - public static List nullIfEmpty(@Nullable List ls) { + public static @Nullable List nullIfEmpty(@Nullable List ls) { return ls == null || ls.isEmpty() ? null : ls; } diff --git a/rewrite-core/src/main/java/org/openrewrite/internal/RecipeIntrospectionUtils.java b/rewrite-core/src/main/java/org/openrewrite/internal/RecipeIntrospectionUtils.java index a3cc7e156d3..f7b5e5023fc 100644 --- a/rewrite-core/src/main/java/org/openrewrite/internal/RecipeIntrospectionUtils.java +++ b/rewrite-core/src/main/java/org/openrewrite/internal/RecipeIntrospectionUtils.java @@ -87,8 +87,7 @@ public static Constructor getPrimaryConstructor(Class recipeClass) { } } - @Nullable - public static Constructor getZeroArgsConstructor(Class recipeClass) { + public static @Nullable Constructor getZeroArgsConstructor(Class recipeClass) { Constructor[] constructors = recipeClass.getConstructors(); for (Constructor constructor : constructors) { if (constructor.getParameterCount() == 0) { diff --git a/rewrite-core/src/main/java/org/openrewrite/internal/ReflectionUtils.java b/rewrite-core/src/main/java/org/openrewrite/internal/ReflectionUtils.java index 420c86ec539..8056e60ff88 100644 --- a/rewrite-core/src/main/java/org/openrewrite/internal/ReflectionUtils.java +++ b/rewrite-core/src/main/java/org/openrewrite/internal/ReflectionUtils.java @@ -38,8 +38,7 @@ public class ReflectionUtils { */ private static final Map, Method[]> declaredMethodsCache = new ConcurrentHashMap<>(256); - @Nullable - public static Method findMethod(Class clazz, String name, Class... paramTypes) { + public static @Nullable Method findMethod(Class clazz, String name, Class... paramTypes) { Class searchType = clazz; while (searchType != null) { Method[] methods = (searchType.isInterface() ? searchType.getMethods() : @@ -80,8 +79,7 @@ private static Method[] getDeclaredMethods(Class clazz) { return result; } - @Nullable - private static List findConcreteMethodsOnInterfaces(Class clazz) { + private static @Nullable List findConcreteMethodsOnInterfaces(Class clazz) { List result = null; for (Class ifc : clazz.getInterfaces()) { for (Method ifcMethod : ifc.getMethods()) { diff --git a/rewrite-core/src/main/java/org/openrewrite/marker/GitProvenance.java b/rewrite-core/src/main/java/org/openrewrite/marker/GitProvenance.java index 6c933807068..345ed68ecef 100644 --- a/rewrite-core/src/main/java/org/openrewrite/marker/GitProvenance.java +++ b/rewrite-core/src/main/java/org/openrewrite/marker/GitProvenance.java @@ -74,8 +74,7 @@ public class GitProvenance implements Marker { * @param baseUrl the portion of the URL which precedes the organization * @return the portion of the git origin URL which corresponds to the organization the git repository is organized under */ - @Nullable - public String getOrganizationName(String baseUrl) { + public @Nullable String getOrganizationName(String baseUrl) { if (origin == null) { return null; } @@ -102,8 +101,7 @@ public String getOrganizationName(String baseUrl) { * which accepts a "baseUrl" parameter should be used instead */ @Deprecated - @Nullable - public String getOrganizationName() { + public @Nullable String getOrganizationName() { if (origin == null) { return null; } @@ -118,8 +116,7 @@ public String getOrganizationName() { } } - @Nullable - public String getRepositoryName() { + public @Nullable String getRepositoryName() { if (origin == null) { return null; } @@ -137,9 +134,8 @@ public String getRepositoryName() { * @return A marker containing git provenance information. * @deprecated Use {@link #fromProjectDirectory(Path, BuildEnvironment) instead}. */ - @Nullable @Deprecated - public static GitProvenance fromProjectDirectory(Path projectDir) { + public static @Nullable GitProvenance fromProjectDirectory(Path projectDir) { return fromProjectDirectory(projectDir, null); } @@ -149,8 +145,7 @@ public static GitProvenance fromProjectDirectory(Path projectDir) { * determined from a {@link BuildEnvironment} marker if possible. * @return A marker containing git provenance information. */ - @Nullable - public static GitProvenance fromProjectDirectory(Path projectDir, @Nullable BuildEnvironment environment) { + public static @Nullable GitProvenance fromProjectDirectory(Path projectDir, @Nullable BuildEnvironment environment) { if (environment != null) { if (environment instanceof JenkinsBuildEnvironment) { JenkinsBuildEnvironment jenkinsBuildEnvironment = (JenkinsBuildEnvironment) environment; @@ -191,8 +186,7 @@ private static void printRequireGitDirOrWorkTreeException(Exception e) { } } - @Nullable - private static GitProvenance fromGitConfig(Path projectDir) { + private static @Nullable GitProvenance fromGitConfig(Path projectDir) { String branch = null; try (Repository repository = new RepositoryBuilder().findGitDir(projectDir.toFile()).build()) { String changeset = getChangeset(repository); @@ -217,8 +211,7 @@ private static GitProvenance fromGitConfig(Repository repository, @Nullable Stri getCommitters(repository)); } - @Nullable - static String resolveBranchFromGitConfig(Repository repository) { + static @Nullable String resolveBranchFromGitConfig(Repository repository) { String branch; try { try (Git git = Git.open(repository.getDirectory())) { @@ -253,8 +246,7 @@ static String resolveBranchFromGitConfig(Repository repository) { } - @Nullable - private static String localBranchName(Repository repository, @Nullable String remoteBranch) throws IOException, GitAPIException { + private static @Nullable String localBranchName(Repository repository, @Nullable String remoteBranch) throws IOException, GitAPIException { if (remoteBranch == null) { return null; } else if (remoteBranch.startsWith("remotes/")) { @@ -276,8 +268,7 @@ private static String localBranchName(Repository repository, @Nullable String re return branch; } - @Nullable - private static String getOrigin(Repository repository) { + private static @Nullable String getOrigin(Repository repository) { Config storedConfig = repository.getConfig(); String url = storedConfig.getString("remote", "origin", "url"); if (url == null) { @@ -289,8 +280,7 @@ private static String getOrigin(Repository repository) { return url; } - @Nullable - private static AutoCRLF getAutocrlf(Repository repository) { + private static @Nullable AutoCRLF getAutocrlf(Repository repository) { WorkingTreeOptions opt = repository.getConfig().get(WorkingTreeOptions.KEY); switch (opt.getAutoCRLF()) { case FALSE: @@ -304,8 +294,7 @@ private static AutoCRLF getAutocrlf(Repository repository) { } } - @Nullable - private static EOL getEOF(Repository repository) { + private static @Nullable EOL getEOF(Repository repository) { WorkingTreeOptions opt = repository.getConfig().get(WorkingTreeOptions.KEY); switch (opt.getEOL()) { case CRLF: @@ -345,8 +334,7 @@ private static List getCommitters(Repository repository) { } } - @Nullable - private static String getChangeset(Repository repository) throws IOException { + private static @Nullable String getChangeset(Repository repository) throws IOException { ObjectId head = repository.resolve(Constants.HEAD); if (head == null) { return null; diff --git a/rewrite-core/src/main/java/org/openrewrite/marker/Markup.java b/rewrite-core/src/main/java/org/openrewrite/marker/Markup.java index b05cd7fbd9a..2c3f8f002a7 100644 --- a/rewrite-core/src/main/java/org/openrewrite/marker/Markup.java +++ b/rewrite-core/src/main/java/org/openrewrite/marker/Markup.java @@ -156,9 +156,8 @@ public String getMessage() { return message; } - @Nullable @Override - public String getDetail() { + public @Nullable String getDetail() { return detail; } } @@ -181,9 +180,8 @@ public String getMessage() { return message; } - @Nullable @Override - public String getDetail() { + public @Nullable String getDetail() { return detail; } } diff --git a/rewrite-core/src/main/java/org/openrewrite/marker/OperatingSystemProvenance.java b/rewrite-core/src/main/java/org/openrewrite/marker/OperatingSystemProvenance.java index a4fbf81ef99..1dd205b9e30 100644 --- a/rewrite-core/src/main/java/org/openrewrite/marker/OperatingSystemProvenance.java +++ b/rewrite-core/src/main/java/org/openrewrite/marker/OperatingSystemProvenance.java @@ -231,8 +231,7 @@ public enum EOL { /** * Locates the given executable in the system path. Returns null if not found. */ - @Nullable - public File findInPath(String name) { + public @Nullable File findInPath(String name) { String exeName = getExecutableName(name); if (exeName.contains(File.separator)) { File candidate = new File(exeName); diff --git a/rewrite-core/src/main/java/org/openrewrite/marker/ci/BuildEnvironment.java b/rewrite-core/src/main/java/org/openrewrite/marker/ci/BuildEnvironment.java index 3e2269301f3..4fdf01406f2 100644 --- a/rewrite-core/src/main/java/org/openrewrite/marker/ci/BuildEnvironment.java +++ b/rewrite-core/src/main/java/org/openrewrite/marker/ci/BuildEnvironment.java @@ -22,8 +22,8 @@ import java.util.function.UnaryOperator; public interface BuildEnvironment extends Marker { - @Nullable - static BuildEnvironment build(UnaryOperator environment) { + + static @Nullable BuildEnvironment build(UnaryOperator environment) { if (environment.apply("BITBUCKET_COMMIT") != null) { return BitbucketBuildEnvironment.build(environment); } diff --git a/rewrite-core/src/main/java/org/openrewrite/remote/LocalRemoteArtifactCache.java b/rewrite-core/src/main/java/org/openrewrite/remote/LocalRemoteArtifactCache.java index 543cd7f07e6..88804f09832 100644 --- a/rewrite-core/src/main/java/org/openrewrite/remote/LocalRemoteArtifactCache.java +++ b/rewrite-core/src/main/java/org/openrewrite/remote/LocalRemoteArtifactCache.java @@ -39,15 +39,13 @@ public LocalRemoteArtifactCache(Path cacheDir) { } @Override - @Nullable - public Path get(URI uri) { + public @Nullable Path get(URI uri) { Path resolved = cacheDir.resolve(hashUri(uri)); return Files.exists(resolved) ? resolved : null; } @Override - @Nullable - public Path put(URI uri, InputStream artifactInputStream, Consumer onError) { + public @Nullable Path put(URI uri, InputStream artifactInputStream, Consumer onError) { try { Path artifact = cacheDir.resolve(UUID.randomUUID() + ".tmp"); try (InputStream is = artifactInputStream) { diff --git a/rewrite-core/src/main/java/org/openrewrite/remote/Remote.java b/rewrite-core/src/main/java/org/openrewrite/remote/Remote.java index 9febfb17582..53b7a496ad1 100644 --- a/rewrite-core/src/main/java/org/openrewrite/remote/Remote.java +++ b/rewrite-core/src/main/java/org/openrewrite/remote/Remote.java @@ -55,9 +55,8 @@ public interface Remote extends SourceFile { R withDescription(String description); - @Nullable @Override - default Checksum getChecksum() { + default @Nullable Checksum getChecksum() { return null; } diff --git a/rewrite-core/src/main/java/org/openrewrite/remote/RemoteArtifactCache.java b/rewrite-core/src/main/java/org/openrewrite/remote/RemoteArtifactCache.java index c25affdd867..5c9ee55dfd3 100644 --- a/rewrite-core/src/main/java/org/openrewrite/remote/RemoteArtifactCache.java +++ b/rewrite-core/src/main/java/org/openrewrite/remote/RemoteArtifactCache.java @@ -31,8 +31,7 @@ public interface RemoteArtifactCache { @Nullable Path put(URI uri, InputStream is, Consumer onError); - @Nullable - default Path compute(URI uri, Callable<@Nullable InputStream> artifactStream, Consumer onError) { + default @Nullable Path compute(URI uri, Callable<@Nullable InputStream> artifactStream, Consumer onError) { Path artifact = get(uri); if (artifact == null) { try { diff --git a/rewrite-core/src/main/java/org/openrewrite/scheduling/RecipeRunCycle.java b/rewrite-core/src/main/java/org/openrewrite/scheduling/RecipeRunCycle.java index 840164fe861..d08b85bb17d 100644 --- a/rewrite-core/src/main/java/org/openrewrite/scheduling/RecipeRunCycle.java +++ b/rewrite-core/src/main/java/org/openrewrite/scheduling/RecipeRunCycle.java @@ -237,8 +237,7 @@ private void recordSourceFileResult(@Nullable String beforePath, @Nullable Strin recordSourceFileResult(beforePath, afterPath, recipeStack.subList(0, recipeStack.size() - 1), effortSeconds, ctx); } - @Nullable - private SourceFile handleError(Recipe recipe, SourceFile sourceFile, @Nullable SourceFile after, + private @Nullable SourceFile handleError(Recipe recipe, SourceFile sourceFile, @Nullable SourceFile after, Throwable t) { ctx.getOnError().accept(t); diff --git a/rewrite-core/src/main/java/org/openrewrite/scheduling/WatchableExecutionContext.java b/rewrite-core/src/main/java/org/openrewrite/scheduling/WatchableExecutionContext.java index aba03bed03c..dc798d4420a 100644 --- a/rewrite-core/src/main/java/org/openrewrite/scheduling/WatchableExecutionContext.java +++ b/rewrite-core/src/main/java/org/openrewrite/scheduling/WatchableExecutionContext.java @@ -45,15 +45,13 @@ public void putCycle(RecipeRunCycle cycle) { delegate.putMessage(CURRENT_CYCLE, cycle); } - @Nullable @Override - public T getMessage(String key) { + public @Nullable T getMessage(String key) { return delegate.getMessage(key); } - @Nullable @Override - public T pollMessage(String key) { + public @Nullable T pollMessage(String key) { return delegate.pollMessage(key); } diff --git a/rewrite-core/src/main/java/org/openrewrite/semver/CaretRange.java b/rewrite-core/src/main/java/org/openrewrite/semver/CaretRange.java index 83a2e09791a..58cdd690477 100644 --- a/rewrite-core/src/main/java/org/openrewrite/semver/CaretRange.java +++ b/rewrite-core/src/main/java/org/openrewrite/semver/CaretRange.java @@ -93,8 +93,7 @@ public static Validated build(String pattern, @Nullable String metad return Validated.valid("caretRange", new CaretRange(lower, upper, metadataPattern)); } - @Nullable - private static String normalizeWildcard(@Nullable String part) { + private static @Nullable String normalizeWildcard(@Nullable String part) { return "*".equals(part) || "x".equals(part) || "X".equals(part) ? null : part; } } diff --git a/rewrite-core/src/main/java/org/openrewrite/style/NamedStyles.java b/rewrite-core/src/main/java/org/openrewrite/style/NamedStyles.java index 2bc13939ab5..8ac29fadbe6 100644 --- a/rewrite-core/src/main/java/org/openrewrite/style/NamedStyles.java +++ b/rewrite-core/src/main/java/org/openrewrite/style/NamedStyles.java @@ -54,8 +54,7 @@ public class NamedStyles implements Marker { Collection