View | Details | Raw Unified | Return to bug 234583 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java (-94 / +396 lines)
Lines 84-90 Link Here
84
	formatUnit("bugs.b230944", "X01.java");
84
	formatUnit("bugs.b230944", "X01.java");
85
}
85
}
86
public void testBug230944b() throws JavaModelException {
86
public void testBug230944b() throws JavaModelException {
87
	this.preferences.comment_line_length = 40;
87
	this.formatterPrefs.comment_line_length = 40;
88
	formatUnit("bugs.b230944", "X02.java");
88
	formatUnit("bugs.b230944", "X02.java");
89
}
89
}
90
90
Lines 97-103 Link Here
97
	formatUnit("bugs.b231263", "BadFormattingSample.java");
97
	formatUnit("bugs.b231263", "BadFormattingSample.java");
98
}
98
}
99
public void testBug231263a() throws JavaModelException {
99
public void testBug231263a() throws JavaModelException {
100
	this.preferences.comment_line_length = 40;
100
	this.formatterPrefs.comment_line_length = 40;
101
	formatUnit("bugs.b231263", "X.java");
101
	formatUnit("bugs.b231263", "X.java");
102
}
102
}
103
103
Lines 107-135 Link Here
107
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=231297"
107
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=231297"
108
 */
108
 */
109
public void testBug231297() throws JavaModelException {
109
public void testBug231297() throws JavaModelException {
110
	this.preferences.comment_line_length = 40;
110
	this.formatterPrefs.comment_line_length = 40;
111
	formatUnit("bugs.b231297", "X.java");
111
	formatUnit("bugs.b231297", "X.java");
112
}
112
}
113
public void testBug231297a() throws JavaModelException {
113
public void testBug231297a() throws JavaModelException {
114
	this.preferences.comment_line_length = 30;
114
	this.formatterPrefs.comment_line_length = 30;
115
	formatUnit("bugs.b231297", "X01.java");
115
	formatUnit("bugs.b231297", "X01.java");
116
}
116
}
117
public void testBug231297b() throws JavaModelException {
117
public void testBug231297b() throws JavaModelException {
118
	// Difference with old formatter:
118
	// Difference with old formatter:
119
	// 1) fixed non formatted inline tag description
119
	// 1) fixed non formatted inline tag description
120
	this.preferences.comment_line_length = 40;
120
	this.formatterPrefs.comment_line_length = 40;
121
	formatUnit("bugs.b231297", "X02.java");
121
	formatUnit("bugs.b231297", "X02.java");
122
}
122
}
123
public void testBug231297c() throws JavaModelException {
123
public void testBug231297c() throws JavaModelException {
124
	// Difference with old formatter:
124
	// Difference with old formatter:
125
	// 1) fixed non formatted inline tag description
125
	// 1) fixed non formatted inline tag description
126
	this.preferences.comment_line_length = 40;
126
	this.formatterPrefs.comment_line_length = 40;
127
	formatUnit("bugs.b231297", "X03.java");
127
	formatUnit("bugs.b231297", "X03.java");
128
}
128
}
129
public void testBug231297d() throws JavaModelException {
129
public void testBug231297d() throws JavaModelException {
130
	// Difference with old formatter:
130
	// Difference with old formatter:
131
	// 1) fixed non formatted inline tag description
131
	// 1) fixed non formatted inline tag description
132
	this.preferences.comment_line_length = 40;
132
	this.formatterPrefs.comment_line_length = 40;
133
	formatUnit("bugs.b231297", "X03b.java");
133
	formatUnit("bugs.b231297", "X03b.java");
134
}
134
}
135
135
Lines 139-181 Link Here
139
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=232285"
139
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=232285"
140
 */
140
 */
141
public void testBug232285a() throws JavaModelException {
141
public void testBug232285a() throws JavaModelException {
142
	this.preferences.comment_line_length = 40;
142
	this.formatterPrefs.comment_line_length = 40;
143
	formatUnit("bugs.b232285", "X01.java");
143
	formatUnit("bugs.b232285", "X01.java");
144
}
144
}
145
public void testBug232285b() throws JavaModelException {
145
public void testBug232285b() throws JavaModelException {
146
	this.preferences.comment_line_length = 40;
146
	this.formatterPrefs.comment_line_length = 40;
147
	formatUnit("bugs.b232285", "X01b.java");
147
	formatUnit("bugs.b232285", "X01b.java");
148
}
148
}
149
public void testBug232285c() throws JavaModelException {
149
public void testBug232285c() throws JavaModelException {
150
	this.preferences.comment_line_length = 40;
150
	this.formatterPrefs.comment_line_length = 40;
151
	formatUnit("bugs.b232285", "X01c.java");
151
	formatUnit("bugs.b232285", "X01c.java");
152
}
152
}
153
public void testBug232285d() throws JavaModelException {
153
public void testBug232285d() throws JavaModelException {
154
	this.preferences.comment_line_length = 40;
154
	this.formatterPrefs.comment_line_length = 40;
155
	formatUnit("bugs.b232285", "X01d.java");
155
	formatUnit("bugs.b232285", "X01d.java");
156
}
156
}
157
public void testBug232285e() throws JavaModelException {
157
public void testBug232285e() throws JavaModelException {
158
	this.preferences.comment_line_length = 40;
158
	this.formatterPrefs.comment_line_length = 40;
159
	formatUnit("bugs.b232285", "X01e.java");
159
	formatUnit("bugs.b232285", "X01e.java");
160
}
160
}
161
public void testBug232285f() throws JavaModelException {
161
public void testBug232285f() throws JavaModelException {
162
	this.preferences.comment_line_length = 40;
162
	this.formatterPrefs.comment_line_length = 40;
163
	formatUnit("bugs.b232285", "X01f.java");
163
	formatUnit("bugs.b232285", "X01f.java");
164
}
164
}
165
public void testBug232285g() throws JavaModelException {
165
public void testBug232285g() throws JavaModelException {
166
	this.preferences.comment_line_length = 40;
166
	this.formatterPrefs.comment_line_length = 40;
167
	formatUnit("bugs.b232285", "X02.java");
167
	formatUnit("bugs.b232285", "X02.java");
168
}
168
}
169
public void testBug232285h() throws JavaModelException {
169
public void testBug232285h() throws JavaModelException {
170
	this.preferences.comment_line_length = 40;
170
	this.formatterPrefs.comment_line_length = 40;
171
	formatUnit("bugs.b232285", "X03.java");
171
	formatUnit("bugs.b232285", "X03.java");
172
}
172
}
173
public void testBug232285i() throws JavaModelException {
173
public void testBug232285i() throws JavaModelException {
174
	this.preferences.comment_line_length = 40;
174
	this.formatterPrefs.comment_line_length = 40;
175
	formatUnit("bugs.b232285", "X04.java");
175
	formatUnit("bugs.b232285", "X04.java");
176
}
176
}
177
public void testBug232285j() throws JavaModelException {
177
public void testBug232285j() throws JavaModelException {
178
	this.preferences.comment_line_length = 40;
178
	this.formatterPrefs.comment_line_length = 40;
179
	formatUnit("bugs.b232285", "X04b.java");
179
	formatUnit("bugs.b232285", "X04b.java");
180
}
180
}
181
181
Lines 185-191 Link Here
185
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=232488"
185
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=232488"
186
 */
186
 */
187
public void testBug232488() throws JavaModelException {
187
public void testBug232488() throws JavaModelException {
188
	this.preferences.comment_line_length = 40;
188
	this.formatterPrefs.comment_line_length = 40;
189
	formatUnit("bugs.b232488", "X01.java");
189
	formatUnit("bugs.b232488", "X01.java");
190
}
190
}
191
191
Lines 195-205 Link Here
195
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=232466"
195
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=232466"
196
 */
196
 */
197
public void testBug232466a() throws JavaModelException {
197
public void testBug232466a() throws JavaModelException {
198
	this.preferences.comment_line_length = 40;
198
	this.formatterPrefs.comment_line_length = 40;
199
	formatUnit("bugs.b232466", "X01.java");
199
	formatUnit("bugs.b232466", "X01.java");
200
}
200
}
201
public void testBug232466b() throws JavaModelException {
201
public void testBug232466b() throws JavaModelException {
202
	this.preferences.comment_line_length = 40;
202
	this.formatterPrefs.comment_line_length = 40;
203
	formatUnit("bugs.b232466", "X02.java");
203
	formatUnit("bugs.b232466", "X02.java");
204
}
204
}
205
205
Lines 218-228 Link Here
218
			"\r\n#]" +
218
			"\r\n#]" +
219
			"}\r\n" +
219
			"}\r\n" +
220
			"";
220
			"";
221
	// TODO fix the incorrect indentation before the javadoc comment (also in 3.3 and 3.4M6)
