zsh-users
 help / color / mirror / code / Atom feed
* Java completion for Java files
@ 2024-02-05 18:04 Henri Tremblay
  2024-02-05 20:43 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Henri Tremblay @ 2024-02-05 18:04 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 835 bytes --]

Hi,

I was directed here to discuss Java completion.

Java now supports (since Java 10 I think) command lines like

java Math.java

or

java src/main/java/org/me/Math.java.

It will then just compile and launch that java file. But zsh won't
autocomplete for that. It only wants a jar, class file or whatever.

I would like normal completion on file and directories with a filter on
.java files. Possibly on top of the classpath way (which I never use so
just deactivating it would be fine with me, but we can keep the existing
and add more completion on top).

The problem is probably somewhere in there:
https://github.com/zsh-users/zsh/blob/master/Completion/Unix/Command/_java
but I don't know enough how it works to propose a fix myself.

Any help would be appreciated,
Henri Tremblay
Java Champion
EasyMock and Objenesis dev lead

[-- Attachment #2: Type: text/html, Size: 3879 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Java completion for Java files
  2024-02-05 18:04 Java completion for Java files Henri Tremblay
@ 2024-02-05 20:43 ` Bart Schaefer
  2024-02-06  2:47   ` Henri Tremblay
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2024-02-05 20:43 UTC (permalink / raw)
  To: Henri Tremblay; +Cc: zsh-users

On Mon, Feb 5, 2024 at 10:04 AM Henri Tremblay <henri.tremblay@gmail.com> wrote:
>
> Java now supports (since Java 10 I think) command lines like
>
> java Math.java
>
> It will then just compile and launch that java file. But zsh won't autocomplete for that. It only wants a jar, class file or whatever.

The issue is here in the _arguments setup for _java:

    '(-):class:_java_class -m main ${(kv)opt_args[(i)(-classpath|-cp)]}' \
    '*::args:= _normal' \
     && return 0

The (-) says that the first word after "java" must either be an option
(start with "-") or must be a class name.  The completion stops there
unless working on the next word.

How does "java" itself distinguish between a class name and a file
name?  Just whether the string ends in ".java"?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Java completion for Java files
  2024-02-05 20:43 ` Bart Schaefer
@ 2024-02-06  2:47   ` Henri Tremblay
  2024-02-06 10:23     ` Michal Politowski
  0 siblings, 1 reply; 5+ messages in thread
From: Henri Tremblay @ 2024-02-06  2:47 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1838 bytes --]

Yes.
Let's say you have a file in a directory:
"src/main/java/org/zsh/Main.java". The class is named Main and is in the
package org.zsh in this case.
If you compile it with "javac src/main/java/org/zsh/Main.java" it will
generate a file named "src/main/java/org/zsh/Main.class".

So, if you execute it the old way, you would do "java -cp src/main/java
org.zsh.Main" which means "Please execute the class with a main() method
that is called Main and found in the package org.zsh. The classpath where
this class can be found is "src/main".

If you execute it the new way, you don't need to compile with javac. So you
only have "src/main/java/org/zsh/Main.java".
And you will execute by doing "java src/main/java/org/zsh/Main.java" and
that's it.

Bottom line, indeed, the ".java" at the end tells that it's a java source
file and not a compile class found in the classpath that you want to
execute.


On Mon, 5 Feb 2024 at 15:44, Bart Schaefer <schaefer@brasslantern.com>
wrote:

> On Mon, Feb 5, 2024 at 10:04 AM Henri Tremblay <henri.tremblay@gmail.com>
> wrote:
> >
> > Java now supports (since Java 10 I think) command lines like
> >
> > java Math.java
> >
> > It will then just compile and launch that java file. But zsh won't
> autocomplete for that. It only wants a jar, class file or whatever.
>
> The issue is here in the _arguments setup for _java:
>
>     '(-):class:_java_class -m main ${(kv)opt_args[(i)(-classpath|-cp)]}' \
>     '*::args:= _normal' \
>      && return 0
>
> The (-) says that the first word after "java" must either be an option
> (start with "-") or must be a class name.  The completion stops there
> unless working on the next word.
>
> How does "java" itself distinguish between a class name and a file
> name?  Just whether the string ends in ".java"?
>

[-- Attachment #2: Type: text/html, Size: 2513 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Java completion for Java files
  2024-02-06  2:47   ` Henri Tremblay
@ 2024-02-06 10:23     ` Michal Politowski
  2024-02-07 16:15       ` Henri Tremblay
  0 siblings, 1 reply; 5+ messages in thread
From: Michal Politowski @ 2024-02-06 10:23 UTC (permalink / raw)
  To: zsh-users

Dnia Mon,  5 Feb 2024 21:47:48 -0500, Henri Tremblay napisał(a):
> Yes.
> Let's say you have a file in a directory:
> "src/main/java/org/zsh/Main.java". The class is named Main and is in the
> package org.zsh in this case.
> If you compile it with "javac src/main/java/org/zsh/Main.java" it will
> generate a file named "src/main/java/org/zsh/Main.class".
> 
> So, if you execute it the old way, you would do "java -cp src/main/java
> org.zsh.Main" which means "Please execute the class with a main() method
> that is called Main and found in the package org.zsh. The classpath where
> this class can be found is "src/main".
> 
> If you execute it the new way, you don't need to compile with javac. So you
> only have "src/main/java/org/zsh/Main.java".
> And you will execute by doing "java src/main/java/org/zsh/Main.java" and
> that's it.
> 
> Bottom line, indeed, the ".java" at the end tells that it's a java source
> file and not a compile class found in the classpath that you want to
> execute.

Not exactly. You can have a class named java on the classpath.

The precise behaviour as specified here https://openjdk.org/jeps/330#Description
(since Java 11) seems to be: if the first non-option argument is
- a name of an existing file with .java extension, or
- a name of an existing file and the --source <version> option is given
then compile/run the source.

> On Mon, 5 Feb 2024 at 15:44, Bart Schaefer <schaefer@brasslantern.com>
> wrote:
> 
> > On Mon, Feb 5, 2024 at 10:04 AM Henri Tremblay <henri.tremblay@gmail.com>
> > wrote:
> > >
> > > Java now supports (since Java 10 I think) command lines like
> > >
> > > java Math.java
> > >
> > > It will then just compile and launch that java file. But zsh won't
> > autocomplete for that. It only wants a jar, class file or whatever.
> >
> > The issue is here in the _arguments setup for _java:
> >
> >     '(-):class:_java_class -m main ${(kv)opt_args[(i)(-classpath|-cp)]}' \
> >     '*::args:= _normal' \
> >      && return 0
> >
> > The (-) says that the first word after "java" must either be an option
> > (start with "-") or must be a class name.  The completion stops there
> > unless working on the next word.
> >
> > How does "java" itself distinguish between a class name and a file
> > name?  Just whether the string ends in ".java"?
> >

-- 
Michał Politowski
Talking has been known to lead to communication if practiced carelessly.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Java completion for Java files
  2024-02-06 10:23     ` Michal Politowski
@ 2024-02-07 16:15       ` Henri Tremblay
  0 siblings, 0 replies; 5+ messages in thread
From: Henri Tremblay @ 2024-02-07 16:15 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 2733 bytes --]

