Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 127007 Details for
Bug 198963
[formatter] 3.3 Code Formatter repeatedly indents block comment
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
New proposed patch
v04.txt (text/plain), 18.79 KB, created by
Frederic Fusier
on 2009-02-27 10:09:01 EST
(
hide
)
Description:
New proposed patch
Filename:
MIME Type:
Creator:
Frederic Fusier
Created:
2009-02-27 10:09:01 EST
Size:
18.79 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#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.34 >diff -u -r1.34 FormatterCommentsBugsTest.java >--- src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java 14 Jan 2009 10:48:43 -0000 1.34 >+++ src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java 27 Feb 2009 14:12:43 -0000 >@@ -38,6 +38,366 @@ > } > > /** >+ * @bug 198963: [formatter] 3.3 Code Formatter repeatedly indents block comment >+ * @test Ensure that no the formatter indents the block comment only once >+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=198963" >+ */ >+public void testBug198963_Tabs01() { >+ this.formatterPrefs.comment_format_block_comment = false; >+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.TAB; >+ String source = >+ "public class Test {\n" + >+ "\n" + >+ " int x = 0; /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ "}"; >+ formatSource(source, >+ "public class Test {\n" + >+ "\n" + >+ " int x = 0; /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ "}" >+ ); >+} >+public void testBug198963_Tabs02() { >+ this.formatterPrefs.comment_format_block_comment = false; >+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.TAB; >+ String source = >+ "public class Test {\n" + >+ "\n" + >+ " int x = 10; /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ "}"; >+ formatSource(source, >+ "public class Test {\n" + >+ "\n" + >+ " int x = 10; /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ "}" >+ ); >+} >+public void testBug198963_Tabs03() { >+ this.formatterPrefs.comment_format_block_comment = false; >+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.TAB; >+ String source = >+ "public class Test {\n" + >+ "\n" + >+ " int x = 100; /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ "}"; >+ formatSource(source, >+ "public class Test {\n" + >+ "\n" + >+ " int x = 100; /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ "}" >+ ); >+} >+public void testBug198963_Tabs04() { >+ this.formatterPrefs.comment_format_block_comment = false; >+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.TAB; >+ String source = >+ "public class Test {\n" + >+ "\n" + >+ " int x = 0; /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ "}"; >+ formatSource(source, >+ "public class Test {\n" + >+ "\n" + >+ " int x = 0; /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ "}" >+ ); >+} >+public void testBug198963_Tabs05() { >+ this.formatterPrefs.comment_format_block_comment = false; >+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.TAB; >+ String source = >+ "public class Test {\n" + >+ "\n" + >+ " /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ " int x = 0;\n" + >+ "}"; >+ formatSource(source, >+ "public class Test {\n" + >+ "\n" + >+ " /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ " int x = 0;\n" + >+ "}" >+ ); >+} >+public void testBug198963_Tabs06() { >+ this.formatterPrefs.comment_format_block_comment = false; >+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.TAB; >+ String source = >+ "public class Test {\n" + >+ "\n" + >+ " /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ " int x = 0;\n" + >+ "}"; >+ formatSource(source, >+ "public class Test {\n" + >+ "\n" + >+ " /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ " int x = 0;\n" + >+ "}" >+ ); >+} >+public void testBug198963_Spaces01() { >+ this.formatterPrefs.comment_format_block_comment = false; >+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE; >+ String source = >+ "public class Test {\n" + >+ "\n" + >+ " int x = 0; /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ "}"; >+ formatSource(source, >+ "public class Test {\n" + >+ "\n" + >+ " int x = 0; /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ "}" >+ ); >+} >+public void testBug198963_Spaces02() { >+ this.formatterPrefs.comment_format_block_comment = false; >+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE; >+ String source = >+ "public class Test {\n" + >+ "\n" + >+ " int x = 10; /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ "}"; >+ formatSource(source, >+ "public class Test {\n" + >+ "\n" + >+ " int x = 10; /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ "}" >+ ); >+} >+public void testBug198963_Spaces03() { >+ this.formatterPrefs.comment_format_block_comment = false; >+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE; >+ String source = >+ "public class Test {\n" + >+ "\n" + >+ " int x = 100; /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ "}"; >+ formatSource(source, >+ "public class Test {\n" + >+ "\n" + >+ " int x = 100; /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ "}" >+ ); >+} >+public void testBug198963_Spaces04() { >+ this.formatterPrefs.comment_format_block_comment = false; >+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE; >+ String source = >+ "public class Test {\n" + >+ "\n" + >+ " int x = 0; /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ "}"; >+ formatSource(source, >+ "public class Test {\n" + >+ "\n" + >+ " int x = 0; /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ "}" >+ ); >+} >+public void testBug198963_Spaces05() { >+ this.formatterPrefs.comment_format_block_comment = false; >+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE; >+ String source = >+ "public class Test {\n" + >+ "\n" + >+ " /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ " int x = 0;\n" + >+ "}"; >+ formatSource(source, >+ "public class Test {\n" + >+ "\n" + >+ " /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ " int x = 0;\n" + >+ "}" >+ ); >+} >+public void testBug198963_Spaces06() { >+ this.formatterPrefs.comment_format_block_comment = false; >+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE; >+ String source = >+ "public class Test {\n" + >+ "\n" + >+ " /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ " int x = 0;\n" + >+ "}"; >+ formatSource(source, >+ "public class Test {\n" + >+ "\n" + >+ " /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ " int x = 0;\n" + >+ "}" >+ ); >+} >+public void testBug198963_Mixed01() { >+ this.formatterPrefs.comment_format_block_comment = false; >+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.MIXED; >+ String source = >+ "public class Test {\n" + >+ "\n" + >+ " int x = 0; /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ "}"; >+ formatSource(source, >+ "public class Test {\n" + >+ "\n" + >+ " int x = 0; /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ "}" >+ ); >+} >+public void testBug198963_Mixed02() { >+ this.formatterPrefs.comment_format_block_comment = false; >+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.MIXED; >+ String source = >+ "public class Test {\n" + >+ "\n" + >+ " int x = 10; /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ "}"; >+ formatSource(source, >+ "public class Test {\n" + >+ "\n" + >+ " int x = 10; /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ "}" >+ ); >+} >+public void testBug198963_Mixed03() { >+ this.formatterPrefs.comment_format_block_comment = false; >+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.MIXED; >+ String source = >+ "public class Test {\n" + >+ "\n" + >+ " int x = 100; /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ "}"; >+ formatSource(source, >+ "public class Test {\n" + >+ "\n" + >+ " int x = 100; /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ "}" >+ ); >+} >+public void testBug198963_Mixed04() { >+ this.formatterPrefs.comment_format_block_comment = false; >+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.MIXED; >+ String source = >+ "public class Test {\n" + >+ "\n" + >+ " int x = 0; /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ "}"; >+ formatSource(source, >+ "public class Test {\n" + >+ "\n" + >+ " int x = 0; /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ "}" >+ ); >+} >+public void testBug198963_Mixed05() { >+ this.formatterPrefs.comment_format_block_comment = false; >+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.MIXED; >+ String source = >+ "public class Test {\n" + >+ "\n" + >+ " /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ " int x = 0;\n" + >+ "}"; >+ formatSource(source, >+ "public class Test {\n" + >+ "\n" + >+ " /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ " int x = 0;\n" + >+ "}" >+ ); >+} >+public void testBug198963_Mixed06() { >+ this.formatterPrefs.comment_format_block_comment = false; >+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.MIXED; >+ String source = >+ "public class Test {\n" + >+ "\n" + >+ " /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ " int x = 0;\n" + >+ "}"; >+ formatSource(source, >+ "public class Test {\n" + >+ "\n" + >+ " /*\n" + >+ " * XXXX\n" + >+ " */\n" + >+ " int x = 0;\n" + >+ "}" >+ ); >+} >+ >+/** > * @bug 204091: [formatter] format region in comment introduces comment start/end tokens > * @test Ensure that a region inside a javadoc comment is well formatted > * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=204091" >#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.158 >diff -u -r1.158 Scribe.java >--- formatter/org/eclipse/jdt/internal/formatter/Scribe.java 14 Jan 2009 10:48:41 -0000 1.158 >+++ formatter/org/eclipse/jdt/internal/formatter/Scribe.java 27 Feb 2009 14:12:45 -0000 >@@ -797,14 +797,12 @@ > case '\t' : > offset += this.tabLength; > break; >- case ' ' : >- offset++; >- break; > case '\r' : > case '\n' : > break; > default: >- return offset; >+ offset++; >+ break; > } > } > return offset; >@@ -1250,51 +1248,85 @@ > this.needSpace = false; > this.pendingSpace = false; > >+ int commentColumn = this.column; > if (includesBlockComments) { > if (printBlockComment(currentTokenStartPosition, currentTokenEndPosition)) { > return; > } > } > >+ int currentIndentationLevel = this.indentationLevel; >+ if ((commentColumn-1) > this.indentationLevel) { >+ this.indentationLevel = commentColumn-1; >+ } > int currentCommentOffset = onFirstColumn ? 0 : getCurrentCommentOffset(start); > boolean formatComment = (isJavadoc && (this.formatComments & CodeFormatter.K_JAVA_DOC) != 0) || (!isJavadoc && (this.formatComments & CodeFormatter.K_MULTI_LINE_COMMENT) != 0); > >- while (nextCharacterStart <= currentTokenEndPosition && (currentCharacter = this.scanner.getNextChar()) != -1) { >- nextCharacterStart = this.scanner.currentPosition; >- >- switch(currentCharacter) { >- case '\r' : >- start = previousStart; >- isNewLine = true; >- if (this.scanner.getNextChar('\n')) { >- currentCharacter = '\n'; >+ try { >+ while (nextCharacterStart <= currentTokenEndPosition && (currentCharacter = this.scanner.getNextChar()) != -1) { >+ nextCharacterStart = this.scanner.currentPosition; >+ >+ switch(currentCharacter) { >+ case '\r' : >+ start = previousStart; >+ isNewLine = true; >+ if (this.scanner.getNextChar('\n')) { >+ currentCharacter = '\n'; >+ nextCharacterStart = this.scanner.currentPosition; >+ } >+ break; >+ case '\n' : >+ start = previousStart; >+ isNewLine = true; > nextCharacterStart = this.scanner.currentPosition; >- } >- break; >- case '\n' : >- start = previousStart; >- isNewLine = true; >- nextCharacterStart = this.scanner.currentPosition; >- break; >- default: >- if (isNewLine) { >- this.column = 1; >- this.line++; >- isNewLine = false; >- >- StringBuffer buffer = new StringBuffer(); >- if (onFirstColumn) { >- // simply insert indentation if necessary >- buffer.append(this.lineSeparator); >- if (indentComment) { >- printIndentationIfNecessary(buffer); >- } >- if (formatComment) { >+ break; >+ default: >+ if (isNewLine) { >+ this.column = 1; >+ this.line++; >+ isNewLine = false; >+ >+ StringBuffer buffer = new StringBuffer(); >+ if (onFirstColumn) { >+ // simply insert indentation if necessary >+ buffer.append(this.lineSeparator); >+ if (indentComment) { >+ printIndentationIfNecessary(buffer); >+ } >+ if (formatComment) { >+ if (ScannerHelper.isWhitespace((char) currentCharacter)) { >+ int previousStartPosition = this.scanner.currentPosition; >+ while(currentCharacter != -1 && currentCharacter != '\r' && currentCharacter != '\n' && ScannerHelper.isWhitespace((char) currentCharacter)) { >+ previousStart = nextCharacterStart; >+ previousStartPosition = this.scanner.currentPosition; >+ currentCharacter = this.scanner.getNextChar(); >+ nextCharacterStart = this.scanner.currentPosition; >+ } >+ if (currentCharacter == '\r' || currentCharacter == '\n') { >+ nextCharacterStart = previousStartPosition; >+ } >+ } >+ if (currentCharacter != '\r' && currentCharacter != '\n') { >+ buffer.append(' '); >+ } >+ } >+ } else { > if (ScannerHelper.isWhitespace((char) currentCharacter)) { > int previousStartPosition = this.scanner.currentPosition; >- while(currentCharacter != -1 && currentCharacter != '\r' && currentCharacter != '\n' && ScannerHelper.isWhitespace((char) currentCharacter)) { >+ int count = 0; >+ loop: while(currentCharacter != -1 && currentCharacter != '\r' && currentCharacter != '\n' && ScannerHelper.isWhitespace((char) currentCharacter)) { >+ if (count >= currentCommentOffset) { >+ break loop; >+ } > previousStart = nextCharacterStart; > previousStartPosition = this.scanner.currentPosition; >+ switch(currentCharacter) { >+ case '\t' : >+ count += this.tabLength; >+ break; >+ default : >+ count ++; >+ } > currentCharacter = this.scanner.getNextChar(); > nextCharacterStart = this.scanner.currentPosition; > } >@@ -1302,62 +1334,37 @@ > nextCharacterStart = previousStartPosition; > } > } >- if (currentCharacter != '\r' && currentCharacter != '\n') { >- buffer.append(' '); >+ buffer.append(this.lineSeparator); >+ if (indentComment) { >+ printIndentationIfNecessary(buffer); > } >- } >- } else { >- if (ScannerHelper.isWhitespace((char) currentCharacter)) { >- int previousStartPosition = this.scanner.currentPosition; >- int count = 0; >- loop: while(currentCharacter != -1 && currentCharacter != '\r' && currentCharacter != '\n' && ScannerHelper.isWhitespace((char) currentCharacter)) { >- if (count >= currentCommentOffset) { >- break loop; >+ if (formatComment) { >+ int previousStartTemp = previousStart; >+ int nextCharacterStartTemp = nextCharacterStart; >+ while(currentCharacter != -1 && currentCharacter != '\r' && currentCharacter != '\n' && ScannerHelper.isWhitespace((char) currentCharacter)) { >+ previousStart = nextCharacterStart; >+ currentCharacter = this.scanner.getNextChar(); >+ nextCharacterStart = this.scanner.currentPosition; > } >- previousStart = nextCharacterStart; >- previousStartPosition = this.scanner.currentPosition; >- switch(currentCharacter) { >- case '\t' : >- count += this.tabLength; >- break; >- default : >- count ++; >+ if (currentCharacter == '*') { >+ buffer.append(' '); >+ } else { >+ previousStart = previousStartTemp; >+ nextCharacterStart = nextCharacterStartTemp; > } >- currentCharacter = this.scanner.getNextChar(); >- nextCharacterStart = this.scanner.currentPosition; >- } >- if (currentCharacter == '\r' || currentCharacter == '\n') { >- nextCharacterStart = previousStartPosition; >- } >- } >- buffer.append(this.lineSeparator); >- if (indentComment) { >- printIndentationIfNecessary(buffer); >- } >- if (formatComment) { >- int previousStartTemp = previousStart; >- int nextCharacterStartTemp = nextCharacterStart; >- while(currentCharacter != -1 && currentCharacter != '\r' && currentCharacter != '\n' && ScannerHelper.isWhitespace((char) currentCharacter)) { >- previousStart = nextCharacterStart; >- currentCharacter = this.scanner.getNextChar(); >- nextCharacterStart = this.scanner.currentPosition; >- } >- if (currentCharacter == '*') { >- buffer.append(' '); >- } else { >- previousStart = previousStartTemp; >- nextCharacterStart = nextCharacterStartTemp; >+ this.scanner.currentPosition = nextCharacterStart; > } >- this.scanner.currentPosition = nextCharacterStart; > } >+ addReplaceEdit(start, previousStart - 1, String.valueOf(buffer)); >+ } else { >+ this.column += (nextCharacterStart - previousStart); > } >- addReplaceEdit(start, previousStart - 1, String.valueOf(buffer)); >- } else { >- this.column += (nextCharacterStart - previousStart); >- } >+ } >+ previousStart = nextCharacterStart; >+ this.scanner.currentPosition = nextCharacterStart; > } >- previousStart = nextCharacterStart; >- this.scanner.currentPosition = nextCharacterStart; >+ } finally { >+ this.indentationLevel = currentIndentationLevel; > } > this.lastNumberOfNewLines = 0; > this.needSpace = false; >@@ -1366,7 +1373,6 @@ > > private boolean printBlockComment(int currentTokenStartPosition, int currentTokenEndPosition) { > >- > // Compute indentation > int maxColumn = this.formatter.preferences.comment_line_length + 1; > int indentLevel = this.indentationLevel;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 198963
:
126872
| 127007