222
	formatSource(source,
221
	formatSource(source,
223
		"public class A {\n" +
222
		"public class A {\n" +
224
		"\n" +
223
		"\n" +
225
		"        /*\n" +
224
		"	/*\n" +
226
		"	 * A block comment on two lines\n" +
225
		"	 * A block comment on two lines\n" +
227
		"	 */\n" +
226
		"	 */\n" +
228
		"\n" +
227
		"\n" +
Lines 247-253 Link Here
247
		"	public void foo() {\n" +
246
		"	public void foo() {\n" +
248
		"	}\n" +
247
		"	}\n" +
249
		"\n" +
248
		"\n" +
250
		"	/*\n" +
249
		"        /*\r\n" +
251
		"         * A block comment \n" +
250
		"         * A block comment \n" +
252
		"         * on two lines\n" +
251
		"         * on two lines\n" +
253
		"         */\n" +
252
		"         */\n" +
Lines 272-288 Link Here
272
		"#]\n" +
271
		"#]\n" +
273
		"\n" +
272
		"\n" +
274
		"}";
273
		"}";
275
	// TODO fix the incorrect indentation before the javadoc comment (also in 3.3 and 3.4M6)
276
	formatSource(source,
274
	formatSource(source,
277
		"public class C {\n" +
275
		"public class C {\n" +
278
		"	\n" +
276
		"	\n" +
279
		"        /**\n" +
277
		"	/**\n" +
280
		"	 * a b c d .\n" +
278
		"	 * a b c d .\n" +
281
		"	 */\n" +
279
		"	 */\n" +
282
		"	void m1() {\n" +
280
		"	void m1() {\n" +
283
		"\n" +
281
		"\n" +
284
		"	}     \n" +
282
		"	}\n" +
285
		"\n" +
286
		"\n" +
283
		"\n" +
287
		"}"
284
		"}"
288
	);
285
	);
Lines 313-319 Link Here
313
		"	 * a b c d .\n" +
310
		"	 * a b c d .\n" +
314
		"	 */\n" +
311
		"	 */\n" +
315
		"	void m1() {\n" +
312
		"	void m1() {\n" +
316
		"	\n" +
313
		"\n" +
317
		"        }     \n" +
314
		"        }     \n" +
318
		"\n" +
315
		"\n" +
319
		"\n" +
316
		"\n" +
Lines 370-380 Link Here
370
		"\n" +
367
		"\n" +
371
		"\n" +
368
		"\n" +
372
		"}";
369
		"}";
373
	// TODO fix the incorrect indentation before the javadoc comment (also in 3.3 and 3.4M6)
374
	formatSource(source,
370
	formatSource(source,
375
		"public class C {\n" +
371
		"public class C {\n" +
376
		"	\n" +
372
		"\n" +
377
		"        /**\n" +
373
		"	/**\n" +
378
		"	 * a b c d .\n" +
374
		"	 * a b c d .\n" +
379
		"	 */\n" +
375
		"	 */\n" +
380
		"        void		m1  (   )   {\n" +
376
		"        void		m1  (   )   {\n" +
Lines 468-484 Link Here
468
		"#]\n" +
464
		"#]\n" +
469
		"\n" +
465
		"\n" +
470
		"}";
466
		"}";
471
	// TODO fix the incorrect indentation before the block comment (also in 3.3 and 3.4M6)
472
	formatSource(source,
467
	formatSource(source,
473
		"public class D {\n" +
468
		"public class D {\n" +
474
		"	\n" +
469
		"	\n" +
475
		"        /*\n" +
470
		"	/*\n" +
476
		"	 * a b c d .\n" +
471
		"	 * a b c d .\n" +
477
		"	 */\n" +
472
		"	 */\n" +
478
		"	void m2() {\n" +
473
		"	void m2() {\n" +
479
		"\n" +
474
		"\n" +
480
		"	}     \n" +
475
		"	}\n" +
481
		"\n" +
482
		"\n" +
476
		"\n" +
483
		"}"
477
		"}"
484
	);
478
	);
Lines 509-515 Link Here
509
		"	 * a b c d .\n" +
503
		"	 * a b c d .\n" +
510
		"	 */\n" +
504
		"	 */\n" +
511
		"	void m2() {\n" +
505
		"	void m2() {\n" +
512
		"	\n" +
506
		"\n" +
513
		"        }     \n" +
507
		"        }     \n" +
514
		"\n" +
508
		"\n" +
515
		"\n" +
509
		"\n" +
Lines 566-576 Link Here
566
		"\n" +
560
		"\n" +
567
		"\n" +
561
		"\n" +
568
		"}";
562
		"}";
569
	// TODO fix the incorrect indentation before the block comment (also in 3.3 and 3.4M6)
570
	formatSource(source,
563
	formatSource(source,
571
		"public class D {\n" +
564
		"public class D {\n" +
572
		"	\n" +
565
		"\n" +
573
		"        /*\n" +
566
		"	/*\n" +
574
		"	 * a b c d .\n" +
567
		"	 * a b c d .\n" +
575
		"	 */\n" +
568
		"	 */\n" +
576
		"        void		m2  (   )   {\n" +
569
		"        void		m2  (   )   {\n" +
Lines 657-669 Link Here
657
		"        }\n" +
650
		"        }\n" +
658
		"#]   \n" +
651
		"#]   \n" +
659
		"}";
652
		"}";
660
	// TODO fix the incorrect indentation before the method declaration (also in 3.3 and 3.4M6)
661
	// Note that the line comment wasn't formatted using 3.3 and 3.4 M6
662
	formatSource(source,
653
	formatSource(source,
663
		"public class E {\n" +
654
		"public class E {\n" +
664
		"	\n" +
655
		"	\n" +
665
		"\n" +
656
		"\n" +
666
		"        void m3() { // this is a bug\n" +
657
		"	void m3() { // this is a bug\n" +
667
		"\n" +
658
		"\n" +
668
		"	}\n" +
659
		"	}\n" +
669
		"   \n" +
660
		"   \n" +
Lines 707-713 Link Here
707
		"public class E {\n" +
698
		"public class E {\n" +
708
		"	\n" +
699
		"	\n" +
709
		"\n" +
700
		"\n" +
710
		"        void            m3()         { // this is a bug\n" +
701
		"        void            m3()         { // this        is a bug\n" +
711
		"\n" +
702
		"\n" +
712
		"	}\n" +
703
		"	}\n" +
713
		"\n" +
704
		"\n" +
Lines 750-756 Link Here
750
		"public class E {       \n" +
741
		"public class E {       \n" +
751
		"	\n" +
742
		"	\n" +
752
		"\n" +
743
		"\n" +
753
		"        void m3() { // this is a bug\n" +
744
		"	void m3() { // this      is        a    bug\n" +
754
		"\n" +
745
		"\n" +
755
		"        }\n" +
746
		"        }\n" +
756
		"   \n" +
747
		"   \n" +
Lines 772-778 Link Here
772
		"public class E {       \n" +
763
		"public class E {       \n" +
773
		"	\n" +
764
		"	\n" +
774
		"\n" +
765
		"\n" +
775
		"        void            m3()         { // this is a bug\n" +
766
		"        void            m3()         { // this        is        a    bug\n" +
776
		"\n" +
767
		"\n" +
777
		"        }\n" +
768
		"        }\n" +
778
		"   \n" +
769
		"   \n" +
Lines 796-802 Link Here
796
		"	\n" +
787
		"	\n" +
797
		"\n" +
788
		"\n" +
798
		"        void            m3()         {     \n" +
789
		"        void            m3()         {     \n" +
799
		"        	// this is a bug\n" +
790
		"		// this is a bug\n" +
800
		"\n" +
791
		"\n" +
801
		"        }\n" +
792
		"        }\n" +
802
		"   \n" +
793
		"   \n" +
Lines 832-894 Link Here
832
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=232788"
823
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=232788"
833
 */
824
 */
834
public void testBug232788_Tabs01() throws JavaModelException {
825
public void testBug232788_Tabs01() throws JavaModelException {
835
	this.preferences.comment_line_length = 40;
826
	this.formatterPrefs.comment_line_length = 40;
836
	this.preferences.tab_size = 1;
827
	this.formatterPrefs.tab_size = 1;
837
	this.preferences.indentation_size = 1;
828
	this.formatterPrefs.indentation_size = 1;
838
	formatUnit("bugs.b232788", "X01_tabs.java");
829
	formatUnit("bugs.b232788", "X01_tabs.java");
839
}
830
}
840
public void testBug232788_Spaces01() throws JavaModelException {
831
public void testBug232788_Spaces01() throws JavaModelException {
841
	this.preferences.comment_line_length = 40;
832
	this.formatterPrefs.comment_line_length = 40;
842
	this.preferences.tab_char = DefaultCodeFormatterOptions.SPACE;
833
	this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE;
843
	this.preferences.tab_size = 1;
834
	this.formatterPrefs.tab_size = 1;
844
	this.preferences.indentation_size = 1;
835
	this.formatterPrefs.indentation_size = 1;
845
	formatUnit("bugs.b232788", "X01_spaces.java");
836
	formatUnit("bugs.b232788", "X01_spaces.java");
846
}
837
}
847
public void testBug232788_Mixed01() throws JavaModelException {
838
public void testBug232788_Mixed01() throws JavaModelException {
848
	this.preferences.comment_line_length = 40;
839
	this.formatterPrefs.comment_line_length = 40;
849
	this.preferences.tab_char = DefaultCodeFormatterOptions.MIXED;
840
	this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.MIXED;
850
	this.preferences.tab_size = 1;
841
	this.formatterPrefs.tab_size = 1;
851
	this.preferences.indentation_size = 1;
842
	this.formatterPrefs.indentation_size = 1;
852
	formatUnit("bugs.b232788", "X01_mixed.java");
843
	formatUnit("bugs.b232788", "X01_mixed.java");
853
}
844
}
854
public void testBug232788_Tabs02() throws JavaModelException {
845
public void testBug232788_Tabs02() throws JavaModelException {
855
	this.preferences.comment_line_length = 40;
846
	this.formatterPrefs.comment_line_length = 40;
856
	this.preferences.tab_size = 0;
847
	this.formatterPrefs.tab_size = 0;
857
	this.preferences.indentation_size = 0;
848
	this.formatterPrefs.indentation_size = 0;
858
	formatUnit("bugs.b232788", "X02_tabs.java");
849
	formatUnit("bugs.b232788", "X02_tabs.java");
859
}
850
}
860
public void testBug232788_Spaces02() throws JavaModelException {
851
public void testBug232788_Spaces02() throws JavaModelException {
861
	this.preferences.comment_line_length = 40;
852
	this.formatterPrefs.comment_line_length = 40;
862
	this.preferences.tab_char = DefaultCodeFormatterOptions.SPACE;
853
	this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE;
863
	this.preferences.tab_size = 0;
854
	this.formatterPrefs.tab_size = 0;
864
	this.preferences.indentation_size = 0;
855
	this.formatterPrefs.indentation_size = 0;
865
	formatUnit("bugs.b232788", "X02_spaces.java");
856
	formatUnit("bugs.b232788", "X02_spaces.java");
866
}
857
}
867
public void testBug232788_Mixed02() throws JavaModelException {
858
public void testBug232788_Mixed02() throws JavaModelException {
868
	this.preferences.comment_line_length = 40;
859
	this.formatterPrefs.comment_line_length = 40;
869
	this.preferences.tab_char = DefaultCodeFormatterOptions.MIXED;
860
	this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.MIXED;
870
	this.preferences.tab_size = 0;
861
	this.formatterPrefs.tab_size = 0;
871
	this.preferences.indentation_size = 0;
862
	this.formatterPrefs.indentation_size = 0;
872
	formatUnit("bugs.b232788", "X02_mixed.java");
863
	formatUnit("bugs.b232788", "X02_mixed.java");
873
}
864
}
874
public void testBug232788_Tabs03() throws JavaModelException {
865
public void testBug232788_Tabs03() throws JavaModelException {
875
	this.preferences.comment_line_length = 40;
866
	this.formatterPrefs.comment_line_length = 40;
876
	this.preferences.tab_size = 1;
867
	this.formatterPrefs.tab_size = 1;
877
	this.preferences.indentation_size = 1;
868
	this.formatterPrefs.indentation_size = 1;
878
	formatUnit("bugs.b232788", "X03_tabs.java");
869
	formatUnit("bugs.b232788", "X03_tabs.java");
879
}
870
}
880
public void testBug232788_Spaces03() throws JavaModelException {
871
public void testBug232788_Spaces03() throws JavaModelException {
881
	this.preferences.comment_line_length = 40;
872
	this.formatterPrefs.comment_line_length = 40;
882
	this.preferences.tab_char = DefaultCodeFormatterOptions.SPACE;
873
	this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE;
883
	this.preferences.tab_size = 1;
874
	this.formatterPrefs.tab_size = 1;
884
	this.preferences.indentation_size = 1;
875
	this.formatterPrefs.indentation_size = 1;
885
	formatUnit("bugs.b232788", "X03_spaces.java");
876
	formatUnit("bugs.b232788", "X03_spaces.java");
886
}
877
}
887
public void testBug232788_Mixed03() throws JavaModelException {
878
public void testBug232788_Mixed03() throws JavaModelException {
888
	this.preferences.comment_line_length = 40;
879
	this.formatterPrefs.comment_line_length = 40;
889
	this.preferences.tab_char = DefaultCodeFormatterOptions.MIXED;
880
	this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.MIXED;
890
	this.preferences.tab_size = 1;
881
	this.formatterPrefs.tab_size = 1;
891
	this.preferences.indentation_size = 1;
882
	this.formatterPrefs.indentation_size = 1;
892
	formatUnit("bugs.b232788", "X03_mixed.java");
883
	formatUnit("bugs.b232788", "X03_mixed.java");
893
}
884
}
894
885
Lines 908-914 Link Here
908
		"         * block           [# #]            \n" +
899
		"         * block           [# #]            \n" +
909
		"         * comment\n" +
900
		"         * comment\n" +
910
		"         */\n" +
901
		"         */\n" +
911
		"        // single          [# #]            line comment\n" +
902
		"        // [#single                       line#] comment\n" +
912
		"}";
903
		"}";
913
	formatSource(source,
904
	formatSource(source,
914
		"\n" +
905
		"\n" +
Lines 916-925 Link Here
916
		"	/**\n" +
907
		"	/**\n" +
917
		"	 * Javadoc comment\n" +
908
		"	 * Javadoc comment\n" +
918
		"	 */\n" +
909
		"	 */\n" +
919
		"	/*\n" +
910
		"        /*\n" +
920
		"	 * block comment\n" +
911
		"	 * block comment\n" +
921
		"	 */\n" +
912
		"	 */\n" +
922
		"	// single line comment\n" +
913
		"        // single line comment\n" +
923
		"}"
914
		"}"
924
	);
915
	);
925
}
916
}
Lines 951-957 Link Here
951
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=233224"
942
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=233224"
952
 */
943
 */
953
public void testBug233224() throws JavaModelException {
944
public void testBug233224() throws JavaModelException {
954
	this.preferences.comment_line_length = 40;
945
	this.formatterPrefs.comment_line_length = 40;
955
	formatUnit("bugs.b233224", "X01.java");
946
	formatUnit("bugs.b233224", "X01.java");
956
}
947
}
957
948
Lines 961-967 Link Here
961
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=233259"
952
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=233259"
962
 */
953
 */
963
public void testBug233259a() throws JavaModelException {
954
public void testBug233259a() throws JavaModelException {
964
	this.preferences.comment_line_length = 40;
955
	this.formatterPrefs.comment_line_length = 40;
965
	String source =
956
	String source =
966
		"public class X {\n" +
957
		"public class X {\n" +
967
		"        /**\n" +
958
		"        /**\n" +
Lines 981-987 Link Here
981
	);
972
	);
982
}
973
}
983
public void testBug233259b() throws JavaModelException {
974
public void testBug233259b() throws JavaModelException {
984
	this.preferences.comment_line_length = 40;
975
	this.formatterPrefs.comment_line_length = 40;
985
	// difference with 3.3 formatter:
976
	// difference with 3.3 formatter:
986
	// split html reference as this allow not to go over the max line width
977
	// split html reference as this allow not to go over the max line width
987
	String source =
978
	String source =
Lines 1004-1010 Link Here
1004
	);
995
	);
1005
}
996
}
1006
public void testBug233259c() throws JavaModelException {
997
public void testBug233259c() throws JavaModelException {
1007
	this.preferences.comment_line_length = 40;
998
	this.formatterPrefs.comment_line_length = 40;
1008
	String source =
999
	String source =
1009
		"public class X {\n" +
1000
		"public class X {\n" +
1010
		"        /**\n" +
1001
		"        /**\n" +
Lines 1025-1031 Link Here
1025
	);
1016
	);
1026
}
1017
}
1027
public void testBug233259d() throws JavaModelException {
1018
public void testBug233259d() throws JavaModelException {
1028
	this.preferences.comment_line_length = 40;
1019
	this.formatterPrefs.comment_line_length = 40;
1029
	String source =
1020
	String source =
1030
		"public class X {\n" +
1021
		"public class X {\n" +
1031
		"        /**\n" +
1022
		"        /**\n" +
Lines 1052-1058 Link Here
1052
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=237942"
1043
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=237942"
1053
 */
1044
 */
1054
public void testBug237942a() throws JavaModelException {
1045
public void testBug237942a() throws JavaModelException {
1055
	this.preferences.comment_line_length = 40;
1046
	this.formatterPrefs.comment_line_length = 40;
1056
	String source =
1047
	String source =
1057
		"public class X {\n" +
1048
		"public class X {\n" +
1058
		"        /**\n" +
1049
		"        /**\n" +
Lines 1072-1078 Link Here
1072
	);
1063
	);
1073
}
1064
}
1074
public void testBug237942b() throws JavaModelException {
1065
public void testBug237942b() throws JavaModelException {
1075
	this.preferences.comment_line_length = 40;
1066
	this.formatterPrefs.comment_line_length = 40;
1076
	// difference with 3.3 formatter:
1067
	// difference with 3.3 formatter:
1077
	// do not split string reference as this can lead to javadoc syntax error
1068
	// do not split string reference as this can lead to javadoc syntax error
1078
	String source =
1069
	String source =
Lines 1094-1100 Link Here
1094
	);
1085
	);
