Lines 10568-10571
Link Here
|
10568 |
DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences); |
10568 |
DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences); |
10569 |
runTest(codeFormatter, "test719", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$ |
10569 |
runTest(codeFormatter, "test719", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$ |
10570 |
} |
10570 |
} |
|
|
10571 |
|
10572 |
/** |
10573 |
* @bug 198074: [formatter] the code formatter doesn't respect my new lines |
10574 |
* @test Ensure that the formatter keep line breaks wrapping set by users in the code |
10575 |
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=198074" |
10576 |
*/ |
10577 |
public void testBug198074() throws JavaModelException { |
10578 |
this.formatterPrefs.preserve_existing_line_breaks = true; |
10579 |
String source = |
10580 |
"public class Test {\n" + |
10581 |
"\n" + |
10582 |
" void foo() {\n" + |
10583 |
"String x = \"select x \"\n" + |
10584 |
" + \"from y \"\n" + |
10585 |
" + \"where z=a\";\n" + |
10586 |
" }\n" + |
10587 |
"}\n"; |
10588 |
formatSource(source, |
10589 |
"public class Test {\n" + |
10590 |
"\n" + |
10591 |
" void foo() {\n" + |
10592 |
" String x = \"select x \"\n" + |
10593 |
" + \"from y \"\n" + |
10594 |
" + \"where z=a\";\n" + |
10595 |
" }\n" + |
10596 |
"}\n" |
10597 |
); |
10598 |
} |
10599 |
// another test case put in bug's comment 1 |
10600 |
public void testBug198074_c1() throws JavaModelException { |
10601 |
this.formatterPrefs.preserve_existing_line_breaks = true; |
10602 |
String source = |
10603 |
"public class Test {\n" + |
10604 |
"\n" + |
10605 |
" String foo(boolean enabled) {\n" + |
10606 |
"if (enabled)\n" + |
10607 |
"{\n" + |
10608 |
" // we need x\n" + |
10609 |
" // we need a select\n" + |
10610 |
" return \"select x \"\n" + |
10611 |
" + \"from X\";}\n" + |
10612 |
" return null;}\n" + |
10613 |
"}\n"; |
10614 |
formatSource(source, |
10615 |
"public class Test {\n" + |
10616 |
"\n" + |
10617 |
" String foo(boolean enabled) {\n" + |
10618 |
" if (enabled) {\n" + |
10619 |
" // we need x\n" + |
10620 |
" // we need a select\n" + |
10621 |
" return \"select x \"\n" + |
10622 |
" + \"from X\";\n" + |
10623 |
" }\n" + |
10624 |
" return null;\n" + |
10625 |
" }\n" + |
10626 |
"}\n" |
10627 |
); |
10628 |
} |
10629 |
// another test case put in bug's comment 3 |
10630 |
public void testBug198074_c3() throws JavaModelException { |
10631 |
this.formatterPrefs.preserve_existing_line_breaks = true; |
10632 |
String source = |
10633 |
"public class Test {\n" + |
10634 |
"\n" + |
10635 |
"public String toString() {\n" + |
10636 |
" return \"YAD01: \"\n" + |
10637 |
" + \" nommbr=\'\"+getName()+\"\'\"\n" + |
10638 |
" + \" nomgrp=\'\"+getService().getArgtbl()+\"\'\"\n" + |
10639 |
" + \" typmbr=\'\"+getMemberType().getArgument()+\"\'\"\n" + |
10640 |
" + \" srcpat=\'\"+getPhysicalPath()+\"\'\"\n" + |
10641 |
" + \" nommdl=\'\"+getModel()+\"\'\"\n" + |
10642 |
" ;\n" + |
10643 |
"}\n" + |
10644 |
"}\n"; |
10645 |
formatSource(source, |
10646 |
"public class Test {\n" + |
10647 |
"\n" + |
10648 |
" public String toString() {\n" + |
10649 |
" return \"YAD01: \"\n" + |
10650 |
" + \" nommbr=\'\" + getName() + \"\'\"\n" + |
10651 |
" + \" nomgrp=\'\" + getService().getArgtbl() + \"\'\"\n" + |
10652 |
" + \" typmbr=\'\" + getMemberType().getArgument() + \"\'\"\n" + |
10653 |
" + \" srcpat=\'\" + getPhysicalPath() + \"\'\"\n" + |
10654 |
" + \" nommdl=\'\" + getModel() + \"\'\";\n" + |
10655 |
" }\n" + |
10656 |
"}\n" |
10657 |
); |
10658 |
} |
10659 |
// duplicate bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=201022 |
10660 |
public void testBug201022() throws JavaModelException { |
10661 |
this.formatterPrefs.preserve_existing_line_breaks = true; |
10662 |
String source = |
10663 |
"public class Test {\n" + |
10664 |
"\n" + |
10665 |
" void foo() {\n" + |
10666 |
" String sQuery =\n" + |
10667 |
" \"select * \" +\n" + |
10668 |
" \"from person p, address a \" +\n" + |
10669 |
" \"where p.person_id = a.person_id \" +\n" + |
10670 |
" \"and p.person_id = ?\";\n" + |
10671 |
" }\n" + |
10672 |
"}\n"; |
10673 |
formatSource(source, |
10674 |
"public class Test {\n" + |
10675 |
"\n" + |
10676 |
" void foo() {\n" + |
10677 |
" String sQuery =\n" + |
10678 |
" \"select * \" +\n" + |
10679 |
" \"from person p, address a \" +\n" + |
10680 |
" \"where p.person_id = a.person_id \" +\n" + |
10681 |
" \"and p.person_id = ?\";\n" + |
10682 |
" }\n" + |
10683 |
"}\n" |
10684 |
); |
10685 |
} |
10686 |
// duplicate bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541 |
10687 |
public void testBug208541() throws JavaModelException { |
10688 |
this.formatterPrefs.preserve_existing_line_breaks = true; |
10689 |
String source = |
10690 |
"public class MyTest {\n" + |
10691 |
"\n" + |
10692 |
" public void testname() throws Exception {\n" + |
10693 |
" int i = 5, j = 6, k = 7;\n" + |
10694 |
" if (new String().length() != 0 &&\n" + |
10695 |
" (i < j && j < k)) {\n" + |
10696 |
"\n" + |
10697 |
" }\n" + |
10698 |
" }\n" + |
10699 |
"}\n"; |
10700 |
formatSource(source, |
10701 |
"public class MyTest {\n" + |
10702 |
"\n" + |
10703 |
" public void testname() throws Exception {\n" + |
10704 |
" int i = 5, j = 6, k = 7;\n" + |
10705 |
" if (new String().length() != 0 &&\n" + |
10706 |
" (i < j && j < k)) {\n" + |
10707 |
"\n" + |
10708 |
" }\n" + |
10709 |
" }\n" + |
10710 |
"}\n" |
10711 |
); |
10712 |
} |
10713 |
// duplicate bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=213700 |
10714 |
public void testBug213700() throws JavaModelException { |
10715 |
this.formatterPrefs.preserve_existing_line_breaks = true; |
10716 |
String source = |
10717 |
"public class Test {\n" + |
10718 |
"\n" + |
10719 |
" void foo() {\n" + |
10720 |
" int a=0, b=0, c=0, d=0, e=0, f=0, g=0, h=0, i=0;\n" + |
10721 |
"if( (a == b && b == c) &&\n" + |
10722 |
" (d == e) &&\n" + |
10723 |
" (f == g && h == i) \n" + |
10724 |
" ){\n" + |
10725 |
"}\n" + |
10726 |
" }\n" + |
10727 |
"}\n"; |
10728 |
formatSource(source, |
10729 |
"public class Test {\n" + |
10730 |
"\n" + |
10731 |
" void foo() {\n" + |
10732 |
" int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0;\n" + |
10733 |
" if ((a == b && b == c) &&\n" + |
10734 |
" (d == e) &&\n" + |
10735 |
" (f == g && h == i)) {\n" + |
10736 |
" }\n" + |
10737 |
" }\n" + |
10738 |
"}\n" |
10739 |
); |
10740 |
} |
10571 |
} |
10741 |
} |