google / google-java-format

Reformats Java source code to comply with Google Java Style.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for Java Records on Java 17

bobaikato opened this issue · comments

Unlike Classes, Records don't get formatted by google-java-format.

Any plan to support Records?

Records should be supported, but note that you'll need to run google-java-format on a JDK version that is new enough to also support records, i.e. it doesn't work when running on JDK 11

@cushon I am using Java 17. But Record doesn't work on IntelliJ.

I'm assuming you're talking about the Google Java Format plugin for IntelliJ. Does IntelliJ itself runs with Java 17? See #533

Thanks, the guide was hellpful.

Can you make me understand why the plugin doesn't just work? It works fine with Java Classes, not Record.

The setup isn't convenient but works.

Can you make me understand why the plugin doesn't just work? It works fine with Java Classes, not Record.

@B0BAI The reason why it doesn't just work is because google-java-format uses a Java-internal API, com.sun.tools.javac, to understand and reformat Java source code.

This API changes depending on which version of Java you're running. So when you run GJF on versions of Java without records, GJF in turn doesn't know how to format them.

Yes, it's really silly! I don't actually know why the GJF developers decided to use this API in the first place, but it's what we've got.

I hope this clarifies things.

To add to my last message, this means that if the version of Java that IntelliJ runs on isn't Java 16+ (I believe IntelliJ uses Java 11 right now), then the GJF plugin can't understand and format records.

Make a lot of sense. I appreciate you taking your time to explain this to me.