Skip to content

Commit 718b88c

Browse files
Replace getDisplayName() and getDescription() methods with fields (#6530)
* 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> * Restore `Find.getDescription()` over conflicting option --------- Co-authored-by: Moderne <team@moderne.io>
1 parent 98c728b commit 718b88c

90 files changed

Lines changed: 508 additions & 798 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

rewrite-core/src/main/java/org/openrewrite/FindGitProvenance.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.openrewrite;
1717

18+
import lombok.Getter;
1819
import org.jspecify.annotations.Nullable;
1920
import org.openrewrite.marker.GitProvenance;
2021
import org.openrewrite.table.DistinctGitProvenance;
@@ -33,17 +34,13 @@ public class FindGitProvenance extends ScanningRecipe<Set<GitProvenance>> {
3334

3435
private final DistinctGitProvenance distinct = new DistinctGitProvenance(this);
3536

36-
@Override
37-
public String getDisplayName() {
38-
return "Show Git source control metadata";
39-
}
37+
@Getter
38+
final String displayName = "Show Git source control metadata";
4039

41-
@Override
42-
public String getDescription() {
43-
return "List out the contents of each unique `GitProvenance` marker in the set of source files. " +
44-
"When everything is working correctly, exactly one such marker should be printed as all source files are " +
45-
"expected to come from the same repository / branch / commit hash.";
46-
}
40+
@Getter
41+
final String description = "List out the contents of each unique `GitProvenance` marker in the set of source files. " +
42+
"When everything is working correctly, exactly one such marker should be printed as all source files are " +
43+
"expected to come from the same repository / branch / commit hash.";
4744

4845
@Override
4946
public Set<GitProvenance> getInitialValue(ExecutionContext ctx) {

rewrite-core/src/main/java/org/openrewrite/ListRuntimeClasspath.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.github.classgraph.Resource;
2020
import io.github.classgraph.ResourceList;
2121
import io.github.classgraph.ScanResult;
22+
import lombok.Getter;
2223
import org.openrewrite.table.ClasspathReport;
2324

2425
import java.net.URI;
@@ -32,15 +33,11 @@
3233
public class ListRuntimeClasspath extends ScanningRecipe<Integer> {
3334
transient ClasspathReport report = new ClasspathReport(this);
3435

35-
@Override
36-
public String getDisplayName() {
37-
return "List runtime classpath";
38-
}
36+
@Getter
37+
final String displayName = "List runtime classpath";
3938

40-
@Override
41-
public String getDescription() {
42-
return "A diagnostic utility which emits the runtime classpath to a data table.";
43-
}
39+
@Getter
40+
final String description = "A diagnostic utility which emits the runtime classpath to a data table.";
4441

4542
@Override
4643
public Integer getInitialValue(ExecutionContext ctx) {

rewrite-core/src/main/java/org/openrewrite/Recipe.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.fasterxml.jackson.databind.json.JsonMapper;
2727
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
2828
import lombok.AccessLevel;
29+
import lombok.Getter;
2930
import lombok.RequiredArgsConstructor;
3031
import lombok.Setter;
3132
import lombok.experimental.FieldDefaults;
@@ -90,15 +91,11 @@ public static Recipe noop() {
9091
}
9192

9293
static class Noop extends Recipe {
93-
@Override
94-
public String getDisplayName() {
95-
return "Do nothing";
96-
}
94+
@Getter
95+
final String displayName = "Do nothing";
9796

98-
@Override
99-
public String getDescription() {
100-
return "Default no-op test, does nothing.";
101-
}
97+
@Getter
98+
final String description = "Default no-op test, does nothing.";
10299
}
103100

104101
/**

rewrite-core/src/main/java/org/openrewrite/config/CompositeRecipe.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.openrewrite.config;
1717

18+
import lombok.Getter;
1819
import lombok.RequiredArgsConstructor;
1920
import org.jspecify.annotations.Nullable;
2021
import org.openrewrite.Recipe;
@@ -36,10 +37,8 @@ public String getDisplayName() {
3637
return getName();
3738
}
3839

39-
@Override
40-
public String getDescription() {
41-
return "A recipe that consists of a list of other recipes.";
42-
}
40+
@Getter
41+
final String description = "A recipe that consists of a list of other recipes.";
4342

4443
@Override
4544
public @Nullable Duration getEstimatedEffortPerOccurrence() {

rewrite-core/src/main/java/org/openrewrite/search/FindParseToPrintInequality.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.openrewrite.search;
1717

18+
import lombok.Getter;
1819
import org.jspecify.annotations.Nullable;
1920
import org.openrewrite.ExecutionContext;
2021
import org.openrewrite.Recipe;
@@ -30,19 +31,15 @@
3031
public class FindParseToPrintInequality extends Recipe {
3132
transient ParseToPrintInequalities inequalities = new ParseToPrintInequalities(this);
3233

33-
@Override
34-
public String getDisplayName() {
35-
return "Find parse to print inequality";
36-
}
34+
@Getter
35+
final String displayName = "Find parse to print inequality";
3736

38-
@Override
39-
public String getDescription() {
40-
return "OpenRewrite `Parser` implementations should produce `SourceFile` objects whose `printAll()` " +
41-
"method should be byte-for-byte equivalent with the original source file. When this isn't true, " +
42-
"recipes can still run on the `SourceFile` and even produce diffs, but the diffs would fail to " +
43-
"apply as a patch to the original source file. Most `Parser` use `Parser#requirePrintEqualsInput` " +
44-
"to produce a `ParseError` when they fail to produce a `SourceFile` that is print idempotent.";
45-
}
37+
@Getter
38+
final String description = "OpenRewrite `Parser` implementations should produce `SourceFile` objects whose `printAll()` " +
39+
"method should be byte-for-byte equivalent with the original source file. When this isn't true, " +
40+
"recipes can still run on the `SourceFile` and even produce diffs, but the diffs would fail to " +
41+
"apply as a patch to the original source file. Most `Parser` use `Parser#requirePrintEqualsInput` " +
42+
"to produce a `ParseError` when they fail to produce a `SourceFile` that is print idempotent.";
4643

4744
@Override
4845
public TreeVisitor<?, ExecutionContext> getVisitor() {

rewrite-core/src/main/java/org/openrewrite/text/EndOfLineAtEndOfFile.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.openrewrite.text;
1717

18+
import lombok.Getter;
1819
import org.jspecify.annotations.Nullable;
1920
import org.openrewrite.*;
2021
import org.openrewrite.binary.Binary;
@@ -25,17 +26,13 @@
2526

2627
public class EndOfLineAtEndOfFile extends Recipe {
2728

28-
@Override
29-
public String getDisplayName() {
30-
return "End of Line @ End of File (EOL @ EOF)";
31-
}
29+
@Getter
30+
final String displayName = "End of Line @ End of File (EOL @ EOF)";
3231

33-
@Override
34-
public String getDescription() {
35-
return "Ensure that the file ends with the newline character.\n\n" +
36-
"*Note*: If this recipe modifies a file, it converts the file into plain text. " +
37-
"As such, this recipe should be run after any recipe that modifies the language-specific LST.";
38-
}
32+
@Getter
33+
final String description = "Ensure that the file ends with the newline character.\n\n" +
34+
"*Note*: If this recipe modifies a file, it converts the file into plain text. " +
35+
"As such, this recipe should be run after any recipe that modifies the language-specific LST.";
3936

4037
@Override
4138
public TreeVisitor<?, ExecutionContext> getVisitor() {

rewrite-core/src/main/java/org/openrewrite/text/RemoveByteOrderMark.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.openrewrite.text;
1717

18+
import lombok.Getter;
1819
import org.jspecify.annotations.Nullable;
1920
import org.openrewrite.*;
2021
import org.openrewrite.binary.Binary;
@@ -25,16 +26,12 @@
2526

2627
public class RemoveByteOrderMark extends Recipe {
2728

28-
@Override
29-
public String getDisplayName() {
30-
return "Remove byte order mark (BOM)";
31-
}
29+
@Getter
30+
final String displayName = "Remove byte order mark (BOM)";
3231

33-
@Override
34-
public String getDescription() {
35-
return "Removes UTF-8 byte order marks from the beginning of files.\n\n" +
36-
"The BOM character (U+FEFF) is generally unnecessary in UTF-8 files and can cause issues with some tools.";
37-
}
32+
@Getter
33+
final String description = "Removes UTF-8 byte order marks from the beginning of files.\n\n" +
34+
"The BOM character (U+FEFF) is generally unnecessary in UTF-8 files and can cause issues with some tools.";
3835

3936
@Override
4037
public TreeVisitor<?, ExecutionContext> getVisitor() {

rewrite-core/src/test/java/org/openrewrite/RecipeLifecycleTest.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.openrewrite;
1717

1818
import lombok.EqualsAndHashCode;
19+
import lombok.Getter;
1920
import lombok.NoArgsConstructor;
2021
import lombok.Value;
2122
import org.intellij.lang.annotations.Language;
@@ -479,15 +480,11 @@ void declarativeRecipeChainFromResourcesLongList() {
479480

480481
@SuppressWarnings("unused") // referenced in yaml
481482
class DefaultConstructorRecipe extends Recipe {
482-
@Override
483-
public String getDisplayName() {
484-
return "DefaultConstructorRecipe";
485-
}
483+
@Getter
484+
final String displayName = "DefaultConstructorRecipe";
486485

487-
@Override
488-
public String getDescription() {
489-
return "DefaultConstructorRecipe.";
490-
}
486+
@Getter
487+
final String description = "DefaultConstructorRecipe.";
491488

492489
@Override
493490
public TreeVisitor<?, ExecutionContext> getVisitor() {
@@ -506,15 +503,11 @@ public PlainText visitText(PlainText text, ExecutionContext ctx) {
506503
@NoArgsConstructor // referenced in yaml
507504
@SuppressWarnings("unused")
508505
class NoArgRecipe extends Recipe {
509-
@Override
510-
public String getDisplayName() {
511-
return "NoArgRecipe";
512-
}
506+
@Getter
507+
final String displayName = "NoArgRecipe";
513508

514-
@Override
515-
public String getDescription() {
516-
return "NoArgRecipe.";
517-
}
509+
@Getter
510+
final String description = "NoArgRecipe.";
518511

519512
@Override
520513
public TreeVisitor<?, ExecutionContext> getVisitor() {

rewrite-core/src/test/java/org/openrewrite/RecipeSchedulerTest.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import lombok.AllArgsConstructor;
1919
import lombok.EqualsAndHashCode;
20+
import lombok.Getter;
2021
import lombok.Value;
2122
import org.jspecify.annotations.Nullable;
2223
import org.junit.jupiter.api.Test;
@@ -168,15 +169,11 @@ void managedWorkingDirectoryWithMultipleRecipes(@TempDir Path path) {
168169

169170
@AllArgsConstructor
170171
class BoomRecipe extends Recipe {
171-
@Override
172-
public String getDisplayName() {
173-
return "We go boom";
174-
}
172+
@Getter
173+
final String displayName = "We go boom";
175174

176-
@Override
177-
public String getDescription() {
178-
return "Test recipe.";
179-
}
175+
@Getter
176+
final String description = "Test recipe.";
180177

181178
@Override
182179
public TreeVisitor<?, ExecutionContext> getVisitor() {
@@ -236,15 +233,11 @@ class RecipeWritingToFile extends ScanningRecipe<RecipeWritingToFile.Accumulator
236233

237234
final int position;
238235

239-
@Override
240-
public String getDisplayName() {
241-
return "Write text to a file";
242-
}
236+
@Getter
237+
final String displayName = "Write text to a file";
243238

244-
@Override
245-
public String getDescription() {
246-
return "Writes text to a file.";
247-
}
239+
@Getter
240+
final String description = "Writes text to a file.";
248241

249242
@Override
250243
public Accumulator getInitialValue(ExecutionContext ctx) {

rewrite-core/src/test/java/org/openrewrite/table/RecipeRunStatsTest.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.openrewrite.table;
1717

1818
import lombok.AllArgsConstructor;
19+
import lombok.Getter;
1920
import org.junit.jupiter.api.Test;
2021
import org.openrewrite.*;
2122
import org.openrewrite.marker.SearchResult;
@@ -28,15 +29,11 @@
2829

2930
@AllArgsConstructor
3031
class RecipeWithApplicabilityTest extends Recipe {
31-
@Override
32-
public String getDisplayName() {
33-
return "Recipe with an applicability test";
34-
}
32+
@Getter
33+
final String displayName = "Recipe with an applicability test";
3534

36-
@Override
37-
public String getDescription() {
38-
return "This recipe is a test utility which exists to exercise RecipeRunStats.";
39-
}
35+
@Getter
36+
final String description = "This recipe is a test utility which exists to exercise RecipeRunStats.";
4037

4138
@Option(displayName = "New text", example = "txt")
4239
String newText;

0 commit comments

Comments
 (0)