-
Notifications
You must be signed in to change notification settings - Fork 861
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update handling of pattern matching in switch
for AST changes in Java 17, in particular the addition of CaseTree#getLabels, which returns a single `DefaultCaseLabelTree` to represent the default case. #683 #684 PiperOrigin-RevId: 411074295
- Loading branch information
Showing
6 changed files
with
86 additions
and
36 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
14 changes: 14 additions & 0 deletions
14
core/src/test/resources/com/google/googlejavaformat/java/testdata/I683.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,14 @@ | ||
interface Test { | ||
|
||
static class Test1 implements Test{} | ||
static class Test2 implements Test{} | ||
|
||
public static void main(String[] args) { | ||
Test test = new Test1(); | ||
switch (test) { | ||
case Test1 test1 -> {} | ||
case Test2 test2 -> {} | ||
default -> throw new IllegalStateException("Unexpected value: " + test); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
core/src/test/resources/com/google/googlejavaformat/java/testdata/I683.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,15 @@ | ||
interface Test { | ||
|
||
static class Test1 implements Test {} | ||
|
||
static class Test2 implements Test {} | ||
|
||
public static void main(String[] args) { | ||
Test test = new Test1(); | ||
switch (test) { | ||
case Test1 test1 -> {} | ||
case Test2 test2 -> {} | ||
default -> throw new IllegalStateException("Unexpected value: " + test); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
core/src/test/resources/com/google/googlejavaformat/java/testdata/I684.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,14 @@ | ||
package example; | ||
|
||
import example.model.SealedInterface; | ||
import example.model.TypeA; | ||
import example.model.TypeB; | ||
|
||
public class Main { | ||
public void apply(SealedInterface sealedInterface) { | ||
switch(sealedInterface) { | ||
case TypeA a -> System.out.println("A!"); | ||
case TypeB b -> System.out.println("B!"); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
core/src/test/resources/com/google/googlejavaformat/java/testdata/I684.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,14 @@ | ||
package example; | ||
|
||
import example.model.SealedInterface; | ||
import example.model.TypeA; | ||
import example.model.TypeB; | ||
|
||
public class Main { | ||
public void apply(SealedInterface sealedInterface) { | ||
switch (sealedInterface) { | ||
case TypeA a -> System.out.println("A!"); | ||
case TypeB b -> System.out.println("B!"); | ||
} | ||
} | ||
} |