-
Notifications
You must be signed in to change notification settings - Fork 864
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust indentation of line comments inside expression switches
For statement switches there's some ambiguity about whether a comment documents the previous or next case: ``` case 1: // case 1 falls through to 2 case 2: doSomething() ``` ``` // this is information about case 1 case 1: // this is information about case 2 case 2: doSomething() ``` For expression switches there is no fall through, so assume that a line comments before a case label always apply to the case label after it. PiperOrigin-RevId: 644163145
- Loading branch information
Showing
4 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
core/src/test/resources/com/google/googlejavaformat/java/testdata/SwitchComment.input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class T { | ||
void f(String v) { | ||
int x = | ||
switch (v) { | ||
// this is a line comment about "zero" | ||
case "zero" -> 0; | ||
case "one" -> | ||
// this is a line comment about "one" | ||
1; | ||
case "two" -> // this is a line comment about "two" | ||
2; | ||
default -> -1; | ||
}; | ||
} | ||
|
||
void g(String v) { | ||
int x = | ||
switch (v) { | ||
// this is a line comment about "zero" | ||
case "zero": | ||
return 0; | ||
case "one": | ||
// this is a line comment about "one" | ||
return 1; | ||
case "two": // this is a line comment about "two" | ||
return 2; | ||
default: | ||
return -1; | ||
}; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
core/src/test/resources/com/google/googlejavaformat/java/testdata/SwitchComment.output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class T { | ||
void f(String v) { | ||
int x = | ||
switch (v) { | ||
// this is a line comment about "zero" | ||
case "zero" -> 0; | ||
case "one" -> | ||
// this is a line comment about "one" | ||
1; | ||
case "two" -> // this is a line comment about "two" | ||
2; | ||
default -> -1; | ||
}; | ||
} | ||
|
||
void g(String v) { | ||
int x = | ||
switch (v) { | ||
// this is a line comment about "zero" | ||
case "zero": | ||
return 0; | ||
case "one": | ||
// this is a line comment about "one" | ||
return 1; | ||
case "two": // this is a line comment about "two" | ||
return 2; | ||
default: | ||
return -1; | ||
}; | ||
} | ||
} |