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

Collapse All | Expand All

(-)formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java (-33 lines)
Lines 117-123 Link Here
117
import org.eclipse.jdt.internal.core.util.CodeSnippetParsingUtil;
117
import org.eclipse.jdt.internal.core.util.CodeSnippetParsingUtil;
118
import org.eclipse.jdt.internal.formatter.align.Alignment;
118
import org.eclipse.jdt.internal.formatter.align.Alignment;
119
import org.eclipse.jdt.internal.formatter.align.AlignmentException;
119
import org.eclipse.jdt.internal.formatter.align.AlignmentException;
120
import org.eclipse.jdt.internal.formatter.comment.CommentRegion;
121
import org.eclipse.jface.text.IRegion;
120
import org.eclipse.jface.text.IRegion;
122
import org.eclipse.text.edits.TextEdit;
121
import org.eclipse.text.edits.TextEdit;
123
122
Lines 886-923 Link Here
886
	}
885
	}
887
886
888
	/**
887
	/**
889
	 * @see org.eclipse.jdt.core.formatter.CodeFormatter#format(int, String, int, int, int, String)
890
	 */
891
	public TextEdit format(String string, CommentRegion region) {
892
		// reset the scribe
893
		this.scribe.reset();
894
895
		if (region == null) {
896
			return failedToFormat();
897
		}
898
899
		long startTime = 0;
900
		if (DEBUG){
901
			startTime = System.currentTimeMillis();
902
		}
903
904
		final char[] compilationUnitSource = string.toCharArray();
905
906
		this.scribe.initializeScanner(compilationUnitSource);
907
908
		TextEdit result = null;
909
		try {
910
			result = region.format(this.preferences.initial_indentation_level, true);
911
		} catch(AbortFormatting e){
912
			return failedToFormat();
913
		}
914
		if (DEBUG){
915
			System.out.println("Formatting time: " + (System.currentTimeMillis() - startTime));  //$NON-NLS-1$
916
		}
917
		return result;
918
	}
919
920
	/**
921
	 * @param source the source of the comment to format
888
	 * @param source the source of the comment to format
922
	 */
889
	 */
923
	public void formatComment(int kind, String source, int start, int end, int indentationLevel) {
890
	public void formatComment(int kind, String source, int start, int end, int indentationLevel) {
(-)formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java (-102 / +30 lines)
Lines 28-42 Link Here
28
import org.eclipse.jdt.internal.compiler.parser.TerminalTokens;
28
import org.eclipse.jdt.internal.compiler.parser.TerminalTokens;
29
import org.eclipse.jdt.internal.compiler.util.Util;
29
import org.eclipse.jdt.internal.compiler.util.Util;
30
import org.eclipse.jdt.internal.core.util.CodeSnippetParsingUtil;
30
import org.eclipse.jdt.internal.core.util.CodeSnippetParsingUtil;
31
import org.eclipse.jdt.internal.formatter.comment.CommentRegion;
32
import org.eclipse.jdt.internal.formatter.comment.JavaDocRegion;
33
import org.eclipse.jdt.internal.formatter.comment.MultiCommentRegion;
34
import org.eclipse.jface.text.Document;
35
import org.eclipse.jface.text.IDocument;
31
import org.eclipse.jface.text.IDocument;
36
import org.eclipse.jface.text.IRegion;
32
import org.eclipse.jface.text.IRegion;
37
import org.eclipse.jface.text.Position;
33
import org.eclipse.jface.text.Position;
38
import org.eclipse.jface.text.Region;
34
import org.eclipse.jface.text.Region;
39
import org.eclipse.text.edits.MultiTextEdit;
40
import org.eclipse.text.edits.TextEdit;
35
import org.eclipse.text.edits.TextEdit;
41
36
42
public class DefaultCodeFormatter extends CodeFormatter {
37
public class DefaultCodeFormatter extends CodeFormatter {
Lines 56-70 Link Here
56
		| K_MULTI_LINE_COMMENT
51
		| K_MULTI_LINE_COMMENT
57
		| K_JAVA_DOC;
52
		| K_JAVA_DOC;
58
53
59
	/*
60
	 * Temporary internal statics to enable new comments formatter
61
	 * see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=102780
62
	 * see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=227043
63
	 * TODO (frederic) remove in 3.5
64
	 */
65
	private final static String NEW_COMMENTS_FORMAT = System.getProperty("org.eclipse.jdt.core.formatter.comments.new"); //$NON-NLS-1$
66
	public static boolean ENABLE_NEW_COMMENTS_FORMAT = !JavaCore.DISABLED.equals(NEW_COMMENTS_FORMAT);
67
68
	// Scanner use to probe the kind of the source given to the formatter
54
	// Scanner use to probe the kind of the source given to the formatter
69
	private static Scanner PROBING_SCANNER;
55
	private static Scanner PROBING_SCANNER;
70
56
Lines 77-91 Link Here
77
	 * @return a new comment region for the comment region range in the
63
	 * @return a new comment region for the comment region range in the
78
	 *         document
64
	 *         document
79
	 * @since 3.1
65
	 * @since 3.1
66
	 * 
67
	 * @deprecated Since version 3.4, CommentRegion are no longer used by
68
	 * 		the formatter to format comments.<br>
69
	 * 		<b>WARNING</b>: This method will be removed from 3.6 version...
80
	 */
70
	 */
81
	public static CommentRegion createRegion(int kind, IDocument document, Position range, CodeFormatterVisitor formatter) {
71
	public static org.eclipse.jdt.internal.formatter.comment.CommentRegion createRegion(int kind, IDocument document, Position range, CodeFormatterVisitor formatter) {
82
		switch (kind & K_MASK) {
72
		switch (kind & K_MASK) {
83
			case K_SINGLE_LINE_COMMENT:
73
			case K_SINGLE_LINE_COMMENT:
84
				return new CommentRegion(document, range, formatter);
74
				return new org.eclipse.jdt.internal.formatter.comment.CommentRegion(document, range, formatter);
85
			case K_MULTI_LINE_COMMENT:
75
			case K_MULTI_LINE_COMMENT:
86
				return new MultiCommentRegion(document, range, formatter);
76
				return new org.eclipse.jdt.internal.formatter.comment.MultiCommentRegion(document, range, formatter);
87
			case K_JAVA_DOC:
77
			case K_JAVA_DOC:
88
				return new JavaDocRegion(document, range, formatter);
78
				return new org.eclipse.jdt.internal.formatter.comment.JavaDocRegion(document, range, formatter);
89
		}
79
		}
90
		return null;
80
		return null;
91
	}
81
	}
Lines 174-190 Link Here
174
			case K_JAVA_DOC :
164
			case K_JAVA_DOC :
175
				// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102780
165
				// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102780
176
				// use the integrated comment formatter to format comment
166
				// use the integrated comment formatter to format comment
177
				if (ENABLE_NEW_COMMENTS_FORMAT) {
167
                return formatComment(kind & K_MASK, source, indentationLevel, lineSeparator, new IRegion[] {new Region(offset, length)});
178
	                return formatComment(kind & K_MASK, source, indentationLevel, lineSeparator, new IRegion[] {new Region(offset, length)});
179
				}
180
				// $FALL-THROUGH$ - fall through next case when old comment formatter is activated
168
				// $FALL-THROUGH$ - fall through next case when old comment formatter is activated
181
			case K_MULTI_LINE_COMMENT :
169
			case K_MULTI_LINE_COMMENT :
182
			case K_SINGLE_LINE_COMMENT :
170
			case K_SINGLE_LINE_COMMENT :
183
				if (ENABLE_NEW_COMMENTS_FORMAT) {
171
                return formatComment(kind & K_MASK, source, indentationLevel, lineSeparator, new IRegion[] {new Region(offset, length)});
184
	                return formatComment(kind & K_MASK, source, indentationLevel, lineSeparator, new IRegion[] {new Region(offset, length)});
185
				}
186
				this.codeSnippetParsingUtil = new CodeSnippetParsingUtil();
187
				return formatComment(kind, source, indentationLevel, lineSeparator, new IRegion[] {new Region(offset, length)}, false);
188
		}
172
		}
189
173
190
		return format(kind, source, new IRegion[] {new Region(offset, length)}, indentationLevel, lineSeparator);
174
		return format(kind, source, new IRegion[] {new Region(offset, length)}, indentationLevel, lineSeparator);
Lines 199-216 Link Here
199
		}
183
		}
