-
-
Notifications
You must be signed in to change notification settings - Fork 943
Description
Hello there jruby-devs and everyone else,
The following issue request is not really a bug report per se; nor a feature request.
And it is super-minor, so it can be ignored. Still, I wanted to mention it at the least.
I am currently writing a bunch of tiny standalone jruby-swing applications,
as I am preparing to update my jruby-specific code (mostly for swing right
now, but it is not confined to swing only; swing is just one base I want to
have in the long run). So one of those applications I draw inspiration
from is for instance this small one here:
https://gist.github.com/igorpopovio/04070fcfcf4c13dad8ff
e. g.
public class ClickCountingApp {
It uses various imports, imported via '*':
import javax.swing.*;
import java.awt.event.*;
Now my plan is to also write a click-counting program in jruby-swing; not
necessarily using that code, but simply using the code as inspiration.
click-event -> counter increment. Super simple.
I did, however had, test something, aka whether '' works here. The
import javax.swing.; part specifically.
I just tested the same syntax in the .rb file, via java_import:
java_import javax.swing.*
I did not expect it to succeed by the way, so I just did this for
testing purposes.
The error message was a bit interesting to me though:
ArgumentError: java_import does not work for Java packages (try include_package instead)
So this behaviour may be correct, but the wording is very strange.
"does not work for Java packages" ... but if I do NOT use the '*'
there, and instead specifically include the swing widget, such
as:
java_import javax.swing.JPanel
then it works perfectly fine. Isn't JPanel part of a "java package"
too? In this context swing?
I assume the message shown makes sense for other use cases and
scenarios, so I am not disputing that. But in my specific example,
I would reason that the message shown may not fit perfectly, as
the only difference here would be the use of *, versus the use of
a specific name instead. So insinuating here that include_package
should be used, may not be correct. (Also I could not get
include_package to work, may have to look up how this is done.)
Anyway, so the first part of this was just to show the above, even
if it may not be too terribly useful. The second part is to perhaps
consider the notification here. I am not sure if it can be worded
better, as I don't know all use cases of it; my own narrow use case
here may not apply to other people's use case, for instance, so my
suggestion may be wrong too. Nonetheless, I'll try to think of
a suggestion that could perhaps be an improvement to the current
status quo next.
So, rather than this specific error:
ArgumentError: java_import does not work for Java packages (try include_package instead)
I would probably add a line or two of extra code that specifically
checks for '*', and then try to give an appropriate message that may
be helpful too, such as:
ArgumentError: java_import does not work for '*'; consider using the specific
name of the class instead
or, IF it actually works as a variant, to perhaps show this variant via java_import
too. Or perhaps a new method? Such as:
java_import_all javax.swing
# ^^^ this would be equivalent to import javax.swing.*;
Not sure if adding a new method is worth it here or not. If a way
already exists then I think it may be useful for the error message
to show the name too; that way new users can self-discover things
rather than rely on e. g. google search, which may not always yield
good results these days. (Or, if there is another method, to also
mention it.)
Anyway - as stated this may not be very important, so I think this
here is more a very minor situation. The way I work around this is
by simply bundling all important widgets in a separate .rb file
that is then automatically included when I subclass or include one
key .rb file, so to me it does not really matter how many individual
widgets I have to include, as a separate .rb file takes care of that.
Only for the prototyping part right now, I re-build things from
scratch now, so I wanted to be initially lazy; otherwise I would not
have even encountered the above situation as I would not have used
'*' really. (Requiring individual widgets is a bit more cumbersome,
but in the long run for any library, it seems to be the better
variant.)
PS: I also added to the title here whether a new method should be added or not.
I don't know if such a method exists, so please bear this in mind. And a new method
may not be needed anyway. I just wanted to mention it. Or the '*' could be allowed
as a valid token; the reason I suggested a name such as java_import_all was simply
so that people can think as a "related method to java_import functionality". I think
jruby used to have another method years ago; at the least I think to remember
having found such examples on the world wide web. Picking good names is very
helpful, so I am not necessarily saying the name suggestion here is good; I came up
with this mostly from the line of thinking that the name we already have, aka
"java_import", is good and to be retained, which is why I simply came up with adding
"_all" or something like that.