Skip to content

Commit 4afa19b

Browse files
Replace getDisplayName() and getDescription() methods with fields
Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.java.recipes.UseDisplayNameAndDescriptionFields?organizationId=QUxML01vZGVybmUvTW9kZXJuZSArIE9wZW5SZXdyaXRl Co-authored-by: Moderne <team@moderne.io>
1 parent f51717c commit 4afa19b

27 files changed

+54
-216
lines changed

src/main/java/org/openrewrite/staticanalysis/AddSerialVersionUidToSerializable.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,11 @@ public class AddSerialVersionUidToSerializable extends Recipe {
4747
@Nullable
4848
String uid;
4949

50-
@Override
51-
public String getDisplayName() {
52-
return "Add `serialVersionUID` to a `Serializable` class when missing";
53-
}
50+
String displayName = "Add `serialVersionUID` to a `Serializable` class when missing";
5451

55-
@Override
56-
public String getDescription() {
57-
return "A `serialVersionUID` field is strongly recommended in all `Serializable` classes. If this is not " +
52+
String description = "A `serialVersionUID` field is strongly recommended in all `Serializable` classes. If this is not " +
5853
"defined on a `Serializable` class, the compiler will generate this value. If a change is later made " +
5954
"to the class, the generated value will change and attempts to deserialize the class will fail.";
60-
}
6155

6256
@Override
6357
public Set<String> getTags() {

src/main/java/org/openrewrite/staticanalysis/AnnotateNullableMethods.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,15 @@ public class AnnotateNullableMethods extends Recipe {
4646

4747
private static final String DEFAULT_NULLABLE_ANN_CLASS = "org.jspecify.annotations.Nullable";
4848

49-
@Override
50-
public String getDisplayName() {
51-
return "Annotate methods which may return `null` with `@Nullable`";
52-
}
49+
String displayName = "Annotate methods which may return `null` with `@Nullable`";
5350

54-
@Override
55-
public String getDescription() {
56-
return "Add `@Nullable` to non-private methods that may return `null`. " +
51+
String description = "Add `@Nullable` to non-private methods that may return `null`. " +
5752
"By default `org.jspecify.annotations.Nullable` is used, but through the `nullableAnnotationClass` option a custom annotation can be provided. " +
5853
"When providing a custom `nullableAnnotationClass` that annotation should be meta annotated with `@Target(TYPE_USE)`. " +
5954
"This recipe scans for methods that do not already have a `@Nullable` annotation and checks their return " +
6055
"statements for potential null values. It also identifies known methods from standard libraries that may " +
6156
"return null, such as methods from `Map`, `Queue`, `Deque`, `NavigableSet`, and `Spliterator`. " +
6257
"The return of streams, or lambdas are not taken into account.";
63-
}
6458

6559
@Override
6660
public Validated<Object> validate() {

src/main/java/org/openrewrite/staticanalysis/AnnotateNullableParameters.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,13 @@ public class AnnotateNullableParameters extends Recipe {
5858
@Nullable
5959
List<String> additionalNullCheckingMethods;
6060

61-
@Override
62-
public String getDisplayName() {
63-
return "Annotate null-checked method parameters with `@Nullable`";
64-
}
61+
String displayName = "Annotate null-checked method parameters with `@Nullable`";
6562

66-
@Override
67-
public String getDescription() {
68-
return "Add `@Nullable` to parameters of public methods that are explicitly checked for `null`. " +
63+
String description = "Add `@Nullable` to parameters of public methods that are explicitly checked for `null`. " +
6964
"By default `org.jspecify.annotations.Nullable` is used, but through the `nullableAnnotationClass` option a custom annotation can be provided. " +
7065
"When providing a custom `nullableAnnotationClass` that annotation should be meta annotated with `@Target(TYPE_USE)`. " +
7166
"This recipe scans for methods that do not already have parameters annotated with `@Nullable` annotation and checks their usages " +
7267
"for potential null checks. Additional null-checking methods can be specified via the `additionalNullCheckingMethods` option.";
73-
}
7468

7569
@Override
7670
public Validated<Object> validate() {

src/main/java/org/openrewrite/staticanalysis/AnnotateRequiredParameters.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,13 @@ public class AnnotateRequiredParameters extends Recipe {
4444
@Nullable
4545
String nonNullAnnotationClass;
4646

47-
@Override
48-
public String getDisplayName() {
49-
return "Annotate required method parameters with `@NonNull`";
50-
}
47+
String displayName = "Annotate required method parameters with `@NonNull`";
5148

52-
@Override
53-
public String getDescription() {
54-
return "Add `@NonNull` to parameters of public methods that are explicitly checked for `null` and throw an exception if null. " +
49+
String description = "Add `@NonNull` to parameters of public methods that are explicitly checked for `null` and throw an exception if null. " +
5550
"By default `org.jspecify.annotations.NonNull` is used, but through the `nonNullAnnotationClass` option a custom annotation can be provided. " +
5651
"When providing a custom `nonNullAnnotationClass` that annotation should be meta annotated with `@Target(TYPE_USE)`. " +
5752
"This recipe scans for methods that do not already have parameters annotated with `@NonNull` annotation and checks for " +
5853
"null validation patterns that throw exceptions, such as `if (param == null) throw new IllegalArgumentException()`.";
59-
}
6054

6155
@Override
6256
public Validated<Object> validate() {

src/main/java/org/openrewrite/staticanalysis/DeclarationSiteTypeVariance.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,10 @@ public class DeclarationSiteTypeVariance extends Recipe {
5555
@Nullable
5656
Boolean excludeFinalClasses;
5757

58-
@Override
59-
public String getDisplayName() {
60-
return "Properly use declaration-site type variance";
61-
}
58+
String displayName = "Properly use declaration-site type variance";
6259

63-
@Override
64-
public String getDescription() {
65-
return "Currently, Java requires use-site type variance, so if someone has `Function<IN, OUT>` method parameter, it should rather be `Function<? super IN, ? extends OUT>`. " +
60+
String description = "Currently, Java requires use-site type variance, so if someone has `Function<IN, OUT>` method parameter, it should rather be `Function<? super IN, ? extends OUT>`. " +
6661
"Unfortunately, it is not easy to notice that `? super` and `? extends` is missing, so this recipe adds it where that would improve the situation.";
67-
}
6862

6963
@Override
7064
public Validated<Object> validate() {

src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNull.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,11 @@ public class EqualsAvoidsNull extends Recipe {
4747
private static final MethodMatcher EQUALS_IGNORE_CASE = new MethodMatcher(JAVA_LANG_STRING + " equalsIgnoreCase(" + JAVA_LANG_STRING + ")");
4848
private static final MethodMatcher CONTENT_EQUALS = new MethodMatcher(JAVA_LANG_STRING + " contentEquals(java.lang.CharSequence)");
4949

50-
@Override
51-
public String getDisplayName() {
52-
return "Equals avoids null";
53-
}
50+
String displayName = "Equals avoids null";
5451

55-
@Override
56-
public String getDescription() {
57-
return "Checks that any combination of String literals is on the left side of an `equals()` comparison. " +
52+
String description = "Checks that any combination of String literals is on the left side of an `equals()` comparison. " +
5853
"Also checks for String literals assigned to some field (such as `someString.equals(anotherString = \"text\"))`. " +
5954
"And removes redundant null checks in conjunction with equals comparisons.";
60-
}
6155

6256
@Override
6357
public Set<String> getTags() {

src/main/java/org/openrewrite/staticanalysis/ExplicitCharsetOnStringGetBytes.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,10 @@ public class ExplicitCharsetOnStringGetBytes extends Recipe {
3737
@Nullable
3838
String encoding;
3939

40-
@Override
41-
public String getDisplayName() {
42-
return "Set charset encoding explicitly when calling `String#getBytes`";
43-
}
40+
String displayName = "Set charset encoding explicitly when calling `String#getBytes`";
4441

45-
@Override
46-
public String getDescription() {
47-
return "This makes the behavior of the code platform neutral. It will not override any " +
42+
String description = "This makes the behavior of the code platform neutral. It will not override any " +
4843
"existing explicit encodings, even if they don't match the default encoding option.";
49-
}
5044

5145
@Override
5246
public TreeVisitor<?, ExecutionContext> getVisitor() {

src/main/java/org/openrewrite/staticanalysis/InstanceOfPatternMatch.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,10 @@
4747
@Value
4848
public class InstanceOfPatternMatch extends Recipe {
4949

50-
@Override
51-
public String getDisplayName() {
52-
return "Changes code to use Java 17's `instanceof` pattern matching";
53-
}
50+
String displayName = "Changes code to use Java 17's `instanceof` pattern matching";
5451

55-
@Override
56-
public String getDescription() {
57-
return "Adds pattern variables to `instanceof` expressions wherever the same (side effect free) expression is referenced in a corresponding type cast expression within the flow scope of the `instanceof`. " +
52+
String description = "Adds pattern variables to `instanceof` expressions wherever the same (side effect free) expression is referenced in a corresponding type cast expression within the flow scope of the `instanceof`. " +
5853
"Currently, this recipe supports `if` statements and ternary operator expressions.";
59-
}
6054

6155
@Override
6256
public Duration getEstimatedEffortPerOccurrence() {

src/main/java/org/openrewrite/staticanalysis/MaskCreditCardNumbers.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,10 @@
3030
@Value
3131
public class MaskCreditCardNumbers extends Recipe {
3232

33-
@Override
34-
public String getDisplayName() {
35-
return "Mask credit card numbers";
36-
}
33+
String displayName = "Mask credit card numbers";
3734

38-
@Override
39-
public String getDescription() {
40-
return "When encountering string literals which appear to be credit card numbers, " +
35+
String description = "When encountering string literals which appear to be credit card numbers, " +
4136
"mask the last eight digits with the letter 'X'.";
42-
}
4337

4438
private static final Pattern CC_PATTERN = Pattern.compile("([0-9]{4} ?[0-9]{4} ?)([0-9]{4} ?[0-9]{4} ?)");
4539
private static final Pattern DIGIT_PATTERN = Pattern.compile("\\d");

src/main/java/org/openrewrite/staticanalysis/MethodNameCasing.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,11 @@ public class MethodNameCasing extends ScanningRecipe<List<MethodNameCasing.Metho
5151
@Nullable
5252
Boolean renamePublicMethods;
5353

54-
@Override
55-
public String getDisplayName() {
56-
return "Standardize method name casing";
57-
}
54+
String displayName = "Standardize method name casing";
5855

59-
@Override
60-
public String getDescription() {
61-
return "Fixes method names that do not follow standard naming conventions. " +
56+
String description = "Fixes method names that do not follow standard naming conventions. " +
6257
"For example, `String getFoo_bar()` would be adjusted to `String getFooBar()` " +
6358
"and `int DoSomething()` would be adjusted to `int doSomething()`.";
64-
}
6559

6660
@Override
6761
public Set<String> getTags() {

0 commit comments

Comments
 (0)