-
Notifications
You must be signed in to change notification settings - Fork 80
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
CDI recipe #340
CDI recipe #340
Conversation
src/test/java/org/openrewrite/java/migrate/jakarta/DeprecatedCDIAPIsRemoved40Test.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/migrate/jakarta/UpdateAddAnnotatedType.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/migrate/jakarta/DeprecatedCDIAPIsRemoved40Test.java
Outdated
Show resolved
Hide resolved
beforeBeanDiscovery.addAnnotatedType(producerType, "my unique id"); // Not this one | ||
beforeBeanDiscovery.addAnnotatedType(String.class, "my other unique id"); // Not this one | ||
|
||
beanManager.getInjectionTargetFactory().createInjectionTarget(producerType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getInjectionTargetFactory
needs to take in the annotatedType
which was previous passed to createInjectionTarget
createInjectionTarget
would take in null. Here are some examples I've seen of this code being used https://www.tabnine.com/code/java/methods/javax.enterprise.inject.spi.BeanManager/getInjectionTargetFactory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldnt get this to work as well since if the arguments are right I was using the simpleName change and that worked..now we need to add different arguments to the methods as well. I updated the test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I'll look into both updates
src/main/java/org/openrewrite/java/migrate/jakarta/UpdateAddAnnotatedType.java
Outdated
Show resolved
Hide resolved
What's the status on this PR? I see some unresolved conversations above, and partial in the title, as well as some small formatting deviations. Let me know when it's ready to review! |
@timtebeek I see some of the formatting deviations you are referring to. I'll push some of those updates for Anu shortly. I did leave a question for you about how to handle the removal of
I initially thought we could just update uses of |
Thanks for taking those changes on! Helps me focus on the function of the recipes in my review.
If you implement After you replace the method invocation with |
This is good to know. I have a meeting coming up in 10 minutes. After that is done I'll look into using JavaVisitor. |
I've gone ahead and updated the code to return |
Description should end with a dot; and reflect what the recipe does. Call super in the normal code path. Remove superfluous nullable annotations. Add missing space in case `false` is retained.
- org.openrewrite.java.migrate.jakarta.UpdateAddAnnotatedType: | ||
methodPattern: jakarta.enterprise.inject.spi.BeforeBeanDiscovery addAnnotatedType(jakarta.enterprise.inject.spi.AnnotatedType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UpdateAddAnnotatedType
is only used once, yet the implementation seems to switch between two types of method patterns. Should it be used once more? Or can we simplify the implementation to only support a single case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@timtebeek I added the javax case as well .Should be there in the final commit.
src/main/java/org/openrewrite/java/migrate/jakarta/UpdateBeanManagerMethod.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than one big test to verify three different Java recipes, as well as some yaml configuration, I'd prefer to see a unit test class per Java recipe; That helps make it clear what each recipe contributes, and allows one to jump from the implementation directly to the associated tests rather than having to deduce that from usage in yaml files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@timtebeek will do that from the next recipe. This one just would up like that
if (type != null) { | ||
type = type.withName(newMethodName); | ||
} | ||
return method.withName(method.getName().withSimpleName(newMethodName)).withMethodType(type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work well with our type system I think, to have a methodName
containing getEvent().fire
. Instead we should likely use a JavaTemplate here to create the chain of method invocations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was also not addressed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@timtebeek I tried to update the code with the template..no matter what I tried it keeps failing.Hence I used this way
// maybeRemoveImport("jakarta.enterprise.inject.spi.BeanManager");
// return JavaTemplate.builder("#{any(jakarta.enterprise.inject.spi.BeanManager)}.getEvent().fire(#{any()})")
// .build()
// .apply(updateCursor(mi), mi.getCoordinates().replace(), mi.getSelect(), mi.getArguments().get(0));
Not sure why the template approach didnt work for getEvent()
src/test/java/org/openrewrite/java/migrate/jakarta/DeprecatedCDIAPIsRemoved40Test.java
Outdated
Show resolved
Hide resolved
@ranuradh There's still unresolved remarks above; could you respond to and address the earlier feedback? |
@timtebeek I fixed all the concerns other than the template usage for getEvent(). |
Looks like there are still conflicts with this branch? |
Would be great if we could get these conflicts resolved before a more thorough review and merge. |
The CI logs seem to be filled with stacktraces on classes added in this PR:
Can we fix those issues? |
And has issues with whitespace that we don't want
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this one @ranuradh ! I've pushed changes in the last few commits that would be good to repeat in other PRs
- have individual unit tests per Java recipe; this helps flush out validation issues
- no need to make recipes configurable if they are specific
- don't match on method simple name; use dedicated method matchers instead
- use wildcards if you want to match similar classes in both
javax
andjakarta
- minimize your tests to only show the recipe relevant code changes, not any common surrounding context
Hope that helps, and look forward to what you'll produce next! :)
What's changed?
This recipe takes care of the following rules:
2 recipes were added -
UpdateAddAnnotatedType: Here an argument String with value null was added to the return type
UpdateBeanManagerMethod : Removes the deprecated method and substitutes with the right call
Anything in particular you'd like reviewers to focus on?
Anyone you would like to review specifically?
@cjobinabo , @timtebeek
Have you considered any alternatives or workarounds?
Any additional context
Checklist
./gradlew licenseFormat