Skip to content

Commit 18d07f8

Browse files
jakub-suligailoveeclipse
authored andcommitted
Changed that single liner dont get folding button
1 parent 823adf6 commit 18d07f8

File tree

2 files changed

+55
-18
lines changed

2 files changed

+55
-18
lines changed

org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/folding/FoldingTest.java

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,15 @@ class X {
295295
void a() { //here should be an annotation
296296
297297
} void b() { //here should be an annotation
298+
298299
}
299300
}
300301
""";
301302
FoldingTestUtils.assertCodeHasRegions(packageFragment, "TestFolding.java", str, 3);
302303
List<IRegion> regions= FoldingTestUtils.getProjectionRangesOfFile(packageFragment, "TestFolding.java", str);
303304
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 2, 4); // JavaDoc
304305
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 5, 6); // 1. Method
305-
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 7, 7); // 2. Method
306+
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 7, 8); // 2. Method
306307
}
307308

308309
@Test
@@ -313,14 +314,15 @@ public void testIfStatementFolding() throws Exception {
313314
public class D {
314315
void x() { //here should be an annotation
315316
if (true) { //here should be an annotation
317+
316318
}
317319
}
318320
}
319321
""";
320322
FoldingTestUtils.assertCodeHasRegions(packageFragment, "TestFolding.java", str, 2);
321323
List<IRegion> regions= FoldingTestUtils.getProjectionRangesOfFile(packageFragment, "TestFolding.java", str);
322-
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 2, 4); // 1. Method
323-
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 3, 3); // if
324+
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 2, 5); // 1. Method
325+
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 3, 4); // if
324326
}
325327

326328
@Test
@@ -353,14 +355,15 @@ public void testWhileStatementFolding() throws Exception {
353355
public class F {
354356
void x() { //here should be an annotation
355357
while (true) { //here should be an annotation
358+
356359
}
357360
}
358361
}
359362
""";
360363
FoldingTestUtils.assertCodeHasRegions(packageFragment, "TestFolding.java", str, 2);
361364
List<IRegion> regions= FoldingTestUtils.getProjectionRangesOfFile(packageFragment, "TestFolding.java", str);
362-
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 2, 4); // 1. Method
363-
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 3, 3); // while
365+
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 2, 5); // 1. Method
366+
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 3, 4); // while
364367
}
365368

366369
@Test
@@ -371,14 +374,15 @@ public void testForStatementFolding() throws Exception {
371374
public class G {
372375
void x() { //here should be an annotation
373376
for(int i=0;i<1;i++){ //here should be an annotation
377+
374378
}
375379
}
376380
}
377381
""";
378382
FoldingTestUtils.assertCodeHasRegions(packageFragment, "TestFolding.java", str, 2);
379383
List<IRegion> regions= FoldingTestUtils.getProjectionRangesOfFile(packageFragment, "TestFolding.java", str);
380-
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 2, 4); // 1. Method
381-
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 3, 3); // for
384+
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 2, 5); // 1. Method
385+
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 3, 4); // for
382386
}
383387

384388
@Test
@@ -389,14 +393,15 @@ public void testEnhancedForStatementFolding() throws Exception {
389393
public class H {
390394
void x() { //here should be an annotation
391395
for(String s: new String[0]){ //here should be an annotation
396+
392397
}
393398
}
394399
}
395400
""";
396401
FoldingTestUtils.assertCodeHasRegions(packageFragment, "TestFolding.java", str, 2);
397402
List<IRegion> regions= FoldingTestUtils.getProjectionRangesOfFile(packageFragment, "TestFolding.java", str);
398-
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 2, 4); // 1. Method
399-
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 3, 3); // for
403+
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 2, 5); // 1. Method
404+
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 3, 4); // for
400405
}
401406

402407
@Test
@@ -426,14 +431,15 @@ public void testSynchronizedStatementFolding() throws Exception {
426431
public class K {
427432
void x() { //here should be an annotation
428433
synchronized(this) { //here should be an annotation
434+
429435
}
430436
}
431437
}
432438
""";
433439
FoldingTestUtils.assertCodeHasRegions(packageFragment, "TestFolding.java", str, 2);
434440
List<IRegion> regions= FoldingTestUtils.getProjectionRangesOfFile(packageFragment, "TestFolding.java", str);
435-
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 2, 4); // 1. Method
436-
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 3, 3); // synchronized
441+
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 2, 5); // 1. Method
442+
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 3, 4); // synchronized
437443
}
438444

