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

8263668: Update java.time to use instanceof pattern variable #3170

Closed
wants to merge 12 commits into from

Conversation

@pconcannon
Copy link
Contributor

@pconcannon pconcannon commented Mar 24, 2021

Hi,

Could someone please review my code for updating the code in the java.time package to make use of the instanceof pattern variable?

Kind regards,
Patrick


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8263668: Update java.time to use instanceof pattern variable

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/3170/head:pull/3170
$ git checkout pull/3170

Update a local copy of the PR:
$ git checkout pull/3170
$ git pull https://git.openjdk.java.net/jdk pull/3170/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 3170

View PR using the GUI difftool:
$ git pr show -t 3170

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/3170.diff

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Mar 24, 2021

👋 Welcome back pconcannon! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr label Mar 24, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Mar 24, 2021

@pconcannon The following labels will be automatically applied to this pull request:

  • core-libs
  • i18n

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.

@mlbridge
Copy link

@mlbridge mlbridge bot commented Mar 24, 2021

Copy link
Contributor

@LanceAndersen LanceAndersen left a comment

Changes look good Patrick.

@openjdk
Copy link

@openjdk openjdk bot commented Mar 24, 2021

@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:

8263668: Update java.time to use instanceof pattern variable

Reviewed-by: lancea, ryadav, naoto, rriggs, dfuchs, scolebourne, chegar

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 master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready label Mar 24, 2021
Copy link
Contributor

@RogerRiggs RogerRiggs left a comment

I generally concur with forax about avoiding the use of single letter variables.

@pconcannon
Copy link
Contributor Author

@pconcannon pconcannon commented Apr 20, 2021

In addition to the other suggestions, java.time could use a round of cleanup to use switch expressions.

Hi Roger, I plan to introduce switch expressions in a follow up issue/PR.

@naotoj
naotoj approved these changes Apr 20, 2021
@dfuch
dfuch approved these changes Apr 21, 2021
@turbanoff
Copy link
Contributor

@turbanoff turbanoff commented Apr 21, 2021

I was able to find (with IntelliJ IDEA help) few more places to improve

    java.time   27 warnings 
        class Clock   2 warnings 
            class FixedClock   1 warning 
                method equals(Object)   1 warning 
                    WARNING Variable 'other' can be replaced with pattern variable 
            class OffsetClock   1 warning 
                method equals(Object)   1 warning 
                    WARNING Variable 'other' can be replaced with pattern variable 
        class Instant   2 warnings 
            method until(Temporal, TemporalUnit)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class LocalDate   5 warnings 
            method minus(TemporalAmount)   1 warning 
                WARNING Variable 'periodToSubtract' can be replaced with pattern variable 
            method plus(long, TemporalUnit)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method plus(TemporalAmount)   1 warning 
                WARNING Variable 'periodToAdd' can be replaced with pattern variable 
            method range(TemporalField)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class LocalDateTime   8 warnings 
            method get(TemporalField)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method getLong(TemporalField)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method isSupported(TemporalField)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method minus(TemporalAmount)   1 warning 
                WARNING Variable 'periodToSubtract' can be replaced with pattern variable 
            method plus(long, TemporalUnit)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method plus(TemporalAmount)   1 warning 
                WARNING Variable 'periodToAdd' can be replaced with pattern variable 
            method range(TemporalField)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class LocalTime   1 warning 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class OffsetDateTime   1 warning 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class Year   1 warning 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class YearMonth   1 warning 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class ZonedDateTime   6 warnings 
            method equals(Object)   1 warning 
                WARNING Variable 'other' can be replaced with pattern variable 
            method minus(TemporalAmount)   1 warning 
                WARNING Variable 'periodToSubtract' can be replaced with pattern variable 
            method plus(TemporalAmount)   1 warning 
                WARNING Variable 'periodToAdd' can be replaced with pattern variable 
            method with(TemporalAdjuster)   2 warnings 
                WARNING Variable 'odt' can be replaced with pattern variable 
                WARNING Variable 'instant' can be replaced with pattern variable 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
    java.time.chrono   13 warnings 
        class ChronoLocalDateImpl   1 warning 
            method plus(long, TemporalUnit)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class ChronoLocalDateTimeImpl   6 warnings 
            method get(TemporalField)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method getLong(TemporalField)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method isSupported(TemporalField)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method plus(long, TemporalUnit)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method range(TemporalField)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class ChronoPeriodImpl   1 warning 
            method validateAmount(TemporalAmount)   1 warning 
                WARNING Variable 'period' can be replaced with pattern variable 
        class ChronoZonedDateTimeImpl   1 warning 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class HijrahDate   1 warning 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class JapaneseDate   1 warning 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class MinguoDate   1 warning 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class ThaiBuddhistDate   1 warning 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
    java.time.format   3 warnings 
        class DecimalStyle   1 warning 
            method equals(Object)   1 warning 
                WARNING Variable 'other' can be replaced with pattern variable 
        class Parsed   2 warnings 
            method resolveFields()   2 warnings 
                WARNING Variable 'czdt' can be replaced with pattern variable 
                WARNING Variable 'cldt' can be replaced with pattern variable 
    java.time.zone   1 warning 
        class TzdbZoneRulesProvider   1 warning 
            method provideRules(String, boolean)   1 warning 
                WARNING Variable 'bytes' can be replaced with pattern variable 

