-
Notifications
You must be signed in to change notification settings - Fork 870
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
Enhanced instanceOf not supported (IntelliJ IDEA plugin) #679
Comments
Hey @Voltariuss, welcome! As an (ex-)user of GJF, I've seen quite a few issues here recently where GJF threw exceptions when trying to format code with certain features (like enhanced switches and text blocks) that the JVM that GJF is run on doesn't itself support. I understand this is a limitation of GJF, because it uses private What version of Java are you using to run GJF? A version older than 17, perhaps? (Or whatever version the enhanced instanceof and text blocks came out - I'm primarily a Kotlin dev nowadays, so I've not been fully keeping up.) If so, what happens if you do use Java 17, or the version when those features came out? I hope this helps! |
A word of caution though: to run GJF on Java 16+, you need to run it with these command-line flags: java \
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \
-jar google-java-format-1.12.0-all-deps.jar <options> [files...] Copied from https://github.com/google/google-java-format#jdk-16. |
Hi @jbduncan! Thank for the answer. I configure my IntelliJ IDEA to use the JDK version 16 and both features presented here are included in this version. Furthermore, I've already seen the caution you quote, but it does not apply in my case because I use directly the IntelliJ IDEA plugin. Sooo... I don't think I can do anything in my case and it's why I think it's an issue of the plugin. But maybe I'm wrong... |
@Voltariuss Thanks for getting back so quickly! Ah, my apologies then. This is where my understanding stops, but I guess GJF legitimately doesn't know how to format those features yet. So I'll leave it to the GJF devs to get back to you on this one. :) |
@Voltariuss Oh, what happens if you use the latest version, 1.12, as a command-line app like my example above? If the error persists, it means GJF doesn't have a fix yet, but if it disappears, then it just means the GJF devs have not yet released 1.12 on the JetBrains Marketplace. |
This issue still exist in 1.13 version. |
Does this issue reproduce if you format one of the files where you're seeing problems with the CLI? Do you know which JDK version your IntelliJ install is using? The formatter has basic support for pattern matching in
|
Tentatively closing, please let me know if you're seeing issues with pattern matching in |
Hey @cushon Thanks for the reply, and sorry for missing your first response: I didn't received any notification about it... The issue still persisting for the public class Test {
public static void main(String[] args) {
Object o = new String("Test");
if (o instanceof String s){
System.out.println(s);
}
}
} System information: |
@Voltariuss, i think this issue is related to #533 You can check this comment for a workaround #533 (comment) |
The shared solution worked for me, thanks for your time by redirecting me to this comment! :) |
Hello,
IntelliJ IDEA: 2021.2.3 (Ultimate Version) Build #IU-212.5457.46, built on October 12, 2021.
google-java-format plugin version: 1.10.0.0
Windows 10
All is explained in the title.
What I see precisely: when I write an enhanced
instanceof
instruction, I can't be able to reorganise parameters of methods within multiple line instead of only one in case of line weight overflow.The parameters remain like this:

In other cases (like remove the new Java feature), I success to obtain this:

Furthermore, I think this is the whole file which can't be formatted, but I don't check it.
It's possible that the issue concern other new Java features.
The text was updated successfully, but these errors were encountered: