@@ -575,13 +575,94 @@ void x() { //here should be an annotation
575575 try { //here should not be an annotation
576576 } catch (Exception e) { //here should not be an annotation
577577 }
578+ int zaehler = 0;
579+ switch (zaehler) { //here should be an annotation
580+ case 0: //here should not be an annotation
581+ break;
582+ default: //here should not be an annotation
583+ break;
584+ }
578585 }
579586 public void bar() { //here should not be an annotation
580587 }
581588 }
582589 """ ;
583- FoldingTestUtils .assertCodeHasRegions (packageFragment , "TestFolding.java" , str , 1 );
590+ FoldingTestUtils .assertCodeHasRegions (packageFragment , "TestFolding.java" , str , 2 );
591+ List <IRegion > regions = FoldingTestUtils .getProjectionRangesOfFile (packageFragment , "TestFolding.java" , str );
592+ FoldingTestUtils .assertContainsRegionUsingStartAndEndLine (regions , str , 2 , 20 ); // Method
593+ FoldingTestUtils .assertContainsRegionUsingStartAndEndLine (regions , str , 15 , 19 ); // switch
594+ }
595+
596+ @ Test
597+ public void testSwitchExpression () throws Exception {
598+ assumeTrue ("Only doable with the new folding" , newFoldingActive );
599+ String str = """
600+ package org.example.test;
601+ class Outer {
602+ void a() { //here should be an annotation
603+ int b = 0;
604+ int c = switch (b) { //here should be an annotation
605+ case 1 -> //here should be an annotation
606+
607+ 1;
608+ case 2 -> //here should not be an annotation
609+ 1;
610+ case 3 -> //here should be an annotation
611+
612+ break;
613+ 1;
614+ case 4 -> { //here should be an annotation
615+ b = 2;
616+ yield 3;
617+ }
618+ case 5 -> { //here should not be an annotation
619+ yield 3;
620+ }
621+ default -> //here should be an annotation
622+
623+ 0;
624+ };
625+ }
626+ }
627+ """ ;
628+ FoldingTestUtils .assertCodeHasRegions (packageFragment , "TestFolding.java" , str , 6 );
629+ List <IRegion > regions = FoldingTestUtils .getProjectionRangesOfFile (packageFragment , "TestFolding.java" , str );
630+ FoldingTestUtils .assertContainsRegionUsingStartAndEndLine (regions , str , 2 , 24 ); // method
631+ FoldingTestUtils .assertContainsRegionUsingStartAndEndLine (regions , str , 4 , 23 ); // switch
632+ FoldingTestUtils .assertContainsRegionUsingStartAndEndLine (regions , str , 5 , 6 ); // 1. case
633+ FoldingTestUtils .assertContainsRegionUsingStartAndEndLine (regions , str , 10 , 11 ); // 3. case
634+ FoldingTestUtils .assertContainsRegionUsingStartAndEndLine (regions , str , 14 , 15 ); // 4. case
635+ FoldingTestUtils .assertContainsRegionUsingStartAndEndLine (regions , str , 21 , 22 ); // default
636+ }
637+
638+ @ Test
639+ public void testSwitchStatment () throws Exception {
640+ assumeTrue ("Only doable with the new folding" , newFoldingActive );
641+ String str = """
642+ package org.example.test;
643+ class Outer {
644+ void a() { //here should be an annotation
645+ int b = 0;
646+ switch (b) { //here should be an annotation
647+ case 0: //here should be an annotation
648+
649+ break;
650+ b = 1;
651+ case 1: //here should not be an annotation
652+ break;
653+
654+ default: //here should be an annotation
655+
656+ break;
657+ }
658+ }
659+ }
660+ """ ;
661+ FoldingTestUtils .assertCodeHasRegions (packageFragment , "TestFolding.java" , str , 4 );
584662 List <IRegion > regions = FoldingTestUtils .getProjectionRangesOfFile (packageFragment , "TestFolding.java" , str );
585- FoldingTestUtils .assertContainsRegionUsingStartAndEndLine (regions , str , 2 , 13 ); // Method
663+ FoldingTestUtils .assertContainsRegionUsingStartAndEndLine (regions , str , 2 , 15 ); // method
664+ FoldingTestUtils .assertContainsRegionUsingStartAndEndLine (regions , str , 4 , 14 ); // switch
665+ FoldingTestUtils .assertContainsRegionUsingStartAndEndLine (regions , str , 5 , 6 ); // case
666+ FoldingTestUtils .assertContainsRegionUsingStartAndEndLine (regions , str , 12 , 13 ); // default
586667 }
587668}
0 commit comments