-
Notifications
You must be signed in to change notification settings - Fork 6k
8268469: Update java.time to use switch expressions #4433
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
Conversation
👋 Welcome back pconcannon! A progress list of the required criteria for merging this PR into |
@pconcannon The following labels will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
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.
Updates look good Patrick
@pconcannon This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been no new commits pushed to the ➡️ To integrate this PR with the above commit message to the |
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 good overall. Some misplaced comments. Also, copyright years should be updated.
src/java.base/share/classes/java/time/chrono/ChronoLocalDateTimeImpl.java
Outdated
Show resolved
Hide resolved
src/java.base/share/classes/java/time/chrono/ThaiBuddhistDate.java
Outdated
Show resolved
Hide resolved
src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.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.
My biggest comment is the spaces used to align, which I strongly object to. I agree with @dfuch comments too.
src/java.base/share/classes/java/time/chrono/ThaiBuddhistDate.java
Outdated
Show resolved
Hide resolved
} | ||
return with(date.plus(amountToAdd, unit), time); | ||
return switch (chronoUnit) { | ||
case NANOS -> plusNanos(amountToAdd); |
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.
Still has unnecessary alignment
There are lots of cases in the PR where ->
is still aligned. I'd like to see all of them unaligned.
return 335 + leap; | ||
} | ||
return switch (this) { | ||
case JANUARY -> 1; |
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.
Unnecessary alignment
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.
The vertical alignment improves readability in these short-line cases. Removing the spaces before the arrows will make it a little harder to discern the difference between the cases.
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.
It is your codebase, not mine, so it is up to you. Aligning things by column is generally frowned on in most style guides because it handles refactoring poorly, resulting in lots of needless change (or people forgetting to realign things - I had to deal with a rogue aligned Javadoc signature today in a PR where exactly that had happened). I also don't see how you write a style guide rule for when these should be aligned and when they should not.
Anyway, this PR isn't really the right place for this discussion - I'm not blocking the PR on this basis (and I'm not an official Reviewer anyway).
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 have a slight preference for the aligned version in the cases where the lines are short and the number of spaces used for padding is not unreasonable. I find the code gains in readability in these cases. In the case where the lines are long - I agree with Stephen that the alignment doesn't bring much readability - and sometime it may even be detrimental as it makes long lines longer. Stephen, would that be an acceptable compromise?
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.
Its certainly a reasonable position to take (ie. if thats what OpenJDK wants to do, its fine by me).
I'm more interested to see how you would write such a thing down in the coding standards that doesn't make the standard worthless.
src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java
Outdated
Show resolved
Hide resolved
return 335 + leap; | ||
} | ||
return switch (this) { | ||
case JANUARY -> 1; |
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 have a slight preference for the aligned version in the cases where the lines are short and the number of spaces used for padding is not unreasonable. I find the code gains in readability in these cases. In the case where the lines are long - I agree with Stephen that the alignment doesn't bring much readability - and sometime it may even be detrimental as it makes long lines longer. Stephen, would that be an acceptable compromise?
… logic of switch/case in LocalDate
/integrate |
Going to push as commit 1d16797. |
@pconcannon Pushed as commit 1d16797. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Hi,
Could someone please review my code for updating the code in the
java.time
packages to make use of the switch expressions?Kind regards,
Patrick
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/4433/head:pull/4433
$ git checkout pull/4433
Update a local copy of the PR:
$ git checkout pull/4433
$ git pull https://git.openjdk.java.net/jdk pull/4433/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 4433
View PR using the GUI difftool:
$ git pr show -t 4433
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/4433.diff