blob: 2057e53ecba02c558e62ecd9129fbe903392e365 [file] [log] [blame]
Stephan Herrmannbe6c0ea2010-04-01 21:59:30 +00001/*******************************************************************************
Stephan Herrmann6aebad52014-10-03 22:19:34 +02002 * Copyright (c) 2000, 2014 IBM Corporation and others.
Stephan Herrmannbe6c0ea2010-04-01 21:59:30 +00003 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11package org.eclipse.jdt.core.tests.formatter.comment;
12
13import java.util.Map;
14
15import junit.framework.Test;
16
17import org.eclipse.jdt.core.JavaCore;
18import org.eclipse.jdt.core.ToolFactory;
19import org.eclipse.jdt.core.formatter.CodeFormatter;
20import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
21
Stephan Herrmannbe6c0ea2010-04-01 21:59:30 +000022import org.eclipse.text.edits.TextEdit;
23
Stephan Herrmann13a070b2010-04-02 03:54:26 +000024public class JavaDocTestCase extends MultiLineTestCase {
Stephan Herrmannbe6c0ea2010-04-01 21:59:30 +000025
26 static {
27// TESTS_NAMES = new String[] { "test109636_2" } ;
28 }
29
Stephan Herrmannbe6c0ea2010-04-01 21:59:30 +000030 public static Test suite() {
31 return buildTestSuite(JavaDocTestCase.class);
32 }
33
34 public JavaDocTestCase(String name) {
35 super(name);
36 }
37
38 protected int getCommentKind() {
39 return CodeFormatter.K_JAVA_DOC;
40 }
41
42 public void testSingleLineComment1() {
43 assertEquals(PREFIX + DELIMITER + INFIX + "test" + DELIMITER + POSTFIX, testFormat(PREFIX + "\t\t" + DELIMITER + "*\t test*/")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
44 }
45
46 public void testSingleLineComment2() {
47 assertEquals(PREFIX + DELIMITER + INFIX + "test" + DELIMITER + POSTFIX, testFormat(PREFIX + "test" + DELIMITER + "\t" + POSTFIX)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
48 }
49
50 public void testSingleLineComment3() {
51 assertEquals(PREFIX + DELIMITER + INFIX + "test" + DELIMITER + POSTFIX, testFormat(PREFIX + DELIMITER + "* test\t*/")); //$NON-NLS-1$ //$NON-NLS-2$
52 }
53
54 public void testSingleLineComment4() {
55 assertEquals(PREFIX + DELIMITER + INFIX + "test" + DELIMITER + POSTFIX, testFormat(PREFIX + "test" + DELIMITER + POSTFIX)); //$NON-NLS-1$ //$NON-NLS-2$
56 }
57
58 public void testSingleLineCommentSpace1() {
59 assertEquals(PREFIX + " test" + POSTFIX, testFormat(PREFIX + "test*/")); //$NON-NLS-1$ //$NON-NLS-2$
60 }
61
62 public void testSingleLineCommentSpace2() {
63 assertEquals(PREFIX + " test" + POSTFIX, testFormat(PREFIX + "test" + POSTFIX)); //$NON-NLS-1$ //$NON-NLS-2$
64 }
65
66 public void testSingleLineCommentSpace3() {
67 assertEquals(PREFIX + " test" + POSTFIX, testFormat(PREFIX + "test*/")); //$NON-NLS-1$ //$NON-NLS-2$
68 }
69
70 public void testSingleLineCommentSpace4() {
71 assertEquals(PREFIX + " test test" + POSTFIX, testFormat(PREFIX + " test test*/")); //$NON-NLS-1$ //$NON-NLS-2$
72 }
73
74 public void testSingleLineCommentTabs1() {
75 assertEquals(PREFIX + " test test" + POSTFIX, testFormat(PREFIX + "\ttest\ttest" + POSTFIX)); //$NON-NLS-1$ //$NON-NLS-2$
76 }
77
78 public void testSingleLineCommentTabs2() {
79 assertEquals(PREFIX + " test test" + POSTFIX, testFormat(PREFIX + "\ttest\ttest*/")); //$NON-NLS-1$ //$NON-NLS-2$
80 }
81
82 public void testMultiLineCommentBreak1() {
83 String input= PREFIX + " test<br>test" + POSTFIX; //$NON-NLS-1$
84 String expected= PREFIX + DELIMITER + INFIX + "test<br>" + DELIMITER + INFIX + "test" + DELIMITER + POSTFIX; //$NON-NLS-1$ //$NON-NLS-2$
85 assertEquals(expected, testFormat(input));
86 }
87
88 public void testMultiLineCommentCodeSnippet1() {
89 String prefix= PREFIX + DELIMITER + INFIX + "<pre>" + DELIMITER + INFIX; //$NON-NLS-1$
90 String postfix= DELIMITER + INFIX + "</pre>" + DELIMITER + POSTFIX; //$NON-NLS-1$
91 String input= prefix + "while (i != 0) i--;" + postfix; //$NON-NLS-1$
92 String expected= prefix + "while (i != 0)" + DELIMITER + INFIX + "\ti--;" + postfix; //$NON-NLS-1$//$NON-NLS-2$
93 String result= testFormat(input);
94 assertEquals(expected, result);
95
96 result= testFormat(result);
97 result= testFormat(result);
98 result= testFormat(result);
99 result= testFormat(result);
100
101 assertEquals(expected, result);
102 }
103
104 /**
105 * [formatting] Error in formatting parts of java code snippets in comment
106 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=44035
107 */
108 public void testMultiLineCommentCodeSnippet2() {
109 String prefix= PREFIX + DELIMITER + INFIX + "<pre>" + DELIMITER + INFIX; //$NON-NLS-1$
110 String postfix= DELIMITER + INFIX + "</pre>" + DELIMITER + POSTFIX; //$NON-NLS-1$
111 String input= prefix + "while (i != 0) { i--; }" + postfix; //$NON-NLS-1$
112 String expected= prefix + "while (i != 0) {" + DELIMITER + INFIX + "\ti--;" + DELIMITER + INFIX + "}" + postfix; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
113 String result= testFormat(input);
114 assertEquals(expected, result);
115
116 result= testFormat(result);
117 result= testFormat(result);
118 result= testFormat(result);
119 result= testFormat(result);
120
121 assertEquals(expected, result);
122 }
123
124 public void testMultiLineCommentCodeSnippet3() {
125 String input= PREFIX + DELIMITER + "<pre>" + DELIMITER + "while (i != 0)" + DELIMITER + "i--;" + DELIMITER + "</pre>" + DELIMITER + POSTFIX; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
126 String expected= PREFIX + DELIMITER + INFIX + "<pre>" + DELIMITER + INFIX + "while (i != 0)" + DELIMITER + INFIX + "\ti--;" + DELIMITER + INFIX + "</pre>" + DELIMITER + POSTFIX; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
127 String result= testFormat(input);
128 assertEquals(expected, result);
129
130 result= testFormat(result);
131 result= testFormat(result);
132 result= testFormat(result);
133 result= testFormat(result);
134
135 assertEquals(expected, result);
136 }
137
138 public void testMultiLineCommentCodeSnippet4() {
139 String input= "/**\n" +
140 " * <pre>\n" +
141 " * public Object[] getChildren(Object parentElement) {\n" +
142 " * if (parentElement instanceof MovingBox) {\n" +
143 " * MovingBox box = (MovingBox) parentElement;\n" +
144 " * return concat(box.getBoxes().toArray(), box.getBooks().toArray(), box\n" +
145 " * .getGames().toArray());\n" +
146 " * }\n" +
147 " * return EMPTY_ARRAY;\n" +
148 " * }\n" +
149 " * </pre>\n" +
150 " */";
151 String expected= "/**\n" +
152 " * <pre>\n" +
153 " * public Object[] getChildren(Object parentElement) {\n" +
154 " * if (parentElement instanceof MovingBox) {\n" +
155 " * MovingBox box = (MovingBox) parentElement;\n" +
156 " * return concat(box.getBoxes().toArray(), box.getBooks().toArray(), box\n" +
157 " * .getGames().toArray());\n" +
158 " * }\n" +
159 " * return EMPTY_ARRAY;\n" +
160 " * }\n" +
161 " * </pre>\n" +
162 " */";
Stephan Herrmann6aebad52014-10-03 22:19:34 +0200163 setUserOption(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, "80"); //$NON-NLS-1$
Stephan Herrmannbe6c0ea2010-04-01 21:59:30 +0000164 String result= testFormat(input);
165 assertEquals(expected, result);
166 }
167
168 public void testMultiLineCommentCodeSnippet5() {
169 String input= "/**\n" +
170 " * <Pre>\n" +
171 " * public Object[] getChildren(Object parentElement) {\n" +
172 " * if (parentElement instanceof MovingBox) {\n" +
173 " * MovingBox box = (MovingBox) parentElement;\n" +
174 " * return concat(box.getBoxes().toArray(), box.getBooks().toArray(), box\n" +
175 " * .getGames().toArray());\n" +
176 " * }\n" +
177 " * return EMPTY_ARRAY;\n" +
178 " * }\n" +
179 " * </Pre>\n" +
180 " */";
181 String expected= "/**\n" +
182 " * <Pre>\n" +
183 " * public Object[] getChildren(Object parentElement) {\n" +
184 " * if (parentElement instanceof MovingBox) {\n" +
185 " * MovingBox box = (MovingBox) parentElement;\n" +
186 " * return concat(box.getBoxes().toArray(), box.getBooks().toArray(), box\n" +
187 " * .getGames().toArray());\n" +
188 " * }\n" +
189 " * return EMPTY_ARRAY;\n" +
190 " * }\n" +
191 " * </Pre>\n" +
192 " */";
Stephan Herrmann6aebad52014-10-03 22:19:34 +0200193 setUserOption(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, "80"); //$NON-NLS-1$
Stephan Herrmannbe6c0ea2010-04-01 21:59:30 +0000194 String result= testFormat(input);
195 assertEquals(expected, result);
196 }
197
198 public void testMultiLineCommentCodeSnippet6() {
199 String input= "/**\n" +
200 " * <PRE>\n" +
201 " * public Object[] getChildren(Object parentElement) {\n" +
202 " * if (parentElement instanceof MovingBox) {\n" +
203 " * MovingBox box = (MovingBox) parentElement;\n" +
204 " * return concat(box.getBoxes().toArray(), box.getBooks().toArray(), box\n" +
205 " * .getGames().toArray());\n" +
206 " * }\n" +
207 " * return EMPTY_ARRAY;\n" +
208 " * }\n" +
209 " * </PRE>\n" +
210 " */";
211 String expected= "/**\n" +
212 " * <PRE>\n" +
213 " * public Object[] getChildren(Object parentElement) {\n" +
214 " * if (parentElement instanceof MovingBox) {\n" +
215 " * MovingBox box = (MovingBox) parentElement;\n" +
216 " * return concat(box.getBoxes().toArray(), box.getBooks().toArray(), box\n" +
217 " * .getGames().toArray());\n" +
218 " * }\n" +
219 " * return EMPTY_ARRAY;\n" +
220 " * }\n" +
221 " * </PRE>\n" +
222 " */";
Stephan Herrmann6aebad52014-10-03 22:19:34 +0200223 setUserOption(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, "80"); //$NON-NLS-1$
Stephan Herrmannbe6c0ea2010-04-01 21:59:30 +0000224 String result= testFormat(input);
225 assertEquals(expected, result);
226 }
227
228 public void testMultiLineCommentCodeSnippetHtmlEntities1() {
229 String prefix= PREFIX + DELIMITER + INFIX + "<pre>" + DELIMITER + INFIX; //$NON-NLS-1$
230 String postfix= DELIMITER + INFIX + "</pre>" + DELIMITER + POSTFIX; //$NON-NLS-1$
231 String input= prefix + "System.out.println(\"test\");" + postfix; //$NON-NLS-1$
232 String expected= prefix + "System.out.println(&quot;test&quot;);" + postfix; //$NON-NLS-1$
233 String result= testFormat(input);
234 assertEquals(expected, result);
235
236 result= testFormat(result);
237 result= testFormat(result);
238 result= testFormat(result);
239 result= testFormat(result);
240
241 assertEquals(expected, result);
242 }
243
244 public void testMultiLineCommentIndentTabs1() {
245 String prefix= "public class Test {" + DELIMITER + "\t\t"; //$NON-NLS-1$ //$NON-NLS-2$
246 String content= PREFIX + DELIMITER + "\t\t\t" + INFIX + "test test" + DELIMITER + "\t\t\t\t" + POSTFIX; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
247 String postfix= DELIMITER + "}"; //$NON-NLS-1$
248 String expected= PREFIX + DELIMITER + "\t\t" + INFIX + "test test" + DELIMITER + "\t\t" + POSTFIX; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
249 setUserOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.TAB);
250 assertEquals(prefix + expected + postfix, testFormat(prefix + content + postfix, prefix.length(), content.length()));
251 }
252
253 /**
254 * [formatting] Comments formatter inserts tabs when it should use spaces
255 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=47491
256 */
257 public void testMultiLineCommentIndentSpaces1() {
258 String prefix= "public class Test {" + DELIMITER + "\t"; //$NON-NLS-1$ //$NON-NLS-2$
259 String content= PREFIX + DELIMITER + "\t\t" + INFIX + "test test" + DELIMITER + " " + POSTFIX; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
260 String postfix= DELIMITER + "}"; //$NON-NLS-1$
261 String expected= PREFIX + DELIMITER + " " + INFIX + "test test" + DELIMITER + " " + POSTFIX; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
262 setUserOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);
263 setUserOption(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "3"); //$NON-NLS-1$
264 assertEquals(prefix + expected + postfix, testFormat(prefix + content + postfix, prefix.length(), content.length()));
265 }
266
267 public void testMultiLineCommentIndentSpaces2() {
268 String prefix= "public class Test {" + DELIMITER + " "; //$NON-NLS-1$ //$NON-NLS-2$
269 String content= PREFIX + DELIMITER + "\t\t" + INFIX + "test test" + DELIMITER + " " + POSTFIX; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
270 String postfix= DELIMITER + "}"; //$NON-NLS-1$
271 String expected= PREFIX + DELIMITER + " " + INFIX + "test test" + DELIMITER + " " + POSTFIX; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
272 setUserOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);
273 setUserOption(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "3"); //$NON-NLS-1$
274 assertEquals(prefix + expected + postfix, testFormat(prefix + content + postfix, prefix.length(), content.length()));
275 }
276
277 public void testMultiLineCommentIndentSpaces3() {
278 String prefix= "public class Test {" + DELIMITER + " \t "; //$NON-NLS-1$ //$NON-NLS-2$
279 String content= PREFIX + DELIMITER + "\t\t" + INFIX + "test test" + DELIMITER + " " + POSTFIX; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
280 String postfix= DELIMITER + "}"; //$NON-NLS-1$
281 String expected= PREFIX + DELIMITER + " " + INFIX + "test test" + DELIMITER + " " + POSTFIX; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
282 setUserOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);
283 setUserOption(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "3"); //$NON-NLS-1$
284 assertEquals(prefix + expected + postfix, testFormat(prefix + content + postfix, prefix.length(), content.length()));
285 }
286
287 public void testMultiLineCommentIndentSpaces4() {
288 String prefix= "public class Test {" + DELIMITER + " \t "; //$NON-NLS-1$ //$NON-NLS-2$
289 String content= PREFIX + DELIMITER + "\t\t" + INFIX + "test test" + DELIMITER + " " + POSTFIX; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
290 String postfix= DELIMITER + "}"; //$NON-NLS-1$
291 String expected= PREFIX + DELIMITER + " " + INFIX + "test test" + DELIMITER + " " + POSTFIX; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
292 setUserOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);
293 setUserOption(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "3"); //$NON-NLS-1$
294 assertEquals(prefix + expected + postfix, testFormat(prefix + content + postfix, prefix.length(), content.length()));
295 }
296
297 /**
298 * [formatting] Repeated insertion of new line when formatting javadoc comment
299 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=50212
300 */
301 public void testMultiLineCommentBlankLineAfterPre1() {
302 String input= PREFIX + DELIMITER + INFIX + "<pre></pre>" + DELIMITER + INFIX + "test" + DELIMITER + POSTFIX; //$NON-NLS-1$ //$NON-NLS-2$
303 String expected= PREFIX + DELIMITER + INFIX + "<pre></pre>" + DELIMITER + INFIX + DELIMITER + INFIX + "test" + DELIMITER + POSTFIX; //$NON-NLS-1$ //$NON-NLS-2$
304 String result= testFormat(input);
305 assertEquals(expected, result);
306 result= testFormat(result);
307 assertEquals(expected, result);
308 }
309
310 /**
311 * [formatting][implementation] comment line length not correctly applied
312 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=46341
313 * Do not wrap.
314 */
315 public void testMultiLineCommentLineBreakBeforeImmutableRegions1() {
316 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "22"); //$NON-NLS-1$
317 String input= PREFIX + DELIMITER + INFIX + "a <code>test</code>" + DELIMITER + POSTFIX; //$NON-NLS-1$
318 String expected= input;
319 String result= testFormat(input);
320 assertEquals(expected, result);
321 }
322
323 /**
324 * [formatting][implementation] comment line length not correctly applied
325 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=46341
326 * Do wrap.
327 */
328 public void testMultiLineCommentLineBreakBeforeImmutableRegions2() {
329 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "21"); //$NON-NLS-1$
330 String input= PREFIX + DELIMITER + INFIX + "a <code>test</code>" + DELIMITER + POSTFIX; //$NON-NLS-1$
331 String expected= PREFIX + DELIMITER + INFIX + "a" + DELIMITER + INFIX + "<code>test</code>" + DELIMITER + POSTFIX; //$NON-NLS-1$ //$NON-NLS-2$
332 String result= testFormat(input);
333 assertEquals(expected, result);
334 }
335
336 /**
337 * [formatting][implementation] comment line length not correctly applied
338 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=46341
339 * Do not wrap. (Consecutive immutable regions on multiple lines.)
340 */
341 public void testMultiLineCommentLineBreakBeforeImmutableRegions3() {
342 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "20"); //$NON-NLS-1$
343 String input= PREFIX + DELIMITER + INFIX + "a <code>" + DELIMITER + INFIX + "testestestestestestestestestest" + DELIMITER + INFIX + "</code>" + DELIMITER + POSTFIX; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
344 String expected= input;
345 String result= testFormat(input);
346 assertEquals(expected, result);
347 }
348
349 /**
350 * Prefs > Java > Code Formatter > Comments: Preview incorrect
351 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=55204
352 * Do not insert blank line before Javadoc tags
353 */
354 public void testMultiLineCommentBlankLineBeforeJavadoctags1() {
355 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_INSERT_EMPTY_LINE_BEFORE_ROOT_TAGS, JavaCore.DO_NOT_INSERT); //$NON-NLS-1$
356 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT, DefaultCodeFormatterConstants.FALSE); //$NON-NLS-1$
357 String input= PREFIX + DELIMITER + INFIX + "Description" + DELIMITER + INFIX + "@param test" + DELIMITER + POSTFIX; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
358 String expected= input;
359 String result= testFormat(input);
360 assertEquals(expected, result);
361 }
362
363 /**
364 * Prefs > Java > Code Formatter > Comments: Preview incorrect
365 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=55204
366 * Do insert blank line before Javadoc tags
367 */
368 public void testMultiLineCommentBlankLineBeforeJavadoctags2() {
369 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_INSERT_EMPTY_LINE_BEFORE_ROOT_TAGS, JavaCore.INSERT); //$NON-NLS-1$
370 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT, DefaultCodeFormatterConstants.TRUE); //$NON-NLS-1$
371 String prefix= PREFIX + DELIMITER + INFIX + "Description"; //$NON-NLS-1$
372 String postfix= DELIMITER + INFIX + "@param test" + DELIMITER + POSTFIX; //$NON-NLS-1$
373 String input= prefix + postfix;
374 String expected= prefix + DELIMITER + INFIX + postfix;
375 String result= testFormat(input);
376 assertEquals(expected, result);
377 }
378
379 /**
380 * Prefs > Java > Code Formatter > Comments: Preview incorrect
381 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=55204
382 * Do not remove blank line before Javadoc tags
383 */
384 public void testMultiLineCommentBlankLineBeforeJavadoctags3() {
385 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_INSERT_EMPTY_LINE_BEFORE_ROOT_TAGS, JavaCore.INSERT); //$NON-NLS-1$
386 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT, DefaultCodeFormatterConstants.TRUE); //$NON-NLS-1$
387 String input= PREFIX + DELIMITER + INFIX + "Description" + DELIMITER + INFIX + DELIMITER + INFIX + "@param test" + DELIMITER + POSTFIX; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
388 String expected= input;
389 String result= testFormat(input);
390 assertEquals(expected, result);
391 }
392
393 /**
394 * Prefs > Java > Code Formatter > Comments: Preview incorrect
395 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=55204
396 * Do remove blank line before Javadoc tags
397 */
398 public void testMultiLineCommentBlankLineBeforeJavadoctags4() {
399 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_INSERT_EMPTY_LINE_BEFORE_ROOT_TAGS, JavaCore.DO_NOT_INSERT); //$NON-NLS-1$
400 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT,DefaultCodeFormatterConstants.TRUE); //$NON-NLS-1$
401 String prefix= PREFIX + DELIMITER + INFIX + "Description"; //$NON-NLS-1$
402 String postfix= DELIMITER + INFIX + "@param test" + DELIMITER + POSTFIX; //$NON-NLS-1$
403 String input= prefix + DELIMITER + INFIX + postfix;
404 String expected= prefix + postfix;
405 String result= testFormat(input);
406 assertEquals(expected, result);
407 }
408
409 /**
410 * Prefs > Java > Code Formatter > Comments: Preview incorrect
411 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=55204
412 * Do not insert blank line before Javadoc tags
413 * @deprecated
414 */
415 public void testMultiLineCommentBlankLineBeforeJavadoctags5() {
416 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_INSERT_EMPTY_LINE_BEFORE_ROOT_TAGS, JavaCore.DO_NOT_INSERT); //$NON-NLS-1$
417 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES, DefaultCodeFormatterConstants.FALSE); //$NON-NLS-1$
418 String input= PREFIX + DELIMITER + INFIX + "Description" + DELIMITER + INFIX + "@param test" + DELIMITER + POSTFIX; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
419 String expected= input;
420 String result= testFormat(input);
421 assertEquals(expected, result);
422 }
423
424 /**
425 * Prefs > Java > Code Formatter > Comments: Preview incorrect
426 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=55204
427 * Do insert blank line before Javadoc tags
428 * @deprecated
429 */
430 public void testMultiLineCommentBlankLineBeforeJavadoctags6() {
431 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_INSERT_EMPTY_LINE_BEFORE_ROOT_TAGS, JavaCore.INSERT); //$NON-NLS-1$
432 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES, DefaultCodeFormatterConstants.TRUE); //$NON-NLS-1$
433 String prefix= PREFIX + DELIMITER + INFIX + "Description"; //$NON-NLS-1$
434 String postfix= DELIMITER + INFIX + "@param test" + DELIMITER + POSTFIX; //$NON-NLS-1$
435 String input= prefix + postfix;
436 String expected= prefix + DELIMITER + INFIX + postfix;
437 String result= testFormat(input);
438 assertEquals(expected, result);
439 }
440
441 /**
442 * Prefs > Java > Code Formatter > Comments: Preview incorrect
443 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=55204
444 * Do not remove blank line before Javadoc tags
445 * @deprecated
446 */
447 public void testMultiLineCommentBlankLineBeforeJavadoctags7() {
448 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_INSERT_EMPTY_LINE_BEFORE_ROOT_TAGS, JavaCore.INSERT); //$NON-NLS-1$
449 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES, DefaultCodeFormatterConstants.TRUE); //$NON-NLS-1$
450 String input= PREFIX + DELIMITER + INFIX + "Description" + DELIMITER + INFIX + DELIMITER + INFIX + "@param test" + DELIMITER + POSTFIX; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
451 String expected= input;
452 String result= testFormat(input);
453 assertEquals(expected, result);
454 }
455
456 /**
457 * Prefs > Java > Code Formatter > Comments: Preview incorrect
458 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=55204
459 * Do remove blank line before Javadoc tags
460 * @deprecated
461 */
462 public void testMultiLineCommentBlankLineBeforeJavadoctags8() {
463 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_INSERT_EMPTY_LINE_BEFORE_ROOT_TAGS, JavaCore.DO_NOT_INSERT); //$NON-NLS-1$
464 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES,DefaultCodeFormatterConstants.TRUE); //$NON-NLS-1$
465 String prefix= PREFIX + DELIMITER + INFIX + "Description"; //$NON-NLS-1$
466 String postfix= DELIMITER + INFIX + "@param test" + DELIMITER + POSTFIX; //$NON-NLS-1$
467 String input= prefix + DELIMITER + INFIX + postfix;
468 String expected= prefix + postfix;
469 String result= testFormat(input);
470 assertEquals(expected, result);
471 }
472
473 /**
474 * [formatting] javadoc formatter removes blank lines between empty javadoc tags (xdoclet fails)
475 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=68577
476 */
477 public void testLineBreaksBetweenEmptyJavaDocTags1() {
478 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT, DefaultCodeFormatterConstants.FALSE); //$NON-NLS-1$
479 String input= PREFIX + DELIMITER + INFIX + "@custom1" + DELIMITER + INFIX + DELIMITER + INFIX + "@custom2" + DELIMITER + POSTFIX; //$NON-NLS-1$//$NON-NLS-2$
480 String expected= input;
481 String result= testFormat(input);
482 assertEquals(expected, result);
483 }
484
485 /**
486 * [formatting] javadoc formatter removes blank lines between empty javadoc tags (xdoclet fails)
487 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=68577
488 */
489 public void testLineBreaksBetweenEmptyJavaDocTags2() {
490 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT, DefaultCodeFormatterConstants.FALSE); //$NON-NLS-1$
491 String input= PREFIX + DELIMITER + INFIX + "@custom1" + DELIMITER + INFIX + "@custom2" + DELIMITER + POSTFIX; //$NON-NLS-1$//$NON-NLS-2$
492 String expected= input;
493 String result= testFormat(input);
494 assertEquals(expected, result);
495 }
496
497 public void testNoChange1() {
498 String content= PREFIX + DELIMITER + POSTFIX;
499 assertEquals(content, testFormat(content));
500 }
501
502 public void testNoFormat1() {
503 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_JAVADOC_COMMENT, DefaultCodeFormatterConstants.FALSE);
504 String content= PREFIX + DELIMITER + INFIX + "test" + DELIMITER + INFIX + "test" + DELIMITER + POSTFIX;
505 assertEquals(content, testFormat(content));
506 }
507
508 /**
509 * @deprecated
510 */
511 public void testNoFormat2() {
512 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT, DefaultCodeFormatterConstants.FALSE);
513 String content= PREFIX + DELIMITER + INFIX + "test" + DELIMITER + INFIX + "test" + DELIMITER + POSTFIX;
514 assertEquals(content, testFormat(content));
515 }
516
517
518 /**
519 * [formatting] Javadoc Formatter mishandles spaces in comments
520 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=49686
521 */
522 public void testInlineTag1() {
523 String input= PREFIX + DELIMITER + INFIX + "{@link Object} has many methods." + DELIMITER + POSTFIX; //$NON-NLS-1$
524 String expected= input;
525 String result= testFormat(input);
526 assertEquals(expected, result);
527 }
528
529 /**
530 * [formatting] Javadoc Formatter mishandles spaces in comments
531 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=49686
532 */
533 public void testInlineTag2() {
534 String input= PREFIX + DELIMITER + INFIX + "{@link Object}s are cool." + DELIMITER + POSTFIX; //$NON-NLS-1$
535 String expected= input;
536 String result= testFormat(input);
537 assertEquals(expected, result);
538 }
539
540 /**
541 * [formatting] Javadoc Formatter mishandles spaces in comments
542 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=49686
543 */
544 public void testMultilineInlineTag1() {
545 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "20"); //$NON-NLS-1$
546 final String prefix= PREFIX + DELIMITER + INFIX + "{@link Object}";
547 final String postfix= "has many methods." + DELIMITER + POSTFIX;
548 String input= prefix + " " + postfix; //$NON-NLS-1$
549 String expected= prefix + DELIMITER + INFIX + postfix;
550 String result= testFormat(input);
551 assertEquals(expected, result);
552 }
553
554 /**
555 * [formatting] Javadoc Formatter mishandles spaces in comments
556 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=49686
557 */
558 public void testMultilineInlineTag2() {
559 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "20"); //$NON-NLS-1$
560 final String prefix= PREFIX + DELIMITER + INFIX + "{@link Objecterr}";
561 final String postfix= "s are cool." + DELIMITER + POSTFIX;
562 String input= prefix + postfix; //$NON-NLS-1$
563 String expected= prefix + DELIMITER + INFIX + postfix;
564 String result= testFormat(input);
565 assertEquals(expected, result);
566 }
567
568 /**
569 * [formatting] Javadoc Formatter mishandles spaces in comments
570 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=49686
571 */
572 public void testTagWordbreaks1() {
573 String input= PREFIX + DELIMITER + INFIX + "<code>Object</code> rocks." + DELIMITER + POSTFIX; //$NON-NLS-1$
574 String expected= input;
575 String result= testFormat(input);
576 assertEquals(expected, result);
577 }
578
579 /**
580 * [formatting] Javadoc Formatter mishandles spaces in comments
581 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=49686
582 */
583 public void testTagWordbreaks2() {
584 String input= PREFIX + DELIMITER + INFIX + "<code>Object</code>s are cool." + DELIMITER + POSTFIX; //$NON-NLS-1$
585 String expected= input;
586 String result= testFormat(input);
587 assertEquals(expected, result);
588 }
589
590 /**
591 * [formatting] Javadoc Formatter mishandles spaces in comments
592 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=49686
593 */
594 public void testMultilineTagWordbreaks1() {
595 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "20"); //$NON-NLS-1$
596 String prefix= PREFIX + DELIMITER + INFIX + "<code>Object</code>";
597 String postfix= "rocks." + DELIMITER + POSTFIX; //$NON-NLS-1$
598 String input= prefix + " " + postfix;
599 String expected= prefix + DELIMITER + INFIX + postfix;
600 String result= testFormat(input);
601 assertEquals(expected, result);
602 }
603
604 /**
605 * [formatting] Javadoc Formatter mishandles spaces in comments
606 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=49686
607 */
608 public void testMultilineTagWordbreaks2() {
609 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "20"); //$NON-NLS-1$
610 final String prefix= PREFIX + DELIMITER + INFIX + "Foo";
611 final String postfix= "<code>Obj</code>s" + DELIMITER + POSTFIX;
612 String input= prefix + " " + postfix;
613 String expected= prefix + DELIMITER + INFIX + postfix;
614 String result= testFormat(input);
615 assertEquals(expected, result);
616 }
617
618 public void testMultiLineComment() {
619 String input= PREFIX + DELIMITER + " TOTO " + POSTFIX; //$NON-NLS-1$
620 String expected= PREFIX + DELIMITER + INFIX + "TOTO" + DELIMITER + POSTFIX; //$NON-NLS-1$
621 final String result = testFormat(input);
622 assertEquals(expected, result);
623 }
624
625 public void testMultiLineComment2() {
626 String input= PREFIX + DELIMITER + "TOTO" + POSTFIX; //$NON-NLS-1$
627 String expected= PREFIX + DELIMITER + INFIX + "TOTO" + DELIMITER + POSTFIX; //$NON-NLS-1$
628 final String result = testFormat(input);
629 assertEquals(expected, result);
630 }
631
632 /**
633 * [formatting] Javadoc formatting: extra newline with [pre]
634 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=52921
635 * <p>
636 * This test only formats once.
637 * </p>
638 */
639 public void testNoExtraNewlineWithPre1() {
640 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_SOURCE, DefaultCodeFormatterConstants.TRUE);
641 String input= PREFIX + DELIMITER + INFIX + "<pre>wrap here</pre>" + DELIMITER + POSTFIX; //$NON-NLS-1$
642 String expected= PREFIX + DELIMITER + INFIX + "<pre>" + DELIMITER + INFIX + "wrap here" + DELIMITER + INFIX + "</pre>" + DELIMITER + POSTFIX; //$NON-NLS-1$; //$NON-NLS-2$; //$NON-NLS-3$;
643 String result= testFormat(input);
644 assertEquals(expected, result);
645
646 // now re-format several times
647 result= testFormat(result);
648 result= testFormat(result);
649 result= testFormat(result);
650 result= testFormat(result);
651
652 expected= PREFIX + DELIMITER + INFIX + "<pre>" + DELIMITER + INFIX + "wrap here" + DELIMITER + INFIX + "</pre>" + DELIMITER + POSTFIX; //$NON-NLS-1$; //$NON-NLS-2$; //$NON-NLS-3$;
653 assertEquals(expected, result);
654 }
655
656 /**
657 * [formatting] Javadoc formatting: extra newline with [pre]
658 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=52921
659 * <p>
660 * This test only formats once.
661 * </p>
662 */
663 public void testNoExtraNewlineWithPre2() {
664 setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_SOURCE, DefaultCodeFormatterConstants.FALSE);
665 String input= PREFIX + DELIMITER + INFIX + "<pre>wrap here</pre>" + DELIMITER + POSTFIX; //$NON-NLS-1$
666 String expected= PREFIX + DELIMITER + INFIX + "<pre>wrap here</pre>" + DELIMITER + POSTFIX; //$NON-NLS-1$
667 String result= testFormat(input);
668 assertEquals(expected, result);
669
670 // now re-format several times
671 result= testFormat(result);
672 result= testFormat(result);
673 result= testFormat(result);
674 result= testFormat(result);
675
676 expected= PREFIX + DELIMITER + INFIX + "<pre>wrap here</pre>" + DELIMITER + POSTFIX; //$NON-NLS-1$
677 assertEquals(expected, result);
678 }
679
680 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=109605
681 public void test109605() {
682 String input = "/**" + DELIMITER +
683 " * <pre>" + DELIMITER +
684 " * " + DELIMITER +
685 " * </pre>" + DELIMITER +
686 " * " + DELIMITER +
687 " * " + DELIMITER +
688 " * @author Darren Pearce" + DELIMITER +
689 " * @version 22-Sep-2005" + DELIMITER +
690 " * " + DELIMITER +
691 " */";
692
693 String expected = "/**" + DELIMITER +
694 " * <pre>" + DELIMITER +
Stephan Herrmann13a070b2010-04-02 03:54:26 +0000695 " * " + DELIMITER +
Stephan Herrmannbe6c0ea2010-04-01 21:59:30 +0000696 " * </pre>" + DELIMITER +
697 " * " + DELIMITER +
698 " * " + DELIMITER +
699 " * @author Darren Pearce" + DELIMITER +
700 " * @version 22-Sep-2005" + DELIMITER +
701 " * " + DELIMITER +
702 " */";
703 String result=testFormat(input);
704 assertEquals(expected, result);
705 }
706
707 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=60453
708 public void test60453() {
709 Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
710 options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "80");
711 options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT, DefaultCodeFormatterConstants.FALSE);
712
713 String input = "/** Creates a new instance of DynamicEventChannel sdf sdfs dsdf dsfsd fd fsd fsdf sdf dsfsd (on the same line)" + DELIMITER +
714 "* @pre obj != null" + DELIMITER +
715 "*/";
716
717 String expected = "/**" + DELIMITER +
718 " * Creates a new instance of DynamicEventChannel sdf sdfs dsdf dsfsd fd fsd fsdf" + DELIMITER +
719 " * sdf dsfsd (on the same line)" + DELIMITER +
720 " * " + DELIMITER +
721 " * @pre obj != null" + DELIMITER +
722 " */";
723 String result=testFormat(input, options);
724 assertEquals(expected, result);
725 }
726
727 /**
728 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=60453
729 * @deprecated
730 */
731 public void test60453_2() {
732 Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
733 options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "80");
734 options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES, DefaultCodeFormatterConstants.FALSE);
735
736 String input = "/** Creates a new instance of DynamicEventChannel sdf sdfs dsdf dsfsd fd fsd fsdf sdf dsfsd (on the same line)" + DELIMITER +
737 "* @pre obj != null" + DELIMITER +
738 "*/";
739
740 String expected = "/**" + DELIMITER +
741 " * Creates a new instance of DynamicEventChannel sdf sdfs dsdf dsfsd fd fsd fsdf" + DELIMITER +
742 " * sdf dsfsd (on the same line)" + DELIMITER +
743 " * " + DELIMITER +
744 " * @pre obj != null" + DELIMITER +
745 " */";
746 String result=testFormat(input, options);
747 assertEquals(expected, result);
748 }
749
750 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=75460
751 public void test75460() {
752 Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
753 options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "200");
754 options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_SOURCE, DefaultCodeFormatterConstants.TRUE);
755 options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT, DefaultCodeFormatterConstants.FALSE);
756
757 String input = "/**" + DELIMITER +
758 "<pre>"+ DELIMITER +
759 " Object[] objects = new Object[3];" + DELIMITER +
760 " objects[0] = new String(\"Hallo Welt !!!\");" + DELIMITER +
761 " objects[1] = new String(\"Test !!!\");" + DELIMITER +
762 " objects[2] = new Integer(\"1980\");" + DELIMITER +
763 " ObjectFile.write(pathname, objects);" + DELIMITER +
764 " Object[] objs = ObjectFile.read(pathname);" + DELIMITER +
765 " for(int i = 0; i < objs.length; i++)" + DELIMITER +
766 " {" + DELIMITER +
767 " System.out.println(objs[i].toString());" + DELIMITER +
768 " }" + DELIMITER +
769 "</pre>"+ DELIMITER +
770 "*/";
771
772 String expected = "/**" + DELIMITER +
773 " * <pre>" + DELIMITER +
774 " * Object[] objects = new Object[3];" + DELIMITER +
775 " * objects[0] = new String(&quot;Hallo Welt !!!&quot;);" + DELIMITER +
776 " * objects[1] = new String(&quot;Test !!!&quot;);" + DELIMITER +
777 " * objects[2] = new Integer(&quot;1980&quot;);" + DELIMITER +
778 " * ObjectFile.write(pathname, objects);" + DELIMITER +
779 " * Object[] objs = ObjectFile.read(pathname);" + DELIMITER +
780 " * for (int i = 0; i &lt; objs.length; i++) {" + DELIMITER +
781 " * System.out.println(objs[i].toString());" + DELIMITER +
782 " * }" + DELIMITER +
783 " * </pre>" + DELIMITER +
784 " */";
785 String result=testFormat(input, options);
786 assertEquals(expected, result);
787 }
788
789 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=152850
790 public void test152850() {
791 Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
792
793 String input = "/**\n" +
794 " * Any text\n" +
795 " * \n" +
796 " * @param b\n" +
797 " */";
798 TextEdit edit = ToolFactory.createCodeFormatter(CommentFormatterUtil.createOptions(options)).format(getCommentKind(), input, 0, input.length(), 0, "\n");
799 assertNotNull(edit);
800 assertEquals("No edit", 0, edit.getChildrenSize());
801 }
802
803 public void test198153() {
804 Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
805
806 String input = "/**" + DELIMITER +
807 " * <pre>" + DELIMITER +
808 " * System.out.println(&#34;hello world&#34;);" + DELIMITER +
809 " * </pre>" + DELIMITER +
810 " */";
811
812 String expected = "/**" + DELIMITER +
813 " * <pre>" + DELIMITER +
814 // No space after "world".
815 " * System.out.println(&quot;hello world&quot;);" + DELIMITER +
816 " * </pre>" + DELIMITER +
817 " */";
818 String result=testFormat(input, options);
819 assertEquals(expected, result);
820 }
821
822 public void test197169() {
823 Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
824
825 String input = "/**" + DELIMITER +
826 " * <pre>" + DELIMITER +
827 " * &#064;Anno1 class Foo {" + DELIMITER +
828 " * &#064;Anno1 class Bar {}" + DELIMITER +
829 " * }" + DELIMITER +
830 " * &#064;Anno2(&#064;Anno1) class Baz {}" + DELIMITER +
831 " * </pre>" + DELIMITER +
832 " */";
833
834 String expected = "/**" + DELIMITER +
835 " * <pre>" + DELIMITER +
836 // Initial &#064 left alone.
837 " * &#064;Anno1" + DELIMITER +
838 " * class Foo {" + DELIMITER +
839 // Left alone even after whitespace.
840 " * &#064;Anno1" + DELIMITER +
841 " * class Bar {" + DELIMITER +
842 " * }" + DELIMITER +
843 " * }" + DELIMITER +
844 " * " + DELIMITER +
845 // Non-initial &#064; expanded.
846 " * &#064;Anno2(@Anno1)" + DELIMITER +
847 " * class Baz {" + DELIMITER +
848 " * }" + DELIMITER +
849 " * </pre>" + DELIMITER +
850 " */";
851 String result=testFormat(input, options);
852 assertEquals(expected, result);
853 }
854
855 public void test109636() {
856 Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
857
858 String input =
859 "/**" + DELIMITER +
860 " * <code>" + DELIMITER +
861 " * <pre>" + DELIMITER +
862 " * setLeadingComment(\"/&#42; traditional comment &#42;/\"); // correct" + DELIMITER +
863 " * setLeadingComment(\"missing comment delimiters\"); // wrong" + DELIMITER +
864 " * setLeadingComment(\"/&#42; unterminated traditional comment \"); // wrong" + DELIMITER +
865 " * setLeadingComment(\"/&#42; broken\\n traditional comment &#42;/\"); // correct" + DELIMITER +
866 " * setLeadingComment(\"// end-of-line comment\\n\"); // correct" + DELIMITER +
867 " * setLeadingComment(\"// end-of-line comment without line terminator\"); // correct" + DELIMITER +
868 " * setLeadingComment(\"// broken\\n end-of-line comment\\n\"); // wrong" + DELIMITER +
869 " * </pre>" + DELIMITER +
870 " * </code>" + DELIMITER +
871 " */";
872
Stephan Herrmannbe6c0ea2010-04-01 21:59:30 +0000873 String result=testFormat(input, options);
Stephan Herrmann13a070b2010-04-02 03:54:26 +0000874 assertEquals(input, result);
Stephan Herrmannbe6c0ea2010-04-01 21:59:30 +0000875 }
876
877 public void test109636_2() {
878 Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
879
880 String input =
881 "/**" + DELIMITER +
882 " * <pre>" + DELIMITER +
883 " * /* Comment ending in multiple stars *&#42;/" + DELIMITER +
884 " * /* Entity-needing character after a star *&lt; &#42;/" + DELIMITER +
885 " * </pre>" + DELIMITER +
886 " */";
887
888 String expected =
889 "/**" + DELIMITER +
890 " * <pre>" + DELIMITER +
891 " * /* Comment ending in multiple stars *&#42;/" + DELIMITER +
892 " * /* Entity-needing character after a star *&lt; &#42;/" + DELIMITER +
893 " * </pre>" + DELIMITER +
894 " */";
895 String result=testFormat(input, options);
896 assertEquals(expected, result);
897 }
898
899 public void test109636_3() {
900 Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
901
902 String input =
903 "/**" + DELIMITER +
904 " * <pre>" + DELIMITER +
905 " * /* Comment ending in multiple stars ***&#42;/" + DELIMITER +
906 " * /* Entity-needing character after a star *&lt; &#42;/" + DELIMITER +
907 " * </pre>" + DELIMITER +
908 " */";
909
910 String expected =
911 "/**" + DELIMITER +
912 " * <pre>" + DELIMITER +
913 " * /* Comment ending in multiple stars ***&#42;/" + DELIMITER +
914 " * /* Entity-needing character after a star *&lt; &#42;/" + DELIMITER +
915 " * </pre>" + DELIMITER +
916 " */";
917 String result=testFormat(input, options);
918 assertEquals(expected, result);
919 }
920
921 public void test109636_4() {
Stephan Herrmann13a070b2010-04-02 03:54:26 +0000922 Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
Stephan Herrmannbe6c0ea2010-04-01 21:59:30 +0000923
Stephan Herrmann13a070b2010-04-02 03:54:26 +0000924 String input =
925 "/**" + DELIMITER +
926 " * <pre>" + DELIMITER +
927 " * setLeadingComment(\"/&#42; traditional comment &#42;/\"); // correct" + DELIMITER +
928 " * setLeadingComment(\"missing comment delimiters\"); // wrong" + DELIMITER +
929 " * setLeadingComment(\"/&#42; unterminated traditional comment \"); // wrong" + DELIMITER +
930 " * setLeadingComment(\"/&#42; broken\\n traditional comment &#42;/\"); // correct" + DELIMITER +
931 " * setLeadingComment(\"// end-of-line comment\\n\"); // correct" + DELIMITER +
932 " * setLeadingComment(\"// end-of-line comment without line terminator\"); // correct" + DELIMITER +
933 " * setLeadingComment(\"// broken\\n end-of-line comment\\n\"); // wrong" + DELIMITER +
934 " * </pre>" + DELIMITER +
935 " */";
Stephan Herrmannbe6c0ea2010-04-01 21:59:30 +0000936
Stephan Herrmann13a070b2010-04-02 03:54:26 +0000937 String expected =
938 "/**" + DELIMITER +
939 " * <pre>" + DELIMITER +
940 " * setLeadingComment(&quot;/* traditional comment &#42;/&quot;); // correct" + DELIMITER +
941 " * setLeadingComment(&quot;missing comment delimiters&quot;); // wrong" + DELIMITER +
942 " * setLeadingComment(&quot;/* unterminated traditional comment &quot;); // wrong" + DELIMITER +
943 " * setLeadingComment(&quot;/* broken\\n traditional comment &#42;/&quot;); // correct" + DELIMITER +
944 " * setLeadingComment(&quot;// end-of-line comment\\n&quot;); // correct" + DELIMITER +
945 " * setLeadingComment(&quot;// end-of-line comment without line terminator&quot;); // correct" + DELIMITER +
946 " * setLeadingComment(&quot;// broken\\n end-of-line comment\\n&quot;); // wrong" + DELIMITER +
947 " * </pre>" + DELIMITER +
948 " */";
949 String result=testFormat(input, options);
950 assertEquals(expected, result);
Stephan Herrmannbe6c0ea2010-04-01 21:59:30 +0000951 }
952
953 /**
954 * @bug 228652: [formatter] New line inserted while formatting a region of a compilation unit.
955 * @test Insure that no new line is inserted before the formatted region
956 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=228652"
957 */
958 public void testBug228652() {
959 Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
960
961 String input =
962 "package a;\r\n" +
963 "\r\n" +
964 "public class Test {\r\n" +
965 "\r\n" +
966 " private int field;\r\n" +
967 " \r\n" +
968 " /**\r\n" +
969 " * fds \r\n" +
970 " */\r\n" +
971 " public void foo() {\r\n" +
972 " }\r\n" +
973 "}";
974
975 String expected =
976 "package a;\r\n" +
977 "\r\n" +
978 "public class Test {\r\n" +
979 "\r\n" +
980 " private int field;\r\n" +
981 " \r\n" +
982 " /**\r\n" +
983 " * fds\r\n" +
984 " */\r\n" +
985 " public void foo() {\r\n" +
986 " }\r\n" +
987 "}";
988
989 String result = testFormat(input, 62, 19, CodeFormatter.K_JAVA_DOC, options);
990 assertEquals(expected, result);
991 }
992}