Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 287833 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java (-1 / +99 lines)
Lines 26-32 Link Here
26
public static Test suite() {
26
public static Test suite() {
27
	return buildModelTestSuite(FormatterCommentsBugsTest.class);
27
	return buildModelTestSuite(FormatterCommentsBugsTest.class);
28
}
28
}
29
29
static {
30
	//TESTS_NAMES = new String[] { "testBug287833b" } ;
31
	}
30
public FormatterCommentsBugsTest(String name) {
32
public FormatterCommentsBugsTest(String name) {
31
    super(name);
33
    super(name);
32
}
34
}
Lines 4848-4851 Link Here
4848
	);
4850
	);
4849
}
4851
}
4850
4852
4853
/**
4854
 * [formatter] Formatter removes the first character after the * in the <pre> tag 
4855
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=287833
4856
 */
4857
public void testBug287833a() {
4858
	String source = 
4859
		"public class test1 {\n" + 
4860
	    "/**\n"+
4861
	    "* <pre>\n"+
4862
	    "*void foo() {\n"+
4863
	    "*}\n"+
4864
	    "* </pre>\n"+
4865
	    "*/\n"+
4866
	    "void foo() {\n"+
4867
	    "}\n"+
4868
	    "}\n";
4869
	    
4870
	formatSource(source, 
4871
		"public class test1 {\n"+
4872
	    "	/**\n"+
4873
	    "	 * <pre>\n"+
4874
	    "	 * void foo() {\n"+
4875
	    "	 * }\n"+
4876
	    "	 * </pre>\n"+
4877
	    "	 */\n"+
4878
	    "	void foo() {\n"+
4879
	    "	}\n" +
4880
	    "}\n");
4881
}
4882
4883
/**
4884
 * [formatter] Formatter removes the first character after the * in the <pre> tag 
4885
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=287833
4886
 */
4887
public void testBug287833b() {
4888
	String source = 
4889
		"public class test1 {\n" + 
4890
	    "/**\n"+
4891
	    "* <pre>\n"+
4892
	    "* void foo() {\n"+
4893
	    "*\r\n"+
4894
	    "* }\n"+
4895
	    "* </pre>\n"+
4896
	    "*/ \n"+
4897
	    "void foo() {\n"+
4898
	    "}\n"+
4899
	    "}\n";
4900
	    
4901
	formatSource(source, 
4902
		"public class test1 {\n"+
4903
	    "	/**\n"+
4904
	    "	 * <pre>\n"+
4905
	    "	 * void foo() {\n"+
4906
	    "	 * \r\n" +
4907
	    "	 * }\n"+
4908
	    "	 * </pre>\n"+
4909
	    "	 */\n"+
4910
	    "	void foo() {\n"+
4911
	    "	}\n" +
4912
	    "}\n");
4913
}
4914
4915
/**
4916
 * [formatter] Formatter removes the first character after the * in the <pre> tag 
4917
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=287833
4918
 */
4919
public void testBug287833c() {
4920
	String source = 
4921
		"public class test1 {\n" + 
4922
	    "/**\n"+
4923
	    "* <pre>\n"+
4924
	    "* void foo() {\n"+
4925
	    "*\n"+
4926
	    "* }\n"+
4927
	    "* </pre>\n"+
4928
	    "*/ \n"+
4929
	    "void foo() {\n"+
4930
	    "}\n"+
4931
	    "}\n";
4932
	    
4933
	formatSource(source, 
4934
		"public class test1 {\n"+
4935
	    "	/**\n"+
4936
	    "	 * <pre>\n"+
4937
	    "	 * void foo() {\n"+
4938
	    "	 * \n" +
4939
	    "	 * }\n"+
4940
	    "	 * </pre>\n"+
4941
	    "	 */\n"+
4942
	    "	void foo() {\n"+
4943
	    "	}\n" +
4944
	    "}\n");
4945
}
4946
4947
4948
4851
}
4949
}
(-)formatter/org/eclipse/jdt/internal/formatter/Scribe.java (-26 / +57 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
				int offsetEnd = prefixOffset + 1;
1903
				char ch = inputBuffer.charAt(offsetEnd);
1904
				switch (ch) {
1905
					case '\n':
1906
					case '\r':
1907
						break;
1908
					case ' ':
1909
					case '\t':
1910
					case '\u000c' :    /* FORM FEED               */
1911
						offsetEnd++;
1912
						break;
1913
					default:
1914
						if (ScannerHelper.isWhitespace(ch)) {
1915
							offsetEnd++;
1916
						}
1917
						break;
1918
				}
1919
				inputBuffer.delete(lineOffset, offsetEnd);
1920
			}
