Skip to content

Commit

Permalink
Add a UsesType precondition to ReplaceConstant
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Dec 21, 2024
1 parent dd2886c commit e93ec04
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import lombok.Value;
import org.jspecify.annotations.Nullable;
import org.openrewrite.*;
import org.openrewrite.java.search.UsesType;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.JavaType;
import org.openrewrite.java.tree.TypeUtils;
Expand Down Expand Up @@ -53,7 +54,7 @@ public String getDescription() {

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return new JavaVisitor<ExecutionContext>() {
JavaVisitor<ExecutionContext> replacementVisitor = new JavaVisitor<ExecutionContext>() {
J.@Nullable Literal literal;

@Override
Expand Down Expand Up @@ -117,5 +118,9 @@ private J.Literal buildLiteral() {
return literal;
}
};
return Preconditions.check(
new UsesType<>(owningType, true),
replacementVisitor
);
}
}

0 comments on commit e93ec04

Please sign in to comment.