Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autowired field into constructor parameter #200

Merged
merged 1 commit into from
Jun 21, 2022

Conversation

BoykoAlex
Copy link
Contributor

@BoykoAlex BoykoAlex commented Jun 8, 2022

Takes fq name of the class and field name and converts that field if it is @Autowired into constructor parameter if there is a qualifying constructor.

Does need some sort of getApplicableTest()? Is it ok to be a recipe? Or you'd rather have it as a visitor? Feedback is welcomed.

@BoykoAlex
Copy link
Contributor Author

@pway99 converted into a Visitor as discussed earlier

@pway99 pway99 self-requested a review June 15, 2022 00:40
Copy link
Contributor

@pway99 pway99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @BoykoAlex, just a few minor suggestions.

Comment on lines 46 to 48
private String classFqName;

private String fieldName;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider making these final


@Override
public J visitClassDeclaration(ClassDeclaration classDecl, ExecutionContext p) {
if (classFqName.equals(classDecl.getType().getFullyQualifiedName())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest using TypeUtils here

Comment on lines 36 to 40
get() = object : Recipe() {
override fun getDisplayName() : String { return "Convert autowired field" }
override fun getVisitor(): TreeVisitor<*, ExecutionContext> {
return AutowiredFieldIntoConstructorParameterVisitor("demo.A", "a")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be

override val recipe: Recipe
        get() = toRecipe{AutowiredFieldIntoConstructorParameterVisitor("demo.A", "a")}

@BoykoAlex
Copy link
Contributor Author

@pway99 I've corrected the PR as suggested. Thanks very much for the review!-)

Copy link
Contributor

@pway99 pway99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @BoykoAlex !

@pway99 pway99 merged commit dff64cc into openrewrite:main Jun 21, 2022
@tkvangorder tkvangorder added this to the 4.23.0 milestone Jul 7, 2022
@tkvangorder tkvangorder added the enhancement New feature or request label Jul 7, 2022
@murdos
Copy link

murdos commented Dec 8, 2022

Hi! Is there any recipe that uses this visitor?
I haven't found any, and I think this would be an interesting recipe.

yeikel pushed a commit to yeikel/rewrite-spring that referenced this pull request Jan 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants