HubSpot / prettier-maven-plugin

Apache License 2.0
116 stars 23 forks source link

Error for Java 14 Switch #32

Closed calvinbayer closed 3 years ago

calvinbayer commented 3 years ago

Unfortunately, Prettier does not work with the "switch" expression in Java 14:

public String foo(int number) {
    return switch (number) {
        case 1 -> "one";
        case 5 -> "five";
        case 10 -> "ten";
    }
}
[ERROR] [error] src/Foo.java: Error: Sad sad panda, parsing errors detected in line: 44, column: 30!
[ERROR] [error] Expecting: one of these possible Token sequences:
[ERROR] [error]   1. ['(']
[ERROR] [error]   2. [Identifier]
[ERROR] [error]   3. ['UnaryPrefixOperator']
[ERROR] [error]   4. ['DecimalLiteral']
[ERROR] [error]   5. ['HexLiteral']
[ERROR] [error]   6. ['OctalLiteral']
[ERROR] [error]   7. ['BinaryLiteral']
[ERROR] [error]   8. ['FloatLiteral']
[ERROR] [error]   9. ['HexFloatLiteral']
[ERROR] [error]   10. ['true']
[ERROR] [error]   11. ['false']
[ERROR] [error]   12. ['CharLiteral']
[ERROR] [error]   13. ['StringLiteral']
[ERROR] [error]   14. ['null']
[ERROR] [error]   15. ['this']
[ERROR] [error]   16. ['void']
[ERROR] [error]   17. ['byte']
[ERROR] [error]   18. ['short']
[ERROR] [error]   19. ['int']
[ERROR] [error]   20. ['long']
[ERROR] [error]   21. ['char']
[ERROR] [error]   22. ['float']
[ERROR] [error]   23. ['double']
[ERROR] [error]   24. ['boolean']
[ERROR] [error]   25. ['@']
[ERROR] [error]   26. [Identifier]
[ERROR] [error]   27. ['super']
[ERROR] [error]   28. ['(']
[ERROR] [error]   29. ['new']
[ERROR] [error] but found: 'switch'!
lorsatti commented 3 years ago

I think that it's covered by https://github.com/jhipster/prettier-java/issues/277

jhaber commented 3 years ago

Indeed, 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 might be worth bumping that prettier-java issue