1095
}
1086
}
1096
public void testBug237942c() throws JavaModelException {
1087
public void testBug237942c() throws JavaModelException {
1097
	this.preferences.comment_line_length = 40;
1088
	this.formatterPrefs.comment_line_length = 40;
1098
	// difference with 3.3 formatter:
1089
	// difference with 3.3 formatter:
1099
	// do not split string reference as this can lead to javadoc syntax error
1090
	// do not split string reference as this can lead to javadoc syntax error
1100
	String source =
1091
	String source =
Lines 1116-1122 Link Here
1116
	);
1107
	);
1117
}
1108
}
1118
public void testBug237942d() throws JavaModelException {
1109
public void testBug237942d() throws JavaModelException {
1119
	this.preferences.comment_line_length = 40;
1110
	this.formatterPrefs.comment_line_length = 40;
1120
	// difference with 3.3 formatter:
1111
	// difference with 3.3 formatter:
1121
	// do not split string reference as this can lead to javadoc syntax error
1112
	// do not split string reference as this can lead to javadoc syntax error
1122
	String source =
1113
	String source =
Lines 1162-1167 Link Here
1162
	);
1153
	);
1163
}
1154
}
1164
1155
1156
//static { TESTS_PREFIX = "testBug234583"; }
1157
/**
1158
 * @bug 234583: [formatter] Code formatter should adapt edits instead of regions
1159
 * @test Ensure that selected region(s) are correctly formatted
1160
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=234583"
1161
 */
