We could probably make this a bit more generic, so that it can cover even more ground.
@Value
public class IsInstanceOf<P> extends TreeVisitor<Tree, P> {
Class<? extends Tree> treeType;
@Nullable
public Tree visit(@Nullable Tree tree, P p) {
if (tree != null && treeType.isInstance(tree.getClass()) {
return SearchResult.found(tree);
}
return tree;
}
}
Then this may be a candidate for inclusion down in `rewrite-core`.
## Have you considered any alternatives or workarounds?
We can also only keep this generic class in rewrite-static-analysis, since that depends on `rewrite-kotlin` which is not in rewrite-core. A lot of projects depend on rewrite-static-analysis further down, so that could help.
## Additional context
Discovered on https://github.com/openrewrite/rewrite-static-analysis/pull/142
Probably best to look at this once rewrite-kotlin has been merged into openrewrite/rewrite; that way the generic class, and it's two+ implementations will be available downstream.
What problem are you trying to solve?
Reduce duplication, also going forward with other languages, in KotlinFileChecker and equivalents
Describe the solution you'd like
https://github.com/openrewrite/rewrite-static-analysis/pull/142/files#r1272998534
}