Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

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

Open
1 task
felixhao28 opened this issue Nov 23, 2018 · 7 comments
Assignees

Comments

@felixhao28
Copy link

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
Copy link
Author

felixhao28 commented Nov 23, 2018

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
Copy link
Contributor

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

@rsese
Copy link

rsese commented Jun 27, 2019

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).

@rsese rsese changed the title Variable definition error with class name starting with underscore Variable definition error with class name starting with underscore or lowercase letter Jun 27, 2019
@sadikovi
Copy link
Contributor

sadikovi commented Jun 27, 2019

@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
Copy link
Author

What is tree-sitter?

@calebmeyer
Copy link

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
Copy link

@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!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants