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

Collapse All | Expand All

(-)formatter/org/eclipse/jdt/internal/formatter/FormatJavadocBlock.java (-15 / +71 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.formatter;
11
package org.eclipse.jdt.internal.formatter;
12
12
13
import org.eclipse.jdt.internal.compiler.parser.Scanner;
13
import org.eclipse.jdt.internal.formatter.comment.IJavaDocTagConstants;
14
import org.eclipse.jdt.internal.formatter.comment.IJavaDocTagConstants;
14
15
15
/**
16
/**
Lines 279-284 Link Here
279
}
280
}
280
281
281
/**
282
/**
283
 * Returns whether the block is immutable or not.
284
 * <p>
285
 * Currently, only {@code} and {@literal} inline tags block are considered as
286
 * immutable.
287
 * </p>
288
 * @return <code>true</code> if the block is immutable,
289
 * 	<code>false</code> otherwise.
290
 */
291
public boolean isImmutable() {
292
	return (this.flags & IMMUTABLE) == IMMUTABLE;
293
}
294
295
/**
282
 * Returns whether the block is a description or inlined in a description.
296
 * Returns whether the block is a description or inlined in a description.
283
 * @see #isParamTag()
297
 * @see #isParamTag()
284
 *
298
 *
Lines 311-319 Link Here
311
}
325
}
312
326
313
/**
327
/**
314
 * Returns whether the text is on the same line of the tag.
328
 * Returns whether the the tag is on one line only.
315
 *
329
 *
316
 * @return <code>true</code> if the text is on the same line than the tag,
330
 * @return <code>true</code> if the tag is on one line only,
317
 * 	<code>false</code> otherwise.
331
 * 	<code>false</code> otherwise.
318
 */
332
 */
319
public boolean isOneLineTag() {
333
public boolean isOneLineTag() {
Lines 331-349 Link Here
331
	return (this.flags & PARAM_TAG) == PARAM_TAG;
345
	return (this.flags & PARAM_TAG) == PARAM_TAG;
332
}
346
}
333
347
334
/**
335
 * Returns whether the block is immutable or not.
336
 * <p>
337
 * Currently, only {@code} and {@literal} inline tags block are considered as
338
 * immutable.
339
 * </p>
340
 * @return <code>true</code> if the block is immutable,
341
 * 	<code>false</code> otherwise.
342
 */
343
public boolean isImmutable() {
344
	return (this.flags & IMMUTABLE) == IMMUTABLE;
345
}
346
347
void setHeaderLine(int javadocLineStart) {
348
void setHeaderLine(int javadocLineStart) {
348
	if (javadocLineStart == this.lineStart) {
349
	if (javadocLineStart == this.lineStart) {
349
		this.flags |= ON_HEADER_LINE;
350
		this.flags |= ON_HEADER_LINE;
Lines 366-371 Link Here
366
		this.reference.toString(buffer);
367
		this.reference.toString(buffer);
367
		buffer.append(")\n"); //$NON-NLS-1$
368
		buffer.append(")\n"); //$NON-NLS-1$
368
	}
369
	}
370
	StringBuffer flagsBuffer = new StringBuffer();
371
	if (isDescription()) {
372
		if (flagsBuffer.length() > 0) flagsBuffer.append(',');
373
		flagsBuffer.append("description"); //$NON-NLS-1$
374
	}
375
	if (isFirst()) {
376
		if (flagsBuffer.length() > 0) flagsBuffer.append(',');
377
		flagsBuffer.append("first"); //$NON-NLS-1$
378
	}
379
	if (isHeaderLine()) {
380
		if (flagsBuffer.length() > 0) flagsBuffer.append(',');
381
		flagsBuffer.append("header line"); //$NON-NLS-1$
382
	}
383
	if (isImmutable()) {
384
		if (flagsBuffer.length() > 0) flagsBuffer.append(',');
385
		flagsBuffer.append("immutable"); //$NON-NLS-1$
386
	}
387
	if (isInDescription()) {
388
		if (flagsBuffer.length() > 0) flagsBuffer.append(',');
389
		flagsBuffer.append("in description"); //$NON-NLS-1$
390
	}
391
	if (isInlined()) {
392
		if (flagsBuffer.length() > 0) flagsBuffer.append(',');
393
		flagsBuffer.append("inlined"); //$NON-NLS-1$
394
	}
395
	if (isInParamTag()) {
396
		if (flagsBuffer.length() > 0) flagsBuffer.append(',');
397
		flagsBuffer.append("in param tag"); //$NON-NLS-1$
398
	}
399
	if (isOneLineTag()) {
400
		if (flagsBuffer.length() > 0) flagsBuffer.append(',');
401
		flagsBuffer.append("one line tag"); //$NON-NLS-1$
402
	}
403
	if (isParamTag()) {
404
		if (flagsBuffer.length() > 0) flagsBuffer.append(',');
405
		flagsBuffer.append("param tag"); //$NON-NLS-1$
406
	}
407
	if (flagsBuffer.length() > 0) {
408
		if (inlined) buffer.append('\t');
409
		buffer.append("	flags: "); //$NON-NLS-1$
410
		buffer.append(flagsBuffer);
411
		buffer.append('\n');
412
	}
369
	if (this.nodesPtr > -1) {
413
	if (this.nodesPtr > -1) {
370
		for (int i = 0; i <= this.nodesPtr; i++) {
414
		for (int i = 0; i <= this.nodesPtr; i++) {
371
			if (inlined) buffer.append('\t');
415
			if (inlined) buffer.append('\t');
Lines 392-395 Link Here
392
		this.nodes[i].toStringDebug(buffer, source);
436
		this.nodes[i].toStringDebug(buffer, source);
393
	}
437
	}
394
}
438
}
439
440
void update(Scanner scanner) {
441
	int blockEnd = scanner.getLineNumber(this.sourceEnd);
442
	if (blockEnd == this.lineStart) {
443
		this.flags |= FormatJavadocBlock.ONE_LINE_TAG;
444
	}
445
	for (int i=0; i<=this.nodesPtr; i++) {
446
		if (!this.nodes[i].isText()) {
447
			((FormatJavadocBlock)this.nodes[i]).update(scanner);
448
		}
449
	}
450
}
395
}
451
}
(-)formatter/org/eclipse/jdt/internal/formatter/FormatJavadocText.java (-2 / +4 lines)
Lines 50-56 Link Here
50
 * child node.
50
 * child node.
51
 */
51
 */
52
void appendText(FormatJavadocText text) {
52
void appendText(FormatJavadocText text) {
53
	this.immutable = text.immutable;
53
	text.immutable = this.immutable;
54
	if (this.depth == text.depth) {
54
	if (this.depth == text.depth) {
55
		addSeparator(text);
55
		addSeparator(text);
56
		this.sourceEnd = text.sourceEnd;
56
		this.sourceEnd = text.sourceEnd;
Lines 169-175 Link Here
169
 *
169
 *
170
 * @return <code>true</code> if the node is an immutable tag,
170
 * @return <code>true</code> if the node is an immutable tag,
171
 *		<code>false</code> otherwise.
171
 *		<code>false</code> otherwise.
172
 *@deprecated Use {@link #isImmutable()} instead
173
 */
172
 */
174
public boolean isImmutableHtmlTag() {
173
public boolean isImmutableHtmlTag() {
175
	return this.htmlTagIndex != -1 && (this.htmlTagIndex & JAVADOC_TAGS_ID_MASK) == JAVADOC_IMMUTABLE_TAGS_ID;
174
	return this.htmlTagIndex != -1 && (this.htmlTagIndex & JAVADOC_TAGS_ID_MASK) == JAVADOC_IMMUTABLE_TAGS_ID;
Lines 230-235 Link Here
230
	StringBuffer indentation = new StringBuffer();
229
	StringBuffer indentation = new StringBuffer();
231
	for (int t=0; t<=this.depth; t++) indentation.append('\t');
230
	for (int t=0; t<=this.depth; t++) indentation.append('\t');
232
	buffer.append(indentation);
231
	buffer.append(indentation);
232
	if (isImmutable()) {
233
		buffer.append("immutable "); //$NON-NLS-1$
234
	}
233
	buffer.append("text"); //$NON-NLS-1$
235
	buffer.append("text"); //$NON-NLS-1$
234
	super.toString(buffer);
236
	super.toString(buffer);
235
	buffer.append(" ("); //$NON-NLS-1$
237
	buffer.append(" ("); //$NON-NLS-1$
(-)formatter/org/eclipse/jdt/internal/formatter/FormatterCommentParser.java (-4 / +1 lines)
Lines 796-805 Link Here
796
		for (int i=0; i<length; i++) {
796
		for (int i=0; i<length; i++) {
797
			FormatJavadocBlock block = (FormatJavadocBlock) this.astStack[i];
797
			FormatJavadocBlock block = (FormatJavadocBlock) this.astStack[i];
798
			block.clean();
798
			block.clean();
799
			int blockEnd = this.scanner.getLineNumber(block.sourceEnd);
799
			block.update(this.scanner);
800
			if (block.lineStart == blockEnd) {
801
				block.flags |= FormatJavadocBlock.ONE_LINE_TAG;
802
			}
803
			formatJavadoc.blocks[i] = block;
800
			formatJavadoc.blocks[i] = block;
804
			if (i== 0) {
801
			if (i== 0) {
805
				block.flags |= FormatJavadocBlock.FIRST;
802
				block.flags |= FormatJavadocBlock.FIRST;
(-)formatter/org/eclipse/jdt/internal/formatter/Scribe.java (-23 / +188 lines)
Lines 842-851 Link Here
842
		return indentation;
842
		return indentation;
843
	}
843
	}
844
844
845
	int getCurrentIndentation(char[] whitespaces) {
845
	int getCurrentIndentation(char[] whitespaces, int offset) {
846
		int length = whitespaces.length;
846
		int length = whitespaces.length;
847
		if (this.tabLength == 0) return length;
847
		if (this.tabLength == 0) return length;
848
		int indentation = 0;
848
		int indentation = offset;
849
		for (int i=0; i<length; i++) {
849
		for (int i=0; i<length; i++) {
850
			char ch = whitespaces[i];
850
			char ch = whitespaces[i];
851
			switch (ch) {
851
			switch (ch) {
Lines 2178-2184 Link Here
2178
							// when following comment column (after having been rounded) is below the preceding one,
2178
							// when following comment column (after having been rounded) is below the preceding one,
2179
							// then it becomes not a good idea to change the trailing flag
2179
							// then it becomes not a good idea to change the trailing flag
2180
							if (trailing == BASIC_TRAILING_COMMENT && hasLineComment) {
2180
							if (trailing == BASIC_TRAILING_COMMENT && hasLineComment) {
2181
								int currentCommentIndentation = getCurrentIndentation(whiteSpaces);
2181
								int currentCommentIndentation = getCurrentIndentation(whiteSpaces, 0);
2182
								int lastCommentIndentation = this.lastLineComment.currentIndentation;
2182
								int lastCommentIndentation = this.lastLineComment.currentIndentation;
2183
								if (this.tabLength > 0) {
2183
								if (this.tabLength > 0) {
2184
									if ((currentCommentIndentation % this.tabLength) == 0) {
2184
									if ((currentCommentIndentation % this.tabLength) == 0) {
Lines 2410-2416 Link Here
2410
    			// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=293300
2410
    			// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=293300
2411
				if (this.lastLineComment.contiguous) {
2411
				if (this.lastLineComment.contiguous) {
2412
					// The leading spaces have been set while looping in the printComment(int) method
2412
					// The leading spaces have been set while looping in the printComment(int) method
2413
					int currentCommentIndentation = getCurrentIndentation(this.lastLineComment.leadingSpaces);
2413
					int currentCommentIndentation = getCurrentIndentation(this.lastLineComment.leadingSpaces, 0);
2414
					// Keep the current comment indentation when over the previous contiguous line comment
2414
					// Keep the current comment indentation when over the previous contiguous line comment
2415
					// and the previous comment has not been reindented
2415
					// and the previous comment has not been reindented
2416
					int lastCommentIndentation = this.lastLineComment.currentIndentation;
2416
					int lastCommentIndentation = this.lastLineComment.currentIndentation;
Lines 2869-2875 Link Here
2869
					if (newLines == 0 && (!node.isImmutable() || block.reference != null)) {
2869
					if (newLines == 0 && (!node.isImmutable() || block.reference != null)) {
2870
						newLines = printJavadocBlockNodesNewLines(block, node, previousEnd);
2870
						newLines = printJavadocBlockNodesNewLines(block, node, previousEnd);
2871
					}
2871
					}
2872
					printJavadocGapLines(previousEnd+1, nodeStart-1, newLines, clearBlankLines, false, null);
2872
					if (block.isImmutable()) {
2873
						printJavadocGapLinesForImmutableBlock(block);
2874
					} else {
2875
						printJavadocGapLines(previousEnd+1, nodeStart-1, newLines, clearBlankLines, false, null);
2876
					}
2873
				} else {
2877
				} else {
2874
					StringBuffer buffer = new StringBuffer();
2878
					StringBuffer buffer = new StringBuffer();
2875
					if (newLines > 0) {
2879
					if (newLines > 0) {
Lines 2900-2906 Link Here
2900
				FormatJavadocText text = (FormatJavadocText) node;
2904
				FormatJavadocText text = (FormatJavadocText) node;
2901
				if (text.isImmutable()) {
2905
				if (text.isImmutable()) {
2902
					// Indent if new line was added
2906
					// Indent if new line was added
2903
					if (newLines > 0 && this.commentIndentation != null) {
2907
					if (text.isImmutableHtmlTag() && newLines > 0 && this.commentIndentation != null) {
2904
				    	addInsertEdit(node.sourceStart, this.commentIndentation);
2908
				    	addInsertEdit(node.sourceStart, this.commentIndentation);
2905
				    	this.column += this.commentIndentation.length();
2909
				    	this.column += this.commentIndentation.length();
2906
					}
2910
					}
Lines 2964-2993 Link Here
2964
		    				int token = this.scanner.getNextToken();
2968
		    				int token = this.scanner.getNextToken();
2965
		    				switch (token) {
2969
		    				switch (token) {
2966
		    					case TerminalTokens.TokenNameWHITESPACE:
2970
		    					case TerminalTokens.TokenNameWHITESPACE:
2967
		    						if (nodeIsText) {
2971
		    						if (CharOperation.indexOf('\n', this.scanner.source, this.scanner.startPosition, this.scanner.currentPosition) >= 0) {
2968
			    						if (CharOperation.indexOf('\n', this.scanner.source, this.scanner.startPosition, this.scanner.currentPosition) >= 0) {
2972
		    							return 0;
2969
			    							return 0;
2970
			    						}
2971
		    						}
2973
		    						}
2972
		    						length = 1;
2974
									lastColumn = getCurrentIndentation(this.scanner.getCurrentTokenSource(), lastColumn);
2973
		    						break;
2975
		    						break;
2974
		    					case TerminalTokens.TokenNameMULTIPLY:
2976
		    					case TerminalTokens.TokenNameMULTIPLY:
2975
		    						if (newLine) {
2977
		    						if (newLine) {
2976
		    							newLine = false;
2978
		    							newLine = false;
2977
		    							continue;
2979
		    							continue;
2978
		    						}
2980
		    						}
2979
		    						length = 1;
2981
		    						lastColumn++;
2980
		    						break;
2982
		    						break;
2981
		    					default:
2983
		    					default:
2982
					    			length = (this.scanner.atEnd() ? this.scanner.eofPosition : this.scanner.currentPosition) - this.scanner.startPosition;
2984
					    			lastColumn += (this.scanner.atEnd() ? this.scanner.eofPosition : this.scanner.currentPosition) - this.scanner.startPosition;
2983
		    						break;
2985
		    						break;
2984
		    				}
2986
		    				}
2985
	    				}
2987
	    				}
2986
	    				catch (InvalidInputException iie) {
2988
	    				catch (InvalidInputException iie) {
2987
	    					// maybe an unterminated string or comment
2989
	    					// maybe an unterminated string or comment
2988
			    			length = (this.scanner.atEnd() ? this.scanner.eofPosition : this.scanner.currentPosition) - this.scanner.startPosition;
2990
			    			lastColumn += (this.scanner.atEnd() ? this.scanner.eofPosition : this.scanner.currentPosition) - this.scanner.startPosition;
2989
	    				}
2991
	    				}
2990
	    				lastColumn += length;
2991
	    				if (lastColumn > maxColumn) {
2992
	    				if (lastColumn > maxColumn) {
2992
	    					return 1;
2993
	    					return 1;
2993
						}
2994
						}
Lines 3347-3353 Link Here
3347
						if (linesGap > 0) {
3348
						if (linesGap > 0) {
3348
							StringBuffer buffer = new StringBuffer();
3349
							StringBuffer buffer = new StringBuffer();
3349
							if (lineCount > 0) {
3350
							if (lineCount > 0) {
3350
								// TODO (eric) https://bugs.eclipse.org/bugs/show_bug.cgi?id=49619
3351
								// TODO https://bugs.eclipse.org/bugs/show_bug.cgi?id=49619
3351
								buffer.append( ' ');
3352
								buffer.append( ' ');
3352
							}
3353
							}
3353
							for (int i = 0; i < linesGap ; i++) {
3354
							for (int i = 0; i < linesGap ; i++) {
Lines 3409-3415 Link Here
3409
				// Insert new lines as not enough was encountered while scanning the whitespaces
3410
				// Insert new lines as not enough was encountered while scanning the whitespaces
3410
				StringBuffer buffer = new StringBuffer();
3411
				StringBuffer buffer = new StringBuffer();
3411
				if (lineCount > 0) {
3412
				if (lineCount > 0) {
3412
					// TODO (eric) https://bugs.eclipse.org/bugs/show_bug.cgi?id=49619
3413
					// TODO https://bugs.eclipse.org/bugs/show_bug.cgi?id=49619
3413
					buffer.append( ' ');
3414
					buffer.append( ' ');
3414
				}
3415
				}
3415
				for (int i = lineCount; i < newLines-1; i++) {
3416
				for (int i = lineCount; i < newLines-1; i++) {
Lines 3440-3446 Link Here
3440
					StringBuffer buffer = new StringBuffer();
3441
					StringBuffer buffer = new StringBuffer();
3441
					if (this.scanner.linePtr > linePtr) {
3442
					if (this.scanner.linePtr > linePtr) {
3442
						if (lineCount > 0) {
3443
						if (lineCount > 0) {
3443
							// TODO (eric) https://bugs.eclipse.org/bugs/show_bug.cgi?id=49619
3444
							// TODO https://bugs.eclipse.org/bugs/show_bug.cgi?id=49619
3444
							buffer.append( ' ');
3445
							buffer.append( ' ');
3445
						}
3446
						}
3446
						buffer.append(this.lineSeparator);
3447
						buffer.append(this.lineSeparator);
Lines 3481-3494 Link Here
3481
3482
3482
		try {
3483
		try {
3483
			// Iterate on text line separators
3484
			// Iterate on text line separators
3484
			int lineNumber = text.lineStart;
3485
			int textLineStart = text.lineStart;
3485
			this.scanner.tokenizeWhiteSpace = false;
3486
			this.scanner.tokenizeWhiteSpace = false;
3486
			StringBuffer buffer = null;
3487
			StringBuffer buffer = null;
3487
			for (int idx=0, max=text.separatorsPtr; idx<=max ; idx++) {
3488
			for (int idx=0, max=text.separatorsPtr; idx<=max ; idx++) {
3488
				int start = (int) text.separators[idx];
3489
				int start = (int) text.separators[idx];
3489
				int lineStart = Util.getLineNumber(start, this.lineEnds, lineNumber-1, this.maxLines);
3490
				int lineStart = Util.getLineNumber(start, this.lineEnds, textLineStart-1, this.maxLines);
3490
				while (lineNumber < lineStart) {
3491
				while (textLineStart < lineStart) {
3491
					int end = this.lineEnds[lineNumber-1];
3492
					int end = this.lineEnds[textLineStart-1];
3492
					this.scanner.resetTo(end, start);
3493
					this.scanner.resetTo(end, start);
3493
					int token = this.scanner.getNextToken();
3494
					int token = this.scanner.getNextToken();
3494
					switch (token) {
3495
					switch (token) {
Lines 3509-3515 Link Here
3509
						this.column += BLOCK_LINE_PREFIX_LENGTH;
3510
						this.column += BLOCK_LINE_PREFIX_LENGTH;
3510
					}
3511
					}
3511
					addReplaceEdit(end+1, this.scanner.getCurrentTokenEndPosition(), buffer.toString());
3512
					addReplaceEdit(end+1, this.scanner.getCurrentTokenEndPosition(), buffer.toString());
3512
					lineNumber++;
3513
					textLineStart++;
3513
				}
3514
				}
3514
			}
3515
			}
3515
		}
3516
		}
Lines 3524-3529 Link Here
3524
		}
3525
		}
3525
	}
3526
	}
3526
3527
3528
	/*
3529
	 *  Print the gap lines for an immutable block.
3530
	 *  That's needed to  be specific as the formatter needs to keep white spaces
3531
	 *  if possible except those which are indentation ones.
3532
	 *  Note that in the peculiar case of a two lines immutable tag (multi lines block),
3533
	 *  the formatter will join the two lines.
3534
	 */
3535
	private void printJavadocGapLinesForImmutableBlock(FormatJavadocBlock block) {
3536
3537
		// Init
3538
		int firstLineEnd = -1; // not initialized
3539
		int newLineStart = -1; // not initialized
3540
		int secondLineStart = -1; // not initialized
3541
		int starPosition = -1; // not initialized
3542
		int offset = 0;
3543
		int start = block.tagEnd + 1;
3544
		int end = block.nodes[0].sourceStart-1;
3545
		this.scanner.resetTo(start, end);
3546
		int lineStart = block.lineStart;
3547
		int lineEnd = Util.getLineNumber(block.nodes[0].sourceEnd, this.lineEnds, lineStart-1, this.maxLines);
3548
		boolean multiLinesBlock = lineEnd > (lineStart+1);
3549
		int previousPosition = this.scanner.currentPosition;
3550
		StringBuffer buffer = null;
3551
		int indentationColumn = 0;
3552
		int leadingSpaces = -1;
3553
3554
		// Scan the existing gap
3555
		while (!this.scanner.atEnd()) {
3556
			char ch = (char) this.scanner.getNextChar();
3557
			switch (ch) {
3558
				case '\t' :
3559
					// increase the corresponding counter from the appropriate tab value
3560
					if (secondLineStart > 0 || firstLineEnd < 0) {
3561
						int reminder = this.tabLength == 0 ? 0 : offset % this.tabLength;
3562
						if (reminder == 0) {
3563
							offset += this.tabLength;
3564
						} else {
3565
							offset = ((offset / this.tabLength) + 1) * this.tabLength;
3566
						}
3567
					} else if (leadingSpaces >= 0) {
3568
						int reminder = this.tabLength == 0 ? 0 : offset % this.tabLength;
3569
						if (reminder == 0) {
3570
							leadingSpaces += this.tabLength;
3571
						} else {
3572
							leadingSpaces = ((offset / this.tabLength) + 1) * this.tabLength;
3573
						}
3574
					}
3575
					break;
3576
				case '\r' :
3577
				case '\n' :
3578
					// new line, store the end of the first one
3579
					if (firstLineEnd < 0) {
3580
						firstLineEnd = previousPosition;
3581
					}
3582
					// print indentation if there were spaces without any star on the line
3583
					if (leadingSpaces > 0 && multiLinesBlock) {
3584
						if (buffer == null) {
3585
							buffer = new StringBuffer();
3586
							this.column = 1;
3587
							printIndentationIfNecessary(buffer);
3588
							buffer.append(BLOCK_LINE_PREFIX);
3589
							this.column += BLOCK_LINE_PREFIX_LENGTH;
3590
							indentationColumn = this.column;
3591
						} else {
3592
							this.column = indentationColumn;
3593
						}
3594
						addReplaceEdit(newLineStart, newLineStart+indentationColumn-2, buffer.toString());
3595
					}
3596
					// store line start and reset positions
3597
					newLineStart = this.scanner.currentPosition;
3598
					leadingSpaces = 0;
3599
					starPosition = -1;
3600
					if (multiLinesBlock) {
3601
						offset = 0;
3602
						secondLineStart = -1;
3603
					}
3604
					break;
3605
				case '*' :
3606
					// store line start position if this is the first star of the line
3607
					if (starPosition < 0 && firstLineEnd > 0) {
3608
						secondLineStart = this.scanner.currentPosition;
3609
						starPosition = this.scanner.currentPosition;
3610
						leadingSpaces = -1;
3611
					}
3612
					break;
3613
				default :
3614
					// increment offset if line has started
3615
					if (secondLineStart > 0) {
3616
						// skip first white space after the first '*'
3617
						if (secondLineStart == starPosition) {
3618
							secondLineStart = this.scanner.currentPosition;
3619
						} else {
3620
							// print indentation before the following characters
3621
							if (offset == 0 && multiLinesBlock) {
3622
								if (buffer == null) {
3623
									buffer = new StringBuffer();
3624
									this.column = 1;
3625
									printIndentationIfNecessary(buffer);
3626
									buffer.append(BLOCK_LINE_PREFIX);
3627
									this.column += BLOCK_LINE_PREFIX_LENGTH;
3628
									indentationColumn = this.column;
3629
								} else {
3630
									this.column = indentationColumn;
3631
								}
3632
								addReplaceEdit(newLineStart, secondLineStart-1, buffer.toString());
3633
							}
3634
							offset++;
3635
						}
3636
					} else if (firstLineEnd < 0) {
3637
						// no new line yet, increment the offset
3638
						offset++;
3639
					} else if (leadingSpaces >= 0) {
3640
						// no star yet, increment the leading spaces
3641
						leadingSpaces++;
3642
					}
3643
					break;
3644
			}
3645
			previousPosition = this.scanner.currentPosition;
3646
		}
3647
		
3648
		// Increment the columns from the numbers of characters counted on the line
3649
		if (multiLinesBlock) {
3650
			this.column += offset;
3651
		} else {
3652
			this.column++;
3653
		}
3654
		
3655
		// Replace the new line with a single space when there's only one separator
3656
		// or, if necessary, print the indentation on the last line
3657
		if (!multiLinesBlock) {
3658
			addReplaceEdit(firstLineEnd, end, " "); //$NON-NLS-1$
3659
		}
3660
		else if (secondLineStart > 0) {
3661
			if (buffer == null) {
3662
				buffer = new StringBuffer();
3663
				this.column = 1;
3664
				printIndentationIfNecessary(buffer);
3665
				buffer.append(BLOCK_LINE_PREFIX);
3666
				this.column += BLOCK_LINE_PREFIX_LENGTH;
3667
				indentationColumn = this.column;
3668
			} else {
3669
				this.column = indentationColumn;
3670
			}
3671
			addReplaceEdit(newLineStart, secondLineStart-1, buffer.toString());
3672
		}
3673
		else if (leadingSpaces > 0) {
3674
			if (buffer == null) {
3675
				buffer = new StringBuffer();
3676
				this.column = 1;
3677
				printIndentationIfNecessary(buffer);
3678
				buffer.append(BLOCK_LINE_PREFIX);
3679
				this.column += BLOCK_LINE_PREFIX_LENGTH;
3680
				indentationColumn = this.column;
3681
			} else {
3682
				this.column = indentationColumn;
3683
			}
3684
			addReplaceEdit(newLineStart, newLineStart+indentationColumn-2, buffer.toString());
3685
		}
3686
3687
		// Reset
3688
		this.needSpace = false;
3689
		this.scanner.resetTo(end+1, this.scannerEndPosition - 1);
3690
	}
3691
3527
	private int printJavadocHtmlTag(FormatJavadocText text, FormatJavadocBlock block, boolean textOnNewLine) {
3692
	private int printJavadocHtmlTag(FormatJavadocText text, FormatJavadocBlock block, boolean textOnNewLine) {
3528
3693
3529
		// Compute indentation if necessary
3694
		// Compute indentation if necessary
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java (-26 / +167 lines)
Lines 4407-4429 Link Here
4407
		" * Comments that can be formated in several lines...\n" + 
4407
		" * Comments that can be formated in several lines...\n" + 
4408
		" * \n" + 
4408
		" * \n" + 
4409
		" * @author Myself\n" + 
4409
		" * @author Myself\n" + 
4410
		" * @version {@code $Revision: 1.51 $ $Date: 2010/02/12 18:33:47 $ $Author: oliviert $ $Source: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java,v $}\n" + 
4410
		" * @version {@code            The  			  text		here     should     not			be   		    			     formatted....   	   }\n" + 
4411
		" */\n" + 
4411
		" */\n" + 
4412
		"public class X01 {\n" + 
4412
		"public class X01 {\n" + 
4413
		"}\n";
4413
		"}\n";
4414
	formatSource(source);
4414
	formatSource(source);
4415
}
4415
}
4416
public void testBug260381a() throws JavaModelException {
4417
	String source = 
4418
		"/**\n" + 
4419
		" * Comments that can be formated in several lines...\n" + 
4420
		" * \n" + 
4421
		" * @author Myself\n" + 
4422
		" * @version {@code          " +
4423
		" *            The  			  text		here     should     not			be   		    			     formatted....   	   }\n" + 
4424
		" */\n" + 
4425
		"public class X01a {\n" + 
4426
		"}\n";
4427
	formatSource(source);
4428
}
4416
public void testBug260381b() throws JavaModelException {
4429
public void testBug260381b() throws JavaModelException {
4417
	String source = 
4430
	String source = 
4418
		"/**\n" + 
4431
		"/**\n" + 
4419
		" * Comments that can be formated in several lines...\n" + 
4432
		" * Comments that can be formated in several lines...\n" + 
4420
		" * \n" + 
4433
		" * \n" + 
4421
		" * @author Myself\n" + 
4434
		" * @author Myself\n" + 
4422
		" * @version <code>$Revision: 1.51 $ $Date: 2010/02/12 18:33:47 $ $Author: oliviert $ $Source: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java,v $</code>\n" + 
4435
		" *  @version {@code\n" + 
4436
		" * The  			  text		here     should     not			be   		    			     formatted....   	   }\n" + 
4423
		" */\n" + 
4437
		" */\n" + 
4424
		"public class X01b {\n" + 
4438
		"public class X01b {\n" + 
4425
		"}\n";
4439
		"}\n";
4426
	formatSource(source);
4440
	formatSource(source,
4441
		"/**\n" + 
4442
		" * Comments that can be formated in several lines...\n" + 
4443
		" * \n" + 
4444
		" * @author Myself\n" + 
4445
		" * @version {@code The  			  text		here     should     not			be   		    			     formatted....   	   }\n" + 
4446
		" */\n" + 
4447
		"public class X01b {\n" + 
4448
		"}\n"
4449
	);
4427
}
4450
}
4428
public void testBug260381c() throws JavaModelException {
4451
public void testBug260381c() throws JavaModelException {
4429
	String source = 
4452
	String source = 
Lines 4431-4438 Link Here
4431
		" * Comments that can be formated in several lines...\n" + 
4454
		" * Comments that can be formated in several lines...\n" + 
4432
		" * \n" + 
4455
		" * \n" + 
4433
		" * @author Myself\n" + 
4456
		" * @author Myself\n" + 
4434
		" * @version\n" + 
4457
		" *  @version {@code     \n" + 
4435
		" *          <code>3.0 xxxxxxxxxxxxxx xwxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</code>\n" + 
4458
		" *          \n" + 
4459
		"            \n" + 
4460
		" *          The  			  text		here     should     not			be   		    			     formatted....   	   }\n" + 
4436
		" */\n" + 
4461
		" */\n" + 
4437
		"public class X01c {\n" + 
4462
		"public class X01c {\n" + 
4438
		"}\n";
4463
		"}\n";
Lines 4441-4447 Link Here
4441
		" * Comments that can be formated in several lines...\n" + 
4466
		" * Comments that can be formated in several lines...\n" + 
4442
		" * \n" + 
4467
		" * \n" + 
4443
		" * @author Myself\n" + 
4468
		" * @author Myself\n" + 
4444
		" * @version <code>3.0 xxxxxxxxxxxxxx xwxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</code>\n" + 
4469
		" * @version {@code     \n" + 
4470
		" *          \n" + 
4471
		" *          \n" + 
4472
		" *          The  			  text		here     should     not			be   		    			     formatted....   	   }\n" + 
4445
		" */\n" + 
4473
		" */\n" + 
4446
		"public class X01c {\n" + 
4474
		"public class X01c {\n" + 
4447
		"}\n"
4475
		"}\n"
Lines 4453-4493 Link Here
4453
		" * Comments that can be formated in several lines...\n" + 
4481
		" * Comments that can be formated in several lines...\n" + 
4454
		" * \n" + 
4482
		" * \n" + 
4455
		" * @author Myself\n" + 
4483
		" * @author Myself\n" + 
4456
		" *  @see Object <code>$Revision: 1.51 $ $Date: 2010/02/12 18:33:47 $ $Author: oliviert $ $Source: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java,v $</code>\n" + 
4484
		" * @version <code>            The  			  text		here     should     not			be   		    			formatted....   	   </code>\n" + 
4457
		" */\n" + 
4485
		" */\n" + 
4458
		"public class X02 {\n" + 
4486
		"public class X02 {\n" + 
4459
		"}\n";
4487
		"}\n";
4488
	formatSource(source);
4489
}
4490
public void testBug260381e() throws JavaModelException {
4491
	String source = 
4492
		"/**\n" + 
4493
		" * Comments that can be formated in several lines...\n" + 
4494
		" * \n" + 
4495
		" * @author Myself\n" + 
4496
		" * @version\n" + 
4497
		" *          <code>            The  			  text		here     should     not			be   		    			formatted....   	   </code>\n" + 
4498
		" */\n" + 
4499
		"public class X02b {\n" + 
4500
		"}\n";
4501
	formatSource(source,
4502
		"/**\n" + 
4503
		" * Comments that can be formated in several lines...\n" + 
4504
		" * \n" + 
4505
		" * @author Myself\n" + 
4506
		" * @version <code>            The  			  text		here     should     not			be   		    			formatted....   	   </code>\n" + 
4507
		" */\n" + 
4508
		"public class X02b {\n" + 
4509
		"}\n"
4510
	);
4511
}
4512
public void testBug260381f() throws JavaModelException {
4513
	String source = 
4514
		"/**\n" + 
4515
		" * Comments that can be formated in several lines...\n" + 
4516
		" * \n" + 
4517
		" * @author Myself\n" + 
4518
		" *  @see Object <code>            The  			  text		here     should     not			be   		    			formatted....   	   </code>\n" + 
4519
		" */\n" + 
4520
		"public class X02c {\n" + 
4521
		"}\n";
4460
	formatSource(source,
4522
	formatSource(source,
4461
		"/**\n" + 
4523
		"/**\n" + 
4462
		" * Comments that can be formated in several lines...\n" + 
4524
		" * Comments that can be formated in several lines...\n" + 
4463
		" * \n" + 
4525
		" * \n" + 
4464
		" * @author Myself\n" + 
4526
		" * @author Myself\n" + 
4465
		" * @see Object\n" + 
4527
		" * @see Object\n" + 
4466
		" *      <code>$Revision: 1.51 $ $Date: 2010/02/12 18:33:47 $ $Author: oliviert $ $Source: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java,v $</code>\n" + 
4528
		" *      <code>            The  			  text		here     should     not			be   		    			formatted....   	   </code>\n" + 
4467
		" */\n" + 
4529
		" */\n" + 
4468
		"public class X02 {\n" + 
4530
		"public class X02c {\n" + 
4469
		"}\n"
4531
		"}\n"
4470
	);
4532
	);
4471
}
4533
}
4472
// TODO (frederic) Disabled as it fails with HEAD...
4534
public void testBug260381g() throws JavaModelException {
4473
public void _testBug260381e() throws JavaModelException {
4474
	String source = 
4535
	String source = 
4475
		"/**\n" + 
4536
		"/**\n" + 
4476
		" * Comments that can be formated in several lines...\n" + 
4537
		" * Comments that can be formated in several lines...\n" + 
4477
		" * \n" + 
4538
		" * \n" + 
4478
		" * {@code $Revision: 1.51 $ $Date: 2010/02/12 18:33:47 $ $Author: oliviert $\n" + 
4539
		" * {@code            The  			  text		here     should     not			be   		    			formatted....   	   }\n" + 
4479
		" * $Source: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java,v $}\n" + 
4480
		" */\n" + 
4540
		" */\n" + 
4481
		"public class X03 {\n" + 
4541
		"public class X03 {\n" + 
4482
		"}\n";
4542
		"}\n";
4483
	formatSource(source);
4543
	formatSource(source);
4484
}
4544
}
4485
public void testBug260381f() throws JavaModelException {
4545
public void testBug260381h() throws JavaModelException {
4546
	String source = 
4547
		"/**\n" + 
4548
		" * Comments that can be formated in several lines...\n" + 
4549
		" * \n" + 
4550
		" * <code>            The  			  text		here     should     \n" + 
4551
		" * not			be   		    			formatted....   	   </code>\n" + 
4552
		" */\n" + 
4553
		"public class X03b {\n" + 
4554
		"}\n";
4555
	formatSource(source);
4556
}
4557
public void testBug260381i() throws JavaModelException {
4558
	String source = 
4559
		"/**\n" + 
4560
		" * Comments that can be formated in several lines...\n" + 
4561
		" * \n" + 
4562
		" * {@code            The  			  text		here     should\n" + 
4563
		" * not			be   		    			formatted....   	   }\n" + 
4564
		" */\n" + 
4565
		"public class X03c {\n" + 
4566
		"}\n";
4567
	formatSource(source,
4568
		"/**\n" + 
4569
		" * Comments that can be formated in several lines...\n" + 
4570
		" * \n" + 
4571
		" * {@code            The  			  text		here     should\n" + 
4572
		" * not			be   		    			formatted....   	   }\n" + 
4573
		" */\n" + 
4574
		"public class X03c {\n" + 
4575
		"}\n"
4576
	);
4577
}
4578
public void testBug260381j() throws JavaModelException {
4579
	String source = 
4580
		"/**\n" + 
4581
		" * Comments that can be formated in several lines...\n" + 
4582
		" * \n" + 
4583
		" * {@code      \n" + 
4584
		" *       The  			  text		here     should\n" + 
4585
		" *       not			\n" + 
4586
		" *       be   		    			formatted....   	   }\n" + 
4587
		" */\n" + 
4588
		"public class X03d {\n" + 
4589
		"}\n";
4590
	formatSource(source,
4591
		"/**\n" + 
4592
		" * Comments that can be formated in several lines...\n" + 
4593
		" * \n" + 
4594
		" * {@code      \n" + 
4595
		" *       The  			  text		here     should\n" + 
4596
		" *       not			\n" + 
4597
		" *       be   		    			formatted....   	   }\n" + 
4598
		" */\n" + 
4599
		"public class X03d {\n" + 
4600
		"}\n"
4601
	);
4602
}
4603
public void testBug260381k() throws JavaModelException {
4486
	String source = 
4604
	String source = 
4487
		"/**\n" + 
4605
		"/**\n" + 
4488
		" * Literal inline tag should also be untouched by the formatter\n" + 
4606
		" * Literal inline tag should also be untouched by the formatter\n" + 
4489
		" * \n" + 
4607
		" * \n" + 
4490
		" * @version {@literal $Revision: 1.51 $ $Date: 2010/02/12 18:33:47 $ $Author: oliviert $ $Source: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java,v $}\n" + 
4608
		" * @version {@literal            The  			  text		here     should     not			be   		    			     formatted....   	   }\n" + 
4491
		" */\n" + 
4609
		" */\n" + 
4492
		"public class X04 {\n" + 
4610
		"public class X04 {\n" + 
4493
		"\n" + 
4611
		"\n" + 
Lines 4730-4736 Link Here
4730
		"public interface I03 {\n" + 
4848
		"public interface I03 {\n" + 
4731
		"	/**\n" + 
4849
		"	/**\n" + 
4732
		"	 * A builder for creating immutable bimap instances, especially\n" + 
4850
		"	 * A builder for creating immutable bimap instances, especially\n" + 
4733
		"	 * {@code public static final} bimaps (\"constant bimaps\"). Example:\n" + 
4851
		"	 * {@code public\n" + 
4852
		"	 * static final} bimaps (\"constant bimaps\"). Example:\n" + 
4734
		"	 * \n" + 
4853
		"	 * \n" + 
4735
		"	 * <pre>\n" + 
4854
		"	 * <pre>\n" + 
4736
		"	 * {\n" + 
4855
		"	 * {\n" + 
Lines 4752-4757 Link Here
4752
		"}\n"
4871
		"}\n"
4753
	);
4872
	);
4754
}
4873
}
4874
public void testBug260381_wksp2_03b() throws JavaModelException {
4875
	String source = 
4876
		"package wksp2;\n" + 
4877
		"\n" + 
4878
		"public interface I03b {\n" + 
4879
		"	/**\n" + 
4880
		"	 * A builder for creating immutable bimap instances, xxxxxxxx {@code public\n" + 
4881
		"	 * static final} bimaps (\"constant bimaps\").\n" + 
4882
		"	 */\n" + 
4883
		"	void foo();\n" + 
4884
		"}\n";
4885
	formatSource(source,
4886
		"package wksp2;\n" + 
4887
		"\n" + 
4888
		"public interface I03b {\n" + 
4889
		"	/**\n" + 
4890
		"	 * A builder for creating immutable bimap instances, xxxxxxxx {@code public\n" + 
4891
		"	 * static final} bimaps (\"constant bimaps\").\n" + 
4892
		"	 */\n" + 
4893
		"	void foo();\n" + 
4894
		"}\n"
4895
	);
4896
}
4755
public void testBug260381_wksp2_04() throws JavaModelException {
4897
public void testBug260381_wksp2_04() throws JavaModelException {
4756
	String source = 
4898
	String source = 
4757
		"package wksp2;\n" + 
4899
		"package wksp2;\n" + 
Lines 4769-4776 Link Here
4769
		"   * ImmutableMultiset.copyOf(c)} returns an {@code ImmutableMultiset<String>}\n" + 
4911
		"   * ImmutableMultiset.copyOf(c)} returns an {@code ImmutableMultiset<String>}\n" + 
4770
		"   * containing each of the strings in {@code c}, while\n" + 
4912
		"   * containing each of the strings in {@code c}, while\n" + 
4771
		"   * {@code ImmutableMultiset.of(c)} returns an\n" + 
4913
		"   * {@code ImmutableMultiset.of(c)} returns an\n" + 
4772
		"   * {@code ImmutableMultiset<Collection<String>>} containing one element (the\n" + 
4914
		"   * {@code ImmutableMultiset<Collection<String>>} containing one element\n" + 
4773
		"   * given collection itself).\n" + 
4915
		"   * (the given collection itself).\n" + 
4774
		"   *\n" + 
4916
		"   *\n" + 
4775
		"   * <p><b>Note:</b> Despite what the method name suggests, if {@code elements}\n" + 
4917
		"   * <p><b>Note:</b> Despite what the method name suggests, if {@code elements}\n" + 
4776
		"   * is an {@code ImmutableMultiset}, no copy will actually be performed, and\n" + 
4918
		"   * is an {@code ImmutableMultiset}, no copy will actually be performed, and\n" + 
Lines 4934-4941 Link Here
4934
		"	 * {@code occurrences == 1}, this method has the identical effect to\n" + 
5076
		"	 * {@code occurrences == 1}, this method has the identical effect to\n" + 
4935
		"	 * {@link #add(Object)}. This method is functionally equivalent (except in\n" + 
5077
		"	 * {@link #add(Object)}. This method is functionally equivalent (except in\n" + 
4936
		"	 * the case of overflow) to the call\n" + 
5078
		"	 * the case of overflow) to the call\n" + 
4937
		"	 * {@code addAll(Collections.nCopies(element, occurrences))}, which would\n" + 
5079
		"	 * {@code addAll(Collections.nCopies(element,\n" + 
4938
		"	 * presumably perform much more poorly.\n" + 
5080
		"	 * occurrences))}, which would presumably perform much more poorly.\n" + 
4939
		"	 * \n" + 
5081
		"	 * \n" + 
4940
		"	 * @param element\n" + 
5082
		"	 * @param element\n" + 
4941
		"	 *            the element to add occurrences of; may be {@code null} only if\n" + 
5083
		"	 *            the element to add occurrences of; may be {@code null} only if\n" + 
Lines 4987-4998 Link Here
4987
		"	/**\n" + 
5129
		"	/**\n" + 
4988
		"	 * Constructs a new, empty multiset, sorted according to the specified\n" + 
5130
		"	 * Constructs a new, empty multiset, sorted according to the specified\n" + 
4989
		"	 * comparator. All elements inserted into the multiset must be <i>mutually\n" + 
5131
		"	 * comparator. All elements inserted into the multiset must be <i>mutually\n" + 
4990
		"	 * comparable</i> by the specified comparator:\n" + 
5132
		"	 * comparable</i> by the specified comparator: {@code comparator.compare(e1,\n" + 
4991
		"	 * {@code comparator.compare(e1, e2)} must not throw a\n" + 
5133
		"	 * e2)} must not throw a {@code ClassCastException} for any elements\n" + 
4992
		"	 * {@code ClassCastException} for any elements {@code e1} and {@code e2} in\n" + 
5134
		"	 * {@code e1} and {@code e2} in the multiset. If the user attempts to add an\n" + 
4993
		"	 * the multiset. If the user attempts to add an element to the multiset that\n" + 
5135
		"	 * element to the multiset that violates this constraint, the\n" + 
4994
		"	 * violates this constraint, the {@code add(Object)} call will throw a\n" + 
5136
		"	 * {@code add(Object)} call will throw a {@code ClassCastException}.\n" + 
4995
		"	 * {@code ClassCastException}.\n" + 
4996
		"	 * \n" + 
5137
		"	 * \n" + 
4997
		"	 * @param comparator\n" + 
5138
		"	 * @param comparator\n" + 
4998
		"	 *            the comparator that will be used to sort this multiset. A null\n" + 
5139
		"	 *            the comparator that will be used to sort this multiset. A null\n" + 

Return to bug 260381