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

(-)formatter/org/eclipse/jdt/internal/formatter/Scribe.java (-5 / +33 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 3335-3352 Link Here
3335
						// Count the lines until the exact start position of the code
3353
						// Count the lines until the exact start position of the code
3336
						this.scanner.resetTo(end+1, nextStart-1);
3354
						this.scanner.resetTo(end+1, nextStart-1);
3337
						int newLines = 0;
3355
						int newLines = 0;
3356
						int realEnd = nextStart;
3357
						boolean spaceFound = true;
3338
						try {
3358
						try {
3339
							int token = this.scanner.getNextToken();
3359
							int token = this.scanner.getNextToken();
3340
							loop: while (true) {
3360
							loop: while (true) {
3341
								switch (token) {
3361
								switch (token) {
3342
									case TerminalTokens.TokenNameWHITESPACE:
3362
									case TerminalTokens.TokenNameWHITESPACE:
3343
										if (CharOperation.indexOf('\n', this.scanner.source, this.scanner.startPosition, this.scanner.currentPosition) < 0) {
3363
										if (CharOperation.indexOf('\n', this.scanner.source, this.scanner.startPosition, this.scanner.currentPosition) < 0) {
3364
											if (realEnd != nextStart)
3365
												realEnd++;
3366
											spaceFound = true;
3344
											break loop;
3367
											break loop;
3345
										}
3368
										}
3346
										newLines++;
3369
										newLines++;
3347
										break;
3370
										break;
3348
									case TerminalTokens.TokenNameMULTIPLY:
3371
									case TerminalTokens.TokenNameMULTIPLY:
3349
										nextStart = this.scanner.currentPosition + 1;
3372
										realEnd = this.scanner.currentPosition;
3373
										spaceFound = false;
3350
										break;
3374
										break;
3351
									default:
3375
									default:
3352
										break loop;
3376
										break loop;
Lines 3358-3364 Link Here
3358
							// skip
3382
							// skip
3359
						}
3383
						}
3360
						if (newLines == 0) newLines=1;
3384
						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);
3385
						printJavadocGapLines(end+1, realEnd-1, newLines, false/* clear first blank lines inside <pre> tag as done by old formatter */, false, null);
3386
						if (realEnd < nextStart)
3387
							nextStart = realEnd;
3388
						if (spaceFound == false)
3389
							addInsertEdit(realEnd, " "); //$NON-NLS-1$
3362
						printCodeSnippet(nextStart, codeEnd);
3390
						printCodeSnippet(nextStart, codeEnd);
3363
						nextStart = (int) text.separators[max];
3391
						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);
3392
	    				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/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
}

Return to bug 287833