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 (-26 / +57 lines)
Lines 1848-1856 Link Here
1848
				CommentFormatterUtil.log(e);
1848
				CommentFormatterUtil.log(e);
1849
				return;
1849
				return;
1850
			}
1850
			}
1851
			int prefixOffset= inputBuffer.indexOf(contentPrefix, lineOffset);
1851
			int prefixOffset = inputBuffer.indexOf(contentPrefix, lineOffset);
1852
			if (prefixOffset >= 0 && inputBuffer.substring(lineOffset, prefixOffset).trim().length() == 0)
1852
			if (prefixOffset >= 0 && inputBuffer.substring(lineOffset, prefixOffset).trim().length() == 0) {
1853
				inputBuffer.delete(lineOffset, prefixOffset + 1 + 1);
1853
				int offsetEnd = prefixOffset + 1;
1854
				char ch = inputBuffer.charAt(offsetEnd);
1855
				switch (ch) {
1856
					case '\n':
1857
					case '\r':
1858
						break;
1859
					case ' ':
1860
					case '\t':
1861
					case '\u000c' :    /* FORM FEED               */
1862
						offsetEnd++;
1863
						break;
1864
					default:
1865
						if (ScannerHelper.isWhitespace(ch)) {
1866
							offsetEnd++;
1867
						}
1868
						break;
1869
				}
1870
				inputBuffer.delete(lineOffset, offsetEnd);
1871
			}
1854
		}
1872
		}
1855
1873
1856
		// 2 - convert HTML to Java (@see JavaDocRegion#convertHtml2Java)
1874
		// 2 - convert HTML to Java (@see JavaDocRegion#convertHtml2Java)
Lines 3267-3300 Link Here
3267
    			if (codeEnd > end) {
3285
    			if (codeEnd > end) {
3268
    				if (this.formatter.preferences.comment_format_source) {
3286
    				if (this.formatter.preferences.comment_format_source) {
3269
						if (textStart < end) addReplaceEdit(textStart, end, buffer.toString());
3287
						if (textStart < end) addReplaceEdit(textStart, end, buffer.toString());
3270
						// Count the lines until the exact start position of the code
3288
						// See whether there's a space before the code
3271
						this.scanner.resetTo(end+1, nextStart-1);
3289
						boolean needLeadingSpace = false;
3272
						int newLines = 0;
3290
						if (linesGap > 0) {
3273
						try {
3291
							int lineStart = this.scanner.getLineStart(startLine);
3274
							int token = this.scanner.getNextToken();
3292
							if (nextStart > lineStart) { // if code starts at the line, then no leading space is needed
3275
							loop: while (true) {
3293
								this.scanner.resetTo(lineStart, nextStart-1);
3276
								switch (token) {
3294
								try {
3277
									case TerminalTokens.TokenNameWHITESPACE:
3295
									int token = this.scanner.getNextToken();
3278
										if (CharOperation.indexOf('\n', this.scanner.source, this.scanner.startPosition, this.scanner.currentPosition) < 0) {
3296
									if (token == TerminalTokens.TokenNameWHITESPACE) {
3279
											break loop;
3297
										// skip indentation
3280
										}
3298
										token = this.scanner.getNextToken();
3281
										newLines++;
3299
										needLeadingSpace = false; // there may be no star after
3282
										break;
3300
									} else {
3283
									case TerminalTokens.TokenNameMULTIPLY:
3301
										needLeadingSpace = true;
3284
										nextStart = this.scanner.currentPosition + 1;
3302
									}
3285
										break;
3303
									if (token == TerminalTokens.TokenNameMULTIPLY) {
3286
									default:
3304
										nextStart = this.scanner.currentPosition;
3287
										break loop;
3305
										// skip javadoc comment star
3306
										token = this.scanner.getNextToken();
3307
										needLeadingSpace = true;
3308
									}
3309
									if (token == TerminalTokens.TokenNameWHITESPACE) {
3310
										needLeadingSpace = false;
3311
										nextStart++;
3312
									}
3313
								}
3314
								catch (InvalidInputException iie) {
3315
									// skip
3288
								}
3316
								}
3289
								token = this.scanner.getNextToken();
3290
							}
3317
							}
3291
						}
3318
						}
3292
						catch (InvalidInputException iie) {
3319
						// Format gap lines before code
3293
							// skip
3320
						int newLines = linesGap;
3294
						}
3295
						if (newLines == 0) newLines=1;
3321
						if (newLines == 0) newLines=1;
3296
		    			printJavadocGapLines(end+1, nextStart-1, newLines, false/* clear first blank lines inside <pre> tag as done by old formatter */, false, null);
3322
						printJavadocGapLines(end+1, nextStart-1, newLines, false/* clear first blank lines inside <pre> tag as done by old formatter */, false, null);
3323
						if (needLeadingSpace) {
3324
							addInsertEdit(nextStart, " "); //$NON-NLS-1$
3325
						}
3326
						// Format the code
3297
						printCodeSnippet(nextStart, codeEnd);
3327
						printCodeSnippet(nextStart, codeEnd);
3328
						// Format the gap lines after the code
3298
						nextStart = (int) text.separators[max];
3329
						nextStart = (int) text.separators[max];
3299
	    				printJavadocGapLines(codeEnd+1, nextStart-1, 1, false/* clear blank lines inside <pre> tag as done by old formatter */, false, null);
3330
	    				printJavadocGapLines(codeEnd+1, nextStart-1, 1, false/* clear blank lines inside <pre> tag as done by old formatter */, false, null);
3300
	    				return 2;
3331
	    				return 2;
(-)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 4808-4811 Link Here
4808
	);
4810
	);
4809
}
4811
}
4810
4812
4813
/**
4814
 * [formatter] Formatter removes the first character after the * in the <pre> tag 
4815
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=287833
4816
 */
