Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should support pattern matching guards #535

Closed
vincentditlevinz opened this issue May 2, 2022 · 4 comments · Fixed by #559
Closed

Should support pattern matching guards #535

vincentditlevinz opened this issue May 2, 2022 · 4 comments · Fixed by #559

Comments

@vincentditlevinz
Copy link

Prettier-Java 1.6.1

Input:

package com.vimat.model;

public record Buyer(String name, double bestPrice, double joker) {
  public boolean hasBestOffer(Buyer other) {
      return switch (other) { 
        case null -> true;
        case Buyer b && this.bestPrice > b.bestPrice -> true;
        default -> false;
      };
    }
}

Output:

[ERROR] src/main/java/com/vimat/model/Buyer.java: Error: Sad sad panda, parsing errors detected in line: 7, column: 20!
[ERROR] Expecting --> '->' <-- but found --> '&&' <--!
[ERROR]         ->compilationUnit
[ERROR]         ->ordinaryCompilationUnit
[ERROR]         ->typeDeclaration
[ERROR]         ->classDeclaration
[ERROR]         ->recordDeclaration
[ERROR]         ->recordBody
[ERROR]         ->recordBodyDeclaration
[ERROR]         ->classBodyDeclaration
[ERROR]         ->classMemberDeclaration
[ERROR]         ->methodDeclaration
[ERROR]         ->methodBody
[ERROR]         ->block
[ERROR]         ->blockStatements
[ERROR]         ->blockStatement
[ERROR]         ->statement
[ERROR]         ->statementWithoutTrailingSubstatement
[ERROR]         ->returnStatement
[ERROR]         ->expression
[ERROR]         ->ternaryExpression
[ERROR]         ->binaryExpression
[ERROR]         ->unaryExpression
[ERROR]         ->primary
[ERROR]         ->primaryPrefix
[ERROR]         ->switchStatement
[ERROR]         ->switchBlock
[ERROR]         ->switchRule
[ERROR]     at Object.parse (/home/vinz/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.17/prettier-maven-plugin-0.17-prettier-java-1.6.1/prettier-java/node_modules/java-parser/src/index.js:41:11)
[ERROR]     at Object.parse (/home/vinz/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.17/prettier-maven-plugin-0.17-prettier-java-1.6.1/prettier-java/node_modules/prettier-plugin-java/dist/parser.js:4:26)
[ERROR]     at Object.parse$a [as parse] (/home/vinz/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.17/prettier-maven-plugin-0.17-prettier-java-1.6.1/prettier-java/node_modules/prettier/index.js:13652:19)
[ERROR]     at coreFormat (/home/vinz/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.17/prettier-maven-plugin-0.17-prettier-java-1.6.1/prettier-java/node_modules/prettier/index.js:15183:16)
[ERROR]     at formatWithCursor$1 (/home/vinz/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.17/prettier-maven-plugin-0.17-prettier-java-1.6.1/prettier-java/node_modules/prettier/index.js:15423:14)
[ERROR]     at Object.formatWithCursor (/home/vinz/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.17/prettier-maven-plugin-0.17-prettier-java-1.6.1/prettier-java/node_modules/prettier/index.js:60171:12)
[ERROR]     at format$1 (/home/vinz/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.17/prettier-maven-plugin-0.17-prettier-java-1.6.1/prettier-java/node_modules/prettier/bin-prettier.js:16640:21)
[ERROR]     at Object.formatFiles$1 [as formatFiles] (/home/vinz/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.17/prettier-maven-plugin-0.17-prettier-java-1.6.1/prettier-java/node_modules/prettier/bin-prettier.js:16754:22)
[ERROR]     at async main (/home/vinz/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.17/prettier-maven-plugin-0.17-prettier-java-1.6.1/prettier-java/node_modules/prettier/bin-prettier.js:18616:5)
[ERROR]     at async Object.run (/home/vinz/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.17/prettier-maven-plugin-0.17-prettier-java-1.6.1/prettier-java/node_modules/prettier/bin-prettier.js:18559:5)

Expected behavior:

Should support pattern matching guards

@clementdessoude
Copy link
Contributor

Thank you for reporting this @vincentditlevinz ! We indeed did not introduce this preview feature yet, but it should be feasible without breaking the existing !

@fischermatte
Copy link

We are having the same issue. Is there any documentation which states that prettier-java is ready for Java 17+ ? We are having other issues with records as well.

@clementdessoude
Copy link
Contributor

Hello @vincentditlevinz and @fischermatte ! The #559 should fix the issue !

@fischermatte could you create another issue for the records issue you have ? It would be very helpful in order to provide some fixes !

@fischermatte
Copy link

fischermatte commented Dec 1, 2022

@clementdessoude thx a lot! I will try v2 and let you know if there is still something breaking.

Update: I checked it and it looks like there are no troubles with records when running spotless:apply. So 👍for fixing this! What occurs strange to me is now with v2: When I run spotless:check after (!) I sucessfully ran spotless:apply it still fails with plenty of errors. Shouldn't both goals work the same? Anyway - this is another issue not related to this one here.

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

Successfully merging a pull request may close this issue.

3 participants