1162
public void testBug234583a() throws JavaModelException {
1163
	String source = 
1164
		"public class X {\n" + 
1165
		"[#                        int i= 1;               #]\n" + 
1166
		"}\n";
1167
	formatSource(source,
1168
		"public class X {\n" + 
1169
		"	int i = 1;\n" + 
1170
		"}\n"
1171
	);
1172
}
1173
public void testBug234583b() throws JavaModelException {
1174
	String source = 
1175
		"public class X {      \n" + 
1176
		"\n" + 
1177
		"\n" + 
1178
		"\n" + 
1179
		"[#                        int i= 1;               #]\n" + 
1180
		"\n" + 
1181
		"\n" + 
1182
		"\n" + 
1183
		"\n" + 
1184
		"     }\n";
1185
	formatSource(source,
1186
		"public class X {      \n" + 
1187
		"\n" + 
1188
		"\n" + 
1189
		"\n" + 
1190
		"	int i = 1;\n" + 
1191
		"\n" + 
1192
		"\n" + 
1193
		"\n" + 
1194
		"\n" + 
1195
		"     }\n"
1196
	);
1197
}
1198
public void testBug234583c() throws JavaModelException {
1199
	String source = 
1200
		"public class X {      \n" + 
1201
		"\n" + 
1202
		"\n" + 
1203
		"\n" + 
1204
		"[#                        int i= 1;               \n" + 
1205
		"#]\n" + 
1206
		"\n" + 
1207
		"\n" + 
1208
		"\n" + 
1209
		"     }\n";
1210
	formatSource(source,
1211
		"public class X {      \n" + 
1212
		"\n" + 
1213
		"\n" + 
1214
		"\n" + 
1215
		"	int i = 1;\n" + 
1216
		"\n" + 
1217
		"\n" + 
1218
		"\n" + 
1219
		"     }\n"
1220
	);
1221
}
1222
public void testBug234583d() throws JavaModelException {
1223
	String source = 
1224
		"public class X {      \n" + 
1225
		"\n" + 
1226
		"\n" + 
1227
		"[#\n" + 
1228
		"                        int i= 1;               \n" + 
1229
		"\n" + 
1230
		"#]\n" + 
1231
		"\n" + 
1232
		"\n" + 
1233
		"     }\n";
1234
	formatSource(source,
1235
		"public class X {      \n" + 
1236
		"\n" + 
1237
		"\n" + 
1238
		"	int i = 1;\n" + 
1239
		"\n" + 
1240
		"\n" + 
1241
		"     }\n"
1242
	);
1243
}
1244
public void testBug234583e() throws JavaModelException {
1245
	String source = 
1246
		"public class X {      \n" + 
1247
		"\n" + 
1248
		"[#\n" + 
1249
		"\n" + 
1250
		"                        int i= 1;               \n" + 
1251
		"\n" + 
1252
		"\n" + 
1253
		"#]\n" + 
1254
		"\n" + 
1255
		"     }\n";
1256
	formatSource(source,
1257
		"public class X {      \n" + 
1258
		"\n" + 
1259
		"	int i = 1;\n" + 
1260
		"\n" + 
1261
		"     }\n"
1262
	);
1263
}
1264
public void testBug234583f() throws JavaModelException {
1265
	String source = 
1266
		"public class X {      \n" + 
1267
		"[#\n" + 
1268
		"\n" + 
1269
		"\n" + 
1270
		"                        int i= 1;               \n" + 
1271
		"\n" + 
1272
		"\n" + 
1273
		"\n" + 
1274
		"#]\n" + 
1275
		"     }\n";
1276
	formatSource(source,
1277
		"public class X {      \n" + 
1278
		"\n" + 
1279
		"	int i = 1;\n" + 
1280
		"\n" + 
1281
		"     }\n"
1282
	);
1283
}
1284
public void testBug234583g() throws JavaModelException {
1285
	String source = 
1286
		"public class X {      [#\n" + 
1287
		"\n" + 
1288
		"\n" + 
1289
		"\n" + 
1290
		"                        int i= 1;               \n" + 
1291
		"\n" + 
1292
		"\n" + 
1293
		"\n" + 
1294
		"\n" + 
1295
		"#]     }\n";
1296
	formatSource(source,
1297
		"public class X {      \n" + 
1298
		"\n" + 
1299
		"	int i = 1;\n" + 
1300
		"\n" + 
1301
		"     }\n"
1302
	);
1303
}
1304
public void testBug234583h() throws JavaModelException {
1305
	String source = 
1306
		"public class X {   [#   \n" + 
1307
		"\n" + 
1308
		"\n" + 
1309
		"\n" + 
1310
		"                        int i= 1;               \n" + 
1311
		"\n" + 
1312
		"\n" + 
1313
		"\n" + 
1314
		"\n" + 
1315
		"   #]  }\n";
1316
	formatSource(source,
1317
		"public class X {   \n" + 
1318
		"\n" + 
1319
		"	int i = 1;\n" + 
1320
		"\n" + 
1321
		"  }\n"
1322
	);
1323
}
1324
public void testBug234583i() throws JavaModelException {
1325
	String source = 
1326
		"public class X {[#      \n" + 
1327
		"\n" + 
1328
		"\n" + 
1329
		"\n" + 
1330
		"                        int i= 1;               \n" + 
1331
		"\n" + 
1332
		"\n" + 
1333
		"\n" + 
1334
		"\n" + 
1335
		"     #]}\n";
1336
	formatSource(source,
1337
		"public class X {\n" + 
1338
		"\n" + 
1339
		"	int i = 1;\n" + 
1340
		"\n" + 
1341
		"}\n"
1342
	);
1343
}
1344
// duplicate https://bugs.eclipse.org/bugs/show_bug.cgi?id=239447
1345
public void testBug234583_Bug239447() throws JavaModelException {
1346
	String source = 
1347
		"public class Bug239447 {\n" + 
1348
		"	private static final String CONTENT = \"test.ObjectB {\\n\"\n" + 
1349
		"[#			     + \"     multiEle = { name=\\\"Foo\\\" }\\n\"#]\n" + 
1350
		"			+ \"     multiEle = :x { name=\\\"Bar\\\" }\\n\" + \"   singleEle = x;\\n\"\n" + 
1351
		"			+ \"}\";\n" + 
1352
		"\n" + 
1353
		"}\n";
1354
	formatSource(source,
1355
		"public class Bug239447 {\n" + 
1356
		"	private static final String CONTENT = \"test.ObjectB {\\n\"\n" + 
1357
		"			+ \"     multiEle = { name=\\\"Foo\\\" }\\n\"\n" + 
1358
		"			+ \"     multiEle = :x { name=\\\"Bar\\\" }\\n\" + \"   singleEle = x;\\n\"\n" + 
1359
		"			+ \"}\";\n" + 
1360
		"\n" + 
1361
		"}\n"
1362
	);
1363
}
1364
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=237453
1365
public void testBug234583_Bug237453a() throws JavaModelException {
1366
	String source = 
1367
		"package test1;\n" + 
1368
		"\n" + 
1369
		"public class E1 {\n" + 
1370
		" 	void foo() {\n" + 
1371
		"	}\n" + 
1372
		" 	[#\n" + 
1373
		"	#]\n" + 
1374
		" 	void bar() {\n" + 
1375
		"	}\n" + 
1376
		"}";
1377
	formatSource(source,
1378
		"package test1;\n" + 
1379
		"\n" + 
1380
		"public class E1 {\n" + 
1381
		" 	void foo() {\n" + 
1382
		"	}\n" + 
1383
		" 	\n" + 
1384
		" 	void bar() {\n" + 
1385
		"	}\n" + 
1386
		"}"
1387
	);
1388
}
1389
public void testBug234583_Bug237453b() throws JavaModelException {
1390
	String source = 
1391
		"package test1;\n" + 
1392
		"\n" + 
1393
		"public class E1 {\n" + 
1394
		" 	void foo() {\n" + 
1395
		"	}\n" + 
1396
		" 	\n" + 
1397
		"[#	#]\n" + 
1398
		" 	void bar() {\n" + 
1399
		"	}\n" + 
1400
		"}";
1401
	formatSource(source,
1402
		"package test1;\n" + 
1403
		"\n" + 
1404
		"public class E1 {\n" + 
1405
		" 	void foo() {\n" + 
1406
		"	}\n" + 
1407
		" 	\n" + 
1408
		"	\n" + 
1409
		" 	void bar() {\n" + 
1410
		"	}\n" + 
1411
		"}"
1412
	);
1413
}
1414
// duplicate https://bugs.eclipse.org/bugs/show_bug.cgi?id=237592
1415
public void testBug234583_Bug237592() throws JavaModelException {
1416
	String source = 
1417
		"package test;\n" + 
1418
		"\n" + 
1419
		"public class Test {\n" + 
1420
		"\n" + 
1421
		"	void foo() {\n" + 
1422
		"	}\n" + 
1423
		"\n" + 
1424
		"[#	  #]\n" + 
1425
		"	\n" + 
1426
		"	\n" + 
1427
		"	\n" + 
1428
		"	\n" + 
1429
		"	\n" + 
1430
		"[#	 #]\n" + 
1431
		"	\n" + 
1432
		"	\n" + 
1433
		"	\n" + 
1434
		"	\n" + 
1435
		"	\n" + 
1436
		"	void bar() {\n" + 
1437
		"	}\n" + 
1438
		"\n" + 
1439
		"}\n";
1440
	formatSource(source,
1441
		"package test;\n" + 
1442
		"\n" + 
1443
		"public class Test {\n" + 
1444
		"\n" + 
1445
		"	void foo() {\n" + 
1446
		"	}\n" + 
1447
		"\n" + 
1448
		"	\n" + 
1449
		"	\n" + 
1450
		"	\n" + 
1451
		"	\n" + 
1452
		"	\n" + 
1453
		"	\n" + 
1454
		"	 \n" + 
1455
		"	\n" + 
1456
		"	\n" + 
1457
		"	\n" + 
1458
		"	\n" + 
1459
		"	\n" + 
1460
		"	void bar() {\n" + 
1461
		"	}\n" + 
1462
		"\n" + 
1463
		"}\n"
1464
	);
1465
}
1466
1165
/**
1467
/**
1166
 * @bug 236230: [formatter] SIOOBE while formatting a compilation unit.
1468
 * @bug 236230: [formatter] SIOOBE while formatting a compilation unit.
1167
 * @test Ensure that no exception occurs while formatting
1469
 * @test Ensure that no exception occurs while formatting
Lines 1239-1245 Link Here
1239
	);
1541
	);
1240
}
1542
}
1241
public void testBug236230c() throws JavaModelException {
1543
public void testBug236230c() throws JavaModelException {
1242
	this.preferences.comment_format_header = true;
1544
	this.formatterPrefs.comment_format_header = true;
1243
	String source =
1545
	String source =
1244
		"/**\n" +
1546
		"/**\n" +
1245
		" * Need a javadoc comment before to get the exception.\n" +
1547
		" * Need a javadoc comment before to get the exception.\n" +
Lines 1493-1499 Link Here
1493
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=238090"
1795
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=238090"
1494
 */
1796
 */
