We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Singleton
1 parent b52a552 commit 9bc5e2eCopy full SHA for 9bc5e2e
1 file changed
rewrite-core/src/main/java/org/openrewrite/Singleton.java
@@ -81,12 +81,8 @@ public class Singleton extends Recipe {
81
"The easiest way is to use Lombok's `@Value` annotation on your recipe class, which automatically " +
82
"generates correct `equals()` and `hashCode()` implementations based on all fields.";
83
84
- @Nullable Integer recipeIndex;
85
-
86
public boolean isSingleton(ExecutionContext ctx) {
87
- if (recipeIndex == null) {
88
- recipeIndex = ctx.getCycleDetails().getRecipePosition();
89
- }
+ Integer recipeIndex = ctx.computeMessageIfAbsent(getClass().getName() + "@" + Integer.toHexString(hashCode()), key -> ctx.getCycleDetails().getRecipePosition());
90
return recipeIndex == ctx.getCycleDetails().getRecipePosition();
91
}
92
0 commit comments