200
184
201
		this.codeSnippetParsingUtil = new CodeSnippetParsingUtil();
185
		this.codeSnippetParsingUtil = new CodeSnippetParsingUtil();
186
		boolean includeComments =  (kind & F_INCLUDE_COMMENTS) != 0;
202
		switch(kind & K_MASK) {
187
		switch(kind & K_MASK) {
203
			case K_CLASS_BODY_DECLARATIONS :
188
			case K_CLASS_BODY_DECLARATIONS :
204
				return formatClassBodyDeclarations(source, indentationLevel, lineSeparator, regions);
189
				return formatClassBodyDeclarations(source, indentationLevel, lineSeparator, regions, includeComments);
205
			case K_COMPILATION_UNIT :
190
			case K_COMPILATION_UNIT :
206
				boolean includeComments =  (kind & F_INCLUDE_COMMENTS) != 0; // || FORCE_NEW_COMMENTS_FORMAT;
207
				return formatCompilationUnit(source, indentationLevel, lineSeparator, regions, includeComments);
191
				return formatCompilationUnit(source, indentationLevel, lineSeparator, regions, includeComments);
208
			case K_EXPRESSION :
192
			case K_EXPRESSION :
209
				return formatExpression(source, indentationLevel, lineSeparator, regions);
193
				return formatExpression(source, indentationLevel, lineSeparator, regions, includeComments);
210
			case K_STATEMENTS :
194
			case K_STATEMENTS :
211
				return formatStatements(source, indentationLevel, lineSeparator, regions);
195
				return formatStatements(source, indentationLevel, lineSeparator, regions, includeComments);
212
			case K_UNKNOWN :
196
			case K_UNKNOWN :
213
				includeComments =  (kind & F_INCLUDE_COMMENTS) != 0; // || FORCE_NEW_COMMENTS_FORMAT;
214
				return probeFormatting(source, indentationLevel, lineSeparator, regions, includeComments);
197
				return probeFormatting(source, indentationLevel, lineSeparator, regions, includeComments);
215
			case K_JAVA_DOC :
198
			case K_JAVA_DOC :
216
			case K_MULTI_LINE_COMMENT :
199
			case K_MULTI_LINE_COMMENT :
Lines 221-234 Link Here
221
		return null;
204
		return null;
222
	}
205
	}
223
206
224
	private TextEdit formatClassBodyDeclarations(String source, int indentationLevel, String lineSeparator, IRegion[] regions) {
207
	private TextEdit formatClassBodyDeclarations(String source, int indentationLevel, String lineSeparator, IRegion[] regions, boolean includeComments) {
225
		ASTNode[] bodyDeclarations = this.codeSnippetParsingUtil.parseClassBodyDeclarations(source.toCharArray(), getDefaultCompilerOptions(), true);
208
		ASTNode[] bodyDeclarations = this.codeSnippetParsingUtil.parseClassBodyDeclarations(source.toCharArray(), getDefaultCompilerOptions(), true);
226
209
227
		if (bodyDeclarations == null) {
210
		if (bodyDeclarations == null) {
228
			// a problem occurred while parsing the source
211
			// a problem occurred while parsing the source
229
			return null;
212
			return null;
230
		}
213
		}
231
		return internalFormatClassBodyDeclarations(source, indentationLevel, lineSeparator, bodyDeclarations, regions);
214
		return internalFormatClassBodyDeclarations(source, indentationLevel, lineSeparator, bodyDeclarations, regions, includeComments);
232
	}
215
	}
233
216
234
	/*
217
	/*
Lines 271-325 Link Here
271
		return null;
254
		return null;
272
	}
255
	}
273
256
274
	/**
275
	 * Returns the resulting text edit after formatting the given comment.
276
	 *
277
	 * @param kind the given kind
278
	 * @param source the given source
279
	 * @param indentationLevel the given indentation level
280
	 * @param lineSeparator the given line separator
281
	 * @param regions the given regions
282
	 * @param includeComments TODO
283
	 * @return the resulting text edit
284
	 */
285
	private TextEdit formatComment(int kind, String source, int indentationLevel, String lineSeparator, IRegion[] regions, boolean includeComments) {
286
		Object oldOption = oldCommentFormatOption();
287
		boolean isFormattingComments = false;
288
		if (oldOption == null) {
289
			switch (kind & K_MASK) {
290
				case K_SINGLE_LINE_COMMENT:
291
					isFormattingComments = DefaultCodeFormatterConstants.TRUE.equals(this.options.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_LINE_COMMENT));
292
					break;
293
				case K_MULTI_LINE_COMMENT:
294
					isFormattingComments = DefaultCodeFormatterConstants.TRUE.equals(this.options.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_BLOCK_COMMENT));
295
					break;
296
				case K_JAVA_DOC:
297
					isFormattingComments = DefaultCodeFormatterConstants.TRUE.equals(this.options.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_JAVADOC_COMMENT));
298
			}
299
		} else {
300
			isFormattingComments = DefaultCodeFormatterConstants.TRUE.equals(oldOption);
301
		}
302
		if (isFormattingComments) {
303
			if (lineSeparator != null) {
304
				this.preferences.line_separator = lineSeparator;
305
			} else {
306
				this.preferences.line_separator = Util.LINE_SEPARATOR;
307
			}
308
			this.preferences.initial_indentation_level = indentationLevel;
309
			this.newCodeFormatter = new CodeFormatterVisitor(this.preferences, this.options, regions, null, includeComments);
310
311
			IRegion coveredRegion = getCoveredRegion(regions);
312
			int offset = coveredRegion.getOffset();
313
			int length = coveredRegion.getLength();
314
315
			final CommentRegion region = createRegion(kind, new Document(source), new Position(offset, length), this.newCodeFormatter);
316
			if (region != null) {
317
				return this.newCodeFormatter.format(source, region);
318
			}
319
		}
320
		return new MultiTextEdit();
321
	}
322
323
	private TextEdit formatCompilationUnit(String source, int indentationLevel, String lineSeparator, IRegion[] regions, boolean includeComments) {
257
	private TextEdit formatCompilationUnit(String source, int indentationLevel, String lineSeparator, IRegion[] regions, boolean includeComments) {
324
		CompilationUnitDeclaration compilationUnitDeclaration = this.codeSnippetParsingUtil.parseCompilationUnit(source.toCharArray(), getDefaultCompilerOptions(), true);
258
		CompilationUnitDeclaration compilationUnitDeclaration = this.codeSnippetParsingUtil.parseCompilationUnit(source.toCharArray(), getDefaultCompilerOptions(), true);
325
259
Lines 335-358 Link Here
335
		return this.newCodeFormatter.format(source, compilationUnitDeclaration);
269
		return this.newCodeFormatter.format(source, compilationUnitDeclaration);
336
	}
270
	}
337
271
338
	private TextEdit formatExpression(String source, int indentationLevel, String lineSeparator, IRegion[] regions) {
272
	private TextEdit formatExpression(String source, int indentationLevel, String lineSeparator, IRegion[] regions, boolean includeComments) {
339
		Expression expression = this.codeSnippetParsingUtil.parseExpression(source.toCharArray(), getDefaultCompilerOptions(), true);
273
		Expression expression = this.codeSnippetParsingUtil.parseExpression(source.toCharArray(), getDefaultCompilerOptions(), true);
340
274
341
		if (expression == null) {
275
		if (expression == null) {
342
			// a problem occurred while parsing the source
276
			// a problem occurred while parsing the source
343
			return null;
277
			return null;
344
		}
278
		}
345
		return internalFormatExpression(source, indentationLevel, lineSeparator, expression, regions);
279
		return internalFormatExpression(source, indentationLevel, lineSeparator, expression, regions, includeComments);
346
	}
280
	}
347
281
348
	private TextEdit formatStatements(String source, int indentationLevel, String lineSeparator, IRegion[] regions) {
282
	private TextEdit formatStatements(String source, int indentationLevel, String lineSeparator, IRegion[] regions, boolean includeComments) {
349
		ConstructorDeclaration constructorDeclaration = this.codeSnippetParsingUtil.parseStatements(source.toCharArray(), getDefaultCompilerOptions(), true, false);
283
		ConstructorDeclaration constructorDeclaration = this.codeSnippetParsingUtil.parseStatements(source.toCharArray(), getDefaultCompilerOptions(), true, false);
350
284
351
		if (constructorDeclaration.statements == null) {
285
		if (constructorDeclaration.statements == null) {
352
			// a problem occured while parsing the source
286
			// a problem occured while parsing the source
353
			return null;
287
			return null;
354
		}
288
		}
355
		return internalFormatStatements(source, indentationLevel, lineSeparator, constructorDeclaration, regions);
289
		return internalFormatStatements(source, indentationLevel, lineSeparator, constructorDeclaration, regions, includeComments);
356
	}
290
	}