1903
		}
1921
		}
1904
1922
1905
		// 2 - convert HTML to Java (@see JavaDocRegion#convertHtml2Java)
1923
		// 2 - convert HTML to Java (@see JavaDocRegion#convertHtml2Java)
Lines 3332-3365 Link Here
3332
    			if (codeEnd > end) {
3350
    			if (codeEnd > end) {
3333
    				if (this.formatter.preferences.comment_format_source) {
3351
    				if (this.formatter.preferences.comment_format_source) {
3334
						if (textStart < end) addReplaceEdit(textStart, end, buffer.toString());
3352
						if (textStart < end) addReplaceEdit(textStart, end, buffer.toString());
3335
						// Count the lines until the exact start position of the code
3353
						// See whether there's a space before the code
3336
						this.scanner.resetTo(end+1, nextStart-1);
3354
						boolean needLeadingSpace = false;
3337
						int newLines = 0;
3355
						if (linesGap > 0) {
3338
						try {
3356
							int lineStart = this.scanner.getLineStart(startLine);
3339
							int token = this.scanner.getNextToken();
3357
							if (nextStart > lineStart) { // if code starts at the line, then no leading space is needed
3340
							loop: while (true) {
3358
								this.scanner.resetTo(lineStart, nextStart-1);
3341
								switch (token) {
3359
								try {
3342
									case TerminalTokens.TokenNameWHITESPACE:
3360
									int token = this.scanner.getNextToken();
3343
										if (CharOperation.indexOf('\n', this.scanner.source, this.scanner.startPosition, this.scanner.currentPosition) < 0) {
3361
									if (token == TerminalTokens.TokenNameWHITESPACE) {
3344
											break loop;
3362
										// skip indentation
3345
										}
3363
										token = this.scanner.getNextToken();
3346
										newLines++;
3364
										needLeadingSpace = false; // there may be no star after
3347
										break;
3365
									} else {
3348
									case TerminalTokens.TokenNameMULTIPLY:
3366
										needLeadingSpace = true;
3349
										nextStart = this.scanner.currentPosition + 1;
3367
									}
3350
										break;
3368
									if (token == TerminalTokens.TokenNameMULTIPLY) {
3351
									default:
3369
										nextStart = this.scanner.currentPosition;
3352
										break loop;
3370
										// skip javadoc comment star
3371
										token = this.scanner.getNextToken();
3372
										needLeadingSpace = true;
3373
									}
3374
									if (token == TerminalTokens.TokenNameWHITESPACE) {
3375
										needLeadingSpace = false;
3376
										nextStart++;
3377
									}
3378
								}
3379
								catch (InvalidInputException iie) {
3380
									// skip
3353
								}
3381
								}
3354
								token = this.scanner.getNextToken();
3355
							}
3382
							}
3356
						}
3383
						}
3357
						catch (InvalidInputException iie) {
3384
						// Format gap lines before code
3358
							// skip
3385
						int newLines = linesGap;
3359
						}
3360
						if (newLines == 0) newLines=1;
3386
						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);
3387
						printJavadocGapLines(end+1, nextStart-1, newLines, false/* clear first blank lines inside <pre> tag as done by old formatter */, false, null);
3388
						if (needLeadingSpace) {
3389
							addInsertEdit(nextStart, " "); //$NON-NLS-1$
3390
						}
3391
						// Format the code
3362
						printCodeSnippet(nextStart, codeEnd);
3392
						printCodeSnippet(nextStart, codeEnd);
3393
						// Format the gap lines after the code
3363
						nextStart = (int) text.separators[max];
3394
						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);
3395
	    				printJavadocGapLines(codeEnd+1, nextStart-1, 1, false/* clear blank lines inside <pre> tag as done by old formatter */, false, null);
3365
	    				return 2;
3396
	    				return 2;

Return to bug 287833