@@ -410,6 +410,86 @@ private static Foo<String> getFoo() {
410410 assertEqualString (preview1 , expected1 );
411411 }
412412
413+ @ Test
414+ public void testAddPermittedTypesToSwitchStatement2 () throws Exception {
415+ fJProject1 = JavaProjectHelper .createJavaProject ("TestProject1" , "bin" );
416+ fJProject1 .setRawClasspath (projectsetup .getDefaultClasspath (), null );
417+ JavaProjectHelper .set22CompilerOptions (fJProject1 );
418+
419+ fSourceFolder = JavaProjectHelper .addSourceContainer (fJProject1 , "src" );
420+ IPackageFragment pack1 = fSourceFolder .createPackageFragment ("test" , false , null );
421+
422+ String shape = """
423+ package test;
424+ public sealed class Shape permits Circle, Square {
425+ }
426+ """ ;
427+ pack1 .createCompilationUnit ("Shape.java" , shape , false , null );
428+
429+ String circle = """
430+ package test;
431+ public final class Circle extends Shape {
432+ }
433+ """ ;
434+ pack1 .createCompilationUnit ("Circle.java" , circle , false , null );
435+
436+ String square = """
437+ package test;
438+ public final class Square extends Shape {
439+ }
440+ """ ;
441+ pack1 .createCompilationUnit ("Square.java" , square , false , null );
442+
443+ String test = """
444+ package test;
445+
446+ public class TestSwitch {
447+
448+ public static void main(String[] args) {
449+ Shape shape = getShape();
450+ switch (shape) {
451+ }
452+ }
453+
454+ private static Shape getShape() {
455+ return new Circle();
456+ }
457+ }
458+ """ ;
459+
460+ ICompilationUnit cu = pack1 .createCompilationUnit ("TestSwitch.java" , test , false , null );
461+
462+ CompilationUnit astRoot = getASTRoot (cu );
463+ ArrayList <IJavaCompletionProposal > proposals = collectCorrections (cu , astRoot , 1 );
464+ assertCorrectLabels (proposals );
465+
466+ CUCorrectionProposal proposal1 = (CUCorrectionProposal ) proposals .get (0 );
467+ String preview1 = getPreviewContent (proposal1 );
468+
469+ String expected1 = """
470+ package test;
471+
472+ public class TestSwitch {
473+
474+ public static void main(String[] args) {
475+ Shape shape = getShape();
476+ switch (shape) {
477+ case Circle c -> {}
478+ case Square s -> {}
479+ case null -> {}
480+ default -> {}
481+ }
482+ }
483+
484+ private static Shape getShape() {
485+ return new Circle();
486+ }
487+ }
488+ """ ;
489+
490+ assertEqualString (preview1 , expected1 );
491+ }
492+
413493 @ Test
414494 public void testAddPermittedTypesToSwitchExpression () throws Exception {
415495 fJProject1 = JavaProjectHelper .createJavaProject ("TestProject1" , "bin" );
0 commit comments