atom / language-java

Java package for Atom
Other
62 stars 58 forks source link

`new` operator does not work well with full qualifier #181

Open felixhao28 opened 5 years ago

felixhao28 commented 5 years ago

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

sadikovi commented 5 years ago

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

felixhao28 commented 5 years ago

d48e7137f6634cc094f092b68e6b110f51f47630

felixhao28 commented 5 years ago

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

sadikovi commented 5 years ago

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

Vigilans commented 4 years ago

The regression is caused in these lines:

https://github.com/atom/language-java/blob/47ddbb650f00b80dbf54205a2d27ad2dd7ec9678/grammars/java.cson#L1059-L1062

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

sadikovi commented 4 years ago

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

Vigilans commented 4 years ago

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:

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.