### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: formatter/org/eclipse/jdt/internal/formatter/Scribe.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/Scribe.java,v retrieving revision 1.162.2.5 diff -u -r1.162.2.5 Scribe.java --- formatter/org/eclipse/jdt/internal/formatter/Scribe.java 20 Jul 2009 15:47:05 -0000 1.162.2.5 +++ formatter/org/eclipse/jdt/internal/formatter/Scribe.java 23 Sep 2009 09:54:28 -0000 @@ -1848,9 +1848,27 @@ CommentFormatterUtil.log(e); return; } - int prefixOffset= inputBuffer.indexOf(contentPrefix, lineOffset); - if (prefixOffset >= 0 && inputBuffer.substring(lineOffset, prefixOffset).trim().length() == 0) - inputBuffer.delete(lineOffset, prefixOffset + 1 + 1); + int prefixOffset = inputBuffer.indexOf(contentPrefix, lineOffset); + if (prefixOffset >= 0 && inputBuffer.substring(lineOffset, prefixOffset).trim().length() == 0) { + int offsetEnd = prefixOffset + 1; + char ch = inputBuffer.charAt(offsetEnd); + switch (ch) { + case '\n': + case '\r': + break; + case ' ': + case '\t': + case '\u000c' : /* FORM FEED */ + offsetEnd++; + break; + default: + if (ScannerHelper.isWhitespace(ch)) { + offsetEnd++; + } + break; + } + inputBuffer.delete(lineOffset, offsetEnd); + } } // 2 - convert HTML to Java (@see JavaDocRegion#convertHtml2Java) @@ -3267,34 +3285,47 @@ if (codeEnd > end) { if (this.formatter.preferences.comment_format_source) { if (textStart < end) addReplaceEdit(textStart, end, buffer.toString()); - // Count the lines until the exact start position of the code - this.scanner.resetTo(end+1, nextStart-1); - int newLines = 0; - try { - int token = this.scanner.getNextToken(); - loop: while (true) { - switch (token) { - case TerminalTokens.TokenNameWHITESPACE: - if (CharOperation.indexOf('\n', this.scanner.source, this.scanner.startPosition, this.scanner.currentPosition) < 0) { - break loop; - } - newLines++; - break; - case TerminalTokens.TokenNameMULTIPLY: - nextStart = this.scanner.currentPosition + 1; - break; - default: - break loop; + // See whether there's a space before the code + boolean needLeadingSpace = false; + if (linesGap > 0) { + int lineStart = this.scanner.getLineStart(startLine); + if (nextStart > lineStart) { // if code starts at the line, then no leading space is needed + this.scanner.resetTo(lineStart, nextStart-1); + try { + int token = this.scanner.getNextToken(); + if (token == TerminalTokens.TokenNameWHITESPACE) { + // skip indentation + token = this.scanner.getNextToken(); + needLeadingSpace = false; // there may be no star after + } else { + needLeadingSpace = true; + } + if (token == TerminalTokens.TokenNameMULTIPLY) { + nextStart = this.scanner.currentPosition; + // skip javadoc comment star + token = this.scanner.getNextToken(); + needLeadingSpace = true; + } + if (token == TerminalTokens.TokenNameWHITESPACE) { + needLeadingSpace = false; + nextStart++; + } + } + catch (InvalidInputException iie) { + // skip } - token = this.scanner.getNextToken(); } } - catch (InvalidInputException iie) { - // skip - } + // Format gap lines before code + int newLines = linesGap; if (newLines == 0) newLines=1; - printJavadocGapLines(end+1, nextStart-1, newLines, false/* clear first blank lines inside
tag as done by old formatter */, false, null); + printJavadocGapLines(end+1, nextStart-1, newLines, false/* clear first blank lines insidetag as done by old formatter */, false, null); + if (needLeadingSpace) { + addInsertEdit(nextStart, " "); //$NON-NLS-1$ + } + // Format the code printCodeSnippet(nextStart, codeEnd); + // Format the gap lines after the code nextStart = (int) text.separators[max]; printJavadocGapLines(codeEnd+1, nextStart-1, 1, false/* clear blank lines insidetag as done by old formatter */, false, null); return 2; #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java,v retrieving revision 1.38.2.7 diff -u -r1.38.2.7 FormatterCommentsBugsTest.java --- src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java 26 Jun 2009 15:02:22 -0000 1.38.2.7 +++ src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java 23 Sep 2009 09:54:30 -0000 @@ -26,7 +26,9 @@ public static Test suite() { return buildModelTestSuite(FormatterCommentsBugsTest.class); } - +static { + //TESTS_NAMES = new String[] { "testBug287833b" } ; + } public FormatterCommentsBugsTest(String name) { super(name); } @@ -4808,4 +4810,100 @@ ); } +/** + * [formatter] Formatter removes the first character after the * in thetag + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=287833 + */ +public void testBug287833a() { + String source = + "public class test1 {\n" + + "/**\n"+ + "*\n"+ + "*void foo() {\n"+ + "*}\n"+ + "*\n"+ + "*/\n"+ + "void foo() {\n"+ + "}\n"+ + "}\n"; + + formatSource(source, + "public class test1 {\n"+ + " /**\n"+ + " *\n"+ + " * void foo() {\n"+ + " * }\n"+ + " *\n"+ + " */\n"+ + " void foo() {\n"+ + " }\n" + + "}\n"); +} + +/** + * [formatter] Formatter removes the first character after the * in thetag + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=287833 + */ +public void testBug287833b() { + String source = + "public class test1 {\n" + + "/**\n"+ + "*\n"+ + "* void foo() {\n"+ + "*\r\n"+ + "* }\n"+ + "*\n"+ + "*/ \n"+ + "void foo() {\n"+ + "}\n"+ + "}\n"; + + formatSource(source, + "public class test1 {\n"+ + " /**\n"+ + " *\n"+ + " * void foo() {\n"+ + " * \r\n" + + " * }\n"+ + " *\n"+ + " */\n"+ + " void foo() {\n"+ + " }\n" + + "}\n"); +} + +/** + * [formatter] Formatter removes the first character after the * in thetag + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=287833 + */ +public void testBug287833c() { + String source = + "public class test1 {\n" + + "/**\n"+ + "*\n"+ + "* void foo() {\n"+ + "*\n"+ + "* }\n"+ + "*\n"+ + "*/ \n"+ + "void foo() {\n"+ + "}\n"+ + "}\n"; + + formatSource(source, + "public class test1 {\n"+ + " /**\n"+ + " *\n"+ + " * void foo() {\n"+ + " * \n" + + " * }\n"+ + " *\n"+ + " */\n"+ + " void foo() {\n"+ + " }\n" + + "}\n"); +} + + + }