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

Collapse All | Expand All

(-)formatter/org/eclipse/jdt/internal/formatter/Scribe.java (-7 / +21 lines)
Lines 1897-1905 Link Here
1897
				CommentFormatterUtil.log(e);
1897
				CommentFormatterUtil.log(e);
1898
				return;
1898
				return;
1899
			}
1899
			}
1900
			int prefixOffset= inputBuffer.indexOf(contentPrefix, lineOffset);
1900
			int prefixOffset = inputBuffer.indexOf(contentPrefix, lineOffset);
1901
			if (prefixOffset >= 0 && inputBuffer.substring(lineOffset, prefixOffset).trim().length() == 0)
1901
			if (prefixOffset >= 0 && inputBuffer.substring(lineOffset, prefixOffset).trim().length() == 0) {
1902
				inputBuffer.delete(lineOffset, prefixOffset + 1 + 1);
1902
				if (inputBuffer.charAt(prefixOffset + 1) == ' ' || inputBuffer.charAt(prefixOffset + 1) == '\t')
1903
					inputBuffer.delete(lineOffset, prefixOffset + 1 + 1);
1904
				else
1905
					inputBuffer.delete(lineOffset, prefixOffset + 1);
1906
			}
1903
		}
1907
		}
1904
1908
1905
		// 2 - convert HTML to Java (@see JavaDocRegion#convertHtml2Java)
1909
		// 2 - convert HTML to Java (@see JavaDocRegion#convertHtml2Java)
Lines 3330-3352 Link Here
3330
			if (isCode) {
3334
			if (isCode) {
3331
    			int codeEnd = (int) (text.separators[max] >>> 32);
3335
    			int codeEnd = (int) (text.separators[max] >>> 32);
3332
    			if (codeEnd > end) {
3336
    			if (codeEnd > end) {
3333
    				if (this.formatter.preferences.comment_format_source) {
3337
    				if (this.formatter.preferences.comment_format_source) {				
3334
						if (textStart < end) addReplaceEdit(textStart, end, buffer.toString());
3338
						if (textStart < end) addReplaceEdit(textStart, end, buffer.toString());						
3335
						// Count the lines until the exact start position of the code
3339
						// Count the lines until the exact start position of the code
3336
						this.scanner.resetTo(end+1, nextStart-1);
3340
						this.scanner.resetTo(end+1, nextStart-1);
3337
						int newLines = 0;
3341
						int newLines = 0;
3342
						int realEnd = nextStart;
3343
						boolean spaceFound = true;
3338
						try {
3344
						try {
3339
							int token = this.scanner.getNextToken();
3345
							int token = this.scanner.getNextToken();
3340
							loop: while (true) {
3346
							loop: while (true) {
3341
								switch (token) {
3347
								switch (token) {
3342
									case TerminalTokens.TokenNameWHITESPACE:
3348
									case TerminalTokens.TokenNameWHITESPACE:
3343
										if (CharOperation.indexOf('\n', this.scanner.source, this.scanner.startPosition, this.scanner.currentPosition) < 0) {
3349
										if (CharOperation.indexOf('\n', this.scanner.source, this.scanner.startPosition, this.scanner.currentPosition) < 0) {
3350
											if (realEnd != nextStart)
3351
												realEnd++;
3352
											spaceFound = true;
3344
											break loop;
3353
											break loop;
3345
										}
3354
										}
3346
										newLines++;
3355
										newLines++;
3347
										break;
3356
										break;
3348
									case TerminalTokens.TokenNameMULTIPLY:
3357
									case TerminalTokens.TokenNameMULTIPLY:
3349
										nextStart = this.scanner.currentPosition + 1;
3358
										realEnd = this.scanner.currentPosition;
3359
										spaceFound = false;
3350
										break;
3360
										break;
3351
									default:
3361
									default:
3352
										break loop;
3362
										break loop;
Lines 3358-3364 Link Here
3358
							// skip
3368
							// skip
3359
						}
3369
						}
3360
						if (newLines == 0) newLines=1;
3370
						if (newLines == 0) newLines=1;
3361
		    			printJavadocGapLines(end+1, nextStart-1, newLines, false/* clear first blank lines inside <pre> tag as done by old formatter */, false, null);
3371
		    			printJavadocGapLines(end+1, realEnd-1, newLines, false/* clear first blank lines inside <pre> tag as done by old formatter */, false, null);
3372
		    			if (realEnd < nextStart)
3373
		    				nextStart = realEnd;
3374
		    			if (spaceFound == false)
3375
			    			addInsertEdit(realEnd, " "); //$NON-NLS-1$
3362
						printCodeSnippet(nextStart, codeEnd);
3376
						printCodeSnippet(nextStart, codeEnd);
3363
						nextStart = (int) text.separators[max];
3377
						nextStart = (int) text.separators[max];
3364
	    				printJavadocGapLines(codeEnd+1, nextStart-1, 1, false/* clear blank lines inside <pre> tag as done by old formatter */, false, null);
3378
	    				printJavadocGapLines(codeEnd+1, nextStart-1, 1, false/* clear blank lines inside <pre> tag as done by old formatter */, false, null);
(-)src/org/eclipse/jdt/core/tests/formatter/comment/JavaDocTestCase.java (-1 / +31 lines)
Lines 27-33 Link Here
27
public class JavaDocTestCase extends CommentTestCase {
27
public class JavaDocTestCase extends CommentTestCase {
28
28
29
	static {
29
	static {
30
//		TESTS_NAMES = new String[] { "test109636_2" } ;
30
	//	TESTS_NAMES = new String[] { "testNoRemoveFirstCharacter" } ;
31
	}
31
	}
32
32
33
	protected static final String INFIX= MultiCommentLine.MULTI_COMMENT_CONTENT_PREFIX;
33
	protected static final String INFIX= MultiCommentLine.MULTI_COMMENT_CONTENT_PREFIX;
Lines 1012-1015 Link Here
1012
		String result = testFormat(input, 62, 19, CodeFormatter.K_JAVA_DOC, options);
1012
		String result = testFormat(input, 62, 19, CodeFormatter.K_JAVA_DOC, options);
1013
		assertEquals(expected, result);
1013
		assertEquals(expected, result);
1014
	}
1014
	}
1015
	
1016
	/**
1017
	 * [formatter] Formatter removes the first character after the * in the <pre> tag 
1018
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=287833
1019
	 */
1020
	public void testNoRemoveFirstCharacter() {
1021
		String input= PREFIX + DELIMITER + 
1022
				INFIX + "<pre>" + DELIMITER + 
1023
				" *void foo() {"  + DELIMITER +
1024
				" *}" + DELIMITER +
1025
				" * </pre>" + DELIMITER +
1026
				POSTFIX;
1027
1028
		String expected = PREFIX + DELIMITER + 
1029
				INFIX + "<pre>" + DELIMITER + 
1030
				" * void foo() {"  + DELIMITER +
1031
				" * }" + DELIMITER + 
1032
				" * </pre>" + DELIMITER +
1033
				POSTFIX;
1034
		String result= testFormat(input);
1035
		assertEquals(expected, result);
1036
1037
		// now re-format several times
1038
		result= testFormat(result);
1039
		result= testFormat(result);
1040
		result= testFormat(result);
1041
		result= testFormat(result);
1042
1043
		assertEquals(expected, result);
1044
	}
1015
}
1045
}

Return to bug 287833