4817
public void testBug287833a() {
4818
	String source = 
4819
		"public class test1 {\n" + 
4820
	    "/**\n"+
4821
	    "* <pre>\n"+
4822
	    "*void foo() {\n"+
4823
	    "*}\n"+
4824
	    "* </pre>\n"+
4825
	    "*/\n"+
4826
	    "void foo() {\n"+
4827
	    "}\n"+
4828
	    "}\n";
4829
	    
4830
	formatSource(source, 
4831
		"public class test1 {\n"+
4832
	    "	/**\n"+
4833
	    "	 * <pre>\n"+
4834
	    "	 * void foo() {\n"+
4835
	    "	 * }\n"+
4836
	    "	 * </pre>\n"+
4837
	    "	 */\n"+
4838
	    "	void foo() {\n"+
4839
	    "	}\n" +
4840
	    "}\n");
4841
}
4842
4843
/**
4844
 * [formatter] Formatter removes the first character after the * in the <pre> tag 
4845
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=287833
4846
 */
4847
public void testBug287833b() {
4848
	String source = 
4849
		"public class test1 {\n" + 
4850
	    "/**\n"+
4851
	    "* <pre>\n"+
4852
	    "* void foo() {\n"+
4853
	    "*\r\n"+
4854
	    "* }\n"+
4855
	    "* </pre>\n"+
4856
	    "*/ \n"+
4857
	    "void foo() {\n"+
4858
	    "}\n"+
4859
	    "}\n";
4860
	    
4861
	formatSource(source, 
4862
		"public class test1 {\n"+
4863
	    "	/**\n"+
4864
	    "	 * <pre>\n"+
4865
	    "	 * void foo() {\n"+
4866
	    "	 * \r\n" +
4867
	    "	 * }\n"+
4868
	    "	 * </pre>\n"+
4869
	    "	 */\n"+
4870
	    "	void foo() {\n"+
4871
	    "	}\n" +
4872
	    "}\n");
4873
}
4874
4875
/**
4876
 * [formatter] Formatter removes the first character after the * in the <pre> tag 
4877
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=287833
4878
 */
4879
public void testBug287833c() {
4880
	String source = 
4881
		"public class test1 {\n" + 
4882
	    "/**\n"+
4883
	    "* <pre>\n"+
4884
	    "* void foo() {\n"+
4885
	    "*\n"+
4886
	    "* }\n"+
4887
	    "* </pre>\n"+
4888
	    "*/ \n"+
4889
	    "void foo() {\n"+
4890
	    "}\n"+
4891
	    "}\n";
4892
	    
4893
	formatSource(source, 
4894
		"public class test1 {\n"+
4895
	    "	/**\n"+
4896
	    "	 * <pre>\n"+
4897
	    "	 * void foo() {\n"+
4898
	    "	 * \n" +
4899
	    "	 * }\n"+
4900
	    "	 * </pre>\n"+
4901
	    "	 */\n"+
4902
	    "	void foo() {\n"+
4903
	    "	}\n" +
4904
	    "}\n");
4905
}
4906
4907
4908
4811
}
4909
}

Return to bug 287833