1495
public void testBug238090() throws JavaModelException {
1797
public void testBug238090() throws JavaModelException {
1496
	this.preferences.comment_line_length = 40;
1798
	this.formatterPrefs.comment_line_length = 40;
1497
	String source =
1799
	String source =
1498
		"package test.bugs;\n" +
1800
		"package test.bugs;\n" +
1499
		"public class LongNameClass {\n" +
1801
		"public class LongNameClass {\n" +
Lines 1964-1970 Link Here
1964
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=241345"
2266
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=241345"
1965
 */
2267
 */
1966
public void testBug241345() throws JavaModelException {
2268
public void testBug241345() throws JavaModelException {
1967
	this.preferences.comment_format_html = false;
2269
	this.formatterPrefs.comment_format_html = false;
1968
	String source = 
2270
	String source = 
1969
		"/**\n" + 
2271
		"/**\n" + 
1970
		" * <p>Should not format HTML paragraph</p>\n" + 
2272
		" * <p>Should not format HTML paragraph</p>\n" + 
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java (+324 lines)
Lines 54-59 Link Here
54
	private static final String LINE_SEPARATOR = System.getProperty("line.separator");
54
	private static final String LINE_SEPARATOR = System.getProperty("line.separator");
55
	private long time;
55
	private long time;
56
56
57
	DefaultCodeFormatterOptions formatterPrefs;
58
57
	static {
59
	static {
58
//		TESTS_NUMBERS = new int[] { 715 };
60
//		TESTS_NUMBERS = new int[] { 715 };
59
//		TESTS_RANGE = new int[] { 715, -1 };
61
//		TESTS_RANGE = new int[] { 715, -1 };
Lines 147-152 Link Here
147
149
148
		return org.eclipse.jdt.internal.core.util.Util.editedString(source, edit);
150
		return org.eclipse.jdt.internal.core.util.Util.editedString(source, edit);
149
	}
151
	}
152
	
153
	/**
154
	 * Init formatter preferences with Eclipse default settings.
155
	 */
156
	protected void setUp() throws Exception {
157
	    super.setUp();
158
		this.formatterPrefs = DefaultCodeFormatterOptions.getEclipseDefaultSettings();
159
	}
150
160
151
	/**
161
	/**
152
	 * Create project and set the jar placeholder.
162
	 * Create project and set the jar placeholder.
Lines 203-208 Link Here
203
		assertSourceEquals("Different number of length", Util.convertToIndependantLineDelimiter(expectedContents), actualContents);
213
		assertSourceEquals("Different number of length", Util.convertToIndependantLineDelimiter(expectedContents), actualContents);
204
	}
214
	}
205
215
216
	DefaultCodeFormatter codeFormatter() {
217
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(this.formatterPrefs, JAVA_PROJECT.getOptions(true));
218
		return codeFormatter;
219
	}
220
	
221
	void assertLineEquals(String actualContents, String originalSource, String expectedContents) {
222
		String outputSource = expectedContents == null ? originalSource : expectedContents;
223
		assertLineEquals(actualContents, originalSource, outputSource, false /* do not check null */);
224
	}
225
	
226
	void formatSource(String source, String formattedOutput) {
227
		formatSource(source, formattedOutput, CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS, 0, true /*repeat formatting twice*/);
228
	}
229
	
230
	void formatSource(String source, String formattedOutput, boolean repeat) {
231
		formatSource(source, formattedOutput, CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS, 0, repeat);
232
	}
233
	
234
	void formatSource(String source, String formattedOutput, int kind, int indentationLevel, boolean repeat) {
235
		int regionStart = source.indexOf("[#");
236
		if (regionStart != -1) {
237
			IRegion[] regions =  new Region[10];
238
			int idx = 0;
239
			int start = 0;
240
			int delta = 0;
241
			StringBuffer buffer = new StringBuffer();
242
			while (regionStart != -1) {
243
				buffer.append(source.substring(start, regionStart));
244
				int regionEnd = source.indexOf("#]", regionStart+2);
245
				buffer.append(source.substring(regionStart+2, regionEnd));
246
				regions[idx++] = new Region(regionStart-delta, regionEnd-(regionStart+2));
247
				delta += 4;
248
				start = regionEnd + 2;
249
				regionStart = source.indexOf("[#", start);
250
			}
251
			buffer.append(source.substring(start, source.length()));
252
			String newSource = buffer.toString();
253
			String result;
254
			if (idx == 1) {
255
				// Use offset and length until bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=233967 is fixed
256
				result = runFormatter(codeFormatter(), newSource, kind, indentationLevel, regions[0].getOffset(), regions[0].getLength(), LINE_SEPARATOR, repeat);
257
			} else {
258
				System.arraycopy(regions, 0, regions = new Region[idx], 0, idx);
259
				result = runFormatter(codeFormatter(), newSource, kind, indentationLevel, regions, LINE_SEPARATOR);
260
			}
261
			assertLineEquals(result, newSource, formattedOutput);
262
		} else {
263
			formatSource(source, formattedOutput, kind, indentationLevel, false, 0, -1, null, repeat);
264
		}
265
	}
266
	
267
	void formatSource(String source, String formattedOutput, int kind, int indentationLevel, boolean checkNull, int offset, int length, String lineSeparator, boolean repeat) {
268
		DefaultCodeFormatter codeFormatter = codeFormatter();
269
		String result;
270
		if (length == -1) {
271
			result = runFormatter(codeFormatter, source, kind, indentationLevel, offset, source.length(), lineSeparator, repeat);
272
		} else {
273
			result = runFormatter(codeFormatter, source, kind, indentationLevel, offset, length, lineSeparator, repeat);
274
		}
275
		assertLineEquals(result, source, formattedOutput);
276
	}
277
278
206
	private void runTest(String packageName, String compilationUnitName) {
279
	private void runTest(String packageName, String compilationUnitName) {
207
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(DefaultCodeFormatterConstants.getEclipse21Settings());
280
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(DefaultCodeFormatterConstants.getEclipse21Settings());
208
		preferences.number_of_empty_lines_to_preserve = 0;
281
		preferences.number_of_empty_lines_to_preserve = 0;
Lines 9456-9461 Link Here
9456
9529
9457
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=203304
9530
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=203304
9458
	public void test671() {
9531
	public void test671() {
9532
		/* old version
9459
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9533
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9460
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9534
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9461
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9535
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
Lines 9464-9469 Link Here
9464
				new Region(101, 20)
9538
				new Region(101, 20)
9465
		};
9539
		};
9466
		runTest(codeFormatter, "test671", "A.java", CodeFormatter.K_COMPILATION_UNIT, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
9540
		runTest(codeFormatter, "test671", "A.java", CodeFormatter.K_COMPILATION_UNIT, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
9541
		*/
9542
		String source = 
9543
			"public class A {\n" + 
9544
			"	public static void main(String[] args) {\n" + 
9545
			"[#		int a     =     1;#]\n" + 
9546
			"		int b     =     2;\n" + 
9547
			"[#		int c     =     3;#]\n" + 
9548
			"	}\n" + 
9549
			"}\n";
9550
		formatSource(source,
9551
			"public class A {\n" + 
9552
			"	public static void main(String[] args) {\n" + 
9553
			"		int a = 1;\n" + 
9554
			"		int b     =     2;\n" + 
9555
			"		int c = 3;\n" + 
9556
			"	}\n" + 
9557
			"}\n",
9558
			CodeFormatter.K_COMPILATION_UNIT,
9559
			0 /*no indentation*/,
9560
			true /*repeat formatting twice*/
9561
		);
9467
	}
9562
	}
9468
9563
9469
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=203304
9564
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=203304
Lines 9492-9497 Link Here
9492
9587
9493
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=203304
9588
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=203304
9494
	public void test674() {
9589
	public void test674() {
9590
		/* old version
9495
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9591
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9496
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9592
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9497
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9593
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
Lines 9500-9505 Link Here
9500
				new Region(276, 54)
9596
				new Region(276, 54)
9501
		};
9597
		};
9502
		runTest(codeFormatter, "test674", "A.java", CodeFormatter.K_CLASS_BODY_DECLARATIONS, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
9598
		runTest(codeFormatter, "test674", "A.java", CodeFormatter.K_CLASS_BODY_DECLARATIONS, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
9599
		*/
9600
		String source = 
9601
			"public class A {\n" + 
9602
			"	\n" + 
9603
			"	\n" + 
9604
			"	private class Inner1 {[#\n" + 
9605
			"	    	 \n" + 
9606
			"	    	 \n" + 
9607
			"	    	      void    bar () {   }\n" + 
9608
			"	    	      \n" + 
9609
			"	    	   void    i()\n" + 
9610
			"	    	   {\n" + 
9611
			"	    		   \n" + 
9612
			"	    	      }\n" + 
9613
			"	     #]}\n" + 
9614
			"	     \n" + 
9615
			"	     \n" + 
9616
			"	private class Inner2 {\n" + 
9617
			"	    	     void    xy()  {\n" + 
9618
			"	    	    	 \n" + 
9619
			"	    }\n" + 
9620
			"	     }\n" + 
9621
			"}\n" + 
9622
			"class B {[#\n" + 
9623
			"	     private      void foo() {\n" + 
9624
			"	    	 \n" + 
9625
			"	          }\n" + 
9626
			"#]}\n";
9627
		formatSource(source,
9628
			"public class A {\n" + 
9629
			"	\n" + 
9630
			"	\n" + 
9631
			"	private class Inner1 {\n" + 
9632
			"\n" + 
9633
			"		void bar() {\n" + 
9634
			"		}\n" + 
9635
			"\n" + 
9636
			"		void i() {\n" + 
9637
			"\n" + 
9638
			"		}\n" + 
9639
			"	}\n" + 
9640
			"	     \n" + 
9641
			"	     \n" + 
9642
			"	private class Inner2 {\n" + 
9643
			"	    	     void    xy()  {\n" + 
9644
			"	    	    	 \n" + 
9645
			"	    }\n" + 
9646
			"	     }\n" + 
9647
			"}\n" + 
9648
			"class B {\n" + 
9649
			"	private void foo() {\n" + 
9650
			"\n" + 
9651
			"	}\n" + 
9652
			"}\n",
9653
			CodeFormatter.K_CLASS_BODY_DECLARATIONS,
9654
			0 /*no indentation*/,
9655
			true /*repeat formatting twice*/
9656
		);
9503
	}
9657
	}
9504
9658
9505
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=203304
9659
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=203304
Lines 9631-9636 Link Here
9631
9785
9632
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
9786
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
9633
	public void test685() {
9787
	public void test685() {
9788
		/* old version
9634
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9789
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9635
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9790
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9636
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9791
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
Lines 9638-9643 Link Here
9638
				new Region(18, 35)
9793
				new Region(18, 35)
9639
		};
9794
		};
9640
		runTest(codeFormatter, "test685", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
9795
		runTest(codeFormatter, "test685", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
9796
		*/
9797
		String source = 
9798
			"public class A {\n" + 
9799
			" [#                       int i=1;    #]           \n" + 
9800
			"}\n";
9801
		// Note that whitespaces outside the region are kept after the formatting
9802
		// This is intentional since fix for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=234583
9803
		// The formatter should not touch code outside the given region(s)...
9804
		formatSource(source,
9805
			"public class A {\n" + 
9806
			" 	int i = 1;           \n" + 
9807
			"}\n",
9808
			CodeFormatter.K_UNKNOWN,
9809
			0 /*no indentation*/,
9810
			true /*repeat formatting twice*/
9811
		);
9641
	}
9812
	}
9642
9813
9643
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
9814
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
Lines 9661-9666 Link Here
9661
9832
9662
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
9833
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
9663
	public void test688a() {
9834
	public void test688a() {
9835
		/* old version
9664
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9836
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9665
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9837
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9666
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9838
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
Lines 9668-9676 Link Here
9668
				new Region(18, 48)
9840
				new Region(18, 48)
9669
		};
9841
		};
9670
		runTest(codeFormatter, "test688", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
9842
		runTest(codeFormatter, "test688", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
9843
		*/
9844
		String source = 
9845
			"public class A {\n" + 
9846
			" [#                       int i=1;               \n" + 
9847
			"}#]\n";
9848
		// Note that whitespaces outside the region are kept after the formatting
9849
		// This is intentional since fix for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=234583
9850
		// The formatter should not touch code outside the given region(s)...
9851
		formatSource(source,
9852
			"public class A {\n" + 
9853
			" 	int i = 1;\n" + 
9854
			"}\n",
9855
			CodeFormatter.K_UNKNOWN,
9856
			0 /*no indentation*/,
9857
			true /*repeat formatting twice*/
9858
		);
9671
	}
9859
	}
9672
9860
9673
	public void test688b() {
9861
	public void test688b() {
9862
		/* old version
9674
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9863
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9675
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9864
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9676
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9865
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
Lines 9678-9683 Link Here
9678
				new Region(18, 49)
9867
				new Region(18, 49)
9679
		};
9868
		};
9680
		runTest(codeFormatter, "test688", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
9869
		runTest(codeFormatter, "test688", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
9870
		*/
9871
		String source = 
9872
			"public class A {\n" + 
9873
			" [#                       int i=1;               \n" + 
9874
			"}\n#]";
9875
		// Note that whitespaces outside the region are kept after the formatting
9876
		// This is intentional since fix for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=234583
9877
		// The formatter should not touch code outside the given region(s)...
9878
		formatSource(source,
9879
			"public class A {\n" + 
9880
			" 	int i = 1;\n" + 
9881
			"}\n"
9882
		);
9681
	}
9883
	}
9682
9884
9683
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
9885
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
Lines 9694-9699 Link Here
9694
9896
9695
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
9897
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
9696
	public void test690() {
9898
	public void test690() {
9899
		/* old version
9697
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9900
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9698
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9901
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9699
		preferences.line_separator = "\r";//$NON-NLS-1$
9902
		preferences.line_separator = "\r";//$NON-NLS-1$
Lines 9702-9711 Link Here
9702
				new Region(31, 23)
9905
				new Region(31, 23)
9703
		};
9906
		};
9704
		runTest(codeFormatter, "test689", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\r");//$NON-NLS-1$ //$NON-NLS-2$
9907
		runTest(codeFormatter, "test689", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\r");//$NON-NLS-1$ //$NON-NLS-2$
9908
		*/
9909
		this.formatterPrefs.line_separator = "\r";//$NON-NLS-1$
9910
		String source = 
9911
			"package pkg1;\n" + 
9912
			"public class A {\n" + 
9913
			"[#        int i = 1;     #]\n" + 
9914
			"\n" + 
9915
			"}\n";
9916
		// Note that whitespaces outside the region are kept after the formatting
9917
		// This is intentional since fix for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=234583
9918
		// The formatter should not touch code outside the given region(s)...
9919
		formatSource(source,
9920
			"package pkg1;\n" + 
9921
			"public class A {\n" + 
9922
			"	int i = 1;\n" + 
9923
			"\n" + 
9924
			"}\n",
9925
			CodeFormatter.K_UNKNOWN,
9926
			0 /*no indentation*/,
9927
			true /*repeat formatting twice*/
9928
		);
9705
	}
9929
	}
9706
9930
9707
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
9931
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
9708
	public void test691() {
9932
	public void test691() {
9933
		/* old version
9709
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9934
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9710
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9935
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9711
		preferences.line_separator = "\r\n";//$NON-NLS-1$
9936
		preferences.line_separator = "\r\n";//$NON-NLS-1$
Lines 9714-9719 Link Here
9714
				new Region(31, 22)
9939
				new Region(31, 22)
9715
		};
9940
		};
9716
		runTest(codeFormatter, "test689", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\r\n");//$NON-NLS-1$ //$NON-NLS-2$
9941
		runTest(codeFormatter, "test689", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\r\n");//$NON-NLS-1$ //$NON-NLS-2$
9942
		*/
9943
		this.formatterPrefs.line_separator = "\r\n";//$NON-NLS-1$
9944
		String source = 
9945
			"package pkg1;\n" + 
9946
			"public class A {\n" + 
9947
			"[#        int i = 1;    #] \n" + 
9948
			"\n" + 
9949
			"}\n";
9950
		// Note that whitespaces outside the region are kept after the formatting
9951
		// This is intentional since fix for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=234583
9952
		// The formatter should not touch code outside the given region(s)...
9953
		formatSource(source,
9954
			"package pkg1;\n" + 
9955
			"public class A {\n" + 
9956
			"	int i = 1; \n" + 
9957
			"\n" + 
9958
			"}\n",
9959
			CodeFormatter.K_UNKNOWN,
9960
			0 /*no indentation*/,
9961
			true /*repeat formatting twice*/
9962
		);
9717
	}
9963
	}
9718
9964
9719
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
9965
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
Lines 9810-9815 Link Here
9810
10056
9811
	// variation on bugs 208541, 213283, 213284
10057
	// variation on bugs 208541, 213283, 213284
9812
	public void test697a() {
10058
	public void test697a() {
10059
		/* old version
9813
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
10060
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9814
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
10061
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9815
		preferences.line_separator = "\n";//$NON-NLS-1$
10062
		preferences.line_separator = "\n";//$NON-NLS-1$
Lines 9818-9827 Link Here
9818
				new Region(17, 55) // end of line selection
10065
				new Region(17, 55) // end of line selection
9819
		};
10066
		};
9820
		runTest(codeFormatter, "test697", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
10067
		runTest(codeFormatter, "test697", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
10068
		*/
10069
		String source = 
10070
			"public class A {\n" + 
10071
			"[#	\n" + 
10072
			"	\n" + 
10073
			"	\n" + 
10074
			"                        int i = 1;               #]\n" + 
10075
			"\n" + 
10076
			"\n" + 
10077
			"\n" + 
10078
			"}\n" + 
10079
			"";
10080
		// Note that whitespaces outside the region are kept after the formatting
10081
		// This is intentional since fix for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=234583
10082
		// The formatter should not touch code outside the given region(s)...
10083
		formatSource(source,
10084
			"public class A {\n" + 
10085
			"\n" + 
10086
			"	int i = 1;\n" + 
10087
			"\n" + 
10088
			"\n" + 
10089
			"\n" + 
10090
			"}\n",
10091
			CodeFormatter.K_UNKNOWN,
10092
			0 /*no indentation*/,
10093
			true /*repeat formatting twice*/
10094
		);
9821
	}
10095
	}
9822
10096
9823
	// variation on bugs 208541, 213283, 213284
10097
	// variation on bugs 208541, 213283, 213284
9824
	public void test697b() {
10098
	public void test697b() {
10099
		/* old version
9825
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
10100
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9826
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
10101
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9827
		preferences.line_separator = "\n";//$NON-NLS-1$
10102
		preferences.line_separator = "\n";//$NON-NLS-1$
Lines 9830-9835 Link Here
9830
				new Region(17, 56) // end of line selection + 1
10105
				new Region(17, 56) // end of line selection + 1
9831
		};
10106
		};
9832
		runTest(codeFormatter, "test697", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
10107
		runTest(codeFormatter, "test697", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
10108
		*/
10109
		String source = 
10110
			"public class A {\n" + 
10111
			"[#	\n" + 
10112
			"	\n" + 
10113
			"	\n" + 
10114
			"                        int i = 1;               \n" + 
10115
			"#]\n" + 
10116
			"\n" + 
10117
			"\n" + 
10118
			"}\n" + 
10119
			"";
10120
		// Note that whitespaces outside the region are kept after the formatting
10121
		// This is intentional since fix for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=234583
10122
		// The formatter should not touch code outside the given region(s)...
10123
		formatSource(source,
10124
			"public class A {\n" + 
10125
			"\n" + 
10126
			"	int i = 1;\n" + 
10127
			"\n" + 
10128
			"\n" + 
10129
			"}\n",
10130
			CodeFormatter.K_UNKNOWN,
10131
			0 /*no indentation*/,
10132
			true /*repeat formatting twice*/
10133
		);
9833
	}
10134
	}
9834
10135
9835
	// variation on bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
10136
	// variation on bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
Lines 10128-10136 Link Here
10128
		String resourcePath = getResource("test713", "formatter.xml");
10429
		String resourcePath = getResource("test713", "formatter.xml");
10129
		Map options = DecodeCodeFormatterPreferences.decodeCodeFormatterOptions(resourcePath, "Dani");
10430
		Map options = DecodeCodeFormatterPreferences.decodeCodeFormatterOptions(resourcePath, "Dani");
10130
		assertNotNull("No preferences", options);
10431
		assertNotNull("No preferences", options);
10432
		/* old version
10131
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
10433
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
10132
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
10434
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
10133
		runTest(codeFormatter, "test713", "A.java", CodeFormatter.K_COMPILATION_UNIT, 0, false, 76, 27);//$NON-NLS-1$ //$NON-NLS-2$
10435
		runTest(codeFormatter, "test713", "A.java", CodeFormatter.K_COMPILATION_UNIT, 0, false, 76, 27);//$NON-NLS-1$ //$NON-NLS-2$
10436
		*/
10437
		this.formatterPrefs = new DefaultCodeFormatterOptions(options);
10438
		String source = 
10439
			"package pack;\n" + 
10440
			"\n" + 
10441
			"public class A {\n" + 
10442
			"    /**\n" + 
10443
			"         * @see A.Inner\n" + 
10444
			"         */\n" + 
10445
			"[#    public class Inner { }\n" + 
10446
			"#]}";
10447
		formatSource(source,
10448
			"package pack;\n" + 
10449
			"\n" + 
10450
			"public class A {\n" + 
10451
			"    /**\n" + 
10452
			"         * @see A.Inner\n" + 
10453
			"         */\n" + 
10454
			"	public class Inner {\n" + 
10455
			"	}\n" + 
10456
			"}"
10457
		);
10134
	}
10458
	}
10135
10459
10136
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102780
10460
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102780
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsClearBlankLinesTests.java (-4 / +4 lines)
Lines 51-60 Link Here
51
}
51
}
52
52
53
DefaultCodeFormatter codeFormatter() {
53
DefaultCodeFormatter codeFormatter() {
54
	this.preferences.comment_clear_blank_lines_in_block_comment = true;
54
	this.formatterPrefs.comment_clear_blank_lines_in_block_comment = true;
55
	this.preferences.comment_clear_blank_lines_in_javadoc_comment = true;
55
	this.formatterPrefs.comment_clear_blank_lines_in_javadoc_comment = true;
56
	this.preferences.comment_format_header = true;
56
	this.formatterPrefs.comment_format_header = true;
57
	DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(this.preferences);
57
	DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(this.formatterPrefs);
58
	return codeFormatter;
58
	return codeFormatter;
59
}
59
}
60
60
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterJavadocDontIndentTagsTests.java (-2 / +2 lines)
Lines 50-57 Link Here
50
}
50
}
51
51
52
DefaultCodeFormatter codeFormatter() {
52
DefaultCodeFormatter codeFormatter() {
53
	this.preferences.comment_indent_root_tags = false; // Eclipse default is true
53
	this.formatterPrefs.comment_indent_root_tags = false; // Eclipse default is true
54
	DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(this.preferences);
54
	DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(this.formatterPrefs);
55
	return codeFormatter;
55
	return codeFormatter;
56
}
56
}
57
57
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsTests.java (-75 / +1 lines)
Lines 38-46 Link Here
38
import org.eclipse.jdt.internal.core.util.CodeSnippetParsingUtil;
38
import org.eclipse.jdt.internal.core.util.CodeSnippetParsingUtil;
39
import org.eclipse.jdt.internal.core.util.SimpleDocument;
39
import org.eclipse.jdt.internal.core.util.SimpleDocument;
40
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter;
40
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter;
41
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatterOptions;
42
import org.eclipse.jface.text.IRegion;
43
import org.eclipse.jface.text.Region;
44
41
45
/**
42
/**
46
 * Javadoc formatter test suite using the Eclipse default settings.
43
 * Javadoc formatter test suite using the Eclipse default settings.
Lines 59-66 Link Here
59
56
60
	public static List ALL_TEST_SUITES = null;
57
	public static List ALL_TEST_SUITES = null;
61
58
62
	DefaultCodeFormatterOptions preferences;
63
64
public static Test suite() {
59
public static Test suite() {
65
	return buildModelTestSuite(FormatterCommentsTests.class);
60
	return buildModelTestSuite(FormatterCommentsTests.class);
66
}
61
}
Lines 68-77 Link Here
68
public FormatterCommentsTests(String name) {
63
public FormatterCommentsTests(String name) {
69
	super(name);
64
	super(name);
70
}
65
}
71
protected void setUp() throws Exception {
72
    super.setUp();
73
	this.preferences = DefaultCodeFormatterOptions.getEclipseDefaultSettings();
74
}
75
66
76
/**
67
/**
77
 * Create project and set the jar placeholder.
68
 * Create project and set the jar placeholder.
Lines 97-167 Link Here
97
	}
88
	}
98
}
89
}
99
90
100
DefaultCodeFormatter codeFormatter() {
101
	DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(this.preferences, JAVA_PROJECT.getOptions(true));
102
	return codeFormatter;
103
}
104
105
/* (non-Javadoc)
106
 * @see org.eclipse.jdt.core.tests.formatter.FormatterRegressionTests#assertLineEquals(java.lang.String, java.lang.String, java.lang.String, boolean)
107
 */