357
291
358
	private IRegion getCoveredRegion(IRegion[] regions) {
292
	private IRegion getCoveredRegion(IRegion[] regions) {
Lines 443-449 Link Here
443
		return this.defaultCompilerOptions;
377
		return this.defaultCompilerOptions;
444
	}
378
	}
445
379
446
	private TextEdit internalFormatClassBodyDeclarations(String source, int indentationLevel, String lineSeparator, ASTNode[] bodyDeclarations, IRegion[] regions) {
380
	private TextEdit internalFormatClassBodyDeclarations(String source, int indentationLevel, String lineSeparator, ASTNode[] bodyDeclarations, IRegion[] regions, boolean includeComments) {
447
		if (lineSeparator != null) {
381
		if (lineSeparator != null) {
448
			this.preferences.line_separator = lineSeparator;
382
			this.preferences.line_separator = lineSeparator;
449
		} else {
383
		} else {
Lines 451-461 Link Here
451
		}
385
		}
452
		this.preferences.initial_indentation_level = indentationLevel;
386
		this.preferences.initial_indentation_level = indentationLevel;
453
387
454
		this.newCodeFormatter = new CodeFormatterVisitor(this.preferences, this.options, regions, this.codeSnippetParsingUtil, false);
388
		this.newCodeFormatter = new CodeFormatterVisitor(this.preferences, this.options, regions, this.codeSnippetParsingUtil, includeComments);
455
		return this.newCodeFormatter.format(source, bodyDeclarations);
389
		return this.newCodeFormatter.format(source, bodyDeclarations);
456
	}
390
	}
457
391
458
	private TextEdit internalFormatExpression(String source, int indentationLevel, String lineSeparator, Expression expression, IRegion[] regions) {
392
	private TextEdit internalFormatExpression(String source, int indentationLevel, String lineSeparator, Expression expression, IRegion[] regions, boolean includeComments) {
459
		if (lineSeparator != null) {
393
		if (lineSeparator != null) {
460
			this.preferences.line_separator = lineSeparator;
394
			this.preferences.line_separator = lineSeparator;
461
		} else {
395
		} else {
Lines 463-475 Link Here
463
		}
397
		}
464
		this.preferences.initial_indentation_level = indentationLevel;
398
		this.preferences.initial_indentation_level = indentationLevel;
465
399
466
		this.newCodeFormatter = new CodeFormatterVisitor(this.preferences, this.options, regions, this.codeSnippetParsingUtil, false);
400
		this.newCodeFormatter = new CodeFormatterVisitor(this.preferences, this.options, regions, this.codeSnippetParsingUtil, includeComments);
467
401
468
		TextEdit textEdit = this.newCodeFormatter.format(source, expression);
402
		TextEdit textEdit = this.newCodeFormatter.format(source, expression);
469
		return textEdit;
403
		return textEdit;
470
	}
404
	}
471
405
472
	private TextEdit internalFormatStatements(String source, int indentationLevel, String lineSeparator, ConstructorDeclaration constructorDeclaration, IRegion[] regions) {
406
	private TextEdit internalFormatStatements(String source, int indentationLevel, String lineSeparator, ConstructorDeclaration constructorDeclaration, IRegion[] regions, boolean includeComments) {
473
		if (lineSeparator != null) {
407
		if (lineSeparator != null) {
474
			this.preferences.line_separator = lineSeparator;
408
			this.preferences.line_separator = lineSeparator;
475
		} else {
409
		} else {
Lines 477-483 Link Here
477
		}
411
		}
478
		this.preferences.initial_indentation_level = indentationLevel;
412
		this.preferences.initial_indentation_level = indentationLevel;
479
413
480
		this.newCodeFormatter = new CodeFormatterVisitor(this.preferences, this.options, regions, this.codeSnippetParsingUtil, false);
414
		this.newCodeFormatter = new CodeFormatterVisitor(this.preferences, this.options, regions, this.codeSnippetParsingUtil, includeComments);
481
415
482
		return this.newCodeFormatter.format(source, constructorDeclaration);
416
		return this.newCodeFormatter.format(source, constructorDeclaration);
483
	}
417
	}
Lines 523-535 Link Here
523
					break;
457
					break;
524
			}
458
			}
525
			if (kind != -1) {
459
			if (kind != -1) {
526
				// https://bugs.eclipse.org/bugs/show_bug.cgi?id=227043
460
				return formatComment(kind, source, indentationLevel, lineSeparator, regions);
527
				// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102780
528
				// use the integrated comment formatter to format comment
529
				if (ENABLE_NEW_COMMENTS_FORMAT /*|| FORCE_NEW_COMMENTS_FORMAT*/) {
530
					return formatComment(kind, source, indentationLevel, lineSeparator, regions);
531
				}
532
				return formatComment(kind, source, indentationLevel, lineSeparator, regions, includeComments);
533
			}
461
			}
