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 153944 Details for
Bug 293300
[formatter] The formatter is still unstable in certain circumstances
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
New proposed patch for M4
v18.txt (text/plain), 64.66 KB, created by
Frederic Fusier
on 2009-12-07 13:06:31 EST
(
hide
)
Description:
New proposed patch for M4
Filename:
MIME Type:
Creator:
Frederic Fusier
Created:
2009-12-07 13:06:31 EST
Size:
64.66 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java,v >retrieving revision 1.199 >diff -u -r1.199 Scanner.java >--- compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java 12 Nov 2009 20:24:54 -0000 1.199 >+++ compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java 7 Dec 2009 17:58:03 -0000 >@@ -3664,36 +3664,26 @@ > if (this.currentPosition <= 0) > return "NOT started!\n\n"+ new String(this.source); //$NON-NLS-1$ > >- char front[] = new char[this.startPosition]; >- System.arraycopy(this.source, 0, front, 0, this.startPosition); >+ StringBuffer buffer = new StringBuffer(); >+ if (this.startPosition < 1000) { >+ buffer.append(this.source, 0, this.startPosition); >+ } else { >+ buffer.append("<source beginning>\n...\n"); //$NON-NLS-1$ >+ int line = Util.getLineNumber(this.startPosition-1000, this.lineEnds, 0, this.lineEnds.length); >+ int lineStart = getLineStart(line); >+ buffer.append(this.source, lineStart, this.startPosition-lineStart); >+ } > >+ buffer.append("\n===============================\nStarts here -->"); //$NON-NLS-1$ > int middleLength = (this.currentPosition - 1) - this.startPosition + 1; >- char middle[]; > if (middleLength > -1) { >- middle = new char[middleLength]; >- System.arraycopy( >- this.source, >- this.startPosition, >- middle, >- 0, >- middleLength); >- } else { >- middle = CharOperation.NO_CHAR; >+ buffer.append(this.source, this.startPosition, middleLength); > } >+ buffer.append("<-- Ends here\n===============================\n"); //$NON-NLS-1$ > >- char end[] = new char[this.eofPosition - (this.currentPosition - 1)]; >- System.arraycopy( >- this.source, >- (this.currentPosition - 1) + 1, >- end, >- 0, >- this.eofPosition - (this.currentPosition - 1) - 1); >+ buffer.append(this.source, (this.currentPosition - 1) + 1, this.eofPosition - (this.currentPosition - 1) - 1); > >- return new String(front) >- + "\n===============================\nStarts here -->" //$NON-NLS-1$ >- + new String(middle) >- + "<-- Ends here\n===============================\n" //$NON-NLS-1$ >- + new String(end); >+ return buffer.toString(); > } > public String toStringAction(int act) { > switch (act) { >Index: formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java,v >retrieving revision 1.221 >diff -u -r1.221 CodeFormatterVisitor.java >--- formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java 5 Nov 2009 17:41:08 -0000 1.221 >+++ formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java 7 Dec 2009 17:58:04 -0000 >@@ -1868,7 +1868,7 @@ > this.scribe.indent(); > } > this.scribe.printNextToken(TerminalTokens.TokenNameLBRACE, insertSpaceBeforeBrace); >- this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT); >+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.UNMODIFIABLE_TRAILING_COMMENT); > } > private void formatStatements(BlockScope scope, final Statement[] statements, boolean insertNewLineAfterLastStatement) { > int statementsLength = statements.length; >@@ -4254,7 +4254,7 @@ > } else { > // no method body > this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon); >- this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT); >+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.COMPLEX_TRAILING_COMMENT); > } > return false; > } >@@ -4951,12 +4951,12 @@ > this.scribe.unIndent(); > } > statement.traverse(this, scope); >- this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT); > wasACase = true; > wasAStatement = false; > if (this.preferences.indent_switchstatements_compare_to_cases) { > this.scribe.indent(); > } >+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.COMPLEX_TRAILING_COMMENT); > } else if (statement instanceof BreakStatement) { > if (this.preferences.indent_breaks_compare_to_cases) { > if (wasAStatement && !this.preferences.indent_switchstatements_compare_to_cases) { >Index: formatter/org/eclipse/jdt/internal/formatter/Location.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/Location.java,v >retrieving revision 1.16 >diff -u -r1.16 Location.java >--- formatter/org/eclipse/jdt/internal/formatter/Location.java 25 Oct 2009 15:59:51 -0000 1.16 >+++ formatter/org/eclipse/jdt/internal/formatter/Location.java 7 Dec 2009 17:58:04 -0000 >@@ -43,7 +43,7 @@ > this.outputColumn = scribe.column; > this.outputLine = scribe.line; > this.inputOffset = sourceRestart; >- this.inputColumn = scribe.getCurrentIndentation(sourceRestart); >+ this.inputColumn = scribe.getCurrentColumn(sourceRestart); > this.outputIndentationLevel = scribe.indentationLevel; > this.lastNumberOfNewLines = scribe.lastNumberOfNewLines; > this.needSpace = scribe.needSpace; >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.182 >diff -u -r1.182 Scribe.java >--- formatter/org/eclipse/jdt/internal/formatter/Scribe.java 16 Nov 2009 18:29:58 -0000 1.182 >+++ formatter/org/eclipse/jdt/internal/formatter/Scribe.java 7 Dec 2009 17:58:05 -0000 >@@ -106,12 +106,23 @@ > private static final int INCLUDE_LINE_COMMENTS = CodeFormatter.F_INCLUDE_COMMENTS | CodeFormatter.K_SINGLE_LINE_COMMENT; > private static final int SKIP_FIRST_WHITESPACE_TOKEN = -2; > private static final int INVALID_TOKEN = 2000; >- static final int NO_TRAILING_COMMENT = 0; >- static final int BASIC_TRAILING_COMMENT = 1; >- static final int IMPORT_TRAILING_COMMENT = 2; >+ static final int NO_TRAILING_COMMENT = 0x0000; >+ static final int BASIC_TRAILING_COMMENT = 0x0100; >+ static final int COMPLEX_TRAILING_COMMENT = 0x0200; >+ static final int IMPORT_TRAILING_COMMENT = COMPLEX_TRAILING_COMMENT | 0x0001; >+ static final int UNMODIFIABLE_TRAILING_COMMENT = 0x0400; > private int formatComments = 0; > private int headerEndPosition = -1; > String commentIndentation; // indentation requested in comments (usually in javadoc root tags description) >+ // Class to store previous line comment information >+ class LineComment { >+ boolean contiguous = false; >+ int currentColumn, indentation; >+ int lines; >+ char[] leadingSpaces; >+ } >+ final LineComment lastLineComment = new LineComment(); >+ > > // New way to format javadoc > private FormatterCommentParser formatterCommentParser; // specialized parser to format comments >@@ -787,10 +798,10 @@ > return null; > } > >- private int getCurrentCommentOffset(int start) { >+ private int getCurrentCommentColumn(int start) { > int linePtr = -Arrays.binarySearch(this.lineEnds, start); >- int offset = 0; >- int beginningOfLine = getLineEnd(linePtr - 1); >+ int commentColumn = 1; >+ int beginningOfLine = getLineEnd(linePtr - 1)+1; > if (beginningOfLine == -1) { > beginningOfLine = 0; > } >@@ -800,35 +811,70 @@ > // find the position of the beginning of the line containing the comment > while (beginningOfLine > currentStartPosition) { > if (linePtr > 0) { >- beginningOfLine = getLineEnd(--linePtr); >+ beginningOfLine = getLineEnd(--linePtr)+1; > } else { > beginningOfLine = 0; > break; > } > } >- for (int i = currentStartPosition - 1; i >= beginningOfLine ; i--) { >+ for (int i=beginningOfLine; i < currentStartPosition ; i++) { > char currentCharacter = source[i]; > switch (currentCharacter) { > case '\t' : >- offset += this.tabLength; >+ if (this.tabLength != 0) { >+ int reminder = commentColumn % this.tabLength; >+ if (reminder == 0) { >+ commentColumn += this.tabLength; >+ } else { >+ commentColumn = ((commentColumn / this.tabLength) + 1) * this.tabLength + 1; >+ } >+ } >+ break; >+ case '\r' : >+ case '\n' : >+ commentColumn = 0; >+ break; >+ default: >+ commentColumn++; >+ break; >+ } >+ } >+ return commentColumn; >+ } >+ >+ int getCurrentColumn(char[] whitespaces) { >+ int length = whitespaces.length; >+ if (this.tabLength == 0) return length; >+ int currentColumn = 1; >+ for (int i=0; i<length; i++) { >+ char ch = whitespaces[i]; >+ switch (ch) { >+ case '\t' : >+ int reminder = (currentColumn-1) % this.tabLength; >+ if (reminder == 0) { >+ currentColumn += this.tabLength; >+ } else { >+ currentColumn = ((currentColumn / this.tabLength) + 1) * this.tabLength + 1; >+ } > break; > case '\r' : > case '\n' : >+ currentColumn = 0; > break; > default: >- offset++; >+ currentColumn++; > break; > } > } >- return offset; >+ return currentColumn; > } > >- int getCurrentIndentation(int start) { >+ int getCurrentColumn(int start) { > int linePtr = Arrays.binarySearch(this.lineEnds, start); > if (linePtr < 0) { > linePtr = -linePtr - 1; > } >- int offset = 0; >+ int currentColumn = 1; > int beginningOfLine = getLineEnd(linePtr)+1; > if (beginningOfLine == -1) { > beginningOfLine = 0; >@@ -839,19 +885,27 @@ > char currentCharacter = source[i]; > switch (currentCharacter) { > case '\t' : >- offset += this.tabLength; >+ if (this.tabLength != 0) { >+ int reminder = (currentColumn-1) % this.tabLength; >+ if (reminder == 0) { >+ currentColumn += this.tabLength; >+ } else { >+ currentColumn = ((currentColumn / this.tabLength) + 1) * this.tabLength + 1; >+ } >+ } > break; > case '\r' : > case '\n' : >+ currentColumn = 0; > break; > case ' ': >- offset++; >+ currentColumn++; > break; > default: >- return offset; >+ return currentColumn; > } > } >- return offset; >+ return currentColumn; > } > > public String getEmptyLines(int linesNumber) { >@@ -1009,7 +1063,7 @@ > StringBuffer buffer = new StringBuffer(getNewLine()); > > // Look for current indentation >- int currentColumn = getCurrentIndentation(this.scanner.currentPosition); >+ int currentIndentation = getCurrentColumn(this.scanner.currentPosition) - 1; > > // Determine whether the alignment indentation can be used or not > // So far, the best algorithm is to use it when >@@ -1036,14 +1090,14 @@ > } > > // Use the current indentation if over the computed indentation >- if (this.indentationLevel < currentColumn) { >- this.indentationLevel = currentColumn; >+ if (this.indentationLevel < currentIndentation) { >+ this.indentationLevel = currentIndentation; > } > > // Debug > if (DefaultCodeFormatter.DEBUG) { > System.out.println(" - format brace = "+this.formatBrace); //$NON-NLS-1$ >- System.out.println(" - current column = "+currentColumn); //$NON-NLS-1$ >+ System.out.println(" - current column = "+(currentIndentation+1)); //$NON-NLS-1$ > System.out.println(" - current position = "+this.scanner.currentPosition); //$NON-NLS-1$ > System.out.print(" - current line = "); //$NON-NLS-1$ > int linePtr = Arrays.binarySearch(this.lineEnds, this.scanner.currentPosition); >@@ -1387,7 +1441,7 @@ > if ((commentColumn-1) > this.indentationLevel) { > this.indentationLevel = commentColumn-1; > } >- int currentCommentOffset = onFirstColumn ? 0 : getCurrentCommentOffset(start); >+ int currentCommentIndentation = onFirstColumn ? 0 : getCurrentCommentColumn(start) - 1; > boolean formatComment = (isJavadoc && (this.formatComments & CodeFormatter.K_JAVA_DOC) != 0) || (!isJavadoc && (this.formatComments & CodeFormatter.K_MULTI_LINE_COMMENT) != 0); > > try { >@@ -1441,19 +1495,26 @@ > } else { > if (ScannerHelper.isWhitespace((char) currentCharacter)) { > int previousStartPosition = this.scanner.currentPosition; >- int count = 0; >+ int currentIndentation = 0; > loop: while(currentCharacter != -1 && currentCharacter != '\r' && currentCharacter != '\n' && ScannerHelper.isWhitespace((char) currentCharacter)) { >- if (count >= currentCommentOffset) { >+ if (currentIndentation >= currentCommentIndentation) { > break loop; > } > previousStart = nextCharacterStart; > previousStartPosition = this.scanner.currentPosition; > switch(currentCharacter) { > case '\t' : >- count += this.tabLength; >+ if (this.tabLength != 0) { >+ int reminder = currentIndentation % this.tabLength; >+ if (reminder == 0) { >+ currentIndentation += this.tabLength; >+ } else { >+ currentIndentation = ((currentIndentation / this.tabLength) + 1) * this.tabLength; >+ } >+ } > break; > default : >- count ++; >+ currentIndentation ++; > } > currentCharacter = this.scanner.getNextChar(); > nextCharacterStart = this.scanner.currentPosition; >@@ -2108,27 +2169,59 @@ > // If following token is a line comment on the same line or the line just after, > // then it might be not really formatted as a trailing comment > boolean realTrailing = trailing > NO_TRAILING_COMMENT; >- if (trailing == IMPORT_TRAILING_COMMENT && this.scanner.currentCharacter == '/' && lines <= 1) { >- int currentPosition = this.scanner.currentPosition; >- if (this.scanner.getNextToken() == TerminalTokens.TokenNameCOMMENT_LINE) { >- int token = this.scanner.getNextToken(); >- while (token == TerminalTokens.TokenNameCOMMENT_LINE) { >- token = this.scanner.getNextToken(); >+ if (realTrailing && this.scanner.currentCharacter == '/' && (lines == 0 || (lines == 1 && !hasLineComment && trailing == IMPORT_TRAILING_COMMENT))) { >+ // sometimes changing the trailing may not be the best idea >+ // for complex trailing comment, it's basically a good idea >+ boolean canChangeTrailing = (trailing & COMPLEX_TRAILING_COMMENT) != 0; >+ // for basic trailing comment preceded by a line comment, then it depends on the comments relative position >+ // when following comment column (after having been rounded) is below the preceding one, >+ // then it becomes not a good idea to change the trailing flag >+ if (trailing == BASIC_TRAILING_COMMENT && hasLineComment) { >+ int currentCommentColumn = getCurrentColumn(whiteSpaces); >+ int lastCommentColumn = this.lastLineComment.currentColumn; >+ if (this.tabLength > 0) { >+ if ((currentCommentColumn % this.tabLength) == 0) { >+ lastCommentColumn = (lastCommentColumn / this.tabLength) * this.tabLength; >+ } else { >+ currentCommentColumn = ((currentCommentColumn / this.tabLength) + 1) * this.tabLength; >+ } > } >- if (token == TerminalTokens.TokenNameWHITESPACE) { >- char[] secondWhiteSpaces = this.scanner.getCurrentTokenSource(); >- loop: for (int i = 0, max = secondWhiteSpaces.length; i < max; i++) { >- switch(secondWhiteSpaces[i]) { >- case '\r' : >- case '\n' : >+ canChangeTrailing = currentCommentColumn >= lastCommentColumn; >+ } >+ // if the trailing can be change, then look at the following tokens >+ if (canChangeTrailing) { >+ int currentPosition = this.scanner.currentPosition; >+ if (this.scanner.getNextToken() == TerminalTokens.TokenNameCOMMENT_LINE) { >+ realTrailing = !hasLineComment; >+ switch (this.scanner.getNextToken()) { >+ case TerminalTokens.TokenNameCOMMENT_LINE: >+ // at least two contiguous line comments >+ // the formatter should not consider comments as trailing ones >+ realTrailing = false; >+ break; >+ case TerminalTokens.TokenNameWHITESPACE: >+ if (this.scanner.getNextToken() == TerminalTokens.TokenNameCOMMENT_LINE) { >+ // at least two contiguous line comments >+ // the formatter should not consider comments as trailing ones > realTrailing = false; >- break loop; >- } >+ } >+ break; > } > } >+ this.scanner.resetTo(currentPosition, this.scanner.eofPosition - 1); > } >- this.scanner.resetTo(currentPosition, this.scanner.eofPosition - 1); > } >+ // Look whether comments line may be contiguous or not >+ // Note that when preceding token is a comment line, then only one line >+ // is enough to have an empty line as the line end is included in the comment line... >+ // If comments are contiguous, store the white spaces to be able to compute the current comment indentation >+ if (lines > 1 || (lines == 1 && hasLineComment)) { >+ this.lastLineComment.contiguous = false; >+ } >+ this.lastLineComment.leadingSpaces = whiteSpaces; >+ this.lastLineComment.lines = lines; >+ // Strategy to consume spaces and eventually leave at this stage >+ // depends on the fact that a trailing comment is expected or not > if (realTrailing) { > // if a line comment is consumed, no other comment can be on the same line after > if (hasLineComment) { >@@ -2200,6 +2293,7 @@ > this.scanner.resetTo(this.scanner.getCurrentTokenStartPosition(), this.scannerEndPosition - 1); > return; > } >+ this.lastLineComment.contiguous = false; > if (rejectBlockComment) break; > if (lines >= 1) { > if (lines > 1) { >@@ -2223,6 +2317,7 @@ > this.scanner.resetTo(this.scanner.getCurrentTokenStartPosition(), this.scannerEndPosition - 1); > return; > } >+ this.lastLineComment.contiguous = false; > if (rejectJavadocComment) break; > if (lines >= 1) { > if (lines > 1) { >@@ -2246,6 +2341,7 @@ > lines = 0; > break; > default : >+ this.lastLineComment.contiguous = false; > // step back one token > this.scanner.resetTo(currentTokenStartPosition, this.scannerEndPosition - 1); > return; >@@ -2300,12 +2396,64 @@ > int start = currentTokenStartPosition; > int nextCharacterStart = currentTokenStartPosition; > >- if (this.indentationLevel != 0) { >- if (!this.formatter.preferences.never_indent_line_comments_on_first_column >- || !isOnFirstColumn(start)) { >- printIndentationIfNecessary(); >+ // Print comment line indentation >+ int commentIndentationLevel; >+ if (this.indentationLevel == 0) { >+ commentIndentationLevel = this.column - 1; >+ } else { >+ if (this.formatter.preferences.never_indent_line_comments_on_first_column && >+ isOnFirstColumn(start)) { >+ commentIndentationLevel = this.column - 1; >+ } else { >+ // Indentation may be specific for contiguous comment >+ // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=293300 >+ if (this.lastLineComment.contiguous) { >+ // The leading spaces have been set while looping in the printComment(int) method >+ int currentCommentIndentation = getCurrentColumn(this.lastLineComment.leadingSpaces); >+ // Keep the current comment indentation when over the previous contiguous line comment >+ // and the previous comment has not been reindented >+ int lastCommentColumn = this.lastLineComment.currentColumn; >+ if (this.tabLength > 0) { >+ if ((currentCommentIndentation % this.tabLength) == 0) { >+ lastCommentColumn = (lastCommentColumn / this.tabLength) * this.tabLength; >+ } else { >+ currentCommentIndentation = ((currentCommentIndentation / this.tabLength) + 1) * this.tabLength; >+ } >+ } >+ if (currentCommentIndentation >= lastCommentColumn && this.lastLineComment.indentation != this.indentationLevel) { >+ int currentIndentationLevel = this.indentationLevel; >+ this.indentationLevel = this.lastLineComment.indentation ; >+ printIndentationIfNecessary(); >+ this.indentationLevel = currentIndentationLevel; >+ commentIndentationLevel = this.lastLineComment.indentation ; >+ } else { >+ printIndentationIfNecessary(); >+ commentIndentationLevel = this.column - 1; >+ } >+ } else { >+ if (this.currentAlignment != null && this.currentAlignment.name.equals("array_initializer") && //$NON-NLS-1$ >+ this.indentationLevel < this.currentAlignment.breakIndentationLevel && >+ this.lastLineComment.lines > 0) >+ { >+ int currentIndentationLevel = this.indentationLevel; >+ this.indentationLevel = this.currentAlignment.breakIndentationLevel; >+ printIndentationIfNecessary(); >+ this.indentationLevel = currentIndentationLevel; >+ commentIndentationLevel = this.currentAlignment.breakIndentationLevel; >+ } else { >+ printIndentationIfNecessary(); >+ commentIndentationLevel = this.column - 1; >+ } >+ } > } > } >+ >+ // Store line comment information >+ this.lastLineComment.contiguous = true; >+ this.lastLineComment.currentColumn = getCurrentCommentColumn(currentTokenStartPosition); >+ this.lastLineComment.indentation = commentIndentationLevel; >+ >+ // Add pending space if necessary > if (this.pendingSpace) { > addInsertEdit(currentTokenStartPosition, " "); //$NON-NLS-1$ > } >@@ -3983,6 +4131,7 @@ > this.needSpace = false; > this.pendingSpace = false; > this.preserveLineBreakIndentation = false; >+ this.lastLineComment.contiguous = false; > } > > public void printNextToken(int expectedTokenType){ >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java,v >retrieving revision 1.10 >diff -u -r1.10 FormatterBugsTests.java >--- src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java 16 Nov 2009 18:30:01 -0000 1.10 >+++ src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java 7 Dec 2009 17:58:09 -0000 >@@ -334,7 +334,15 @@ > "\n" + > "public class X02 {\n" + > "}\n"; >- formatSource(source); >+ formatSource(source, >+ "import java.util.List;\n" + >+ "import java.util.Set;\n" + >+ "\n" + >+ "//import java.util.HashMap;\n" + >+ "\n" + >+ "public class X02 {\n" + >+ "}\n" >+ ); > } > public void testBug199265c1() throws JavaModelException { > String source = >@@ -379,6 +387,58 @@ > "}\n"; > formatSource(source); > } >+public void testBug199265d1() throws JavaModelException { >+ String source = >+ "import java.util.Set; // trailing comment\n" + >+ "// line comment\n" + >+ "import java.util.Map; // trailing comment\n" + >+ "// line comment\n" + >+ "public class X04 {\n" + >+ "\n" + >+ "}\n"; >+ formatSource(source, >+ "import java.util.Set; // trailing comment\n" + >+ "// line comment\n" + >+ "import java.util.Map; // trailing comment\n" + >+ "// line comment\n" + >+ "\n" + >+ "public class X04 {\n" + >+ "\n" + >+ "}\n" >+ ); >+} >+public void testBug199265d2() throws JavaModelException { >+ String source = >+ "import java.util.Set; // trailing comment\n" + >+ "// line comment\n" + >+ "import java.util.Map; // trailing comment\n" + >+ "// line comment\n" + >+ "\n" + >+ "public class X04 {\n" + >+ "\n" + >+ "}\n"; >+ formatSource(source); >+} >+public void testBug199265d3() throws JavaModelException { >+ String source = >+ "import java.util.Set; // trailing comment\n" + >+ " // line comment\n" + >+ "import java.util.Map; // trailing comment\n" + >+ " // line comment\n" + >+ "public class X04 {\n" + >+ "\n" + >+ "}\n"; >+ formatSource(source, >+ "import java.util.Set; // trailing comment\n" + >+ "// line comment\n" + >+ "import java.util.Map; // trailing comment\n" + >+ "// line comment\n" + >+ "\n" + >+ "public class X04 {\n" + >+ "\n" + >+ "}\n" >+ ); >+} > public void testBug199265_wksp1a() throws JavaModelException { > String source = > "package wksp1;\n" + >@@ -837,7 +897,7 @@ > String source = > "package massive;\n" + > "\n" + >- "public class X05b\n" + >+ "public class X05\n" + > "{\n" + > "\n" + > " public void foo() throws NullPointerException {\n" + >@@ -859,7 +919,7 @@ > formatSource(source, > "package massive;\n" + > "\n" + >- "public class X05b {\n" + >+ "public class X05 {\n" + > "\n" + > " public void foo() throws NullPointerException {\n" + > "\n" + >@@ -888,7 +948,7 @@ > String source = > "package massive;\n" + > "\n" + >- "public class X05b\n" + >+ "public class X05\n" + > "{\n" + > "\n" + > " public void foo() throws NullPointerException {\n" + >@@ -910,7 +970,7 @@ > formatSource(source, > "package massive;\n" + > "\n" + >- "public class X05b\n" + >+ "public class X05\n" + > "{\n" + > "\n" + > " public void foo() throws NullPointerException\n" + >@@ -1555,6 +1615,1302 @@ > } > > /** >+ * @bug 293300: [formatter] The formatter is still unstable in certain circumstances >+ * @test Verify that formatting twice a compilation unit does not produce different output >+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=293300" >+ */ >+public void testBug293300_wksp1_01() { >+ String source = >+ "package wksp1;\n" + >+ "\n" + >+ "public class X01 {\n" + >+ "\n" + >+ " boolean foo(int test, int value) {\n" + >+ " // This comment may also be impacted after having been split in several lines. Furthermore, it\'s also important to verify that the algorithm works when the comment is split into several lines. It\'s a common use case that it may works for 1, 2 but not for 3 iterations...\n" + >+ " if (test == 0) {\n" + >+ " // skip\n" + >+ " } else if (Math.sqrt(Math.pow(test, 2)) > 10) // This is the offending comment after having been split into several lines\n" + >+ " return false;\n" + >+ " return true;\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, >+ "package wksp1;\n" + >+ "\n" + >+ "public class X01 {\n" + >+ "\n" + >+ " boolean foo(int test, int value) {\n" + >+ " // This comment may also be impacted after having been split in several\n" + >+ " // lines. Furthermore, it\'s also important to verify that the algorithm\n" + >+ " // works when the comment is split into several lines. It\'s a common use\n" + >+ " // case that it may works for 1, 2 but not for 3 iterations...\n" + >+ " if (test == 0) {\n" + >+ " // skip\n" + >+ " } else if (Math.sqrt(Math.pow(test, 2)) > 10) // This is the offending\n" + >+ " // comment after having\n" + >+ " // been split into\n" + >+ " // several lines\n" + >+ " return false;\n" + >+ " return true;\n" + >+ " }\n" + >+ "}\n" >+ ); >+} >+public void testBug293300_wkps1_02() { >+ String source = >+ "package wksp1;\n" + >+ "\n" + >+ "public class X02 {\n" + >+ " String field;\n" + >+ " public X02(String test) {\n" + >+ " field= test.toLowerCase();\n" + >+ " try {\n" + >+ " testWhetherItWorksOrNot(test); // This comment will be split and should not involve instability\n" + >+ " } catch (Exception e) {\n" + >+ " return;\n" + >+ " }\n" + >+ " }\n" + >+ " private void testWhetherItWorksOrNot(String test) {\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, >+ "package wksp1;\n" + >+ "\n" + >+ "public class X02 {\n" + >+ " String field;\n" + >+ "\n" + >+ " public X02(String test) {\n" + >+ " field = test.toLowerCase();\n" + >+ " try {\n" + >+ " testWhetherItWorksOrNot(test); // This comment will be split and\n" + >+ " // should not involve instability\n" + >+ " } catch (Exception e) {\n" + >+ " return;\n" + >+ " }\n" + >+ " }\n" + >+ "\n" + >+ " private void testWhetherItWorksOrNot(String test) {\n" + >+ " }\n" + >+ "}\n" >+ ); >+} >+public void testBug293300_wkps1_03() { >+ String source = >+ "package wksp1;\n" + >+ "\n" + >+ "public class X03 {\n" + >+ "public static final native int foo(\n" + >+ " int firstParameter,\n" + >+ " int secondParameter,\n" + >+ " int[] param3); //When a long comment is placed here with at least one line to follow,\n" + >+ " // the second line may be difficult to be formatted correctly\n" + >+ "public static final native int bar();\n" + >+ "\n" + >+ "}\n"; >+ formatSource(source, >+ "package wksp1;\n" + >+ "\n" + >+ "public class X03 {\n" + >+ " public static final native int foo(int firstParameter, int secondParameter,\n" + >+ " int[] param3); // When a long comment is placed here with at least\n" + >+ " // one line to follow,\n" + >+ " // the second line may be difficult to be formatted\n" + >+ " // correctly\n" + >+ "\n" + >+ " public static final native int bar();\n" + >+ "\n" + >+ "}\n" >+ ); >+} >+public void testBug293300_wkps1_04() { >+ String source = >+ "package wksp1;\n" + >+ "\n" + >+ "interface Y04_____________________________ {\n" + >+ "}\n" + >+ "\n" + >+ "public interface X04 extends Y04_____________________________ { // modifier constant\n" + >+ " // those constants are depending upon ClassFileConstants (relying that classfiles only use the 16 lower bits)\n" + >+ " final int AccDefault = 0;\n" + >+ "}\n"; >+ formatSource(source, >+ "package wksp1;\n" + >+ "\n" + >+ "interface Y04_____________________________ {\n" + >+ "}\n" + >+ "\n" + >+ "public interface X04 extends Y04_____________________________ { // modifier\n" + >+ " // constant\n" + >+ " // those constants are depending upon ClassFileConstants (relying that\n" + >+ " // classfiles only use the 16 lower bits)\n" + >+ " final int AccDefault = 0;\n" + >+ "}\n" >+ ); >+} >+public void testBug293300_wkps1_05() { >+ String source = >+ "package wksp1;\n" + >+ "\n" + >+ "public class X05 {\n" + >+ " private final static String[] TEST_BUG = {\"a\", //$NON-NLS-1$\n" + >+ " \"b\", //$NON-NLS-1$\n" + >+ " \"c\", //$NON-NLS-1$\n" + >+ " };\n" + >+ "}\n"; >+ formatSource(source, >+ "package wksp1;\n" + >+ "\n" + >+ "public class X05 {\n" + >+ " private final static String[] TEST_BUG = { \"a\", //$NON-NLS-1$\n" + >+ " \"b\", //$NON-NLS-1$\n" + >+ " \"c\", //$NON-NLS-1$\n" + >+ " };\n" + >+ "}\n" >+ ); >+} >+public void testBug293300_wkps1_05_JoinLinesComments_BracesNextLine() { >+ this.formatterPrefs.join_wrapped_lines = false; >+ setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE); >+ String source = >+ "package wksp1;\n" + >+ "\n" + >+ "public class X05 {\n" + >+ " private final static String[] TEST_BUG = {\"a\", //$NON-NLS-1$\n" + >+ " \"b\", //$NON-NLS-1$\n" + >+ " \"c\", //$NON-NLS-1$\n" + >+ " };\n" + >+ "}\n"; >+ formatSource(source, >+ "package wksp1;\n" + >+ "\n" + >+ "public class X05\n" + >+ "{\n" + >+ " private final static String[] TEST_BUG =\n" + >+ " { \"a\", //$NON-NLS-1$\n" + >+ " \"b\", //$NON-NLS-1$\n" + >+ " \"c\", //$NON-NLS-1$\n" + >+ " };\n" + >+ "}\n" >+ ); >+} >+public void testBug293300_wksp2_01() { >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X01 {\n" + >+ "\n" + >+ " protected String foo(String[] tests) {\n" + >+ " String result = null;\n" + >+ " for (int i = 0; i < tests.length; i++) {\n" + >+ " String test = tests[i];\n" + >+ " if (test.startsWith(\"test\")) { //$NON-NLS-1$\n" + >+ " //we got the malformed tree exception here\n" + >+ " result = test;\n" + >+ " }\n" + >+ " }\n" + >+ " return result;\n" + >+ " }\n" + >+ "\n" + >+ "}\n"; >+ formatSource(source, >+ "package wksp2;\n" + >+ "\n" + >+ "public class X01 {\n" + >+ "\n" + >+ " protected String foo(String[] tests) {\n" + >+ " String result = null;\n" + >+ " for (int i = 0; i < tests.length; i++) {\n" + >+ " String test = tests[i];\n" + >+ " if (test.startsWith(\"test\")) { //$NON-NLS-1$\n" + >+ " // we got the malformed tree exception here\n" + >+ " result = test;\n" + >+ " }\n" + >+ " }\n" + >+ " return result;\n" + >+ " }\n" + >+ "\n" + >+ "}\n" >+ ); >+} >+public void testBug293300_wksp2_02() { >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X02 {\n" + >+ "\n" + >+ "\n" + >+ " public void foo(int kind) {\n" + >+ " switch (kind) {\n" + >+ " case 0 :\n" + >+ " break;\n" + >+ " case 1 :\n" + >+ " //the first formatting looks strange on this already splitted\n" + >+ " // comment\n" + >+ " if (true)\n" + >+ " return;\n" + >+ " //fall through\n" + >+ " default:\n" + >+ " if (kind < 0)\n" + >+ " return;\n" + >+ " break;\n" + >+ " }\n" + >+ " }\n" + >+ "\n" + >+ "}\n"; >+ formatSource(source, >+ "package wksp2;\n" + >+ "\n" + >+ "public class X02 {\n" + >+ "\n" + >+ " public void foo(int kind) {\n" + >+ " switch (kind) {\n" + >+ " case 0:\n" + >+ " break;\n" + >+ " case 1:\n" + >+ " // the first formatting looks strange on this already splitted\n" + >+ " // comment\n" + >+ " if (true)\n" + >+ " return;\n" + >+ " // fall through\n" + >+ " default:\n" + >+ " if (kind < 0)\n" + >+ " return;\n" + >+ " break;\n" + >+ " }\n" + >+ " }\n" + >+ "\n" + >+ "}\n" >+ ); >+} >+public void testBug293300_wksp2_03() { >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X03 {\n" + >+ " public byte[] foo(byte value) {\n" + >+ " byte[] result = new byte[10];\n" + >+ " int valTest = 0;\n" + >+ " switch (value) {\n" + >+ " case 1 :\n" + >+ " for (int j = 10; j >= 0; j--) {\n" + >+ " result[j] = (byte) (valTest & 0xff); // Bottom 8\n" + >+ " // bits\n" + >+ " valTest = valTest >>> 2;\n" + >+ " }\n" + >+ " break;\n" + >+ " }\n" + >+ " return result;\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, >+ "package wksp2;\n" + >+ "\n" + >+ "public class X03 {\n" + >+ " public byte[] foo(byte value) {\n" + >+ " byte[] result = new byte[10];\n" + >+ " int valTest = 0;\n" + >+ " switch (value) {\n" + >+ " case 1:\n" + >+ " for (int j = 10; j >= 0; j--) {\n" + >+ " result[j] = (byte) (valTest & 0xff); // Bottom 8\n" + >+ " // bits\n" + >+ " valTest = valTest >>> 2;\n" + >+ " }\n" + >+ " break;\n" + >+ " }\n" + >+ " return result;\n" + >+ " }\n" + >+ "}\n" >+ ); >+} >+public void testBug293300_wksp2_04() { >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X04 {\n" + >+ "\n" + >+ " void foo() {\n" + >+ " int lastDiagonal[]= new int[1000000 + 1]; // this line comments configuration\n" + >+ " // may screw up the formatter to know which one\n" + >+ " int origin= 1000000 / 2; // needs to stay at its current indentation or not\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, >+ "package wksp2;\n" + >+ "\n" + >+ "public class X04 {\n" + >+ "\n" + >+ " void foo() {\n" + >+ " int lastDiagonal[] = new int[1000000 + 1]; // this line comments\n" + >+ " // configuration\n" + >+ " // may screw up the formatter to know which one\n" + >+ " int origin = 1000000 / 2; // needs to stay at its current indentation or\n" + >+ " // not\n" + >+ " }\n" + >+ "}\n" >+ ); >+} >+private static final String EXPECTED_OUTPUT_WKSP2E1 = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X05 {\n" + >+ " void foo(int val) {\n" + >+ " try {\n" + >+ " loop: for (int i = 0; i < 10; i++) {\n" + >+ " switch (val) {\n" + >+ " case 1:\n" + >+ " if (i == 0) {\n" + >+ " if (true) {\n" + >+ " val++;\n" + >+ " } // these comments\n" + >+ " // may be wrongly\n" + >+ " // realigned\n" + >+ " // by the formatter\n" + >+ "\n" + >+ " // other comment\n" + >+ " val--;\n" + >+ " continue loop;\n" + >+ " }\n" + >+ " default:\n" + >+ " throw new IllegalArgumentException();\n" + >+ " }\n" + >+ " }\n" + >+ " } finally {\n" + >+ " }\n" + >+ " }\n" + >+ "}\n"; >+public void testBug293300_wksp2_05() { >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X05 {\n" + >+ " void foo(int val) {\n" + >+ " try {\n" + >+ " loop: for (int i=0; i<10; i++) {\n" + >+ " switch (val) {\n" + >+ " case 1 :\n" + >+ " if (i==0) {\n" + >+ " if (true) {\n" + >+ " val++;\n" + >+ " } //these comments\n" + >+ " // may be wrongly\n" + >+ " // realigned\n" + >+ " // by the formatter\n" + >+ "\n" + >+ " // other comment\n" + >+ " val--;\n" + >+ " continue loop;\n" + >+ " }\n" + >+ " default :\n" + >+ " throw new IllegalArgumentException();\n" + >+ " }\n" + >+ " }\n" + >+ " }\n" + >+ " finally {\n" + >+ " }\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, EXPECTED_OUTPUT_WKSP2E1); >+} >+public void testBug293300_wksp2_05b() { >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X05 {\n" + >+ " void foo(int val) {\n" + >+ " try {\n" + >+ " loop: for (int i=0; i<10; i++) {\n" + >+ " switch (val) {\n" + >+ " case 1 :\n" + >+ " if (i==0) {\n" + >+ " if (true) {\n" + >+ " val++;\n" + >+ " } //these comments\n" + >+ " // may be wrongly\n" + >+ " // realigned\n" + >+ " // by the formatter\n" + >+ "\n" + >+ " // other comment\n" + >+ " val--;\n" + >+ " continue loop;\n" + >+ " }\n" + >+ " default :\n" + >+ " throw new IllegalArgumentException();\n" + >+ " }\n" + >+ " }\n" + >+ " }\n" + >+ " finally {\n" + >+ " }\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, EXPECTED_OUTPUT_WKSP2E1); >+} >+private static final String EXPECTED_OUTPUT_WKSP2E3 = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X05 {\n" + >+ " void foo(int val) {\n" + >+ " try {\n" + >+ " loop: for (int i = 0; i < 10; i++) {\n" + >+ " switch (val) {\n" + >+ " case 1:\n" + >+ " if (i == 0) {\n" + >+ " if (true) {\n" + >+ " val++;\n" + >+ " } // these comments\n" + >+ " // may be wrongly\n" + >+ " // realigned\n" + >+ " // by the formatter\n" + >+ "\n" + >+ " // other comment\n" + >+ " val--;\n" + >+ " continue loop;\n" + >+ " }\n" + >+ " default:\n" + >+ " throw new IllegalArgumentException();\n" + >+ " }\n" + >+ " }\n" + >+ " } finally {\n" + >+ " }\n" + >+ " }\n" + >+ "}\n"; >+public void testBug293300_wksp2_05c() { >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X05 {\n" + >+ " void foo(int val) {\n" + >+ " try {\n" + >+ " loop: for (int i=0; i<10; i++) {\n" + >+ " switch (val) {\n" + >+ " case 1 :\n" + >+ " if (i==0) {\n" + >+ " if (true) {\n" + >+ " val++;\n" + >+ " } //these comments\n" + >+ " // may be wrongly\n" + >+ " // realigned\n" + >+ " // by the formatter\n" + >+ "\n" + >+ " // other comment\n" + >+ " val--;\n" + >+ " continue loop;\n" + >+ " }\n" + >+ " default :\n" + >+ " throw new IllegalArgumentException();\n" + >+ " }\n" + >+ " }\n" + >+ " }\n" + >+ " finally {\n" + >+ " }\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, EXPECTED_OUTPUT_WKSP2E3); >+} >+public void testBug293300_wksp2_05d() { >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X05 {\n" + >+ " void foo(int val) {\n" + >+ " try {\n" + >+ " loop: for (int i=0; i<10; i++) {\n" + >+ " switch (val) {\n" + >+ " case 1 :\n" + >+ " if (i==0) {\n" + >+ " if (true) {\n" + >+ " val++;\n" + >+ " } //these comments\n" + >+ " // may be wrongly\n" + >+ " // realigned\n" + >+ " // by the formatter\n" + >+ "\n" + >+ " // other comment\n" + >+ " val--;\n" + >+ " continue loop;\n" + >+ " }\n" + >+ " default :\n" + >+ " throw new IllegalArgumentException();\n" + >+ " }\n" + >+ " }\n" + >+ " }\n" + >+ " finally {\n" + >+ " }\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, EXPECTED_OUTPUT_WKSP2E3); >+} >+public void testBug293300_wksp2_05e() { >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X05 {\n" + >+ " void foo(int val) {\n" + >+ " try {\n" + >+ " loop: for (int i=0; i<10; i++) {\n" + >+ " switch (val) {\n" + >+ " case 1 :\n" + >+ " if (i==0) {\n" + >+ " if (true) {\n" + >+ " val++;\n" + >+ " } //these comments\n" + >+ " // may be wrongly\n" + >+ " // realigned\n" + >+ " // by the formatter\n" + >+ "\n" + >+ " // other comment\n" + >+ " val--;\n" + >+ " continue loop;\n" + >+ " }\n" + >+ " default :\n" + >+ " throw new IllegalArgumentException();\n" + >+ " }\n" + >+ " }\n" + >+ " }\n" + >+ " finally {\n" + >+ " }\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, EXPECTED_OUTPUT_WKSP2E3); >+} >+private static final String EXPECTED_OUTPUT_WKSP2E1_SPACES = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X05 {\n" + >+ " void foo(int val) {\n" + >+ " try {\n" + >+ " loop: for (int i = 0; i < 10; i++) {\n" + >+ " switch (val) {\n" + >+ " case 1:\n" + >+ " if (i == 0) {\n" + >+ " if (true) {\n" + >+ " val++;\n" + >+ " } // these comments\n" + >+ " // may be wrongly\n" + >+ " // realigned\n" + >+ " // by the formatter\n" + >+ "\n" + >+ " // other comment\n" + >+ " val--;\n" + >+ " continue loop;\n" + >+ " }\n" + >+ " default:\n" + >+ " throw new IllegalArgumentException();\n" + >+ " }\n" + >+ " }\n" + >+ " } finally {\n" + >+ " }\n" + >+ " }\n" + >+ "}\n"; >+public void testBug293300_wksp2_05_spaces() { >+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE; >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X05 {\n" + >+ " void foo(int val) {\n" + >+ " try {\n" + >+ " loop: for (int i=0; i<10; i++) {\n" + >+ " switch (val) {\n" + >+ " case 1 :\n" + >+ " if (i==0) {\n" + >+ " if (true) {\n" + >+ " val++;\n" + >+ " } //these comments\n" + >+ " // may be wrongly\n" + >+ " // realigned\n" + >+ " // by the formatter\n" + >+ "\n" + >+ " // other comment\n" + >+ " val--;\n" + >+ " continue loop;\n" + >+ " }\n" + >+ " default :\n" + >+ " throw new IllegalArgumentException();\n" + >+ " }\n" + >+ " }\n" + >+ " }\n" + >+ " finally {\n" + >+ " }\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, EXPECTED_OUTPUT_WKSP2E1_SPACES); >+} >+public void testBug293300_wksp2_05b_spaces() { >+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE; >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X05 {\n" + >+ " void foo(int val) {\n" + >+ " try {\n" + >+ " loop: for (int i=0; i<10; i++) {\n" + >+ " switch (val) {\n" + >+ " case 1 :\n" + >+ " if (i==0) {\n" + >+ " if (true) {\n" + >+ " val++;\n" + >+ " } //these comments\n" + >+ " // may be wrongly\n" + >+ " // realigned\n" + >+ " // by the formatter\n" + >+ "\n" + >+ " // other comment\n" + >+ " val--;\n" + >+ " continue loop;\n" + >+ " }\n" + >+ " default :\n" + >+ " throw new IllegalArgumentException();\n" + >+ " }\n" + >+ " }\n" + >+ " }\n" + >+ " finally {\n" + >+ " }\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, EXPECTED_OUTPUT_WKSP2E1_SPACES); >+} >+private static final String EXPECTED_OUTPUT_WKSP2E3_SPACES = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X05 {\n" + >+ " void foo(int val) {\n" + >+ " try {\n" + >+ " loop: for (int i = 0; i < 10; i++) {\n" + >+ " switch (val) {\n" + >+ " case 1:\n" + >+ " if (i == 0) {\n" + >+ " if (true) {\n" + >+ " val++;\n" + >+ " } // these comments\n" + >+ " // may be wrongly\n" + >+ " // realigned\n" + >+ " // by the formatter\n" + >+ "\n" + >+ " // other comment\n" + >+ " val--;\n" + >+ " continue loop;\n" + >+ " }\n" + >+ " default:\n" + >+ " throw new IllegalArgumentException();\n" + >+ " }\n" + >+ " }\n" + >+ " } finally {\n" + >+ " }\n" + >+ " }\n" + >+ "}\n"; >+public void testBug293300_wksp2_05c_spaces() { >+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE; >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X05 {\n" + >+ " void foo(int val) {\n" + >+ " try {\n" + >+ " loop: for (int i=0; i<10; i++) {\n" + >+ " switch (val) {\n" + >+ " case 1 :\n" + >+ " if (i==0) {\n" + >+ " if (true) {\n" + >+ " val++;\n" + >+ " } //these comments\n" + >+ " // may be wrongly\n" + >+ " // realigned\n" + >+ " // by the formatter\n" + >+ "\n" + >+ " // other comment\n" + >+ " val--;\n" + >+ " continue loop;\n" + >+ " }\n" + >+ " default :\n" + >+ " throw new IllegalArgumentException();\n" + >+ " }\n" + >+ " }\n" + >+ " }\n" + >+ " finally {\n" + >+ " }\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, EXPECTED_OUTPUT_WKSP2E3_SPACES); >+} >+public void testBug293300_wksp2_05d_spaces() { >+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE; >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X05 {\n" + >+ " void foo(int val) {\n" + >+ " try {\n" + >+ " loop: for (int i=0; i<10; i++) {\n" + >+ " switch (val) {\n" + >+ " case 1 :\n" + >+ " if (i==0) {\n" + >+ " if (true) {\n" + >+ " val++;\n" + >+ " } //these comments\n" + >+ " // may be wrongly\n" + >+ " // realigned\n" + >+ " // by the formatter\n" + >+ "\n" + >+ " // other comment\n" + >+ " val--;\n" + >+ " continue loop;\n" + >+ " }\n" + >+ " default :\n" + >+ " throw new IllegalArgumentException();\n" + >+ " }\n" + >+ " }\n" + >+ " }\n" + >+ " finally {\n" + >+ " }\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, EXPECTED_OUTPUT_WKSP2E3_SPACES); >+} >+public void testBug293300_wksp2_05e_spaces() { >+ this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE; >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X05 {\n" + >+ " void foo(int val) {\n" + >+ " try {\n" + >+ " loop: for (int i=0; i<10; i++) {\n" + >+ " switch (val) {\n" + >+ " case 1 :\n" + >+ " if (i==0) {\n" + >+ " if (true) {\n" + >+ " val++;\n" + >+ " } //these comments\n" + >+ " // may be wrongly\n" + >+ " // realigned\n" + >+ " // by the formatter\n" + >+ "\n" + >+ " // other comment\n" + >+ " val--;\n" + >+ " continue loop;\n" + >+ " }\n" + >+ " default :\n" + >+ " throw new IllegalArgumentException();\n" + >+ " }\n" + >+ " }\n" + >+ " }\n" + >+ " finally {\n" + >+ " }\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, EXPECTED_OUTPUT_WKSP2E3_SPACES); >+} >+public void testBug293300_wksp_06() { >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X06 {\n" + >+ "public static final native int foo(\n" + >+ " String field, //First field\n" + >+ " int[] array); //This comment may cause trouble for the formatter, especially if there\'s another\n" + >+ " // line below \n" + >+ "public static final native int bar();\n" + >+ "}\n"; >+ formatSource(source, >+ "package wksp2;\n" + >+ "\n" + >+ "public class X06 {\n" + >+ " public static final native int foo(String field, // First field\n" + >+ " int[] array); // This comment may cause trouble for the formatter,\n" + >+ " // especially if there\'s another\n" + >+ " // line below\n" + >+ "\n" + >+ " public static final native int bar();\n" + >+ "}\n" >+ ); >+} >+public void testBug293300_wksp_07() { >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X07 {\n" + >+ " void foo(boolean test) {\n" + >+ " if (test) {\n" + >+ " while (true) {\n" + >+ " try {\n" + >+ " try {\n" + >+ " } finally {\n" + >+ " if (true) {\n" + >+ " try {\n" + >+ " toString();\n" + >+ " } catch (Exception e) {\n" + >+ " } // nothing\n" + >+ " }\n" + >+ " } // first comment which does not move\n" + >+ "\n" + >+ " // second comment which should not move\n" + >+ " toString();\n" + >+ " } catch (Exception e) {\n" + >+ " }\n" + >+ "\n" + >+ " } // last comment\n" + >+ "\n" + >+ " }\n" + >+ "\n" + >+ " return;\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source); >+} >+public void testBug293300_wksp2_08() { >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X08 {\n" + >+ "int foo(int x) {\n" + >+ " while (x < 0) {\n" + >+ " switch (x) {\n" + >+ " \n" + >+ " }\n" + >+ " } // end while\n" + >+ "\n" + >+ " // fill in output parameter\n" + >+ " if(x > 10)\n" + >+ " x = 1;\n" + >+ "\n" + >+ " // return the value\n" + >+ " return x;\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, >+ "package wksp2;\n" + >+ "\n" + >+ "public class X08 {\n" + >+ " int foo(int x) {\n" + >+ " while (x < 0) {\n" + >+ " switch (x) {\n" + >+ "\n" + >+ " }\n" + >+ " } // end while\n" + >+ "\n" + >+ " // fill in output parameter\n" + >+ " if (x > 10)\n" + >+ " x = 1;\n" + >+ "\n" + >+ " // return the value\n" + >+ " return x;\n" + >+ " }\n" + >+ "}\n" >+ ); >+} >+public void testBug293300_wksp2_08b() { >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X08 {\n" + >+ "int foo(int x) {\n" + >+ " while (x < 0) {\n" + >+ " switch (x) {\n" + >+ " \n" + >+ " }\n" + >+ " } /* end while */\n" + >+ "\n" + >+ " // fill in output parameter\n" + >+ " if(x > 10)\n" + >+ " x = 1;\n" + >+ "\n" + >+ " // return the value\n" + >+ " return x;\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, >+ "package wksp2;\n" + >+ "\n" + >+ "public class X08 {\n" + >+ " int foo(int x) {\n" + >+ " while (x < 0) {\n" + >+ " switch (x) {\n" + >+ "\n" + >+ " }\n" + >+ " } /* end while */\n" + >+ "\n" + >+ " // fill in output parameter\n" + >+ " if (x > 10)\n" + >+ " x = 1;\n" + >+ "\n" + >+ " // return the value\n" + >+ " return x;\n" + >+ " }\n" + >+ "}\n" >+ ); >+} >+public void testBug293300_wksp2_08c() { >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X08 {\n" + >+ "int foo(int x) {\n" + >+ " while (x < 0) {\n" + >+ " switch (x) {\n" + >+ " \n" + >+ " }\n" + >+ " } /** end while */\n" + >+ "\n" + >+ " // fill in output parameter\n" + >+ " if(x > 10)\n" + >+ " x = 1;\n" + >+ "\n" + >+ " // return the value\n" + >+ " return x;\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, >+ "package wksp2;\n" + >+ "\n" + >+ "public class X08 {\n" + >+ " int foo(int x) {\n" + >+ " while (x < 0) {\n" + >+ " switch (x) {\n" + >+ "\n" + >+ " }\n" + >+ " }\n" + >+ " /** end while */\n" + >+ "\n" + >+ " // fill in output parameter\n" + >+ " if (x > 10)\n" + >+ " x = 1;\n" + >+ "\n" + >+ " // return the value\n" + >+ " return x;\n" + >+ " }\n" + >+ "}\n" >+ ); >+} >+public void testBug293300_wksp2_09() { >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X09 {\n" + >+ "void foo(int param) {\n" + >+ " int local = param - 10000; // first comment\n" + >+ " // on several lines\n" + >+ " // following unrelated comment\n" + >+ " // also on several lines\n" + >+ " int value = param + 10000;\n" + >+ "}\n" + >+ "}\n"; >+ formatSource(source, >+ "package wksp2;\n" + >+ "\n" + >+ "public class X09 {\n" + >+ " void foo(int param) {\n" + >+ " int local = param - 10000; // first comment\n" + >+ " // on several lines\n" + >+ " // following unrelated comment\n" + >+ " // also on several lines\n" + >+ " int value = param + 10000;\n" + >+ " }\n" + >+ "}\n" >+ ); >+} >+public void testBug293300_wksp2_10() { >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X10 {\n" + >+ "\n" + >+ " private String field; // Trailing comment of the field\n" + >+ " // This comment was not well formatted\n" + >+ " // as an unexpected line was inserted after the first one\n" + >+ "\n" + >+ " // -------------------------------\n" + >+ " X10() {}\n" + >+ "}\n"; >+ formatSource(source, >+ "package wksp2;\n" + >+ "\n" + >+ "public class X10 {\n" + >+ "\n" + >+ " private String field; // Trailing comment of the field\n" + >+ " // This comment was not well formatted\n" + >+ " // as an unexpected line was inserted after the\n" + >+ " // first one\n" + >+ "\n" + >+ " // -------------------------------\n" + >+ " X10() {\n" + >+ " }\n" + >+ "}\n" >+ ); >+} >+public void testBug293300_wksp2_11() { >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public abstract class X11 {\n" + >+ "\n" + >+ " // [NEW] \n" + >+ " /**\n" + >+ " * Comment foo\n" + >+ " */\n" + >+ " public abstract StringBuffer foo();\n" + >+ "//#if defined(TEST)\n" + >+ "//#else\n" + >+ "//#endif\n" + >+ "\n" + >+ " // [NEW]\n" + >+ " /**\n" + >+ " * Comment foo2\n" + >+ " */\n" + >+ " public abstract StringBuffer foo2();\n" + >+ " // [NEW]\n" + >+ " /**\n" + >+ " * Comment foo3\n" + >+ " */\n" + >+ " public abstract StringBuffer foo3();\n" + >+ "\n" + >+ "}\n"; >+ formatSource(source, >+ "package wksp2;\n" + >+ "\n" + >+ "public abstract class X11 {\n" + >+ "\n" + >+ " // [NEW]\n" + >+ " /**\n" + >+ " * Comment foo\n" + >+ " */\n" + >+ " public abstract StringBuffer foo();\n" + >+ "\n" + >+ " // #if defined(TEST)\n" + >+ " // #else\n" + >+ " // #endif\n" + >+ "\n" + >+ " // [NEW]\n" + >+ " /**\n" + >+ " * Comment foo2\n" + >+ " */\n" + >+ " public abstract StringBuffer foo2();\n" + >+ "\n" + >+ " // [NEW]\n" + >+ " /**\n" + >+ " * Comment foo3\n" + >+ " */\n" + >+ " public abstract StringBuffer foo3();\n" + >+ "\n" + >+ "}\n" >+ ); >+} >+public void testBug293300_wksp2_12a() { >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X12 {\n" + >+ "\n" + >+ "\n" + >+ " private boolean sampleField = false; //trailing comment of the field which\n" + >+ " //was wrongly formatted in previous\n" + >+ " //version as an unexpected empty lines was\n" + >+ " //inserted after the second comment line...\n" + >+ "\n" + >+ "\n" + >+ " /**\n" + >+ " Javadoc comment\n" + >+ " */\n" + >+ " public X12() {}\n" + >+ "}\n"; >+ formatSource(source, >+ "package wksp2;\n" + >+ "\n" + >+ "public class X12 {\n" + >+ "\n" + >+ " private boolean sampleField = false; // trailing comment of the field which\n" + >+ " // was wrongly formatted in previous\n" + >+ " // version as an unexpected empty\n" + >+ " // lines was\n" + >+ " // inserted after the second comment\n" + >+ " // line...\n" + >+ "\n" + >+ " /**\n" + >+ " * Javadoc comment\n" + >+ " */\n" + >+ " public X12() {\n" + >+ " }\n" + >+ "}\n" >+ ); >+} >+public void testBug293300_wksp2_12b() { >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X12 {\n" + >+ "\n" + >+ "\n" + >+ " private boolean sampleField = false; //trailing comment of the field which\n" + >+ " //was wrongly formatted in previous\n" + >+ " //version as an unexpected empty lines was\n" + >+ " //inserted after the second comment line...\n" + >+ "\n" + >+ "\n" + >+ " /**\n" + >+ " Javadoc comment\n" + >+ " */\n" + >+ " public X12() {}\n" + >+ "}\n"; >+ formatSource(source, >+ "package wksp2;\n" + >+ "\n" + >+ "public class X12 {\n" + >+ "\n" + >+ " private boolean sampleField = false; // trailing comment of the field which\n" + >+ " // was wrongly formatted in previous\n" + >+ " // version as an unexpected empty\n" + >+ " // lines was\n" + >+ " // inserted after the second comment\n" + >+ " // line...\n" + >+ "\n" + >+ " /**\n" + >+ " * Javadoc comment\n" + >+ " */\n" + >+ " public X12() {\n" + >+ " }\n" + >+ "}\n" >+ ); >+} >+public void testBug293300_wksp2_13() { >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X13 {\n" + >+ "void foo(int x) {\n" + >+ " switch (x) {\n" + >+ " default : // regular object ref\n" + >+ "// if (compileTimeType.isRawType() && runtimeTimeType.isBoundParameterizedType()) {\n" + >+ "// scope.problemReporter().unsafeRawExpression(this, compileTimeType, runtimeTimeType);\n" + >+ "// }\n" + >+ " }\n" + >+ "}\n" + >+ "}\n"; >+ formatSource(source, >+ "package wksp2;\n" + >+ "\n" + >+ "public class X13 {\n" + >+ " void foo(int x) {\n" + >+ " switch (x) {\n" + >+ " default: // regular object ref\n" + >+ " // if (compileTimeType.isRawType() &&\n" + >+ " // runtimeTimeType.isBoundParameterizedType()) {\n" + >+ " // scope.problemReporter().unsafeRawExpression(this,\n" + >+ " // compileTimeType, runtimeTimeType);\n" + >+ " // }\n" + >+ " }\n" + >+ " }\n" + >+ "}\n" >+ ); >+} >+public void testBug293300_wksp2_14() { >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public interface X14 {\n" + >+ "void foo();\n" + >+ "// line 1\n" + >+ "// line 2\n" + >+ "void bar();\n" + >+ "}\n"; >+ formatSource(source, >+ "package wksp2;\n" + >+ "\n" + >+ "public interface X14 {\n" + >+ " void foo();\n" + >+ "\n" + >+ " // line 1\n" + >+ " // line 2\n" + >+ " void bar();\n" + >+ "}\n" >+ ); >+} >+// TODO (frederic) try to fix the formatter instability in the following test case >+public void _testBug293300_wksp2_15a() { >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X15 {\n" + >+ " void foo(int[] params) {\n" + >+ " if (params.length > 0) { // trailing comment formatted in several lines...\n" + >+ "// int length = params == null ? : 0 params.length; // this commented lined causes troubles for the formatter but only if the comment starts at column 1...\n" + >+ " for (int i=0; i<params.length; i++) {\n" + >+ " }\n" + >+ " }\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, >+ "\n" + >+ "public class X15 {\n" + >+ " void foo(int[] params) {\n" + >+ " if (params.length > 0) { // trailing comment formatted in several\n" + >+ " // lines...\n" + >+ " // int length = params == null ? : 0 params.length; // this\n" + >+ " // commented\n" + >+ " // lined causes troubles for the formatter but only if the comment\n" + >+ " // starts at column 1...\n" + >+ " for (int i = 0; i < params.length; i++) {\n" + >+ " }\n" + >+ " }\n" + >+ " }\n" + >+ "}\n" >+ ); >+} >+public void testBug293300_wksp2_15b() { >+ String source = >+ "package wksp2;\n" + >+ "\n" + >+ "public class X15 {\n" + >+ " void foo(int[] params) {\n" + >+ " if (params.length > 0) { // trailing comment formatted in several lines...\n" + >+ " // int length = params == null ? : 0 params.length; // this commented lined does not cause troubles for the formatter when the comments is not on column 1...\n" + >+ " for (int i=0; i<params.length; i++) {\n" + >+ " }\n" + >+ " }\n" + >+ " }\n" + >+ "}\n"; >+ formatSource(source, >+ "package wksp2;\n" + >+ "\n" + >+ "public class X15 {\n" + >+ " void foo(int[] params) {\n" + >+ " if (params.length > 0) { // trailing comment formatted in several\n" + >+ " // lines...\n" + >+ " // int length = params == null ? : 0 params.length; // this\n" + >+ " // commented lined does not cause troubles for the formatter when\n" + >+ " // the comments is not on column 1...\n" + >+ " for (int i = 0; i < params.length; i++) {\n" + >+ " }\n" + >+ " }\n" + >+ " }\n" + >+ "}\n" >+ ); >+} >+public void testBug293300_wksp3_01() { >+ String source = >+ "package wksp3;\n" + >+ "\n" + >+ "public class X01 {\n" + >+ "static String[] constant = {\n" + >+ "// comment\n" + >+ "\"first\",\n" + >+ "// comment\n" + >+ "\"second\",\n" + >+ "};\n" + >+ "}\n"; >+ formatSource(source, >+ "package wksp3;\n" + >+ "\n" + >+ "public class X01 {\n" + >+ " static String[] constant = {\n" + >+ " // comment\n" + >+ " \"first\",\n" + >+ " // comment\n" + >+ " \"second\", };\n" + >+ "}\n" >+ ); >+} >+ >+/** > * @bug 293496: [formatter] 'insert_space_before_opening_brace_in_array_initializer' preference may be reset in certain circumstances > * @test Verify that non ArithmeticException occurs when using tab size = 0 > * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=293496" >Index: src/org/eclipse/jdt/core/tests/formatter/FormatterMassiveRegressionTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterMassiveRegressionTests.java,v >retrieving revision 1.12 >diff -u -r1.12 FormatterMassiveRegressionTests.java >--- src/org/eclipse/jdt/core/tests/formatter/FormatterMassiveRegressionTests.java 13 Nov 2009 18:33:08 -0000 1.12 >+++ src/org/eclipse/jdt/core/tests/formatter/FormatterMassiveRegressionTests.java 7 Dec 2009 17:58:09 -0000 >@@ -273,6 +273,7 @@ > private static String ECLIPSE_MILESTONE; > private static String JDT_CORE_VERSION; > private static String PATCH_BUG, PATCH_VERSION; >+ private static String TEMP_OUTPUT; > private static boolean JDT_CORE_HEAD; > private final static IPath[] EXPECTED_FAILURES = INPUT_DIR.getPath().indexOf("v34") < 0 > ? new IPath[] { >@@ -479,11 +480,13 @@ > String token = tokenizer.nextToken(); > if (token.equals("clean")) { > CLEAN = true; >+ } else if (token.equals("tmp")) { >+ TEMP_OUTPUT = PATCH_BUG; > } > } > setOutputDir(outputDir, buffer); > if (CLEAN) { >- if (PATCH_BUG != null || JDT_CORE_HEAD) { >+ if (TEMP_OUTPUT == null && (PATCH_BUG != null || JDT_CORE_HEAD)) { > System.err.println("Reference can only be updated using a version (i.e. with a closed buildnotes_jdt-core.html)!"); > System.exit(1); > } >@@ -542,6 +545,9 @@ > if (PATCH_BUG != null) { > logDir = new File(logDir, "tests"); > logDir = new File(logDir, PATCH_BUG); >+ if (TEMP_OUTPUT != null) { >+ logDir = new File(logDir, "tmp"); >+ } > logDir = new File(logDir, PATCH_VERSION); > // folder = folder.getFolder("tests"); > // if (!folder.exists()) folder.create(true, true, null); >@@ -635,6 +641,11 @@ > if (OUTPUT_DIR.getName().equals(ECLIPSE_VERSION)) { > OUTPUT_DIR = OUTPUT_DIR.getParentFile(); > } >+ >+ // Add the temporary output if any >+ if (TEMP_OUTPUT != null) { >+ OUTPUT_DIR = new File(OUTPUT_DIR, TEMP_OUTPUT); >+ } > > // Compute output sub-directories depending on profiles > if (NO_COMMENTS || BRACES != null || JOIN_LINES != null) {
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 293300
:
153921
|
153924
| 153944