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

new operator does not work well with full qualifier #181

Open

Description

@felixhao28

Description

public class A {
    void f() {
        java.io.File myFile = java.io.File.create(folderPath);
        java.io.File myFile = new java.io.File(folderPath);
    }
}

image

Expected behavior: [What you expect to happen]

"java.io" after new is not recognized as part of class name. It should be separated "java", ".", "io".

Activity

  1. sadikovi commented on Dec 3, 2018

    @sadikovi
    Contributor

    Can you include the language-java version that you are testing against?

  2. felixhao28 commented on Dec 3, 2018

    @felixhao28
    Author
  3. felixhao28 commented on Dec 4, 2018

    @felixhao28
    Author

    might be related, extends does not work well with full qualifiers either:

    class RenderType extends com.jfinal.plugin.ehcache.RenderType {
        public static final int BEETL_RENDER = 6;
    }

    image

  4. sadikovi commented on Dec 4, 2018

    @sadikovi
    Contributor

    This looks like a regression, because it was fixed at some point, if I remember correctly. I will investigate.

  5. Vigilans commented on Nov 27, 2019

    @Vigilans
    Contributor

    The regression is caused in these lines:

    # If the above fails *then* just look for Wow
    # (must be followed by a variable name, we use '\n' to cover multi-line definitions,
    # or varargs for function definitions)
    'match': '\\b((?:[A-Za-z_]\\w*\\s*\\.\\s*)*[A-Z_]\\w*)\\b((?=\\s*[A-Za-z$_\\n])|(?=\\s*\\.\\.\\.))'

    the constraint must be followed by a variable name prevents java.io.File to be recognized as a type.

  6. sadikovi commented on Dec 7, 2019

    @sadikovi
    Contributor

    That's not correct. It does get recognised, the regex skips the first item in fully qualified class name - just need to fix that. It would be tricky to fix all of the situations - I have a tree-sitter PR that would address this issue (and bunch of others).

  7. Vigilans commented on Dec 7, 2019

    @Vigilans
    Contributor

    It would be fixed naturally if java.io.File is recoginized as a type and fall into object-type scope to be parsed...

    @sadikovi If you agree type in constructor call should be rendered as type (where langs like cpp & ts do so), you can take a look at this branch at your convenience, which is come up to solve #216.

    It is simple enough by just doing following things:

    • Add (?=\\() match to object-type, to allow type to be recognized in a constructor call.
    • Remove function-call and parens from anonymous-classes-and-new, and patch a (...) matching for constructor calls.
    • Fix the udpated scopes in test by:
      • Replace all 'meta.function-call.java', 'entity.name.function.java' with 'storage.type.java';
      • Remove 'meta.function-call.java' before 'punctuation.definition.parameters.*.bracket.round.java'

    Effect:


    Update:

    Oh, sorry for that I ignored the extends case. What I talked about is about the new case in the title, and it's related to object-type. The extends case is caused by object-type-inherited.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions