Open LiJun990105 opened 1 month ago
The formatter has support for those features:
$ java -jar google-java-format-1.22.0-all-deps.jar T.java
package com.google.errorprone.bugpatterns;
class T {
private static <V> void add(JsonNode jsonNode, String key, V value) {
switch (value) {
case String s -> ((ObjectNode) jsonNode).put(key, s);
case Short i -> ((ObjectNode) jsonNode).put(key, i);
case Integer i -> ((ObjectNode) jsonNode).put(key, i);
case Long l -> ((ObjectNode) jsonNode).put(key, 1);
case Float v -> ((ObjectNode) jsonNode).put(key, v);
case Double v -> ((ObjectNode) jsonNode).put(key, v);
case BigDecimal bigDecimal -> ((ObjectNode) jsonNode).put(key, bigDecimal);
case BigInteger bigInteger -> ((ObjectNode) jsonNode).put(key, bigInteger);
case Boolean b -> ((ObjectNode) jsonNode).put(key, b);
case byte[] bytes -> ((ObjectNode) jsonNode).put(key, bytes);
case null, default -> ((ObjectNode) jsonNode).put(key, to(value));
}
}
}
The issue is that it needs to be running on a JDK version that is new enough to recognize them, so if IntelliJ is using an older boot JDK it won't work. Configuring IntelliJ to run on JDK 22 works around the error: https://intellij-support.jetbrains.com/hc/en-us/articles/206544879-Selecting-the-JDK-version-the-IDE-will-run-under