Do you have plans to adjust them too?

@pconcannon
Copy link
Contributor Author

@pconcannon pconcannon commented Apr 21, 2021

I was able to find (with IntelliJ IDEA help) few more places to improve

    java.time   27 warnings 
        class Clock   2 warnings 
            class FixedClock   1 warning 
                method equals(Object)   1 warning 
                    WARNING Variable 'other' can be replaced with pattern variable 
            class OffsetClock   1 warning 
                method equals(Object)   1 warning 
                    WARNING Variable 'other' can be replaced with pattern variable 
        class Instant   2 warnings 
            method until(Temporal, TemporalUnit)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class LocalDate   5 warnings 
            method minus(TemporalAmount)   1 warning 
                WARNING Variable 'periodToSubtract' can be replaced with pattern variable 
            method plus(long, TemporalUnit)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method plus(TemporalAmount)   1 warning 
                WARNING Variable 'periodToAdd' can be replaced with pattern variable 
            method range(TemporalField)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class LocalDateTime   8 warnings 
            method get(TemporalField)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method getLong(TemporalField)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method isSupported(TemporalField)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method minus(TemporalAmount)   1 warning 
                WARNING Variable 'periodToSubtract' can be replaced with pattern variable 
            method plus(long, TemporalUnit)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method plus(TemporalAmount)   1 warning 
                WARNING Variable 'periodToAdd' can be replaced with pattern variable 
            method range(TemporalField)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class LocalTime   1 warning 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class OffsetDateTime   1 warning 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class Year   1 warning 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class YearMonth   1 warning 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class ZonedDateTime   6 warnings 
            method equals(Object)   1 warning 
                WARNING Variable 'other' can be replaced with pattern variable 
            method minus(TemporalAmount)   1 warning 
                WARNING Variable 'periodToSubtract' can be replaced with pattern variable 
            method plus(TemporalAmount)   1 warning 
                WARNING Variable 'periodToAdd' can be replaced with pattern variable 
            method with(TemporalAdjuster)   2 warnings 
                WARNING Variable 'odt' can be replaced with pattern variable 
                WARNING Variable 'instant' can be replaced with pattern variable 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
    java.time.chrono   13 warnings 
        class ChronoLocalDateImpl   1 warning 
            method plus(long, TemporalUnit)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class ChronoLocalDateTimeImpl   6 warnings 
            method get(TemporalField)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method getLong(TemporalField)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method isSupported(TemporalField)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method plus(long, TemporalUnit)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method range(TemporalField)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class ChronoPeriodImpl   1 warning 
            method validateAmount(TemporalAmount)   1 warning 
                WARNING Variable 'period' can be replaced with pattern variable 
        class ChronoZonedDateTimeImpl   1 warning 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class HijrahDate   1 warning 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class JapaneseDate   1 warning 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class MinguoDate   1 warning 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
        class ThaiBuddhistDate   1 warning 
            method with(TemporalField, long)   1 warning 
                WARNING Variable 'f' can be replaced with pattern variable 
    java.time.format   3 warnings 
        class DecimalStyle   1 warning 
            method equals(Object)   1 warning 
                WARNING Variable 'other' can be replaced with pattern variable 
        class Parsed   2 warnings 
            method resolveFields()   2 warnings 
                WARNING Variable 'czdt' can be replaced with pattern variable 
                WARNING Variable 'cldt' can be replaced with pattern variable 
    java.time.zone   1 warning 
        class TzdbZoneRulesProvider   1 warning 
            method provideRules(String, boolean)   1 warning 
                WARNING Variable 'bytes' can be replaced with pattern variable 

Do you have plans to adjust them too?

Hi @turbanoff, thanks for finding these. Will take a look shortly!

@naotoj
naotoj approved these changes Apr 21, 2021
@pconcannon
Copy link
Contributor Author

@pconcannon pconcannon commented Apr 22, 2021

Hi @turbanoff, thanks for finding these. Will take a look shortly!

As this PR is already quite large, I will create a second issue to track these further changes. Thanks again for your help

@pconcannon
Copy link
Contributor Author

@pconcannon pconcannon commented Apr 22, 2021

/integrate

@openjdk openjdk bot closed this Apr 22, 2021
@openjdk openjdk bot added integrated and removed ready rfr labels Apr 22, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Apr 22, 2021

@pconcannon Pushed as commit 28af31d.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@YassinHajaj
Copy link

@YassinHajaj YassinHajaj commented Apr 22, 2021

Hi @pconcannon , good job !

However, is there a reason why you're not using chronoUnit in LocalDateTime:1687 ?

    @Override
    public long until(Temporal endExclusive, TemporalUnit unit) {
        LocalDateTime end = LocalDateTime.from(endExclusive);
        if (unit instanceof ChronoUnit chronoUnit) {
            if (unit.isTimeBased()) { <-- HERE
                long amount = date.daysUntil(end.date);
@pconcannon pconcannon deleted the pconcannon:JDK-8263668 branch May 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment