google / google/google-java-format

Allow to provide source file java language version

Abierto
#975 0 comentarios 1 reacción 0 asignados Ver en GitHub
Lenguaje dominante
Java
Estrellas
6.2k
Forks
937
Merge medio
6 min
PR fusionados (30 d)
3

Descripción

When formatting files with `google-java-format`, the parser uses the same source version as its own runtime version (running `google-java-format` on JDK X implies that that Java source files are conformant with JDK `X`), but this is actually not necessary true and files may be aiming for a different (older) Java version. Nowadays it is a common pattern to use `--release` flag to compiler for a specific older version of the language using a newer JDK.

Unfortunately Java language is not fully backward compatible and some features have introduced breaking changes like reserved identifiers `var`, `with, `yield` or `record` (see current list in [JLS Section 3.8](https://docs.oracle.com/javase/specs/jls/se21/html/jls-3.html#jls-3.8))

For files who were designed to compile with an older Java version and who are using now reserved identifiers, this cause their processing with `google-java-format` using a recent JDK version to fail.

A solution would be to allow to pass either the `source` or the `release` option to the java parser to adapt its own parsing to the java version used by the file.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.