108
void assertLineEquals(String actualContents, String originalSource, String expectedContents, boolean checkNull) {
109
	String outputSource = expectedContents == null ? originalSource : expectedContents;
110
	super.assertLineEquals(actualContents, originalSource, outputSource, checkNull);
111
}
112
113
void formatSource(String source, String formattedOutput) {
114
	formatSource(source, formattedOutput, CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS, 0, true /*repeat formatting twice*/);
115
}
116
117
void formatSource(String source, String formattedOutput, boolean repeat) {
118
	formatSource(source, formattedOutput, CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS, 0, repeat);
119
}
120
121
void formatSource(String source, String formattedOutput, int kind, int indentationLevel, boolean repeat) {
122
	int regionStart = source.indexOf("[#");
123
	if (regionStart != -1) {
124
		IRegion[] regions =  new Region[10];
125
		int idx = 0;
126
		int start = 0;
127
		int delta = 0;
128
		StringBuffer buffer = new StringBuffer();
129
		while (regionStart != -1) {
130
			buffer.append(source.substring(start, regionStart));
131
			int regionEnd = source.indexOf("#]", regionStart+2);
132
			buffer.append(source.substring(regionStart+2, regionEnd));
133
			regions[idx++] = new Region(regionStart-delta, regionEnd-(regionStart+2));
134
			delta += 4;
135
			start = regionEnd + 2;
136
			regionStart = source.indexOf("[#", start);
137
		}
138
		buffer.append(source.substring(start, source.length()));
139
		String newSource = buffer.toString();
140
		String result;
141
		if (idx == 1) {
142
			// Use offset and length until bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=233967 is fixed
143
			result = runFormatter(codeFormatter(), newSource, kind, indentationLevel, regions[0].getOffset(), regions[0].getLength(), Util.LINE_SEPARATOR, repeat);
144
		} else {
145
			System.arraycopy(regions, 0, regions = new Region[idx], 0, idx);
146
			result = runFormatter(codeFormatter(), newSource, kind, indentationLevel, regions, Util.LINE_SEPARATOR);
147
		}
148
		assertLineEquals(result, newSource, formattedOutput, false);
149
	} else {
150
		formatSource(source, formattedOutput, kind, indentationLevel, false, 0, -1, null, repeat);
151
	}
152
}
153
154
void formatSource(String source, String formattedOutput, int kind, int indentationLevel, boolean checkNull, int offset, int length, String lineSeparator, boolean repeat) {
155
	DefaultCodeFormatter codeFormatter = codeFormatter();
156
	String result;
157
	if (length == -1) {
158
		result = runFormatter(codeFormatter, source, kind, indentationLevel, offset, source.length(), lineSeparator, repeat);
159
	} else {
160
		result = runFormatter(codeFormatter, source, kind, indentationLevel, offset, length, lineSeparator, repeat);
161
	}
162
	assertLineEquals(result, source, formattedOutput, checkNull);
163
}
164
165
void compareFormattedSource(ICompilationUnit compilationUnit) throws JavaModelException {
91
void compareFormattedSource(ICompilationUnit compilationUnit) throws JavaModelException {
166
	DefaultCodeFormatter codeFormatter = codeFormatter();
92
	DefaultCodeFormatter codeFormatter = codeFormatter();
167
	String source = compilationUnit.getSource();
93
	String source = compilationUnit.getSource();
Lines 849-855 Link Here
849
}
775
}
850
// TODO Pass this test
776
// TODO Pass this test
851
public void _testLineComments11() throws JavaModelException {
777
public void _testLineComments11() throws JavaModelException {
852
	this.preferences.comment_line_length = 40;
778
	this.formatterPrefs.comment_line_length = 40;
853
	formatUnit("comments.line", "X11.java");
779
	formatUnit("comments.line", "X11.java");
854
}
780
}
855
781
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterJavadocDontIndentTagsDescriptionTests.java (-2 / +2 lines)
Lines 50-57 Link Here
50
}
50
}
51
51
52
DefaultCodeFormatter codeFormatter() {
52
DefaultCodeFormatter codeFormatter() {
53
	this.preferences.comment_indent_parameter_description = false; // Eclipse default is true
53
	this.formatterPrefs.comment_indent_parameter_description = false; // Eclipse default is true
54
	DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(this.preferences);
54
	DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(this.formatterPrefs);
55
	return codeFormatter;
55
	return codeFormatter;
56
}
56
}
57
57
(-)formatter/org/eclipse/jdt/internal/formatter/Scribe.java (-117 / +213 lines)
Lines 165-190 Link Here
165
			if (index >= 0) {
165
			if (index >= 0) {
166
				// the offset of the region is inside a comment => restart the region from the comment start
166
				// the offset of the region is inside a comment => restart the region from the comment start
167
				adaptedOffset = this.commentPositions[index][0];
167
				adaptedOffset = this.commentPositions[index][0];
168
				if (adaptedOffset < 0) adaptedOffset = -adaptedOffset;
168
				if (adaptedOffset >= 0) {
169
				adaptedLength = length + offset - adaptedOffset;
169
					// adapt only javadoc or block commments. Since fix for bug
170
				commentIndex = index;
170
					// https://bugs.eclipse.org/bugs/show_bug.cgi?id=238210
171
				// include also the indentation edit just before the comment if any
171
					// edits in line comments only concerns whitespaces hence can be
172
				for (int j=0; j<this.editsIndex; j++) {
172
					// treated as edits in code
173
					int editOffset = this.edits[j].offset;
173
					adaptedLength = length + offset - adaptedOffset;
174
					int editEnd = editOffset + this.edits[j].length;
174
					commentIndex = index;
175
					if (editEnd == adaptedOffset) {
175
					// include also the indentation edit just before the comment if any
176
						if (j > 0 && this.edits[j].replacement.trim().length() == 0) {
176
					for (int j=0; j<this.editsIndex; j++) {
177
							adaptedLength += adaptedOffset - this.edits[j].offset;
177
						int editOffset = this.edits[j].offset;
178
							adaptedOffset = editOffset;
178
						int editEnd = editOffset + this.edits[j].length;
179
						if (editEnd == adaptedOffset) {
180
							if (j > 0 && this.edits[j].replacement.trim().length() == 0) {
181
								adaptedLength += adaptedOffset - this.edits[j].offset;
182
								adaptedOffset = editOffset;
183
								break;
184
							}
185
						} else if (editEnd > adaptedOffset) {
179
							break;
186
							break;
180
						}
187
						}
181
					} else if (editEnd > adaptedOffset) {
182
						break;
183
					}
188
					}
184
				}
189
				}
185
			}
190
			}
