HubSpot / prettier-maven-plugin

Apache License 2.0
116 stars 23 forks source link

Java 15 multi-line strings #30

Closed binkley closed 3 years ago

binkley commented 3 years ago

The parser for prettier doesn't like Java 15 multi-line strings. To wit:

public class Java15 {
    public static void main(String[] args) {
        Object x = 7;
        final var javaVersion = System.getProperty("java.version");
        if (null != javaVersion) x = """
                Uncle
                Bob says: %s""".formatted(javaVersion);
        if (x instanceof String msg) out.println(new Fooby<>(3, msg));
    }
}

produces:

[ERROR] [error] src/main/java/hm/binkley/Java15.java: Error: Sad sad panda, parsing errors detected in line: 13, column: 40!
[ERROR] [error] Expecting --> ';' <-- but found --> '"
[ERROR] [error]                 Uncle
[ERROR] [error]                 Bob says: %s"' <--!

(The sample code was to try out some Java 15 features, hence it's unseriousness.)

jhaber commented 3 years ago

I don't actually own the parser or formatting code, all of that lives in https://github.com/jhipster/prettier-java

This repo just packages up the functionality into a Maven module. It looks like there's an open issue for Java 13, it might be worth bumping that issue and trying to pull Java 15 syntax into scope as well: https://github.com/jhipster/prettier-java/issues/277