Skip to content

Commit

Permalink
Add support for yield statement
Browse files Browse the repository at this point in the history
Implement visitYield.

Fixes google#489

from ntkoopman:yield b46d1f0

COPYBARA_INTEGRATE_REVIEW=google#489
PiperOrigin-RevId: 314633394
  • Loading branch information
ntkoopman authored and google-java-format Team committed Jun 4, 2020
1 parent 22d8c55 commit 5202af9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ public Void visitBindingPattern(BindingPatternTree node, Void unused) {
@Override
public Void visitYield(YieldTree node, Void aVoid) {
sync(node);
return super.visitYield(node, aVoid);
token("yield");
builder.space();
scan(node.getValue(), null);
token(";");
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,23 @@ class ExpressionSwitch {
default -> odd(x - 1);
};
}
}

{
int f = switch (i) {
case 0 -> 0;
default -> {
yield n / i;
}
};

int g = switch (i) {
case 0: yield 0;
default: yield n/i;
};

switch (i) {
case 0 -> { System.out.println("0"); }
default -> System.out.println("default");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,29 @@ class ExpressionSwitch {
default -> odd(x - 1);
};
}

{
int f =
switch (i) {
case 0 -> 0;
default -> {
yield n / i;
}
};

int g =
switch (i) {
case 0:
yield 0;
default:
yield n / i;
};

switch (i) {
case 0 -> {
System.out.println("0");
}
default -> System.out.println("default");
}
}
}

0 comments on commit 5202af9

Please sign in to comment.