186
			index = getCommentIndex(commentIndex, offset+length-1);
191
			index = getCommentIndex(commentIndex, offset+length-1);
187
			if (index >= 0) {
192
			if (index >= 0 && this.commentPositions[index][0] >= 0) { // only javadoc or block comment
188
				// the region end is inside a comment => set the region end at the comment end
193
				// the region end is inside a comment => set the region end at the comment end
189
				int commentEnd = this.commentPositions[index][1];
194
				int commentEnd = this.commentPositions[index][1];
190
				if (commentEnd < 0) commentEnd = -commentEnd;
195
				if (commentEnd < 0) commentEnd = -commentEnd;
Lines 194-261 Link Here
194
			if (adaptedLength != length) {
199
			if (adaptedLength != length) {
195
				// adapt the region and jump to next one
200
				// adapt the region and jump to next one
196
				this.adaptedRegions[i] = new Region(adaptedOffset, adaptedLength);
201
				this.adaptedRegions[i] = new Region(adaptedOffset, adaptedLength);
197
				continue;
202
			} else {
203
				this.adaptedRegions[i] = aRegion;
198
			}
204
			}
205
		}
206
	}
199
207
200
			if (offset > 0) {
208
	/*
201
				if (isAdaptableRegion(offset, length)) {
209
	 * Adapt edits to regions.
202
					// if we have a selection, search for overlapping edits
210
	 * 
203
					int upperBound = offset;
211
	 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=234583"
204
					int lowerBound = 0;
212
	 * 	for more details
205
					boolean upperFound = false;
213
	 */
206
					int regionEnd = offset + length;
214
	private void adaptEdits() {
207
					for (int j = 0, max2 = this.editsIndex - 1; j <= max2; j++) {
215
208
						// search for lower bound
216
		// See if adapting edits is really necessary
209
						int editOffset = this.edits[j].offset;
217
		int max = this.regions.length;
210
						if (upperFound && lowerBound == 0) {
218
		if (max == 1) {
211
							int editLength = this.edits[j].length;
219
			if (this.regions[0].getOffset() == 0 && this.regions[0].getLength() == this.scannerEndPosition) {
212
							if (editOffset == regionEnd) { // matching edit found
220
				// No need to adapt as the regions covers the whole source
213
								lowerBound = regionEnd;
221
				return;
214
								break;
222
			}
215
							} else if (editOffset + editLength < regionEnd) {
223
		}
216
								continue;
224
217
							} else {
225
		// Sort edits
218
								lowerBound = editOffset + editLength; // upper and lower bounds found
226
		OptimizedReplaceEdit[] sortedEdits = new OptimizedReplaceEdit[this.editsIndex];
219
								break;
227
		System.arraycopy(this.edits, 0, sortedEdits, 0, this.editsIndex);
220
							}
228
		Arrays.sort(sortedEdits, new Comparator() {
221
							// search for upper bound
229
			public int compare(Object o1, Object o2) {
222
						} else {
230
		    	OptimizedReplaceEdit edit1 = (OptimizedReplaceEdit) o1;
223
							int next = j+1;
231
		    	OptimizedReplaceEdit edit2 = (OptimizedReplaceEdit) o2;
224
							if (next == max2) {
232
				return edit1.offset - edit2.offset;
225
								// https://bugs.eclipse.org/bugs/show_bug.cgi?id=213284
233
            }
226
								// checked all edits, no upper bound found: leave the loop
234
		});
227
								break;
235
228
							}
236
		// Adapt overlapping edits
229
							if (this.edits[next].offset < offset) {
237
		int currentEdit = -1;
230
								continue;
238
		for (int i = 0; i < max; i++) {
239
			IRegion region = this.adaptedRegions[i];
240
			int offset = region.getOffset();
241
			int length = region.getLength();
242
243
			// modify overlapping edits on the region (if any)
244
			int index = adaptEdit(sortedEdits, currentEdit, offset, offset+length);
245
			if (index != -1) {
246
				currentEdit = index;
247
			}
248
		}
249
	}
250
251
	/*
252
     * Search whether a region overlap edit(s) at its start and/or at its end.
253
     * If so, modify the concerned edits to keep only the modifications which are
254
     * inside the given region.
255
     * 
256
     * The edit modification is done as follow:
257
     * 1) start it from the region start if it overlaps the region's start
258
     * 2) end it at the region end if it overlaps the region's end
259
     * 3) remove from the replacement string the number of lines which are outside
260
     * the region: before when overlapping region's start and after when overlapping
261
     * region's end. Note that the trailing indentation of the replacement string is not
262
     * kept when the region's end is overlapped because it's always outside the
263
     * region.
264
     */
265
    private int adaptEdit(OptimizedReplaceEdit[] sortedEdits, int start, int regionStart, int regionEnd) {
266
    	int bottom = start==-1?0:start, top = sortedEdits.length - 1;
267
    	int topEnd = top;
268
    	int i = 0;
269
    	OptimizedReplaceEdit edit = null;
270
    	int overlapIndex = -1;
271
        int linesOutside= -1;
272
    	
273
    	// Look for an edit overlapping the region start 
274
    	while (bottom <= top) {
275
    		i = bottom + (top - bottom) /2;
276
    		edit = sortedEdits[i];
277
    		int editStart = edit.offset;
278
   			int editEnd = editStart + edit.length;
279
    		if (regionStart < editStart) {  // the edit starts after the region's start => no possible overlap of region's start
280
    			top = i-1;
281
    			if (regionEnd < editStart) { // the edit starts after the region's end => no possible overlap of region's end
282
    				topEnd = top;
283
    			}
284
    		} else {
285
    			if (regionStart >= editEnd) { // the edit ends before the region's start => no possible overlap of region's start
286
	    			bottom = i+1;
287
				} else {
288
					// Count the lines of the edit which are outside the region
289
					linesOutside = 0;
290
					this.scanner.resetTo(editStart, editEnd-1);
291
					while (!this.scanner.atEnd()) {
292
						boolean before = this.scanner.currentPosition < regionStart;
293
	                    char ch = (char) this.scanner.getNextChar();
294
                    	if (ch == '\n' ) {
295
                    		if (before) linesOutside++;
296
                    	}
297
                    }
298
					
299
					// Restart the edit at the beginning of the line where the region start
300
					edit.offset = regionStart;
301
					edit.length -= edit.offset - editStart;
302
303
					// Cut replacement string if necessary
304
					int length = edit.replacement.length();
305
					if (length > 0) {
306
307
						// Count the lines in replacement string
308
						int linesReplaced = 0;
309
						for (int idx=0; idx < length; idx++) {
310
							if (edit.replacement.charAt(idx) == '\n') linesReplaced++;
311
						}
312
313
						// As the edit starts outside the region, remove first lines from edit string if any
314
						if (linesReplaced > 0) {
315
					    	int linesCount = linesOutside >= linesReplaced ? linesReplaced : linesOutside;
316
					    	if (linesCount > 0) {
317
					    		int idx=0;
318
					    		while (idx < length) {
319
					    			char ch = edit.replacement.charAt(idx);
320
					    			if (ch == '\n') {
321
					    				linesCount--;
322
					    				if (linesCount == 0) {
323
					    					idx++;
324
					    					break;
325
					    				}
326
					    			}
327
					    			else if (ch != '\r') {
328
					    				break;
329
					    			}
330
					    			idx++;
331
					    		}
332
					    		if (idx >= length) {
333
					    			edit.replacement = ""; //$NON-NLS-1$
334
					    		} else {
335
					    			edit.replacement = edit.replacement.substring(idx);
336
					    		}
337
					    	}
338
						}
339
					}
340
					overlapIndex = i;
341
					break;
342
				}
343
			}
344
    	}
345
    	
346
    	// Look for an edit overlapping the region end 
347
    	if (overlapIndex != -1) bottom = overlapIndex;
348
    	while (bottom <= topEnd) {
349
    		i = bottom + (topEnd - bottom) /2;
350
    		edit = sortedEdits[i];
351
    		int editStart = edit.offset;
352
   			int editEnd = editStart + edit.length;
353
    		if (regionEnd < editStart) {	// the edit starts after the region's end => no possible overlap of region's end
354
    			topEnd = i-1;
355
    		} else {
356
    			if (regionEnd >= editEnd) {	// the edit ends before the region's end => no possible overlap of region's end
357
	    			bottom = i+1;
358
				} else {
359
					// Count the lines of the edit which are outside the region
360
					linesOutside = 0;
361
					this.scanner.resetTo(editStart, editEnd-1);
362
					while (!this.scanner.atEnd()) {
363
						boolean after = this.scanner.currentPosition >= regionEnd;
364
	                    char ch = (char) this.scanner.getNextChar();
365
                    	if (ch == '\n' ) {
366
                    		if (after) linesOutside++;
367
                    	}
368
                    }
369
370
					// Cut replacement string if necessary
371
					int length = edit.replacement.length();
372
					if (length > 0) {
373
374
						// Count the lines in replacement string
375
						int linesReplaced = 0;
376
						for (int idx=0; idx < length; idx++) {
377
							if (edit.replacement.charAt(idx) == '\n') linesReplaced++;
378
						}
379
380
						// Set the replacement string to the number of missing new lines
381
						// As the end of the edit is out of the region, the possible trailing
382
						// indentation should not be added...
383
						if (linesReplaced > 0) {
384
							int linesCount = linesReplaced > linesOutside ? linesReplaced - linesOutside : 0;
385
							if (linesCount == 0) {
386
				    			edit.replacement = ""; //$NON-NLS-1$
231
							} else {
387
							} else {
232
								upperBound = editOffset;
388
								StringBuffer buffer = new StringBuffer();
233
								upperFound = true;
389
								for (int j=0; j<linesCount; j++) {
234
								// verify if region end is at EOF
390
									buffer.append(this.lineSeparator);
235
								if (this.scannerEndPosition == regionEnd) {
236
									lowerBound = this.scannerEndPosition - 1;
237
									break;
238
								}
391
								}
392
								edit.replacement = buffer.toString();
239
							}
393
							}
240
						}
394
						}
241
					}
395
					}
242
					if (lowerBound != 0) {
396
					edit.length -= editEnd - regionEnd;
243
						if (offset != upperBound || regionEnd != lowerBound) { // ensure we found a different region
397
					return i;
244
							this.adaptedRegions[i] = new Region(upperBound,
245
									lowerBound - upperBound);
246
						}
247
						// keep other unadaptable region
248
					} else {
249
						this.adaptedRegions[i] = this.regions[i];
250
					}
251
				} else {
252
					this.adaptedRegions[i] = this.regions[i];
253
				}
398
				}
254
			} else {
255
				this.adaptedRegions[i] = this.regions[i];
256
			}
399
			}
257
		}
