-
Notifications
You must be signed in to change notification settings - Fork 78
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
Java 10+ Local-Variable Type Inference #218
Conversation
src/test/java/org/openrewrite/java/migrate/lang/VarUsageTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/migrate/lang/VarUsageTest.java
Outdated
Show resolved
Hide resolved
Might want to explicitly state what we want to do with primitives through tests; that could help indicate what we end up doing is intentional; great start! Perhaps as a suggestion: right now your tests are a mix of should & should not apply recipe. Could be helpful to separate those into nested classes each such that you can drop the prefix. |
Yes agree primitives are missing, see my comment here. You suggest grouping the test by applicability instead, currently they are grouped as in the issue. |
👍🏻
Hah; we can do both with Nested within Nested. Especially helpful if there's a lot of cases to visually separate, which it appears we might end up doing here: both covering cases where we do want to make changes and exclusions where we do not want to make changes. And then logically group those based on their applicability to primitives, generics, etc.. at the top level. |
Group Tests for var keywords Add use to Recipe name
GH and I had issues the last days.. But now I updated the Test as we discussed |
Fix format in tests and disable generics tests
Thanks a lot @MBoegers ; I'm asking my colleagues to have a look! :) |
@timtebeek cheers! I have not yet implemented generics, because I felt it really hard to detect them securely. I'd like to get a review for the simple parts and aim for generics a bit later ;) |
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 think the PR looks really good! Some small comments:
- I found a problem with compound definitions, which currently would do the wrong thing.
- The null-type checking can also be improved
- I also noticed that it would currently not apply to code inside static and non-static initializers
- It might be cool to also support the variables of enhanced for-loops (e.g.
for (var s : List.of("a", "b"))
)
src/main/java/org/openrewrite/java/migrate/lang/UseVarKeyword.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/migrate/lang/UseVarKeyword.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/migrate/lang/UseVarKeyword.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/migrate/lang/UseVarKeyword.java
Outdated
Show resolved
Hide resolved
…cking. UseVarKeywordTest: rename method
@MBoegers Thanks for looking into this! Regarding your question:
Definitely! The recipe doesn't need to be perfect from day one. We do however have the do no harm guideline which boils down to that a recipe should rather not make any change than a wrong change. This can in itself already by quite a challenge (and we certainly still have some recipes which violate this rule), but we should make a best effort to not produce any wrong code. So if we can fix the few cases I think I found, I think we can go ahead and integrate this recipe and do improvements in follow-up commits. |
I've updated the PR, as you may see I excluded some features for now. They should be a new issue, otherwise this PRs lifetime explodes :D What is possible by now:
The leftovers:
Should I write some issues like I have them in mind for further refinement? |
14f0bcd
to
55a3d4b
Compare
…type inference into own recipe
…e inference into own recipe
…tor DeclarationCheck to be package private Utility. Prio used UseVarKeywordTest remains as prove of correct refactoring.
bd5e46a
to
76cc27d
Compare
76cc27d
to
019a7a0
Compare
src/main/java/org/openrewrite/java/migrate/lang/var/UseVarForObject.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/migrate/lang/var/DeclarationCheck.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.
Looks very good. It will be interesting to see what turns up when we run this recipe in the SaaS.
src/main/java/org/openrewrite/java/migrate/lang/var/DeclarationCheck.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/migrate/lang/var/UseVarForObject.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/migrate/lang/var/UseVarForPrimitive.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/migrate/lang/var/DeclarationCheck.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/migrate/lang/var/DeclarationCheck.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/migrate/lang/var/UseVarForObject.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/migrate/lang/var/UseVarForPrimitive.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/migrate/lang/var/UseVarForPrimitive.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/migrate/lang/var/UseVarForObject.java
Outdated
Show resolved
Hide resolved
@MBoegers Looks like you just committed some changes. Some of my comments may not apply anymore... |
Co-authored-by: Knut Wannheden <[email protected]>
dcf0360
to
38bb55c
Compare
src/main/java/org/openrewrite/java/migrate/lang/var/package-info.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.
Very nice! @timtebeek Anything else you want to add or should we merge it?
@MBoegers Thanks again for your contribution! |
Thanks to you both for your help |
Yes thanks a lot! I know it was a long one to get through, with a lot of discovery along the way, but really appreciate the effort! |
Implement a recipe for local variable type inference as discussed here: #217
This Draft contains the test suite, as tim suggested.