Skip to content

Commit 075e025

Browse files
cushongoogle-java-format Team
authored andcommitted
Prepare to changes to var in AST
After https://bugs.openjdk.org/browse/JDK-8268850, `VariableTree#getType` returns a new AST node `VarTypeTree` for variables declared with `var`. The new node could be handled in the visitor by implementing `visitVarType`, but that API is only available on the latest JDK versions using var, which would require creating a new version-specific visitor implementation. To defer doing that, this fix re-orders the logic that handles variable types to check if the next token is `var` first, to avoid needing to handle the new AST node. PiperOrigin-RevId: 876244813
1 parent b0ef30a commit 075e025

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3686,15 +3686,15 @@ protected int declareOne(
36863686
builder.open(ZERO);
36873687
{
36883688
visitAnnotations(annotations, BreakOrNot.NO, BreakOrNot.YES);
3689-
if (typeWithDims.isPresent() && typeWithDims.get().node != null) {
3689+
if (isVar) {
3690+
token("var");
3691+
} else if (typeWithDims.isPresent() && typeWithDims.get().node != null) {
36903692
scan(typeWithDims.get().node, null);
36913693
int totalDims = dims.size();
36923694
builder.open(plusFour);
36933695
maybeAddDims(dims);
36943696
builder.close();
36953697
baseDims = totalDims - dims.size();
3696-
} else if (isVar) {
3697-
token("var");
36983698
} else {
36993699
scan(type, null);
37003700
}

0 commit comments

Comments
 (0)