openrewrite / openrewrite/rewrite-static-analysis
Reduce duplication in KotlinFileChecker, GroovyFileChecker, ... with generic tree type instance of checker
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 62
- Forks
- 112
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 40
Description
What problem are you trying to solve?
Reduce duplication, also going forward with other languages, in KotlinFileChecker and equivalents
Preconditions.and(
Preconditions.not(new KotlinFileChecker<>()),
Preconditions.not(new GroovyFileChecker<>())),
Describe the solution you'd like
https://github.com/openrewrite/rewrite-static-analysis/pull/142/files#r1272998534
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with KotlinFileChecker.java and the equivalent Groovy and other language checkers linked in the issue, then read the referenced discussion in pull request 142. Determine whether the generic visitor belongs in rewrite-static-analysis or rewrite-core, replace the duplicated checker pattern, and verify that the existing language-specific checks retain their behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, java, kotlin
- Domain
- tooling
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100