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

Java language migration updates #2020

Merged
merged 1 commit into from May 2, 2022

Conversation

spannm
Copy link
Contributor

@spannm spannm commented Apr 7, 2022

This pull request contains a number of Java language migration updates.
All changes are non-functional. They aim to improve code quality and make use of new Java language features.

  • use Java functional primitives (instead of Guava's)
  • use statement lambdas, use method references where possible
  • avoid unnecessary boxing
  • use Objects.equals
  • use diamond operator without explicit type where permitted
  • fix raw usage of parametrized classes

Tests are green.

…ement lambdas, method references, avoid unneccessary boxing, use Objects.equals, diamond operator without explicit type where permitted, fix raw usage of parametrized classes)
@@ -29,7 +30,7 @@
public Handler decorateHandler(Handler base, Class<?> sqlObjectType, Method method) {
final Transaction txnAnnotation = Stream.of(method, sqlObjectType)
.map(ae -> ae.getAnnotation(Transaction.class))
.filter(txn -> txn != null)
.filter(Objects::nonNull)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is one of those places where the explicit code is more readable than the function reference. Now I have to look up what "Objects::nonNull" does. The previous code was more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's a matter of taste :)
personally I like method references

@@ -42,7 +42,7 @@ public ClasspathBuilder setExtension(@Nullable String extension) {
}

// org.foo.Bar$Inner -> org/foo/Bar$Inner
public ClasspathBuilder appendFullyQualifiedClassName(@Nonnull Class clazz) {
public ClasspathBuilder appendFullyQualifiedClassName(@Nonnull Class<?> clazz) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this change is ok, but it does change a signature (from raw type to any type). @stevenschlansker to double check? It is an internal class, though, so it should be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course we can remove this change if you feel unsure.

Copy link
Member

Choose a reason for hiding this comment

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

Internal APIs are OK to change without regard for compatibility.

@hgschmie
Copy link
Contributor

hgschmie commented Apr 8, 2022

First, thank you for that PR! Most changes are cosmetic; I appreciate that this makes our code base more idiomatic Java 8+ code.

I glanced at the test changes; those all seem good. I wrote a couple of comments on the actual code, again all seems fine. I will try to get the LGTM tests to finish (they crashed halfway through, which seems independent of the actual PR) and merge later today.

Did you hand-make those changes or did you use some tool? I know of people that use the modernizer plugin (https://github.com/gaul/modernizer-maven-plugin) but I had very mixed results with it.

@spannm
Copy link
Contributor Author

spannm commented Apr 8, 2022

First, thank you for that PR! Most changes are cosmetic; I appreciate that this makes our code base more idiomatic Java 8+ code.

...

Did you hand-make those changes or did you use some tool? I know of people that use the modernizer plugin (https://github.com/gaul/modernizer-maven-plugin) but I had very mixed results with it.

Thank you very much for your feedback!
Though I mostly use Eclipse, I have the habit of checking my projects using the Code > Inspect Code feature of IDEA.
This feature is really well done and offers great pointers and insights, even though some of the refactorings most be applied with caution...
IntelliJ IDEA 2021.2.3 Community Edition is what I have here at the moment, great software free or charge ;)

This analysis is in addition to compiler warnings, spotbugs, pmd, checkstyle, all of which you have in place in jdbi.

@spannm
Copy link
Contributor Author

spannm commented Apr 13, 2022

Hi @hgschmie, @stevenschlansker
all above checks are green and the commit has no conflicts with master.
Would you like me to make any amendments?
or could you merge this PR?

@hgschmie hgschmie merged commit d5e5775 into jdbi:master May 2, 2022
@hgschmie
Copy link
Contributor

hgschmie commented May 2, 2022

sorry, got distracted. merged.

@stevenschlansker
Copy link
Member

Changes look OK to me

@spannm
Copy link
Contributor Author

spannm commented May 3, 2022

Thanks for merging.

@spannm spannm deleted the sman-81-jdbi-java-lang-migration branch June 3, 2022 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants