Lines 3503-3508
Link Here
|
3503 |
} |
3503 |
} |
3504 |
|
3504 |
|
3505 |
/** |
3505 |
/** |
|
|
3506 |
* @bug 264112: [Formatter] Wrap when necessary too aggressive on short qualifiers |
3507 |
* @test |
3508 |
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=264112" |
3509 |
*/ |
3510 |
// Max line width = 24 |
3511 |
public void testBug264112_w24_S1() { |
3512 |
this.formatterPrefs.page_width = 24; |
3513 |
String source = |
3514 |
"class Sample1 {void foo() {Other.bar( 100,\n" + |
3515 |
"200,\n" + |
3516 |
"300,\n" + |
3517 |
"400,\n" + |
3518 |
"500,\n" + |
3519 |
"600,\n" + |
3520 |
"700,\n" + |
3521 |
"800,\n" + |
3522 |
"900 );}}\n"; |
3523 |
formatSource(source, |
3524 |
"class Sample1 {\n" + |
3525 |
" void foo() {\n" + |
3526 |
" Other.bar(100,\n" + |
3527 |
" 200,\n" + |
3528 |
" 300,\n" + |
3529 |
" 400,\n" + |
3530 |
" 500,\n" + |
3531 |
" 600,\n" + |
3532 |
" 700,\n" + |
3533 |
" 800,\n" + |
3534 |
" 900);\n" + |
3535 |
" }\n" + |
3536 |
"}\n" |
3537 |
); |
3538 |
} |
3539 |
public void testBug264112_w24_S2() { |
3540 |
this.formatterPrefs.page_width = 24; |
3541 |
String source = |
3542 |
"class Sample2 {int foo(Some a) {return a.getFirst();}}\n"; |
3543 |
formatSource(source, |
3544 |
"class Sample2 {\n" + |
3545 |
" int foo(Some a) {\n" + |
3546 |
" return a.getFirst();\n" + |
3547 |
" }\n" + |
3548 |
"}\n" |
3549 |
); |
3550 |
} |
3551 |
// Max line width = 25 |
3552 |
public void testBug264112_w25_S1() { |
3553 |
this.formatterPrefs.page_width = 25; |
3554 |
String source = |
3555 |
"class Sample1 {void foo() {Other.bar( 100,\n" + |
3556 |
"200,\n" + |
3557 |
"300,\n" + |
3558 |
"400,\n" + |
3559 |
"500,\n" + |
3560 |
"600,\n" + |
3561 |
"700,\n" + |
3562 |
"800,\n" + |
3563 |
"900 );}}\n"; |
3564 |
formatSource(source, |
3565 |
"class Sample1 {\n" + |
3566 |
" void foo() {\n" + |
3567 |
" Other.bar(100,\n" + |
3568 |
" 200,\n" + |
3569 |
" 300,\n" + |
3570 |
" 400,\n" + |
3571 |
" 500,\n" + |
3572 |
" 600,\n" + |
3573 |
" 700,\n" + |
3574 |
" 800, 900);\n" + |
3575 |
" }\n" + |
3576 |
"}\n" |
3577 |
); |
3578 |
} |
3579 |
public void testBug264112_w25_S2() { |
3580 |
this.formatterPrefs.page_width = 25; |
3581 |
String source = |
3582 |
"class Sample2 {int foo(Some a) {return a.getFirst();}}\n"; |
3583 |
formatSource(source, |
3584 |
"class Sample2 {\n" + |
3585 |
" int foo(Some a) {\n" + |
3586 |
" return a.getFirst();\n" + |
3587 |
" }\n" + |
3588 |
"}\n" |
3589 |
); |
3590 |
} |
3591 |
// Max line width = 26 |
3592 |
public void testBug264112_w26_S1() { |
3593 |
this.formatterPrefs.page_width = 26; |
3594 |
String source = |
3595 |
"class Sample1 {void foo() {Other.bar( 100,\n" + |
3596 |
"200,\n" + |
3597 |
"300,\n" + |
3598 |
"400,\n" + |
3599 |
"500,\n" + |
3600 |
"600,\n" + |
3601 |
"700,\n" + |
3602 |
"800,\n" + |
3603 |
"900 );}}\n"; |
3604 |
formatSource(source, |
3605 |
"class Sample1 {\n" + |
3606 |
" void foo() {\n" + |
3607 |
" Other.bar(100,\n" + |
3608 |
" 200, 300,\n" + |
3609 |
" 400, 500,\n" + |
3610 |
" 600, 700,\n" + |
3611 |
" 800, 900);\n" + |
3612 |
" }\n" + |
3613 |
"}\n" |
3614 |
); |
3615 |
} |
3616 |
public void testBug264112_w26_S2() { |
3617 |
this.formatterPrefs.page_width = 26; |
3618 |
String source = |
3619 |
"class Sample2 {int foo(Some a) {return a.getFirst();}}\n"; |
3620 |
formatSource(source, |
3621 |
"class Sample2 {\n" + |
3622 |
" int foo(Some a) {\n" + |
3623 |
" return a.getFirst();\n" + |
3624 |
" }\n" + |
3625 |
"}\n" |
3626 |
); |
3627 |
} |
3628 |
public void testBug264112_wksp1_01() { |
3629 |
String source = |
3630 |
"package wksp1;\n" + |
3631 |
"\n" + |
3632 |
"public class X01 {\n" + |
3633 |
"\n" + |
3634 |
" public Object foo(Object scope) {\n" + |
3635 |
" if (scope != null) {\n" + |
3636 |
" if (true) {\n" + |
3637 |
" for (int i = 0; i < 10; i++) {\n" + |
3638 |
" if (i == 0) {\n" + |
3639 |
" } else if (i < 5) {\n" + |
3640 |
" } else {\n" + |
3641 |
" scope.problemReporter().typeMismatchErrorActualTypeExpectedType(expression, expressionTb, expectedElementsTb);\n" + |
3642 |
" return null;\n" + |
3643 |
" }\n" + |
3644 |
" }\n" + |
3645 |
" }\n" + |
3646 |
" return null;\n" + |
3647 |
" }\n" + |
3648 |
" }\n" + |
3649 |
"\n" + |
3650 |
"}\n"; |
3651 |
formatSource(source, |
3652 |
"package wksp1;\n" + |
3653 |
"\n" + |
3654 |
"public class X01 {\n" + |
3655 |
"\n" + |
3656 |
" public Object foo(Object scope) {\n" + |
3657 |
" if (scope != null) {\n" + |
3658 |
" if (true) {\n" + |
3659 |
" for (int i = 0; i < 10; i++) {\n" + |
3660 |
" if (i == 0) {\n" + |
3661 |
" } else if (i < 5) {\n" + |
3662 |
" } else {\n" + |
3663 |
" scope.problemReporter()\n" + |
3664 |
" .typeMismatchErrorActualTypeExpectedType(\n" + |
3665 |
" expression, expressionTb,\n" + |
3666 |
" expectedElementsTb);\n" + |
3667 |
" return null;\n" + |
3668 |
" }\n" + |
3669 |
" }\n" + |
3670 |
" }\n" + |
3671 |
" return null;\n" + |
3672 |
" }\n" + |
3673 |
" }\n" + |
3674 |
"\n" + |
3675 |
"}\n" |
3676 |
); |
3677 |
} |
3678 |
public void testBug264112_wksp1_02() { |
3679 |
String source = |
3680 |
"package wksp1;\n" + |
3681 |
"\n" + |
3682 |
"public class X02 {\n" + |
3683 |
"\n" + |
3684 |
" public String toString() {\n" + |
3685 |
" StringBuffer buffer = new StringBuffer();\n" + |
3686 |
" if (true) {\n" + |
3687 |
" buffer.append(\"- possible values: [\"); //$NON-NLS-1$ \n" + |
3688 |
" buffer.append(\"]\\n\"); //$NON-NLS-1$ \n" + |
3689 |
" buffer.append(\"- curr. val. index: \").append(currentValueIndex).append(\"\\n\"); //$NON-NLS-1$ //$NON-NLS-2$\n" + |
3690 |
" }\n" + |
3691 |
" buffer.append(\"- description: \").append(description).append(\"\\n\"); //$NON-NLS-1$ //$NON-NLS-2$\n" + |
3692 |
" return buffer.toString();\n" + |
3693 |
" }\n" + |
3694 |
"\n" + |
3695 |
"}\n"; |
3696 |
formatSource(source, |
3697 |
"package wksp1;\n" + |
3698 |
"\n" + |
3699 |
"public class X02 {\n" + |
3700 |
"\n" + |
3701 |
" public String toString() {\n" + |
3702 |
" StringBuffer buffer = new StringBuffer();\n" + |
3703 |
" if (true) {\n" + |
3704 |
" buffer.append(\"- possible values: [\"); //$NON-NLS-1$ \n" + |
3705 |
" buffer.append(\"]\\n\"); //$NON-NLS-1$ \n" + |
3706 |
" buffer.append(\"- curr. val. index: \").append(currentValueIndex).append(\"\\n\"); //$NON-NLS-1$ //$NON-NLS-2$\n" + |
3707 |
" }\n" + |
3708 |
" buffer.append(\"- description: \").append(description).append(\"\\n\"); //$NON-NLS-1$ //$NON-NLS-2$\n" + |
3709 |
" return buffer.toString();\n" + |
3710 |
" }\n" + |
3711 |
"\n" + |
3712 |
"}\n" |
3713 |
); |
3714 |
} |
3715 |
public void testBug264112_wksp2_01() { |
3716 |
String source = |
3717 |
"package wksp2;\n" + |
3718 |
"\n" + |
3719 |
"public class X01 {\n" + |
3720 |
"\n" + |
3721 |
" private static final String PATH_SMOOTH_QUAD_TO = \"SMOOTH\";\n" + |
3722 |
" private static final String XML_SPACE = \" \";\n" + |
3723 |
" private static final String PATH_CLOSE = \"CLOSE\";\n" + |
3724 |
"\n" + |
3725 |
" String foo(Point point, Point point_plus1) {\n" + |
3726 |
" StringBuffer sb = new StringBuffer();\n" + |
3727 |
" while (true) {\n" + |
3728 |
" if (point != null) {\n" + |
3729 |
" // Following message send was unnecessarily split\n" + |
3730 |
" sb.append(PATH_SMOOTH_QUAD_TO)\n" + |
3731 |
" .append(String.valueOf(midValue(point.x, point_plus1.x)))\n" + |
3732 |
" .append(XML_SPACE)\n" + |
3733 |
" .append(String.valueOf(midValue(point.y, point_plus1.y)));\n" + |
3734 |
" } else {\n" + |
3735 |
" break;\n" + |
3736 |
" }\n" + |
3737 |
" }\n" + |
3738 |
" sb.append(PATH_CLOSE);\n" + |
3739 |
"\n" + |
3740 |
" return sb.toString();\n" + |
3741 |
" }\n" + |
3742 |
"\n" + |
3743 |
" private int midValue(int x1, int x2) {\n" + |
3744 |
" return (x1 + x2) / 2;\n" + |
3745 |
" }\n" + |
3746 |
"\n" + |
3747 |
"}\n" + |
3748 |
"class Point {\n" + |
3749 |
" int x,y;\n" + |
3750 |
"}\n"; |
3751 |
formatSource(source, |
3752 |
"package wksp2;\n" + |
3753 |
"\n" + |
3754 |
"public class X01 {\n" + |
3755 |
"\n" + |
3756 |
" private static final String PATH_SMOOTH_QUAD_TO = \"SMOOTH\";\n" + |
3757 |
" private static final String XML_SPACE = \" \";\n" + |
3758 |
" private static final String PATH_CLOSE = \"CLOSE\";\n" + |
3759 |
"\n" + |
3760 |
" String foo(Point point, Point point_plus1) {\n" + |
3761 |
" StringBuffer sb = new StringBuffer();\n" + |
3762 |
" while (true) {\n" + |
3763 |
" if (point != null) {\n" + |
3764 |
" // Following message send was unnecessarily split\n" + |
3765 |
" sb.append(PATH_SMOOTH_QUAD_TO)\n" + |
3766 |
" .append(\n" + |
3767 |
" String.valueOf(midValue(point.x, point_plus1.x)))\n" + |
3768 |
" .append(XML_SPACE)\n" + |
3769 |
" .append(\n" + |
3770 |
" String.valueOf(midValue(point.y, point_plus1.y)));\n" + |
3771 |
" } else {\n" + |
3772 |
" break;\n" + |
3773 |
" }\n" + |
3774 |
" }\n" + |
3775 |
" sb.append(PATH_CLOSE);\n" + |
3776 |
"\n" + |
3777 |
" return sb.toString();\n" + |
3778 |
" }\n" + |
3779 |
"\n" + |
3780 |
" private int midValue(int x1, int x2) {\n" + |
3781 |
" return (x1 + x2) / 2;\n" + |
3782 |
" }\n" + |
3783 |
"\n" + |
3784 |
"}\n" + |
3785 |
"\n" + |
3786 |
"class Point {\n" + |
3787 |
" int x, y;\n" + |
3788 |
"}\n" |
3789 |
); |
3790 |
} |
3791 |
public void testBug264112_wksp2_02() { |
3792 |
String source = |
3793 |
"package wksp2;\n" + |
3794 |
"\n" + |
3795 |
"public class X02 {\n" + |
3796 |
" \n" + |
3797 |
" void test(X02 indexsc) {\n" + |
3798 |
" if (indexsc == null) {\n" + |
3799 |
" } else {\n" + |
3800 |
"\n" + |
3801 |
" indexsc.reopenScan(\n" + |
3802 |
" searchRow, // startKeyValue\n" + |
3803 |
" ScanController.GE, // startSearchOp\n" + |
3804 |
" null, // qualifier\n" + |
3805 |
" null, // stopKeyValue\n" + |
3806 |
" ScanController.GT // stopSearchOp \n" + |
3807 |
" );\n" + |
3808 |
" }\n" + |
3809 |
" \n" + |
3810 |
" }\n" + |
3811 |
"}\n"; |
3812 |
formatSource(source, |
3813 |
"package wksp2;\n" + |
3814 |
"\n" + |
3815 |
"public class X02 {\n" + |
3816 |
"\n" + |
3817 |
" void test(X02 indexsc) {\n" + |
3818 |
" if (indexsc == null) {\n" + |
3819 |
" } else {\n" + |
3820 |
"\n" + |
3821 |
" indexsc.reopenScan(searchRow, // startKeyValue\n" + |
3822 |
" ScanController.GE, // startSearchOp\n" + |
3823 |
" null, // qualifier\n" + |
3824 |
" null, // stopKeyValue\n" + |
3825 |
" ScanController.GT // stopSearchOp\n" + |
3826 |
" );\n" + |
3827 |
" }\n" + |
3828 |
"\n" + |
3829 |
" }\n" + |
3830 |
"}\n" |
3831 |
); |
3832 |
} |
3833 |
|
3834 |
/** |
3506 |
* @bug 297225: [formatter] Indentation may be still wrong in certain circumstances after formatting |
3835 |
* @bug 297225: [formatter] Indentation may be still wrong in certain circumstances after formatting |
3507 |
* @test Verify that comment indentation is correct when there's a mix of tab and spaces in |
3836 |
* @test Verify that comment indentation is correct when there's a mix of tab and spaces in |
3508 |
* existing indentation and all comments formatting is off. |
3837 |
* existing indentation and all comments formatting is off. |