439445
@Test
@@ -495,12 +501,13 @@ public void testInitializerFolding() throws Exception {
495501
package org.example.test;
496502
public class O {
497503
static { //here should be an annotation
504+
498505
}
499506
}
500507
""";
501508
FoldingTestUtils.assertCodeHasRegions(packageFragment, "TestFolding.java", str, 1);
502509
List<IRegion> regions= FoldingTestUtils.getProjectionRangesOfFile(packageFragment, "TestFolding.java", str);
503-
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 2, 2); // static
510+
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 2, 3); // static
504511
}
505512

506513
@Test
@@ -514,6 +521,7 @@ void x() { //here should be an annotation
514521
for(int i=0;i<1;i++){ //here should be an annotation
515522
while(true) { //here should be an annotation
516523
do { //here should be an annotation
524+
517525
} while(false);
518526
}
519527
}
@@ -523,11 +531,11 @@ void x() { //here should be an annotation
523531
""";
524532
FoldingTestUtils.assertCodeHasRegions(packageFragment, "TestFolding.java", str, 5);
525533
List<IRegion> regions= FoldingTestUtils.getProjectionRangesOfFile(packageFragment, "TestFolding.java", str);
526-
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 2, 10); // method
527-
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 3, 9); // if
528-
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 4, 8); // for
529-
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 5, 7); // while
530-
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 6, 6); // do
534+
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 2, 11); // method
535+
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 3, 10); // if
536+
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 4, 9); // for
537+
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 5, 8); // while
538+
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 6, 7); // do
531539
}
532540

533541
@Test
@@ -547,4 +555,33 @@ class Inner2{ //here should be an annotation
547555
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 2, 5); // method
548556
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 3, 4); // inner class
549557
}
558+
559+
560+
@Test
561+
public void testSingleLiner() throws Exception {
562+
assumeTrue("Only doable with the new folding", newFoldingActive);
563+
String str= """
564+
package org.example.test;
565+
public class I {
566+
void x() { //here should be an annotation
567+
do { //here should not be an annotation
568+
} while(false);
569+
for(int i=0;i<1;i++){ //here should not be an annotation
570+
}
571+
synchronized(this) { //here should not be an annotation
572+
}
573+
if (true) { //here should not be an annotation
574+
}
575+
try { //here should not be an annotation
576+
} catch (Exception e) { //here should not be an annotation
577+
}
578+
}
579+
public void bar() { //here should not be an annotation
580+
}
581+
}
582+
""";
583+
FoldingTestUtils.assertCodeHasRegions(packageFragment, "TestFolding.java", str, 1);
584+
List<IRegion> regions= FoldingTestUtils.getProjectionRangesOfFile(packageFragment, "TestFolding.java", str);
585+
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 2, 13); // Method
586+
}
550587
}

org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/folding/DefaultJavaFoldingStructureProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ private boolean isMultiline(IRegion region) {
510510
IDocument document= ctx.getDocument();
511511
int startLine= document.getLineOfOffset(region.getOffset());
512512
int endLine= document.getLineOfOffset(region.getOffset() + region.getLength());
513-
return endLine > startLine;
513+
return endLine > startLine + 1;
514514
} catch (BadLocationException e) {
515515
return false;
516516
}

0 commit comments

Comments
 (0)