You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve AnnotateNullableParameters to avoid duplicate annotations and annotation placement issues (#843)
* fix duplicate nullable annotations
fix annotation position
* Replace known nullable annotations list with simple name matching
Instead of maintaining a hardcoded list of 13 nullable annotation FQNs,
detect any annotation whose simple name contains "null" (case-insensitive).
This automatically covers all frameworks and prevents duplication/conflicts.
* Use .reduce for immediate return in hasNullRelatedAnnotation
---------
Co-authored-by: stefanod <stefano.dallapalma@adyen.com>
Co-authored-by: Tim te Beek <tim@moderne.io>
description = "The fully qualified name of the @Nullable annotation. The annotation should be meta annotated with `@Target(TYPE_USE)`. Defaults to `org.jspecify.annotations.Nullable`",
58
+
description = "The fully qualified name of the @Nullable annotation to add. " +
59
+
"Both `@Target(TYPE_USE)` and declaration annotations (e.g. `javax.annotation.CheckForNull`) are supported. " +
60
+
"Defaults to `org.jspecify.annotations.Nullable`.",
46
61
example = "org.jspecify.annotations.Nullable",
47
62
required = false)
48
63
@Nullable
@@ -61,10 +76,11 @@ public class AnnotateNullableParameters extends Recipe {
61
76
StringdisplayName = "Annotate null-checked method parameters with `@Nullable`";
62
77
63
78
Stringdescription = "Add `@Nullable` to parameters of public methods that are explicitly checked for `null`. " +
64
-
"By default `org.jspecify.annotations.Nullable` is used, but through the `nullableAnnotationClass` option a custom annotation can be provided. " +
65
-
"When providing a custom `nullableAnnotationClass` that annotation should be meta annotated with `@Target(TYPE_USE)`. " +
66
-
"This recipe scans for methods that do not already have parameters annotated with `@Nullable` annotation and checks their usages " +
67
-
"for potential null checks. Additional null-checking methods can be specified via the `additionalNullCheckingMethods` option.";
79
+
"By default `org.jspecify.annotations.Nullable` is used, but through the `nullableAnnotationClass` option a custom annotation can be provided. " +
80
+
"Both `@Target(TYPE_USE)` and declaration annotations (e.g. `javax.annotation.CheckForNull`) are supported. " +
81
+
"Parameters that already carry a known nullable annotation are skipped to avoid duplication. " +
82
+
"This recipe scans for methods that do not already have parameters annotated with a nullable annotation and checks their usages " +
83
+
"for potential null checks. Additional null-checking methods can be specified via the `additionalNullCheckingMethods` option.";
68
84
69
85
@Override
70
86
publicValidated<Object> validate() {
@@ -92,7 +108,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration methodDecl
0 commit comments