openrewrite / openrewrite/rewrite

Allow Traits visitors to schedule after visitors

Open
#5,441 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
3.7k
Forks
571
Avg merge
13h 12m
Merged PRs (30d)
261

Description

What problem are you trying to solve?

Traits are great to simplify development, but can not be used when changes to imports are needed, as the required hooks to register a doAfterVisitor are not exposed.

Describe the solution you'd like

Allow traits to call doAfterVisit, or similar, to register imports to be added/removed for wider applicability.

Have you considered any alternatives or workarounds?

Use the Traits visitor only within another visitor, but this is awkward and might even be more confusing.

Additional context

As seen on the AssertEqualsToAssertThat example, where the imports make it impossible to switch to a Trait.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining the Traits visitor API and the AssertEqualsToAssertThat example at src/main/java/com/yourorg/AssertEqualsToAssertThat.java, especially its import handling. Determine how a Trait could register after-visit behavior; done means the example can be expressed as a Trait while adding or removing its required imports.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.