Conversation
Member
Author
Member
Author
|
any thoughts, would love to ship a better JI support in tools such as rspec? |
e.g. previously a instance_method(:toString) would only exists on java.lang.Object - custom impls in more concrete classes would not show up. which is fine to save space due Java's dispatch rules but the proxy class hierarachy doesn't match reality which we'll need for Java inspect -> toString
need a base to_s impl on java.lang.Object - calling toString() refactored the Java object proxy class tracking in JavaSupport
inspect/to_s are expected to behave like rest of Java proxies (delegating to String) while also Java APIs should always win when there's a conflict in naming e.g. Map#clear vs Hash#clear
this would be a resolution for weird non-readable rspec output ... with Java types - GH-5182
... as there are a few 'uniformity' pieces to figure out
... we'll reuse to test out reflective inspect
headius
approved these changes
Oct 12, 2018
Member
headius
left a comment
There was a problem hiding this comment.
I approve. I only have one question... if a Java type defines its own inspect, that should override the default one from JavaProxy, yes?
Member
Author
yeah, that is always the case with these proxy methods but just to be sure I have added some specs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
...
inspectwill now calltoStringon a Java proxy (unless itsjava.lang.Object#toStringin which case we do the same "bare" hashy-inspect)the motivation here is #5182 ... have seen "useless" hashy-inspect on Java proxied types too many times.
the approach here is the following: proxies use a call-site to determine whether
toStringis overriden.the side effect is that I reverted an old 'feature' where Java (instance) methods, such as toString, only show-up at the lowest level in the Ruby class hierarchy - as explained on #5182 (comment).
there's likely a "cleaner" way -> having
inspectalias-ed whenever a type we process hastoString, maybe we shall eventually refactor to that but there's a much more interesting feature that I am pursuing :current default
inspect(for any Java class missing a customtoString) does only hashy-inspect without any details. would like to be able to reflectively inspect such hierarchies similar to how Ruby shows all instance variables - while I got it working its not currently usable as there's inconsistencies that I need to think through (more on that elsewhere).in terms of compatibility there's some "breaking" change related to
java.util.Mapproxies, which seem to have been historically approached differently than the others - the internally sync state with aHash.clearhad the same effect but did not return void as is prescribed byjava.util.Mapbut insteadselffromRubyHash).inspectfor map proxy needed to be changed, otherwise it would be weird to have a special exception for theMaphierarchy frominspectdoingtoStringon Java proxies (methods for restoring previous behavior provided).