Thanks for the precision.
I wasn't aware of that detail.

On Tue, 6 Feb 2024 at 05:24, Michal Politowski <mpol@meep.pl> wrote:

> Dnia Mon,  5 Feb 2024 21:47:48 -0500, Henri Tremblay napisał(a):
> > Yes.
> > Let's say you have a file in a directory:
> > "src/main/java/org/zsh/Main.java". The class is named Main and is in the
> > package org.zsh in this case.
> > If you compile it with "javac src/main/java/org/zsh/Main.java" it will
> > generate a file named "src/main/java/org/zsh/Main.class".
> >
> > So, if you execute it the old way, you would do "java -cp src/main/java
> > org.zsh.Main" which means "Please execute the class with a main() method
> > that is called Main and found in the package org.zsh. The classpath where
> > this class can be found is "src/main".
> >
> > If you execute it the new way, you don't need to compile with javac. So
> you
> > only have "src/main/java/org/zsh/Main.java".
> > And you will execute by doing "java src/main/java/org/zsh/Main.java" and
> > that's it.
> >
> > Bottom line, indeed, the ".java" at the end tells that it's a java source
> > file and not a compile class found in the classpath that you want to
> > execute.
>
> Not exactly. You can have a class named java on the classpath.
>
> The precise behaviour as specified here
> https://openjdk.org/jeps/330#Description
> (since Java 11) seems to be: if the first non-option argument is
> - a name of an existing file with .java extension, or
> - a name of an existing file and the --source <version> option is given
> then compile/run the source.
>
> > On Mon, 5 Feb 2024 at 15:44, Bart Schaefer <schaefer@brasslantern.com>
> > wrote:
> >
> > > On Mon, Feb 5, 2024 at 10:04 AM Henri Tremblay <
> henri.tremblay@gmail.com>
> > > wrote:
> > > >
> > > > Java now supports (since Java 10 I think) command lines like
> > > >
> > > > java Math.java
> > > >
> > > > It will then just compile and launch that java file. But zsh won't
> > > autocomplete for that. It only wants a jar, class file or whatever.
> > >
> > > The issue is here in the _arguments setup for _java:
> > >
> > >     '(-):class:_java_class -m main
> ${(kv)opt_args[(i)(-classpath|-cp)]}' \
> > >     '*::args:= _normal' \
> > >      && return 0
> > >
> > > The (-) says that the first word after "java" must either be an option
> > > (start with "-") or must be a class name.  The completion stops there
> > > unless working on the next word.
> > >
> > > How does "java" itself distinguish between a class name and a file
> > > name?  Just whether the string ends in ".java"?
> > >
>
> --
> Michał Politowski
> Talking has been known to lead to communication if practiced carelessly.
>
>

[-- Attachment #2: Type: text/html, Size: 3767 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-02-07 16:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-05 18:04 Java completion for Java files Henri Tremblay
2024-02-05 20:43 ` Bart Schaefer
2024-02-06  2:47   ` Henri Tremblay
2024-02-06 10:23     ` Michal Politowski
2024-02-07 16:15       ` Henri Tremblay

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).