400
    	}
258
	}
401
    	return overlapIndex;
402
    }
259
403
260
	private final void addDeleteEdit(int start, int end) {
404
	private final void addDeleteEdit(int start, int end) {
261
		if (this.edits.length == this.editsIndex) {
405
		if (this.edits.length == this.editsIndex) {
Lines 805-810 Link Here
805
	public TextEdit getRootEdit() {
949
	public TextEdit getRootEdit() {
806
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
950
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
807
		adaptRegions();
951
		adaptRegions();
952
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=234583
953
		adaptEdits();
808
954
809
		MultiTextEdit edit = null;
955
		MultiTextEdit edit = null;
810
		int regionsLength = this.adaptedRegions.length;
956
		int regionsLength = this.adaptedRegions.length;
Lines 952-1007 Link Here
952
		this.formatterCommentParser.parseHtmlTags = this.formatter.preferences.comment_format_html;
1098
		this.formatterCommentParser.parseHtmlTags = this.formatter.preferences.comment_format_html;
953
	}
1099
	}
954
1100
955
	/**
956
	 * Returns whether the given region should be adpated of not.
957
	 * A region should be adapted only if:
958
	 * - region does not exceed the page width
959
	 * - on a single line when more than one line in CU
960
	 * @param offset the offset of the region to consider
961
	 * @param length the length of the region to consider
962
	 * @return boolean true if line should be adapted, false otherwhise
963
	 */
964
	private boolean isAdaptableRegion(int offset, int length) {
965
		int regionEnd = offset + length;
966
967
		// first check region width
968
		if (regionEnd > this.pageWidth) {
969
			return false;
970
		}
971
972
		int numberOfLineEnds = this.lineEnds != null && this.lineEnds.length > 0 ? this.lineEnds.length : 0;
973
		if (this.line == numberOfLineEnds + 1) {
974
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=213283
975
			return true; // last line of the CU
976
		}
977
978
		if (this.line > 1 && numberOfLineEnds > 0) { // CU has more than one line
979
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=222182
980
			// take the max number of line ends as right bound when searching for line number
981
			int lineNumber = Util.getLineNumber(offset, this.lineEnds, 0, numberOfLineEnds);
982
			int lineEnd = getLineEnd(lineNumber);
983
			if (regionEnd > lineEnd) {
984
				// if more than one line selected, check whether selection is at line end
985
				for (int i = lineNumber + 1 ; i <=  numberOfLineEnds ; i++) {
986
					int nextLineEnd = getLineEnd(i);
987
					// accept both line ends and line starts
988
					if (regionEnd == nextLineEnd) {
989
						return length > 1; // except when formatting a single character
990
					} else if (regionEnd == lineEnd + 1 || regionEnd == nextLineEnd + 1) {
991
						return true;
992
					}
993
				}
994
				return false; // more than one line selected, no need to adapt region
995
			} else {
996
				if (this.scannerEndPosition - 1 == lineEnd) { // EOF reached?
997
					return false;
998
				}
999
				return true; // a single line was selected
1000
			}
1001
		}
1002
		return false;
1003
	}
1004
1005
	private boolean isOnFirstColumn(int start) {
1101
	private boolean isOnFirstColumn(int start) {
1006
		if (this.lineEnds == null) return start == 0;
1102
		if (this.lineEnds == null) return start == 0;
1007
		int index = Arrays.binarySearch(this.lineEnds, start);
1103
		int index = Arrays.binarySearch(this.lineEnds, start);

Return to bug 234583