atom / language-java

Java package for Atom
Other
62 stars 58 forks source link

Variable definition error with class name starting with underscore or lowercase letter #174

Open felixhao28 opened 6 years ago

felixhao28 commented 6 years ago

Prerequisites

Description

If the class name starts with underscore, the tokenizing of the whole line of variable definition breaks.

public class A {
    public void drop() {
        BaseActionController actionController = new _BaseActionController();
        _BaseActionController actionController = new _BaseActionController();
        BaseActionController actionController = new BaseActionController();
    }
}

image

Steps to Reproduce

  1. Open new tab and select Java language.
  2. Paste code into the editor.

Expected behavior: [What you expect to happen]

_BaseActionController gets treated equally like BaseActionController.

Actual behavior: [What actually happens]

The whole line is not tokenized.

Reproduces how often: [What percentage of the time does it reproduce?]

Versions

You can get this information from copy and pasting the output of atom --version and apm --version from the command line. Also, please include the OS and what version of the OS you're running.

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.

felixhao28 commented 6 years ago

Same happens if the class name starts with a lower case character. And the behavior differs a little bit depending on whether the class is fully consisted of lower case characters.

signPdf sign = new signPdf(userinfor.getUserMail(), userinfor.getUserId(), file, fileSign);
signpdf sign = new signPdf(userinfor.getUserMail(), userinfor.getUserId(), file, fileSign);
SignPdf sign = new signPdf(userinfor.getUserMail(), userinfor.getUserId(), file, fileSign);
sadikovi commented 6 years ago

That is interesting. We might need to extend pattern to handle these characters. Thanks! I will have a look.

rsese commented 5 years ago

Same happens if the class name starts with a lower case character.

This was mentioned on the message board recently:

https://discuss.atom.io/t/java-syntax-highlighting-for-lowercase-object-variable-names/66322

Their example:

public class Test {
  public static void main(String[] args) {
    for (int i = 0; i < 10; i++) {
      System.out.println(i);
    }

    someObjectType tcObj = null;

    for (int i = 0; i < 10; i++) {
      System.out.println(i);
    }
  }
}

And screenshot:

(See someObjectType).

sadikovi commented 5 years ago

@rsese this issue does not exist tree-sitter, along with other stuff like generics, variables, multiline methods, etc. that we struggle to fix properly with regex.

I already use experimental tree-sitter when working with Java; and I am trying to merge my PR as soon as possible to get that into Atom release.

Thanks for letting me know! We can still patch this in TextMate grammar. I will take a look this weekend if it is okay (a bit snowed under with some other stuff at work), or can do tonight, if it is urgent. Let me know!

felixhao28 commented 5 years ago

What is tree-sitter?

calebmeyer commented 5 years ago

Text-mate is where the original syntax highlighting for Atom (and sublime, and I believe VS Code) comes from. It's a whole bunch of regexes with some smarts layered on top so they can do more than a single regex could.

Tree sitter is a new parser generator tool that creates much more correct (and often faster!) parsers using syntax trees: http://tree-sitter.github.io/tree-sitter/

mckinleyrebecca commented 5 years ago

@sadikovi I made the post on the message board about the lowercase object types. This issue is not urgent, but thank you for looking into it!