534
		} catch (InvalidInputException e) {
462
		} catch (InvalidInputException e) {
535
			// ignore
463
			// ignore
Lines 539-557 Link Here
539
		// probe for expression
467
		// probe for expression
540
		Expression expression = this.codeSnippetParsingUtil.parseExpression(source.toCharArray(), getDefaultCompilerOptions(), true);
468
		Expression expression = this.codeSnippetParsingUtil.parseExpression(source.toCharArray(), getDefaultCompilerOptions(), true);
541
		if (expression != null) {
469
		if (expression != null) {
542
			return internalFormatExpression(source, indentationLevel, lineSeparator, expression, regions);
470
			return internalFormatExpression(source, indentationLevel, lineSeparator, expression, regions, includeComments);
543
		}
471
		}
544
472
545
		// probe for body declarations (fields, methods, constructors)
473
		// probe for body declarations (fields, methods, constructors)
546
		ASTNode[] bodyDeclarations = this.codeSnippetParsingUtil.parseClassBodyDeclarations(source.toCharArray(), getDefaultCompilerOptions(), true);
474
		ASTNode[] bodyDeclarations = this.codeSnippetParsingUtil.parseClassBodyDeclarations(source.toCharArray(), getDefaultCompilerOptions(), true);
547
		if (bodyDeclarations != null) {
475
		if (bodyDeclarations != null) {
548
			return internalFormatClassBodyDeclarations(source, indentationLevel, lineSeparator, bodyDeclarations, regions);
476
			return internalFormatClassBodyDeclarations(source, indentationLevel, lineSeparator, bodyDeclarations, regions, includeComments);
549
		}
477
		}
550
478
551
		// probe for statements
479
		// probe for statements
552
		ConstructorDeclaration constructorDeclaration = this.codeSnippetParsingUtil.parseStatements(source.toCharArray(), getDefaultCompilerOptions(), true, false);
480
		ConstructorDeclaration constructorDeclaration = this.codeSnippetParsingUtil.parseStatements(source.toCharArray(), getDefaultCompilerOptions(), true, false);
553
		if (constructorDeclaration.statements != null) {
481
		if (constructorDeclaration.statements != null) {
554
			return internalFormatStatements(source, indentationLevel, lineSeparator, constructorDeclaration, regions);
482
			return internalFormatStatements(source, indentationLevel, lineSeparator, constructorDeclaration, regions, includeComments);
555
		}
483
		}
556
484
557
		// this has to be a compilation unit
485
		// this has to be a compilation unit
(-)formatter/org/eclipse/jdt/internal/formatter/comment/CommentLine.java (+4 lines)
Lines 19-24 Link Here
19
 * General comment line in a comment region.
19
 * General comment line in a comment region.
20
 *
20
 *
21
 * @since 3.0
21
 * @since 3.0
22
 * 
23
 * @deprecated Since version 3.4, comment regions are no longer used by
24
 * 		the formatter to format comments.<br>
25
 * 		<b>WARNING</b>: This class will be removed from 3.6 version...
22
 */
26
 */
23
public abstract class CommentLine implements IBorderAttributes {
27
public abstract class CommentLine implements IBorderAttributes {
24
28
(-)formatter/org/eclipse/jdt/internal/formatter/comment/CommentRange.java (+4 lines)
Lines 22-27 Link Here
22
 * Range in a comment region in comment region coordinates.
22
 * Range in a comment region in comment region coordinates.
23
 *
23
 *
24
 * @since 3.0
24
 * @since 3.0
25
 * 
26
 * @deprecated Since version 3.4, comment regions are no longer used by
27
 * 		the formatter to format comments.<br>
28
 * 		<b>WARNING</b>: This class will be removed from 3.6 version...
25
 */
29
 */
26
public class CommentRange extends Position implements ICommentAttributes, IHtmlTagDelimiters {
30
public class CommentRange extends Position implements ICommentAttributes, IHtmlTagDelimiters {
27
31
(-)formatter/org/eclipse/jdt/internal/formatter/comment/CommentRegion.java (+4 lines)
Lines 35-40 Link Here
35
 * Comment region in a source code document.
35
 * Comment region in a source code document.
36
 *
36
 *
37
 * @since 3.0
37
 * @since 3.0
38
 * 
39
 * @deprecated Since version 3.4, comment regions are no longer used by
40
 * 		the formatter to format comments.<br>
41
 * 		<b>WARNING</b>: This class will be removed from 3.6 version...
38
 */
42
 */
39
public class CommentRegion extends Position implements IHtmlTagDelimiters, IBorderAttributes, ICommentAttributes {
43
public class CommentRegion extends Position implements IHtmlTagDelimiters, IBorderAttributes, ICommentAttributes {
40
44
(-)formatter/org/eclipse/jdt/internal/formatter/comment/IBorderAttributes.java (+4 lines)
Lines 15-20 Link Here
15
 * Comment region border attributes.
15
 * Comment region border attributes.
16
 *
16
 *
17
 * @since 3.0
17
 * @since 3.0
18
 * 
19
 * @deprecated Since version 3.4, comment regions are no longer used by
20
 * 		the formatter to format comments.<br>
21
 * 		<b>WARNING</b>: This class will be removed from 3.6 version...
18
 */
22
 */
19
public interface IBorderAttributes {
23
public interface IBorderAttributes {
20
24
(-)formatter/org/eclipse/jdt/internal/formatter/comment/ICommentAttributes.java (+4 lines)
Lines 15-20 Link Here
15
 * General comment range attributes.
15
 * General comment range attributes.
16
 *
16
 *
17
 * @since 3.0
17
 * @since 3.0
18
 * 
19
 * @deprecated Since version 3.4, comment regions are no longer used by
20
 * 		the formatter to format comments.<br>
21
 * 		<b>WARNING</b>: This class will be removed from 3.6 version...
18
 */
22
 */
19
public interface ICommentAttributes {
23
public interface ICommentAttributes {
20
24
(-)formatter/org/eclipse/jdt/internal/formatter/comment/IHtmlTagDelimiters.java (+4 lines)
Lines 15-20 Link Here
15
 * Html tag constants.
15
 * Html tag constants.
16
 *
16
 *
17
 * @since 3.0
17
 * @since 3.0
18
 * 
19
 * @deprecated Since version 3.4, comment regions are no longer used by
20
 * 		the formatter to format comments.<br>
21
 * 		<b>WARNING</b>: This class will be removed from 3.6 version...
18
 */
22
 */
19
public interface IHtmlTagDelimiters {
23
public interface IHtmlTagDelimiters {
20
24
(-)formatter/org/eclipse/jdt/internal/formatter/comment/JavaDocLine.java (+4 lines)
Lines 15-20 Link Here
15
 * Javadoc comment line in a comment region.
15
 * Javadoc comment line in a comment region.
16
 *
16
 *
17
 * @since 3.0
17
 * @since 3.0
18
 * 
19
 * @deprecated Since version 3.4, comment regions are no longer used by
20
 * 		the formatter to format comments.<br>
21
 * 		<b>WARNING</b>: This class will be removed from 3.6 version...
18
 */
22
 */
19
public class JavaDocLine extends MultiCommentLine {
23
public class JavaDocLine extends MultiCommentLine {
20
24
(-)formatter/org/eclipse/jdt/internal/formatter/comment/JavaDocRegion.java (+4 lines)
Lines 34-39 Link Here
34
 * Javadoc region in a source code document.
34
 * Javadoc region in a source code document.
35
 *
35
 *
36
 * @since 3.0
36
 * @since 3.0
37
 * 
38
 * @deprecated Since version 3.4, comment regions are no longer used by
39
 * 		the formatter to format comments.<br>
40
 * 		<b>WARNING</b>: This class will be removed from 3.6 version...
37
 */
41
 */
38
public class JavaDocRegion extends MultiCommentRegion {
42
public class JavaDocRegion extends MultiCommentRegion {
39
43
(-)formatter/org/eclipse/jdt/internal/formatter/comment/MultiCommentLine.java (+4 lines)
Lines 22-27 Link Here
22
 * Multi-line comment line in a comment region.
22
 * Multi-line comment line in a comment region.
23
 *
23
 *
24
 * @since 3.0
24
 * @since 3.0
25
 * 
26
 * @deprecated Since version 3.4, comment regions are no longer used by
27
 * 		the formatter to format comments.<br>
28
 * 		<b>WARNING</b>: This class will be removed from 3.6 version...
25
 */
29
 */
26
public class MultiCommentLine extends CommentLine implements ICommentAttributes, IHtmlTagDelimiters, IJavaDocTagConstants {
30
public class MultiCommentLine extends CommentLine implements ICommentAttributes, IHtmlTagDelimiters, IJavaDocTagConstants {
27
31
(-)formatter/org/eclipse/jdt/internal/formatter/comment/MultiCommentRegion.java (+4 lines)
Lines 23-28 Link Here
23
 * Multi-comment region in a source code document.
23
 * Multi-comment region in a source code document.
24
 *
24
 *
25
 * @since 3.0
25
 * @since 3.0
26
 * 
27
 * @deprecated Since version 3.4, comment regions are no longer used by
28
 * 		the formatter to format comments.<br>
29
 * 		<b>WARNING</b>: This class will be removed from 3.6 version...
26
 */
30
 */
27
public class MultiCommentRegion extends CommentRegion implements IJavaDocTagConstants {
31
public class MultiCommentRegion extends CommentRegion implements IJavaDocTagConstants {
28
32
(-)formatter/org/eclipse/jdt/internal/formatter/comment/SingleCommentLine.java (+4 lines)
Lines 15-20 Link Here
15
 * Single-line comment line in a comment region.
15
 * Single-line comment line in a comment region.
16
 *
16
 *
17
 * @since 3.0
17
 * @since 3.0
18
 * 
19
 * @deprecated Since version 3.4, comment regions are no longer used by
20
 * 		the formatter to format comments.<br>
21
 * 		<b>WARNING</b>: This class will be removed from 3.6 version...
18
 */
22
 */
19
public class SingleCommentLine extends CommentLine {
23
public class SingleCommentLine extends CommentLine {
20
24
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java (-3 / +137 lines)
Lines 2200-2207 Link Here
2200
		"	  return null;\n" +
2200
		"	  return null;\n" +
2201
		"  }\n" +
2201
		"  }\n" +
2202
		"}\n";
2202
		"}\n";
2203
	// TODO (frederic) line comment should be formatted when F_INCLUDE_COMMENTS
2204
	// flag will work for all snippet kinds
2205
	formatSource(source,
2203
	formatSource(source,
2206
		"/**\n" +
2204
		"/**\n" +
2207
		" * Need a javadoc comment before to get the exception.\n" +
2205
		" * Need a javadoc comment before to get the exception.\n" +
Lines 2213-2219 Link Here
2213
		"	 * If there is an authority, it is:\n" +
2211
		"	 * If there is an authority, it is:\n" +
2214
		"	 * \n" +
2212
		"	 * \n" +
2215
		"	 * <pre>\n" +
2213
		"	 * <pre>\n" +
2216
		"	 * //class	body		snippet\n" +
2214
		"	 * // class body snippet\n" + 
2217
		"	 * public class X {\n" +
2215
		"	 * public class X {\n" +
2218
		"	 * }\n" +
2216
		"	 * }\n" +
2219
		"	 * </pre>\n" +
2217
		"	 * </pre>\n" +
Lines 2265-2270 Link Here
2265
}
2263
}
2266
2264
2267
/**
2265
/**
2266
 * @bug 236406: [formatter] Formatting qualified invocations can be broken when the Line Wrapping policy forces element to be on a new line
2267
 * @test Verify that wrapping policies forcing the first element to be on a new line are working again...
2268
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=236406"
2269
 */
2270
public void testBug236406_CDB1() {
2271
	String source = 
2272
		"/**        Javadoc		comment    	    */void foo1() {System.out.println();}\n" +
2273
		"//        Line		comment    	    \n" +
2274
		"void foo2() {System.out.println();}\n" +
2275
		"/*        Block		comment    	    */\n" +
2276
		"void foo3() {\n" +
2277
		"/*        statement Block		comment    	    */\n" +
2278
		"System.out.println();}\n";
2279
	formatSource(source,
2280
		"/**        Javadoc		comment    	    */\n" + 
2281
		"void foo1() {\n" + 
2282
		"	System.out.println();\n" + 
2283
		"}\n" + 
2284
		"\n" + 
2285
		"//        Line		comment    	    \n" + 
2286
		"void foo2() {\n" + 
2287
		"	System.out.println();\n" + 
2288
		"}\n" + 
2289
		"\n" + 
2290
		"/*        Block		comment    	    */\n" +
2291
		"void foo3() {\n" +
2292
		"	/*        statement Block		comment    	    */\n" + 
2293
		"	System.out.println();\n" + 
2294
		"}",
2295
		CodeFormatter.K_CLASS_BODY_DECLARATIONS
2296
	);
2297
}
2298
public void testBug236406_CDB2() {
2299
	String source = 
2300
		"/**        Javadoc		comment    	    */void foo1() {System.out.println();}\n" +
2301
		"//        Line		comment    	    \n" +
2302
		"void foo2() {System.out.println();}\n" +
2303
		"/*        Block		comment    	    */\n" +
2304
		"void foo3() {\n" +
2305
		"/*        statement Block		comment    	    */\n" +
2306
		"System.out.println();}\n";
2307
	formatSource(source,
2308
		"/** Javadoc comment */\n" + 
2309
		"void foo1() {\n" + 
2310
		"	System.out.println();\n" + 
2311
		"}\n" + 
2312
		"\n" + 
2313
		"// Line comment\n" + 
2314
		"void foo2() {\n" + 
2315
		"	System.out.println();\n" + 
2316
		"}\n" + 
2317
		"\n" + 
2318
		"/* Block comment */\n" +
2319
		"void foo3() {\n" + 
2320
		"	/* statement Block comment */\n" + 
2321
		"	System.out.println();\n" + 
2322
		"}",
2323
		CodeFormatter.K_CLASS_BODY_DECLARATIONS | CodeFormatter.F_INCLUDE_COMMENTS
2324
	);
2325
}
2326
public void testBug236406_EX1() {
2327
	String source = 
2328
		"//        Line		comment    	    \n" +
2329
		"i = \n" +
2330
		"/**        Javadoc		comment    	    */\n" +
2331
		"1     +     (/*      Block		comment*/++a)\n";
2332
	formatSource(source,
2333
		"//        Line		comment    	    \n" + 
2334
		"i =\n" + 
2335
		"/**        Javadoc		comment    	    */\n" + 
2336
		"1 + (/*      Block		comment*/++a)",
2337
		CodeFormatter.K_EXPRESSION
2338
	);
2339
}
2340
public void testBug236406_EX2() {
2341
	String source = 
2342
		"//        Line		comment    	    \n" +
2343
		"i = \n" +
2344
		"/**        Javadoc		comment    	    */\n" +
2345
		"1     +     (/*      Block		comment*/++a)\n";
2346
	formatSource(source,
2347
		"// Line comment\n" + 
2348
		"i =\n" + 
2349
		"/** Javadoc comment */\n" + 
2350
		"1 + (/* Block comment */++a)",
2351
		CodeFormatter.K_EXPRESSION | CodeFormatter.F_INCLUDE_COMMENTS
2352
	);
2353
}
2354
public void testBug236406_ST1() {
2355
	String source = 
2356
		"/**        Javadoc		comment    	    */foo1();\n" +
2357
		"//        Line		comment    	    \n" +
2358
		"foo2();\n" +
2359
		"/*        Block		comment    	    */\n" +
2360
		"foo3(); {\n" +
2361
		"/*        indented Block		comment    	    */\n" +
2362
		"System.out.println();}\n";
2363
	formatSource(source,
2364
		"/**        Javadoc		comment    	    */\n" + 
2365
		"foo1();\n" + 
2366
		"//        Line		comment    	    \n" + 
2367
		"foo2();\n" + 
2368
		"/*        Block		comment    	    */\n" + 
2369
		"foo3();\n" + 
2370
		"{\n" + 
2371
		"	/*        indented Block		comment    	    */\n" + 
2372
		"	System.out.println();\n" + 
2373
		"}",
2374
		CodeFormatter.K_STATEMENTS
2375
	);
2376
}
2377
public void testBug236406_ST2() {
2378
	String source = 
2379
		"/**        Javadoc		comment    	    */foo1();\n" +
2380
		"//        Line		comment    	    \n" +
2381
		"foo2();\n" +
2382
		"/*        Block		comment    	    */\n" +
2383
		"foo3(); {\n" +
2384
		"/*        indented Block		comment    	    */\n" +
2385
		"System.out.println();}\n";
2386
	formatSource(source,
2387
		"/** Javadoc comment */\n" + 
2388
		"foo1();\n" + 
2389
		"// Line comment\n" + 
2390
		"foo2();\n" + 
2391
		"/* Block comment */\n" + 
2392
		"foo3();\n" + 
2393
		"{\n" + 
2394
		"	/* indented Block comment */\n" + 
2395
		"	System.out.println();\n" + 
2396
		"}",
2397
		CodeFormatter.K_STATEMENTS | CodeFormatter.F_INCLUDE_COMMENTS
2398
	);
2399
}
2400
2401
/**
2268
 * @bug 237051: [formatter] Formatter insert blank lines after javadoc if javadoc contains Commons Attributes @@ annotations
2402
 * @bug 237051: [formatter] Formatter insert blank lines after javadoc if javadoc contains Commons Attributes @@ annotations
2269
 * @test Ensure that Commons Attributes @@ annotations do not screw up the comment formatter
2403
 * @test Ensure that Commons Attributes @@ annotations do not screw up the comment formatter
2270
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=237051"
2404
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=237051"
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java (+4 lines)
Lines 239-244 Link Here
239
	void formatSource(String source, String formattedOutput) {
239
	void formatSource(String source, String formattedOutput) {
240
		formatSource(source, formattedOutput, CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS, 0, true /*repeat formatting twice*/);
240
		formatSource(source, formattedOutput, CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS, 0, true /*repeat formatting twice*/);
241
	}
241
	}
242
243
	void formatSource(String source, String formattedOutput, int kind) {
244
		formatSource(source, formattedOutput, kind, 0, true /*repeat formatting twice*/);
245
	}
242
	
246
	
243
	void formatSource(String source, String formattedOutput, boolean repeat) {
247
	void formatSource(String source, String formattedOutput, boolean repeat) {
244
		formatSource(source, formattedOutput, CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS, 0, repeat);
248
		formatSource(source, formattedOutput, CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS, 0, repeat);
(-)src/org/eclipse/jdt/core/tests/formatter/comment/JavaDocTestCase.java (-53 / +36 lines)
Lines 19-27 Link Here
19
import org.eclipse.jdt.core.formatter.CodeFormatter;
19
import org.eclipse.jdt.core.formatter.CodeFormatter;
20
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
20
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
21
21
22
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter;
23
import org.eclipse.jdt.internal.formatter.comment.JavaDocLine;
24
import org.eclipse.jdt.internal.formatter.comment.MultiCommentLine;
25
import org.eclipse.text.edits.TextEdit;
22
import org.eclipse.text.edits.TextEdit;
26
23
27
public class JavaDocTestCase extends CommentTestCase {
24
public class JavaDocTestCase extends CommentTestCase {
Lines 30-40 Link Here
30
//		TESTS_NAMES = new String[] { "test109636_2" } ;
27
//		TESTS_NAMES = new String[] { "test109636_2" } ;
31
	}
28
	}
32
29
33
	protected static final String INFIX= MultiCommentLine.MULTI_COMMENT_CONTENT_PREFIX;
30
	/** @deprecated */
31
	protected static final String INFIX= org.eclipse.jdt.internal.formatter.comment.MultiCommentLine.MULTI_COMMENT_CONTENT_PREFIX;
34
32
35
	protected static final String POSTFIX= MultiCommentLine.MULTI_COMMENT_END_PREFIX;
33
	/** @deprecated */
34
	protected static final String POSTFIX= org.eclipse.jdt.internal.formatter.comment.MultiCommentLine.MULTI_COMMENT_END_PREFIX;
36
35
37
	protected static final String PREFIX= JavaDocLine.JAVADOC_START_PREFIX;
36
	/** @deprecated */
37
	protected static final String PREFIX= org.eclipse.jdt.internal.formatter.comment.JavaDocLine.JAVADOC_START_PREFIX;
38
38
39
	public static Test suite() {
39
	public static Test suite() {
40
		return buildTestSuite(JavaDocTestCase.class);
40
		return buildTestSuite(JavaDocTestCase.class);
Lines 698-704 Link Here
698
698
699
		String expected = "/**" + DELIMITER +
699
		String expected = "/**" + DELIMITER +
700
				" * <pre>" + DELIMITER +
700
				" * <pre>" + DELIMITER +
701
				(DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT ? " * " +  DELIMITER : "") +
701
				" * " +  DELIMITER +
702
				" * </pre>" + DELIMITER +
702
				" * </pre>" + DELIMITER +
703
				" * " +  DELIMITER +
703
				" * " +  DELIMITER +
704
				" * " + DELIMITER +
704
				" * " + DELIMITER +
Lines 876-898 Link Here
876
				" * </code>" + DELIMITER +
876
				" * </code>" + DELIMITER +
877
				" */";
877
				" */";
878
878
879
		String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
880
			? input // do not change as <code> is an immutable tag
881
			:	"/**" + DELIMITER +
882
				" * <code>" + DELIMITER +
883
				" * <pre>" + DELIMITER +
884
				" * setLeadingComment(&quot;/* traditional comment &#42;/&quot;); // correct" + DELIMITER +
885
				" * setLeadingComment(&quot;missing comment delimiters&quot;); // wrong" + DELIMITER +
886
				" * setLeadingComment(&quot;/* unterminated traditional comment &quot;); // wrong" + DELIMITER +
887
				" * setLeadingComment(&quot;/* broken\\n traditional comment &#42;/&quot;); // correct" + DELIMITER +
888
				" * setLeadingComment(&quot;// end-of-line comment\\n&quot;); // correct" + DELIMITER +
889
				" * setLeadingComment(&quot;// end-of-line comment without line terminator&quot;); // correct" + DELIMITER +
890
				" * setLeadingComment(&quot;// broken\\n end-of-line comment\\n&quot;); // wrong" + DELIMITER +
891
				" * </pre>" + DELIMITER +
892
				" * </code>" + DELIMITER +
893
				" */";
894
		String result=testFormat(input, options);
879
		String result=testFormat(input, options);
895
		assertEquals(expected, result);
880
		assertEquals(input, result);
896
	}
881
	}
897
882
898
	public void test109636_2() {
883
	public void test109636_2() {
Lines 940-976 Link Here
940
	}
925
	}
941
926
942
	public void test109636_4() {
927
	public void test109636_4() {
943
		if (DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT) {
928
		Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
944
			Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
929
930
		String input =
931
				"/**" + DELIMITER +
932
				" * <pre>" + DELIMITER +
933
				" * setLeadingComment(\"/&#42; traditional comment &#42;/\");  // correct" + DELIMITER +
934
				" * setLeadingComment(\"missing comment delimiters\");  // wrong" + DELIMITER +
935
				" * setLeadingComment(\"/&#42; unterminated traditional comment \");  // wrong" + DELIMITER +
936
				" * setLeadingComment(\"/&#42; broken\\n traditional comment &#42;/\");  // correct" + DELIMITER +
937
				" * setLeadingComment(\"// end-of-line comment\\n\");  // correct" + DELIMITER +
938
				" * setLeadingComment(\"// end-of-line comment without line terminator\");  // correct" + DELIMITER +
939
				" * setLeadingComment(\"// broken\\n end-of-line comment\\n\");  // wrong" + DELIMITER +
940
				" * </pre>" + DELIMITER +
941
				" */";
945
942
946
			String input =
943
		String expected =
947
					"/**" + DELIMITER +
944
				"/**" + DELIMITER +
948
					" * <pre>" + DELIMITER +
945
				" * <pre>" + DELIMITER +
949
					" * setLeadingComment(\"/&#42; traditional comment &#42;/\");  // correct" + DELIMITER +
946
				" * setLeadingComment(&quot;/* traditional comment &#42;/&quot;); // correct" + DELIMITER +
950
					" * setLeadingComment(\"missing comment delimiters\");  // wrong" + DELIMITER +
947
				" * setLeadingComment(&quot;missing comment delimiters&quot;); // wrong" + DELIMITER +
951
					" * setLeadingComment(\"/&#42; unterminated traditional comment \");  // wrong" + DELIMITER +
948
				" * setLeadingComment(&quot;/* unterminated traditional comment &quot;); // wrong" + DELIMITER +
952
					" * setLeadingComment(\"/&#42; broken\\n traditional comment &#42;/\");  // correct" + DELIMITER +
949
				" * setLeadingComment(&quot;/* broken\\n traditional comment &#42;/&quot;); // correct" + DELIMITER +
953
					" * setLeadingComment(\"// end-of-line comment\\n\");  // correct" + DELIMITER +
950
				" * setLeadingComment(&quot;// end-of-line comment\\n&quot;); // correct" + DELIMITER +
954
					" * setLeadingComment(\"// end-of-line comment without line terminator\");  // correct" + DELIMITER +
951
				" * setLeadingComment(&quot;// end-of-line comment without line terminator&quot;); // correct" + DELIMITER +
955
					" * setLeadingComment(\"// broken\\n end-of-line comment\\n\");  // wrong" + DELIMITER +
952
				" * setLeadingComment(&quot;// broken\\n end-of-line comment\\n&quot;); // wrong" + DELIMITER +
956
					" * </pre>" + DELIMITER +
953
				" * </pre>" + DELIMITER +
957
					" */";
954
				" */";
958
955
		String result=testFormat(input, options);
959
			String expected =
956
		assertEquals(expected, result);
960
					"/**" + DELIMITER +
961
					" * <pre>" + DELIMITER +
962
					" * setLeadingComment(&quot;/* traditional comment &#42;/&quot;); // correct" + DELIMITER +
963
					" * setLeadingComment(&quot;missing comment delimiters&quot;); // wrong" + DELIMITER +
964
					" * setLeadingComment(&quot;/* unterminated traditional comment &quot;); // wrong" + DELIMITER +
965
					" * setLeadingComment(&quot;/* broken\\n traditional comment &#42;/&quot;); // correct" + DELIMITER +
966
					" * setLeadingComment(&quot;// end-of-line comment\\n&quot;); // correct" + DELIMITER +
967
					" * setLeadingComment(&quot;// end-of-line comment without line terminator&quot;); // correct" + DELIMITER +
968
					" * setLeadingComment(&quot;// broken\\n end-of-line comment\\n&quot;); // wrong" + DELIMITER +
969
					" * </pre>" + DELIMITER +
970
					" */";
971
			String result=testFormat(input, options);
972
			assertEquals(expected, result);
973
		}
974
	}
957
	}
975
958
976
	/**
959
	/**
(-)src/org/eclipse/jdt/core/tests/formatter/comment/MultiLineTestCase.java (-13 / +9 lines)
Lines 17-34 Link Here
17
17
18
import junit.framework.Test;
18
import junit.framework.Test;
19
19
20
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter;
21
import org.eclipse.jdt.internal.formatter.comment.MultiCommentLine;
22
23
public class MultiLineTestCase extends CommentTestCase {
20
public class MultiLineTestCase extends CommentTestCase {
24
	static {
21
	static {
25
//		TESTS_NAMES = new String[] { "test170580" } ;
22
//		TESTS_NAMES = new String[] { "test170580" } ;
26
	}
23
	}
27
	protected static final String INFIX= MultiCommentLine.MULTI_COMMENT_CONTENT_PREFIX;
24
	/** @deprecated */
25
	protected static final String INFIX= org.eclipse.jdt.internal.formatter.comment.MultiCommentLine.MULTI_COMMENT_CONTENT_PREFIX;
28
26
29
	protected static final String POSTFIX= MultiCommentLine.MULTI_COMMENT_END_PREFIX;
27
	/** @deprecated */
28
	protected static final String POSTFIX= org.eclipse.jdt.internal.formatter.comment.MultiCommentLine.MULTI_COMMENT_END_PREFIX;
30
29
31
	protected static final String PREFIX= MultiCommentLine.MULTI_COMMENT_START_PREFIX;
30
	/** @deprecated */
31
	protected static final String PREFIX= org.eclipse.jdt.internal.formatter.comment.MultiCommentLine.MULTI_COMMENT_START_PREFIX;
32
32
33
	public static Test suite() {
33
	public static Test suite() {
34
		return buildTestSuite(MultiLineTestCase.class);
34
		return buildTestSuite(MultiLineTestCase.class);
Lines 116-128 Link Here
116
				" * Member comment\n" +//$NON-NLS-1$
116
				" * Member comment\n" +//$NON-NLS-1$
117
				" */";//$NON-NLS-1$
117
				" */";//$NON-NLS-1$
118
		String result= testFormat(input, 0, input.length(), CodeFormatter.K_MULTI_LINE_COMMENT , 2);
118
		String result= testFormat(input, 0, input.length(), CodeFormatter.K_MULTI_LINE_COMMENT , 2);
119
		String expectedOutput = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
119
		String expectedOutput = "/**\n" +
120
			?	"/**\n" +
120
			" * Member comment\n" +
121
				" * Member comment\n" +
121
			" */";
122
				" */"
123
			:	"/***********************************************************************\n" +
124
				"	 * Member comment\n" +
125
				"	 */";
126
		assertEquals("Different output", expectedOutput, result);
122
		assertEquals("Different output", expectedOutput, result);
127
	}
123
	}
128
124
(-)src/org/eclipse/jdt/core/tests/formatter/comment/SingleLineTestCase.java (-62 / +26 lines)
Lines 16-26 Link Here
16
import org.eclipse.jdt.core.formatter.CodeFormatter;
16
import org.eclipse.jdt.core.formatter.CodeFormatter;
17
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
17
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
18
18
19
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter;
20
import org.eclipse.jdt.internal.formatter.comment.SingleCommentLine;
21
22
public class SingleLineTestCase extends CommentTestCase {
19
public class SingleLineTestCase extends CommentTestCase {
23
	protected static final String PREFIX= SingleCommentLine.SINGLE_COMMENT_PREFIX;
20
	/** @deprecated */
21
	protected static final String PREFIX= org.eclipse.jdt.internal.formatter.comment.SingleCommentLine.SINGLE_COMMENT_PREFIX;
24
22
25
	static {
23
	static {
26
//		TESTS_NAMES = new String[] { "test109581" } ;
24
//		TESTS_NAMES = new String[] { "test109581" } ;
Lines 42-50 Link Here
42
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "5"); //$NON-NLS-1$
40
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "5"); //$NON-NLS-1$
43
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_BLOCK_COMMENT, DefaultCodeFormatterConstants.FALSE);
41
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_BLOCK_COMMENT, DefaultCodeFormatterConstants.FALSE);
44
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT, DefaultCodeFormatterConstants.FALSE);
42
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT, DefaultCodeFormatterConstants.FALSE);
45
		String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
43
		String expected =PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + "//"+ DELIMITER + PREFIX + "test";
46
			? PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + "//"+ DELIMITER + PREFIX + "test"
47
			: PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER;
48
		assertEquals(expected, testFormat("//test\ttest" + DELIMITER + "//" + DELIMITER + "//\t\ttest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
44
		assertEquals(expected, testFormat("//test\ttest" + DELIMITER + "//" + DELIMITER + "//\t\ttest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
49
	}
45
	}
50
46
Lines 52-60 Link Here
52
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "5"); //$NON-NLS-1$
48
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "5"); //$NON-NLS-1$
53
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_BLOCK_COMMENT, DefaultCodeFormatterConstants.FALSE);
49
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_BLOCK_COMMENT, DefaultCodeFormatterConstants.FALSE);
54
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT, DefaultCodeFormatterConstants.FALSE);
50
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT, DefaultCodeFormatterConstants.FALSE);
55
		String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
51
		String expected = PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + DELIMITER + PREFIX + "test";
56
			? PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + DELIMITER + PREFIX + "test"
57
			: PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER;
58
		assertEquals(expected, testFormat("//test\t\ttest" + DELIMITER + PREFIX + DELIMITER + "//\t\ttest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
52
		assertEquals(expected, testFormat("//test\t\ttest" + DELIMITER + PREFIX + DELIMITER + "//\t\ttest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
59
	}
53
	}
60
54
Lines 62-84 Link Here
62
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "5"); //$NON-NLS-1$
56
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "5"); //$NON-NLS-1$
63
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_BLOCK_COMMENT, DefaultCodeFormatterConstants.FALSE);
57
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_BLOCK_COMMENT, DefaultCodeFormatterConstants.FALSE);
64
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT, DefaultCodeFormatterConstants.FALSE);
58
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT, DefaultCodeFormatterConstants.FALSE);
65
		String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
59
		String expected = PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + "//"+ DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test";
66
			? PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + "//"+ DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test"
67
			: PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER;
68
		assertEquals(expected, testFormat("//test\ttest" + DELIMITER + "//" + DELIMITER + PREFIX + "test\ttest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
60
		assertEquals(expected, testFormat("//test\ttest" + DELIMITER + "//" + DELIMITER + PREFIX + "test\ttest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
69
	}
61
	}
70
62
71
	public void testCommentBegin1() {
63
	public void testCommentBegin1() {
72
		String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
64
		String expected = PREFIX + "test";
73
			? PREFIX + "test"
74
			: PREFIX + "test" + DELIMITER;
75
		assertEquals(expected, testFormat("//test")); //$NON-NLS-1$ //$NON-NLS-2$
65
		assertEquals(expected, testFormat("//test")); //$NON-NLS-1$ //$NON-NLS-2$
76
	}
66
	}
77
67
78
	public void testCommentBegin2() {
68
	public void testCommentBegin2() {
79
		String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
69
		String expected = PREFIX + "test";
80
			? PREFIX + "test"
81
			: PREFIX + "test" + DELIMITER;
82
		assertEquals(expected, testFormat(PREFIX + "test")); //$NON-NLS-1$ //$NON-NLS-2$
70
		assertEquals(expected, testFormat(PREFIX + "test")); //$NON-NLS-1$ //$NON-NLS-2$
83
	}
71
	}
84
72
Lines 87-100 Link Here
87
	}
75
	}
88
76
89
	public void testCommentDelimiter1() {
77
	public void testCommentDelimiter1() {
90
		String expected = PREFIX + "test" + DELIMITER;
78
		String expected = PREFIX + "test" + DELIMITER + DELIMITER;
91
		if (DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT) expected += DELIMITER;
92
		assertEquals(expected, testFormat("//\t\ttest " + DELIMITER + DELIMITER)); //$NON-NLS-1$ //$NON-NLS-2$
79
		assertEquals(expected, testFormat("//\t\ttest " + DELIMITER + DELIMITER)); //$NON-NLS-1$ //$NON-NLS-2$
93
	}
80
	}
94
81
95
	public void testCommentDelimiter2() {
82
	public void testCommentDelimiter2() {
96
		String expected = PREFIX + "test" + DELIMITER;
83
		String expected = PREFIX + "test" + DELIMITER + DELIMITER ;
97
		if (DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT) expected += DELIMITER ;
98
		assertEquals(expected, testFormat(PREFIX + "test " + DELIMITER + DELIMITER + DELIMITER)); //$NON-NLS-1$ //$NON-NLS-2$
84
		assertEquals(expected, testFormat(PREFIX + "test " + DELIMITER + DELIMITER + DELIMITER)); //$NON-NLS-1$ //$NON-NLS-2$
99
	}
85
	}
100
86
Lines 123-169 Link Here
123
	}
109
	}
124
110
125
	public void testCommentSpace1() {
111
	public void testCommentSpace1() {
126
		String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
112
		String expected = PREFIX + "test test";
127
			? PREFIX + "test test"
128
			: PREFIX + "test test" + DELIMITER;
129
		assertEquals(expected, testFormat("//test\t \t test")); //$NON-NLS-1$ //$NON-NLS-2$
113
		assertEquals(expected, testFormat("//test\t \t test")); //$NON-NLS-1$ //$NON-NLS-2$
130
	}
114
	}
131
115
132
	public void testCommentSpace2() {
116
	public void testCommentSpace2() {
133
		String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
117
		String expected = PREFIX + "test test";
134
			? PREFIX + "test test"
135
			: PREFIX + "test test" + DELIMITER;
136
		assertEquals(expected, testFormat("//test test")); //$NON-NLS-1$ //$NON-NLS-2$
118
		assertEquals(expected, testFormat("//test test")); //$NON-NLS-1$ //$NON-NLS-2$
137
	}
119
	}
138
120
139
	public void testCommentSpace3() {
121
	public void testCommentSpace3() {
140
		String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
122
		String expected = PREFIX + "test test";
141
			? PREFIX + "test test"
142
			: PREFIX + "test test" + DELIMITER;
143
		assertEquals(expected, testFormat(PREFIX + "test \t    \t test")); //$NON-NLS-1$ //$NON-NLS-2$
123
		assertEquals(expected, testFormat(PREFIX + "test \t    \t test")); //$NON-NLS-1$ //$NON-NLS-2$
144
	}
124
	}
145
125
146
	public void testCommentWrapping1() {
126
	public void testCommentWrapping1() {
147
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "5"); //$NON-NLS-1$
127
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "5"); //$NON-NLS-1$
148
		String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
128
		String expected = PREFIX + "test" + DELIMITER + PREFIX + "test";
149
			? PREFIX + "test" + DELIMITER + PREFIX + "test"
150
			: PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER;
151
		assertEquals(expected, testFormat("//test\ttest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
129
		assertEquals(expected, testFormat("//test\ttest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
152
	}
130
	}
153
131
154
	public void testCommentWrapping2() {
132
	public void testCommentWrapping2() {
155
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "1"); //$NON-NLS-1$
133
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "1"); //$NON-NLS-1$
156
		String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
134
		String expected = PREFIX + "test" + DELIMITER + PREFIX + "test";
157
			? PREFIX + "test" + DELIMITER + PREFIX + "test"
158
			: PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER;
159
		assertEquals(expected, testFormat("//test\ttest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
135
		assertEquals(expected, testFormat("//test\ttest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
160
	}
136
	}
161
137
162
	public void testCommentWrapping3() {
138
	public void testCommentWrapping3() {
163
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "32"); //$NON-NLS-1$
139
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "32"); //$NON-NLS-1$
164
		String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
140
		String expected = PREFIX + "test test";
165
			? PREFIX + "test test"
166
			: PREFIX + "test test" + DELIMITER;
167
		assertEquals(expected, testFormat("//test\ttest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
141
		assertEquals(expected, testFormat("//test\ttest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
168
	}
142
	}
169
143
Lines 186-243 Link Here
186
	public void testHeaderComment1() {
160
	public void testHeaderComment1() {
187
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_HEADER, DefaultCodeFormatterConstants.FALSE);
161
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_HEADER, DefaultCodeFormatterConstants.FALSE);
188
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "12"); //$NON-NLS-1$
162
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "12"); //$NON-NLS-1$
189
		String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
163
		String expected = PREFIX + "test test" + DELIMITER + PREFIX + "test test" + DELIMITER + PREFIX + "test test";
190
			? PREFIX + "test test" + DELIMITER + PREFIX + "test test" + DELIMITER + PREFIX + "test test"
191
			: PREFIX + "test test" + DELIMITER + PREFIX + "test test" + DELIMITER + PREFIX + "test test" + DELIMITER;
192
		assertEquals(expected, testFormat("//test\t\t\t\ttest" + DELIMITER + PREFIX + "test test test test")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
164
		assertEquals(expected, testFormat("//test\t\t\t\ttest" + DELIMITER + PREFIX + "test test test test")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
193
	}
165
	}
194
166
195
	public void testHeaderComment2() {
167
	public void testHeaderComment2() {
196
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_HEADER, DefaultCodeFormatterConstants.FALSE);
168
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_HEADER, DefaultCodeFormatterConstants.FALSE);
197
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "24"); //$NON-NLS-1$
169
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "24"); //$NON-NLS-1$
198
		String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
170
		String expected = "// test" + DELIMITER + PREFIX + "test test test test" + DELIMITER;
199
			? "// test" + DELIMITER + PREFIX + "test test test test" + DELIMITER
200
			: PREFIX + "test test test test" + DELIMITER + PREFIX + "test" + DELIMITER;
201
		assertEquals(expected, testFormat("//test\t\t\t" + DELIMITER + PREFIX + "test test test test" + DELIMITER)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
171
		assertEquals(expected, testFormat("//test\t\t\t" + DELIMITER + PREFIX + "test test test test" + DELIMITER)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
202
	}
172
	}
203
173
204
	public void testIllegalLineLength1() {
174
	public void testIllegalLineLength1() {
205
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "1"); //$NON-NLS-1$
175
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "1"); //$NON-NLS-1$
206
		String expected =PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER;
176
		String expected =PREFIX + "test" + DELIMITER + PREFIX + "test";
207
		if (DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT) expected = expected.substring(0, expected.length()-DELIMITER.length());
208
		assertEquals(expected, testFormat("//test\ttest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
177
		assertEquals(expected, testFormat("//test\ttest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
209
	}
178
	}
210
179
211
	public void testIllegalLineLength2() {
180
	public void testIllegalLineLength2() {
212
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "-16"); //$NON-NLS-1$
181
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "-16"); //$NON-NLS-1$
213
		String expected = PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER;
182
		String expected = PREFIX + "test" + DELIMITER + PREFIX + "test";
214
		if (DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT) expected = expected.substring(0, expected.length()-DELIMITER.length());
215
		assertEquals(expected, testFormat(PREFIX + "\t\t test\ttest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
183
		assertEquals(expected, testFormat(PREFIX + "\t\t test\ttest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
216
	}
184
	}
217
185
218
	public void testMultipleComments1() {
186
	public void testMultipleComments1() {
219
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "5"); //$NON-NLS-1$
187
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "5"); //$NON-NLS-1$
220
		String expected = PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER;
188
		String expected = PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test";
221
		if (DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT) expected = expected.substring(0, expected.length()-DELIMITER.length());
222
		assertEquals(expected, testFormat("//test test" + DELIMITER + PREFIX + "test test test test")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
189
		assertEquals(expected, testFormat("//test test" + DELIMITER + PREFIX + "test test test test")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
223
	}
190
	}
224
191
225
	public void testMultipleComments2() {
192
	public void testMultipleComments2() {
226
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "12"); //$NON-NLS-1$
193
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "12"); //$NON-NLS-1$
227
		String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
194
		String expected = "// test test" + DELIMITER +
228
			? "// test test" + DELIMITER +
195
			"// test" + DELIMITER +
229
				"// test" + DELIMITER +
196
			"// " + DELIMITER +
230
				"// " + DELIMITER +
197
			"// test test" + DELIMITER +
231
				"// test test" + DELIMITER +
198
			"// test test";
232
				"// test test"
233
			: PREFIX + "test test" + DELIMITER + PREFIX + "test test" + DELIMITER + PREFIX + "test test" + DELIMITER + PREFIX + "test" + DELIMITER;
234
		assertEquals(expected, testFormat("//test test\ttest" + DELIMITER + PREFIX + DELIMITER + PREFIX + "test test test test")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
199
		assertEquals(expected, testFormat("//test test\ttest" + DELIMITER + PREFIX + DELIMITER + PREFIX + "test test test test")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
235
	}
200
	}
236
201
237
	public void testMultipleComments3() {
202
	public void testMultipleComments3() {
238
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "11"); //$NON-NLS-1$
203
		setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "11"); //$NON-NLS-1$
239
		String expected = PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER;
204
		String expected = PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test";
240
		if (DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT) expected = expected.substring(0, expected.length()-DELIMITER.length());
241
		assertEquals(expected, testFormat("//   test\t\t\ttest\ttest" + DELIMITER + PREFIX + "test test test test")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$
205
		assertEquals(expected, testFormat("//   test\t\t\ttest\ttest" + DELIMITER + PREFIX + "test test test test")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$
242
	}
206
	}
243
207

Return to bug 236406