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

Cleanups and improvements for java_import #6116

merged 3 commits into from Mar 10, 2020


Copy link

@headius headius commented Mar 10, 2020

This PR contains commits to clean up java_import and bring up to date with modern Ruby patterns.

Inspired by #6115.

`java_import` has been defined on Object for many years, but after
all that time it seems it really should have been defined on
Module and toplevel only, similar to the visibility methods and
`define_method`. In addition, it uses unnecessary evals to query
and assign the constant, and if called against a non-Module it
always defines the resulting constant on Object. This leads to
peculiar behavior as reported in jruby#6115.

This change does the following:

* Deprecate and warn for java_import called against arbitrary
  non-Module objects.
* Move java_import to Module and define a top-level version that
  invokes it against Object.
* Eliminate the eval and use const* methods to assign the value.

This should be a bit faster (no evals) and provide a path toward
removing Object#java_import.

All spec:ji passes without any warnings, so at least we are not
using Object#java_import there.
* Move doco to Module#java_import.
* Delete deprecated include_class and java_kind_of.
* Add @deprecated and :nodoc: to Object#java_import.
* Link toplevel java_import doco to Module#java_import.
Module#import called super, which would fall through
Object#java_import eventually and trigger a warning. Invoke
Module#java_import directly instead.
@headius headius requested review from kares and enebo March 10, 2020 18:38
Copy link
Member Author

headius commented Mar 10, 2020

Reviewed offline by @kares and @enebo with 👍 from both. Merging.

@headius headius merged commit eef249b into jruby:master Mar 10, 2020
@headius headius deleted the cleanup_java_import branch March 10, 2020 19:07
@enebo enebo added this to the JRuby milestone Mar 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants