universal-ctags / ctags

A maintained ctags implementation
https://ctags.io
GNU General Public License v2.0
6.51k stars 622 forks source link

Java: Local classes are ignored #1739

Open pyropeter opened 6 years ago

pyropeter commented 6 years ago

Steps to reproduce:

Expected:

I expect ctags to create four tags for greet. It only creates one, inside the interface definition.

The option --kinds-Java=l, which is described with local variables, surprisingly influences this: An additional tag is emitted for the greet implementation inside EnglishGreeting. Still no tags are created for the implementations inside the anonymous classes.

masatake commented 6 years ago

Thank you for reporting. Reproduced. Could you give me shorter input?

masatake commented 6 years ago

It seems that fixing this is not so easy.

masatake commented 6 years ago

The input is recorded as a test case triggering the bug. See #1756.

masatake commented 6 years ago

I'm working on reimplenting the java parser with using a parser generator. What I got today is what you wanted:)

I have to work on this item more.

[yamato@master]~/var/ctags-peg/Units/parser-java.r/anonymous-class.b% cat input.java 
cat input.java 
// See #1739
public class input {
    interface greeting {
    public void greet(String word);
    }

    public void hello () {
    greeting g = new greeting() {
        public void greet (String word) {
        }
    };
    g.greet("hello");
    }
    public void bye () {
    greeting h = new greeting() {
        public void greet (String word) {
        }
    };
    h.greet("bye");
    }

}
[yamato@master]~/var/ctags-peg/Units/parser-java.r/anonymous-class.b% ../../../ctags --kinds-Java=+l --sort=no --fields=+liK -o - input.java
../../../ctags --kinds-Java=+l --sort=no --fields=+liK -o - input.java
input   input.java  /^public class input {$/;"  class   language:Java
greeting    input.java  /^    interface greeting {$/;"  interface   language:Java   class:input
greet   input.java  /^  public void greet(String word);$/;" method  language:Java   interface:input.greeting
hello   input.java  /^    public void hello () {$/;"    method  language:Java   class:input
g   input.java  /^  greeting g = new greeting() {$/;"   local   language:Java   method:input.hello
AnonymousClass88b977650101  input.java  /^  greeting g = new greeting() {$/;"   class   language:Java   method:input.hello  inherits:greeting
greet   input.java  /^      public void greet (String word) {$/;"   method  language:Java   class:input.hello.AnonymousClass88b977650101
bye input.java  /^    public void bye () {$/;"  method  language:Java   class:input
h   input.java  /^  greeting h = new greeting() {$/;"   local   language:Java   method:input.bye
AnonymousClass88b977650201  input.java  /^  greeting h = new greeting() {$/;"   class   language:Java   method:input.bye    inherits:greeting
greet   input.java  /^      public void greet (String word) {$/;"   method  language:Java   class:input.bye.AnonymousClass88b977650201
masatake commented 5 years ago

I have measured the performance of the new Java parser. Too slow. 30 ~ 50 times slower than the current implementation.

I have to rewrite a new one without the parser generator.