### Eclipse Workspace Patch 1.0
#P org.eclipse.jdt.core
Index: buildnotes_jdt-core.html
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/buildnotes_jdt-core.html,v
retrieving revision 1.7185
diff -u -r1.7185 buildnotes_jdt-core.html
--- buildnotes_jdt-core.html 3 Nov 2009 15:54:17 -0000 1.7185
+++ buildnotes_jdt-core.html 5 Nov 2009 14:26:05 -0000
@@ -48,6 +48,7 @@
Project org.eclipse.jdt.core v_A21
(cvs).
What's new in this drop
+Patch v08 for bug 199265
Problem Reports Fixed
241549
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.220
diff -u -r1.220 CodeFormatterVisitor.java
--- formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java 25 Oct 2009 15:59:51 -0000 1.220
+++ formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java 5 Nov 2009 14:26:07 -0000
@@ -16,6 +16,7 @@
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.core.compiler.InvalidInputException;
+import org.eclipse.jdt.core.formatter.CodeFormatter;
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
import org.eclipse.jdt.internal.compiler.ASTVisitor;
import org.eclipse.jdt.internal.compiler.ast.AND_AND_Expression;
@@ -169,7 +170,6 @@
TerminalTokens.TokenNameUNSIGNED_RIGHT_SHIFT,
TerminalTokens.TokenNameGREATER
};
- private int chunkKind;
public int lastLocalDeclarationSourceStart;
private Scanner localScanner;
public DefaultCodeFormatterOptions preferences;
@@ -261,13 +261,6 @@
messageSend.traverse(builder, scope);
return builder;
}
- public boolean checkChunkStart(int kind) {
- if (this.chunkKind != kind) {
- this.chunkKind = kind;
- return true;
- }
- return false;
- }
private boolean commentStartsBlock(int start, int end) {
this.localScanner.resetTo(start, end);
@@ -439,9 +432,9 @@
for (int i = 0; i < fragmentsSize - 1; i++) {
ASTNode fragment = fragments[i];
fragment.traverse(this, scope);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
if (this.scribe.lastNumberOfNewLines == 1) {
- // a new line has been inserted by printTrailingComment()
+ // a new line has been inserted by printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT)
this.scribe.indentationLevel = binaryExpressionAlignment.breakIndentationLevel;
}
if (this.preferences.wrap_before_binary_operator) {
@@ -460,7 +453,7 @@
}
}
fragments[fragmentsSize - 1].traverse(this, scope);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
ok = true;
} catch(AlignmentException e){
this.scribe.redoAlignment(e);
@@ -616,16 +609,16 @@
if (memberAlignment != null) {
this.scribe.alignFragment(memberAlignment, 2);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
} else {
this.scribe.space();
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
}
private void format(ImportReference importRef, boolean isLast) {
this.scribe.printNextToken(TerminalTokens.TokenNameimport);
- this.preferences.number_of_empty_lines_to_preserve = this.preferences.blank_lines_between_import_groups;
+ if (!isLast) this.scribe.blank_lines_between_import_groups = this.preferences.blank_lines_between_import_groups;
this.scribe.space();
if (importRef.isStatic()) {
this.scribe.printNextToken(TerminalTokens.TokenNamestatic);
@@ -641,9 +634,11 @@
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
}
if (isLast) {
- this.scribe.printTrailingComment();
+ this.scribe.blank_lines_between_import_groups = -1;
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.IMPORT_TRAILING_COMMENT);
} else {
- this.scribe.printTrailingComment(this.preferences.blank_lines_between_import_groups);
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.NO_TRAILING_COMMENT);
+ this.scribe.blank_lines_between_import_groups = -1;
}
this.scribe.printNewLine();
}
@@ -726,7 +721,7 @@
if (i != length - 1) {
this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_multiple_field_declarations);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
this.scribe.alignFragment(multiFieldDeclarationsAlignment, i);
if (this.preferences.insert_space_after_comma_in_multiple_field_declarations) {
@@ -735,7 +730,7 @@
} else {
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
this.scribe.alignFragment(fieldAlignment, 2);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
}
ok = true;
@@ -1048,7 +1043,7 @@
for (int i = 0; i < superInterfaceLength; i++) {
if (i > 0) {
this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_superinterfaces);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
this.scribe.alignFragment(interfaceAlignment, i+1);
if (this.preferences.insert_space_after_comma_in_superinterfaces) {
this.scribe.space();
@@ -1143,7 +1138,7 @@
if (this.preferences.insert_space_after_comma_in_enum_declarations) {
this.scribe.space();
}
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
if (fieldDeclaration.initialization instanceof QualifiedAllocationExpression) {
this.scribe.printNewLine();
}
@@ -1164,7 +1159,7 @@
if (this.preferences.insert_space_after_comma_in_enum_declarations) {
this.scribe.space();
}
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
if (fieldDeclaration.initialization instanceof QualifiedAllocationExpression) {
this.scribe.printNewLine();
}
@@ -1173,7 +1168,7 @@
}
if (isNextToken(TerminalTokens.TokenNameSEMICOLON)) {
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
if (hasConstants
|| ((enumConstantsLength - length) != 0)
|| typeDeclaration.methods != null
@@ -1210,7 +1205,7 @@
}
}
this.scribe.printNextToken(TerminalTokens.TokenNameRBRACE);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
if (class_declaration_brace.equals(DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED)) {
this.scribe.unIndent();
}
@@ -1305,7 +1300,7 @@
}
}
this.scribe.printNextToken(TerminalTokens.TokenNameRBRACE);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
if (DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED.equals(block_brace_position)) {
this.scribe.unIndent();
}
@@ -1367,7 +1362,7 @@
for (int j = 0; j < argumentLength; j++) {
if (j > 0) {
this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_method_invocation_arguments);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
this.scribe.alignFragment(argumentsAlignment, j);
if (j > 0 && this.preferences.insert_space_after_comma_in_method_invocation_arguments) {
@@ -1452,7 +1447,7 @@
for (int j = 0; j < argumentLength; j++) {
if (j > 0) {
this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_method_invocation_arguments);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
this.scribe.alignFragment(argumentsAlignment, j);
if (j > 0 && this.preferences.insert_space_after_comma_in_method_invocation_arguments) {
@@ -1532,7 +1527,7 @@
}
if (isNextToken(TerminalTokens.TokenNameSEMICOLON)) {
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
if (i != max - 1) {
this.scribe.printNewLine();
@@ -1556,7 +1551,7 @@
while(isNextToken(TerminalTokens.TokenNameSEMICOLON)) {
this.scribe.printComment();
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
if (hasSemiColon && isFirst) {
this.scribe.printNewLine();
@@ -1571,7 +1566,7 @@
final Statement[] statements = block.statements;
statements[0].traverse(this, scope);
this.scribe.printNextToken(TerminalTokens.TokenNameRBRACE, true);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
private void formatLeftCurlyBrace(final int line, final String bracePosition) {
@@ -1657,7 +1652,7 @@
if (insertSpaceAfterComma) {
this.scribe.space();
}
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
}
@@ -1714,7 +1709,7 @@
for (int i = 0; i < argumentsLength; i++) {
if (i > 0) {
this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_method_invocation_arguments);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
this.scribe.alignFragment(argumentsAlignment, i);
if (i > 0 && this.preferences.insert_space_after_comma_in_method_invocation_arguments) {
@@ -1732,7 +1727,7 @@
for (int i = 0; i < argumentsLength; i++) {
if (i > 0) {
this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_method_invocation_arguments);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
if (i > 0 && this.preferences.insert_space_after_comma_in_method_invocation_arguments) {
this.scribe.space();
@@ -1776,7 +1771,7 @@
for (int i = 0; i < argumentLength; i++) {
if (i > 0) {
this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, spaceBeforeComma);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
this.scribe.alignFragment(argumentsAlignment, i);
if (i > 0 && spaceAfterComma) {
@@ -1830,7 +1825,7 @@
for (int i = 0; i < argumentLength; i++) {
if (i > 0) {
this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, spaceBeforeComma);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
this.scribe.alignFragment(argumentsAlignment, i);
if (i > 0 && spaceAfterComma) {
@@ -1856,11 +1851,11 @@
this.scribe.printNewLine();
this.scribe.indent();
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
this.scribe.unIndent();
} else {
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
}
@@ -1873,7 +1868,7 @@
this.scribe.indent();
}
this.scribe.printNextToken(TerminalTokens.TokenNameLBRACE, insertSpaceBeforeBrace);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
private void formatStatements(BlockScope scope, final Statement[] statements, boolean insertNewLineAfterLastStatement) {
int statementsLength = statements.length;
@@ -1885,7 +1880,7 @@
statement.traverse(this, scope);
if (statement instanceof Expression) {
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
if (i != statementsLength - 1) {
if (!(statement instanceof EmptyStatement) && !(statements[i + 1] instanceof EmptyStatement)) {
this.scribe.printNewLine();
@@ -1903,7 +1898,7 @@
LocalDeclaration nextLocal = (LocalDeclaration) statements[i + 1];
if (currentLocal.declarationSourceStart != nextLocal.declarationSourceStart) {
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
if (i != statementsLength - 1) {
if (!(statement instanceof EmptyStatement) && !(statements[i + 1] instanceof EmptyStatement)) {
this.scribe.printNewLine();
@@ -1914,7 +1909,7 @@
}
} else {
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
if (i != statementsLength - 1) {
if (!(statement instanceof EmptyStatement) && !(statements[i + 1] instanceof EmptyStatement)) {
this.scribe.printNewLine();
@@ -1925,7 +1920,7 @@
}
} else {
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
if (i != statementsLength - 1) {
if (!(statement instanceof EmptyStatement) && !(statements[i + 1] instanceof EmptyStatement)) {
this.scribe.printNewLine();
@@ -1969,7 +1964,7 @@
for (int i = 0; i < thrownExceptionsLength; i++) {
if (i > 0) {
this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, spaceBeforeComma);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
this.scribe.alignFragment(throwsAlignment, i);
if (spaceAfterComma) {
this.scribe.space();
@@ -2047,7 +2042,7 @@
}
if (isNextToken(TerminalTokens.TokenNameSEMICOLON)) {
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
this.scribe.printNewLine();
// realign to the proper value
@@ -2065,7 +2060,7 @@
} else if (isNextToken(TerminalTokens.TokenNameSEMICOLON)) {
// the only body declaration is an empty declaration (';')
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
this.scribe.printComment();
this.scribe.exitMemberAlignment(memberAlignment);
@@ -2296,7 +2291,7 @@
case TerminalTokens.TokenNameCOMMENT_JAVADOC :
case TerminalTokens.TokenNameCOMMENT_BLOCK :
case TerminalTokens.TokenNameCOMMENT_LINE :
- this.scribe.printComment(token);
+ this.scribe.printComment(token, Scribe.NO_TRAILING_COMMENT);
break;
}
} catch(InvalidInputException e) {
@@ -2364,7 +2359,7 @@
for (int i = 0; i < argumentLength; i++) {
if (i > 0) {
this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_allocation_expression);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
this.scribe.alignFragment(argumentsAlignment, i);
if (i > 0 && this.preferences.insert_space_after_comma_in_allocation_expression) {
@@ -2441,7 +2436,7 @@
defaultValue.traverse(this, (BlockScope) null);
}
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
return false;
}
@@ -2577,7 +2572,7 @@
expressions[0].traverse(this, scope);
for (int i = 1; i < expressionsLength; i++) {
this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_array_initializer);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
this.scribe.alignFragment(arrayInitializerAlignment, i);
if (this.preferences.insert_space_after_comma_in_array_initializer) {
this.scribe.space();
@@ -2586,7 +2581,7 @@
if (i == expressionsLength - 1) {
if (isNextToken(TerminalTokens.TokenNameCOMMA)) {
this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_array_initializer);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
}
}
@@ -2610,7 +2605,7 @@
expressions[0].traverse(this, scope);
if (isNextToken(TerminalTokens.TokenNameCOMMA)) {
this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_array_initializer);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
if (insert_new_line_after_opening_brace) {
this.scribe.unIndent();
@@ -2632,14 +2627,14 @@
this.scribe.printNextToken(TerminalTokens.TokenNameLBRACE, this.preferences.insert_space_before_opening_brace_in_array_initializer);
if (isNextToken(TerminalTokens.TokenNameCOMMA)) {
this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_array_initializer);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
this.scribe.printNextToken(TerminalTokens.TokenNameRBRACE, this.preferences.insert_space_between_empty_braces_in_array_initializer);
} else {
formatOpeningBrace(array_initializer_brace_position, this.preferences.insert_space_before_opening_brace_in_array_initializer);
if (isNextToken(TerminalTokens.TokenNameCOMMA)) {
this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_array_initializer);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
this.scribe.printNextToken(TerminalTokens.TokenNameRBRACE, this.preferences.insert_space_between_empty_braces_in_array_initializer);
if (array_initializer_brace_position.equals(DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED)) {
@@ -2808,7 +2803,7 @@
assertStatement.exceptionArgument.traverse(this, scope);
}
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
return false;
}
@@ -2906,7 +2901,7 @@
this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier, true);
}
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
return false;
}
@@ -3034,7 +3029,7 @@
this.scribe.space();
this.scribe.printQualifiedReference(compilationUnitDeclaration.currentPackage.sourceEnd, false/*do not expect parenthesis*/);
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
int blankLinesAfterPackage = this.preferences.blank_lines_after_package;
if (blankLinesAfterPackage > 0) {
this.scribe.printEmptyLines(blankLinesAfterPackage);
@@ -3057,18 +3052,15 @@
}
}
int importLength = imports.length;
- int savedNumberOfLineToPreserve = this.preferences.number_of_empty_lines_to_preserve;
if (importLength != 1) {
format(imports[0], false);
for (int i = 1; i < importLength - 1; i++) {
format(imports[i], false);
}
format(imports[importLength - 1], true);
- this.preferences.number_of_empty_lines_to_preserve = savedNumberOfLineToPreserve;
} else {
format(imports[0], true);
}
- this.preferences.number_of_empty_lines_to_preserve = savedNumberOfLineToPreserve;
int blankLinesAfterImports = this.preferences.blank_lines_after_imports;
if (blankLinesAfterImports > 0) {
@@ -3205,7 +3197,7 @@
this.scribe.space();
}
conditionalExpression.valueIfTrue.traverse(this, scope);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
this.scribe.alignFragment(conditionalExpressionAlignment, 1);
this.scribe.printNextToken(TerminalTokens.TokenNameCOLON, this.preferences.insert_space_before_colon_in_conditional);
@@ -3241,7 +3233,7 @@
this.scribe.printIndentationIfNecessary();
}
this.scribe.scanner.resetTo(constructorDeclaration.declarationSourceEnd + 1, this.scribe.scannerEndPosition - 1);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
switch(this.scribe.scanner.source[this.scribe.scanner.currentPosition]) {
case '\n' :
this.scribe.scanner.currentPosition++;
@@ -3356,14 +3348,14 @@
}
}
this.scribe.printNextToken(TerminalTokens.TokenNameRBRACE);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
if (constructor_declaration_brace.equals(DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED)) {
this.scribe.unIndent();
}
} else {
// no method body
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
return false;
}
@@ -3378,7 +3370,7 @@
this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier, true);
}
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
return false;
}
@@ -3407,7 +3399,7 @@
action.traverse(this, scope);
if (action instanceof Expression) {
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
this.scribe.printNewLine();
this.scribe.unIndent();
@@ -3433,7 +3425,7 @@
this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN, this.preferences.insert_space_before_closing_paren_in_while);
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
return false;
}
@@ -3466,7 +3458,7 @@
this.scribe.printNewLine();
}
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
return false;
}
// field is an enum constant
@@ -3519,7 +3511,7 @@
this.scribe.printNewLine();
}
this.scribe.printNextToken(TerminalTokens.TokenNameRBRACE);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
if (enum_constant_brace.equals(DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED)) {
this.scribe.unIndent();
}
@@ -3605,7 +3597,7 @@
for (int i = 0; i < argumentLength; i++) {
if (i > 0) {
this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_explicit_constructor_call_arguments);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
this.scribe.alignFragment(argumentsAlignment, i);
if (i > 0 && this.preferences.insert_space_after_comma_in_explicit_constructor_call_arguments) {
@@ -3624,7 +3616,7 @@
this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN, this.preferences.insert_space_between_empty_parens_in_method_invocation);
}
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
return false;
}
/**
@@ -3718,7 +3710,7 @@
}
if (action instanceof Expression) {
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
} else {
/*
@@ -3754,7 +3746,7 @@
if (this.preferences.insert_space_after_comma_in_for_inits) {
this.scribe.space();
}
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
}
}
@@ -3780,7 +3772,7 @@
if (this.preferences.insert_space_after_comma_in_for_increments) {
this.scribe.space();
}
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
}
}
@@ -3804,7 +3796,7 @@
}
if (action instanceof Expression) {
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
} else {
/*
@@ -3869,7 +3861,7 @@
thenStatement.traverse(this, scope);
if (thenStatement instanceof Expression) {
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
ok = true;
} catch (AlignmentException e) {
@@ -3882,19 +3874,19 @@
thenStatement.traverse(this, scope);
if (thenStatement instanceof Expression) {
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
if (elseStatement != null) {
this.scribe.printNewLine();
}
} else {
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
this.scribe.printNewLine();
this.scribe.indent();
thenStatement.traverse(this, scope);
if (thenStatement instanceof Expression) {
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
if (elseStatement != null) {
this.scribe.printNewLine();
@@ -3926,7 +3918,7 @@
elseStatement.traverse(this, scope);
if (elseStatement instanceof Expression) {
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
} else {
this.scribe.printNewLine();
@@ -3934,7 +3926,7 @@
elseStatement.traverse(this, scope);
if (elseStatement instanceof Expression) {
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
this.scribe.unIndent();
}
@@ -4011,7 +4003,7 @@
statement.traverse(this, scope);
if (statement instanceof Expression) {
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
return false;
}
@@ -4125,7 +4117,7 @@
this.scribe.printIndentationIfNecessary();
}
this.scribe.scanner.resetTo(methodDeclaration.declarationSourceEnd + 1, this.scribe.scannerEndPosition - 1);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
if (!this.scribe.scanner.atEnd()) {
switch(this.scribe.scanner.source[this.scribe.scanner.currentPosition]) {
case '\n' :
@@ -4255,14 +4247,14 @@
}
}
this.scribe.printNextToken(TerminalTokens.TokenNameRBRACE);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
if (method_declaration_brace.equals(DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED)) {
this.scribe.unIndent();
}
} else {
// no method body
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
return false;
}
@@ -4621,7 +4613,7 @@
for (int i = 0; i < argumentLength; i++) {
if (i > 0) {
this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_allocation_expression);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
this.scribe.alignFragment(argumentsAlignment, i);
if (i > 0 && this.preferences.insert_space_after_comma_in_allocation_expression) {
@@ -4768,7 +4760,7 @@
* Print the semi-colon
*/
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
return false;
}
public boolean visit(SingleMemberAnnotation annotation, BlockScope scope) {
@@ -4850,7 +4842,7 @@
}
this.scribe.checkNLSTag(stringLiteral.sourceStart);
this.scribe.printNextToken(TerminalTokens.TokenNameStringLiteral);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
if (numberOfParens > 0) {
manageClosingParenthesizedExpression(stringLiteral, numberOfParens);
}
@@ -4877,9 +4869,9 @@
for (int i = 0; i < fragmentsSize - 1; i++) {
ASTNode fragment = fragments[i];
fragment.traverse(this, scope);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
if (this.scribe.lastNumberOfNewLines == 1) {
- // a new line has been inserted by printTrailingComment()
+ // a new line has been inserted by printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT)
this.scribe.indentationLevel = binaryExpressionAlignment.breakIndentationLevel;
}
this.scribe.alignFragment(binaryExpressionAlignment, i);
@@ -4889,7 +4881,7 @@
}
}
fragments[fragmentsSize - 1].traverse(this, scope);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
ok = true;
} catch(AlignmentException e){
this.scribe.redoAlignment(e);
@@ -4959,7 +4951,7 @@
this.scribe.unIndent();
}
statement.traverse(this, scope);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
wasACase = true;
wasAStatement = false;
if (this.preferences.indent_switchstatements_compare_to_cases) {
@@ -5017,7 +5009,7 @@
* Print the semi-colon
*/
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
this.scribe.printNewLine();
} else if (statement instanceof LocalDeclaration) {
LocalDeclaration currentLocal = (LocalDeclaration) statement;
@@ -5032,7 +5024,7 @@
* Print the semi-colon
*/
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
this.scribe.printNewLine();
}
} else {
@@ -5040,7 +5032,7 @@
* Print the semi-colon
*/
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
this.scribe.printNewLine();
}
} else {
@@ -5048,7 +5040,7 @@
* Print the semi-colon
*/
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
this.scribe.printNewLine();
}
} else if (!wasACase) {
@@ -5066,7 +5058,7 @@
}
this.scribe.printNewLine();
this.scribe.printNextToken(TerminalTokens.TokenNameRBRACE);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
if (switch_brace.equals(DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED)) {
this.scribe.unIndent();
}
@@ -5133,7 +5125,7 @@
* Print the semi-colon
*/
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
return false;
}
@@ -5385,7 +5377,7 @@
action.traverse(this, scope);
if (action instanceof Expression) {
this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
- this.scribe.printTrailingComment();
+ this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
this.scribe.unIndent();
}
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.178
diff -u -r1.178 Scribe.java
--- formatter/org/eclipse/jdt/internal/formatter/Scribe.java 28 Oct 2009 09:57:10 -0000 1.178
+++ formatter/org/eclipse/jdt/internal/formatter/Scribe.java 5 Nov 2009 14:26:09 -0000
@@ -96,8 +96,9 @@
public int numberOfIndentations;
private boolean useTabsOnlyForLeadingIndents;
- /** indent empty lines*/
+ /** empty lines*/
private final boolean indentEmptyLines;
+ int blank_lines_between_import_groups = -1;
/* Comments formatting */
private static final int INCLUDE_BLOCK_COMMENTS = CodeFormatter.F_INCLUDE_COMMENTS | CodeFormatter.K_MULTI_LINE_COMMENT;
@@ -105,6 +106,9 @@
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;
private int formatComments = 0;
private int headerEndPosition = -1;
String commentIndentation; // indentation requested in comments (usually in javadoc root tags description)
@@ -1065,6 +1069,9 @@
}
return Util.EMPTY_STRING;
}
+ if (this.blank_lines_between_import_groups >= 0) {
+ return getEmptyLines(this.blank_lines_between_import_groups);
+ }
if (this.formatter.preferences.number_of_empty_lines_to_preserve != 0) {
int linesToPreserve = Math.min(count, this.formatter.preferences.number_of_empty_lines_to_preserve);
return getEmptyLines(linesToPreserve);
@@ -1310,9 +1317,11 @@
private void preserveEmptyLines(int count, int insertPosition) {
if (count > 0) {
- if (this.formatter.preferences.number_of_empty_lines_to_preserve != 0) {
+ if (this.blank_lines_between_import_groups >= 0) {
+ printEmptyLines(this.blank_lines_between_import_groups, insertPosition);
+ } else if (this.formatter.preferences.number_of_empty_lines_to_preserve != 0) {
int linesToPreserve = Math.min(count, this.formatter.preferences.number_of_empty_lines_to_preserve);
- this.printEmptyLines(linesToPreserve, insertPosition);
+ printEmptyLines(linesToPreserve, insertPosition);
} else {
printNewLine(insertPosition);
}
@@ -2052,13 +2061,13 @@
}
void printComment() {
- printComment(CodeFormatter.K_UNKNOWN);
+ printComment(CodeFormatter.K_UNKNOWN, NO_TRAILING_COMMENT);
}
/*
* Main method to print and format comments (javadoc, block and single line comments)
*/
- void printComment(int kind) {
+ void printComment(int kind, int trailing) {
final boolean rejectLineComment = kind == CodeFormatter.K_MULTI_LINE_COMMENT || kind == CodeFormatter.K_JAVA_DOC;
final boolean rejectBlockComment = kind == CodeFormatter.K_SINGLE_LINE_COMMENT || kind == CodeFormatter.K_JAVA_DOC;
final boolean rejectJavadocComment = kind == CodeFormatter.K_SINGLE_LINE_COMMENT || kind == CodeFormatter.K_MULTI_LINE_COMMENT;
@@ -2067,13 +2076,15 @@
int currentTokenStartPosition = this.scanner.currentPosition;
boolean hasComment = false;
boolean hasLineComment = false;
- boolean hasWhitespace = false;
- int count = 0;
+ boolean hasWhitespaces = false;
+ int lines = 0;
while ((this.currentToken = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
switch(this.currentToken) {
case TerminalTokens.TokenNameWHITESPACE :
char[] whiteSpaces = this.scanner.getCurrentTokenSource();
- count = 0;
+ int whitespacesStartPosition = this.scanner.getCurrentTokenStartPosition();
+ int whitespacesEndPosition = this.scanner.getCurrentTokenEndPosition();
+ lines = 0;
for (int i = 0, max = whiteSpaces.length; i < max; i++) {
switch(whiteSpaces[i]) {
case '\r' :
@@ -2082,79 +2093,141 @@
i++;
}
}
- count++;
+ lines++;
break;
case '\n' :
- count++;
+ lines++;
}
}
- if (count == 0) {
- hasWhitespace = true;
- addDeleteEdit(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition());
- } else if (hasLineComment) {
- preserveEmptyLines(count, this.scanner.getCurrentTokenStartPosition());
- addDeleteEdit(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition());
- } else if (hasComment) {
- if (count == 1) {
- this.printNewLine(this.scanner.getCurrentTokenStartPosition());
- } else {
- preserveEmptyLines(count - 1, this.scanner.getCurrentTokenStartPosition());
+ // 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 (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' :
+ realTrailing = false;
+ break loop;
+ }
+ }
+ }
}
- addDeleteEdit(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition());
- } else if (count != 0 && (!this.formatter.preferences.join_wrapped_lines || this.formatter.preferences.number_of_empty_lines_to_preserve != 0)) {
- addReplaceEdit(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition(), getPreserveEmptyLines(count-1));
+ this.scanner.resetTo(currentPosition, this.scanner.eofPosition - 1);
+ }
+ if (realTrailing) {
+ // if a line comment is consumed, no other comment can be on the same line after
+ if (hasLineComment) {
+ if (lines >= 1) {
+ currentTokenStartPosition = whitespacesStartPosition;
+ preserveEmptyLines(lines, currentTokenStartPosition);
+ addDeleteEdit(currentTokenStartPosition, whitespacesEndPosition);
+ this.scanner.resetTo(this.scanner.currentPosition, this.scannerEndPosition - 1);
+ return;
+ }
+ this.scanner.resetTo(currentTokenStartPosition, this.scannerEndPosition - 1);
+ return;
+ }
+ // if one or several new lines are consumed, following comments cannot be considered as trailing ones
+ if (lines >= 1) {
+ if (hasComment) {
+ this.printNewLine(whitespacesStartPosition);
+ }
+ this.scanner.resetTo(currentTokenStartPosition, this.scannerEndPosition - 1);
+ return;
+ }
+ // delete consumed white spaces
+ hasWhitespaces = true;
+ currentTokenStartPosition = this.scanner.currentPosition;
+ addDeleteEdit(whitespacesStartPosition, whitespacesEndPosition);
} else {
- addDeleteEdit(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition());
+ if (lines == 0) {
+ hasWhitespaces = true;
+ addDeleteEdit(whitespacesStartPosition, whitespacesEndPosition);
+ } else if (hasLineComment) {
+ currentTokenStartPosition = whitespacesStartPosition;
+ preserveEmptyLines(lines, currentTokenStartPosition);
+ addDeleteEdit(currentTokenStartPosition, whitespacesEndPosition);
+ } else if (hasComment) {
+ if (lines == 1) {
+ this.printNewLine(whitespacesStartPosition);
+ } else {
+ preserveEmptyLines(lines - 1, whitespacesStartPosition);
+ }
+ addDeleteEdit(whitespacesStartPosition, whitespacesEndPosition);
+ } else if (lines != 0 && (!this.formatter.preferences.join_wrapped_lines || this.formatter.preferences.number_of_empty_lines_to_preserve != 0)) {
+ addReplaceEdit(whitespacesStartPosition, whitespacesEndPosition, getPreserveEmptyLines(lines-1));
+ } else {
+ addDeleteEdit(whitespacesStartPosition, whitespacesEndPosition);
+ }
}
currentTokenStartPosition = this.scanner.currentPosition;
break;
case TerminalTokens.TokenNameCOMMENT_LINE :
if (rejectLineComment) break;
- if (count >= 1) {
- if (count > 1) {
- preserveEmptyLines(count - 1, this.scanner.getCurrentTokenStartPosition());
- } else if (count == 1) {
+ if (lines >= 1) {
+ if (lines > 1) {
+ preserveEmptyLines(lines - 1, this.scanner.getCurrentTokenStartPosition());
+ } else if (lines == 1) {
printNewLine(this.scanner.getCurrentTokenStartPosition());
}
- } else if (hasWhitespace) {
+ } else if (hasWhitespaces) {
space();
}
- hasWhitespace = false;
+ hasWhitespaces = false;
printLineComment();
currentTokenStartPosition = this.scanner.currentPosition;
hasLineComment = true;
- count = 0;
+ lines = 0;
break;
case TerminalTokens.TokenNameCOMMENT_BLOCK :
+ if (trailing > NO_TRAILING_COMMENT && lines >= 1) {
+ // a block comment on next line means that there's no trailing comment
+ this.scanner.resetTo(this.scanner.getCurrentTokenStartPosition(), this.scannerEndPosition - 1);
+ return;
+ }
if (rejectBlockComment) break;
- if (count >= 1) {
- if (count > 1) {
- preserveEmptyLines(count - 1, this.scanner.getCurrentTokenStartPosition());
- } else if (count == 1) {
+ if (lines >= 1) {
+ if (lines > 1) {
+ preserveEmptyLines(lines - 1, this.scanner.getCurrentTokenStartPosition());
+ } else if (lines == 1) {
printNewLine(this.scanner.getCurrentTokenStartPosition());
}
- } else if (hasWhitespace) {
+ } else if (hasWhitespaces) {
space();
}
- hasWhitespace = false;
+ hasWhitespaces = false;
printBlockComment(false);
currentTokenStartPosition = this.scanner.currentPosition;
hasLineComment = false;
hasComment = true;
- count = 0;
+ lines = 0;
break;
case TerminalTokens.TokenNameCOMMENT_JAVADOC :
+ if (trailing > NO_TRAILING_COMMENT) {
+ // a javadoc comment should not be considered as a trailing comment
+ this.scanner.resetTo(this.scanner.getCurrentTokenStartPosition(), this.scannerEndPosition - 1);
+ return;
+ }
if (rejectJavadocComment) break;
- if (count >= 1) {
- if (count > 1) {
- preserveEmptyLines(count - 1, this.scanner.getCurrentTokenStartPosition());
- } else if (count == 1) {
+ if (lines >= 1) {
+ if (lines > 1) {
+ preserveEmptyLines(lines - 1, this.scanner.getCurrentTokenStartPosition());
+ } else if (lines == 1) {
printNewLine(this.scanner.getCurrentTokenStartPosition());
}
- } else if (hasWhitespace) {
+ } else if (hasWhitespaces) {
space();
}
- hasWhitespace = false;
+ hasWhitespaces = false;
if (includesJavadocComments()) {
printJavadocComment(this.scanner.startPosition, this.scanner.currentPosition);
} else {
@@ -2164,7 +2237,7 @@
currentTokenStartPosition = this.scanner.currentPosition;
hasLineComment = false;
hasComment = true;
- count = 0;
+ lines = 0;
break;
default :
// step back one token
@@ -2196,10 +2269,10 @@
// Print corresponding comment
switch (kind) {
case CodeFormatter.K_SINGLE_LINE_COMMENT:
- printComment(kind);
+ printComment(kind, NO_TRAILING_COMMENT);
break;
case CodeFormatter.K_MULTI_LINE_COMMENT:
- printComment(kind);
+ printComment(kind, NO_TRAILING_COMMENT);
break;
case CodeFormatter.K_JAVA_DOC:
printJavadocComment(start, end);
@@ -3898,7 +3971,7 @@
this.formatBrace = true;
}
try {
- printComment(CodeFormatter.K_UNKNOWN);
+ printComment(CodeFormatter.K_UNKNOWN, NO_TRAILING_COMMENT);
try {
this.currentToken = this.scanner.getNextToken();
if (expectedTokenType != this.currentToken) {
@@ -3924,7 +3997,7 @@
}
public void printNextToken(int[] expectedTokenTypes, boolean considerSpaceIfAny){
- printComment(CodeFormatter.K_UNKNOWN);
+ printComment(CodeFormatter.K_UNKNOWN, NO_TRAILING_COMMENT);
try {
this.currentToken = this.scanner.getNextToken();
if (Arrays.binarySearch(expectedTokenTypes, this.currentToken) < 0) {
@@ -3948,7 +4021,7 @@
int numberOfIdentifiers = 0;
try {
do {
- printComment(CodeFormatter.K_UNKNOWN);
+ printComment(CodeFormatter.K_UNKNOWN, NO_TRAILING_COMMENT);
switch(this.currentToken = this.scanner.getNextToken()) {
case TerminalTokens.TokenNameEOF :
return;
@@ -3994,7 +4067,7 @@
int currentTokenStartPosition = this.scanner.currentPosition;
try {
do {
- printComment(CodeFormatter.K_UNKNOWN);
+ printComment(CodeFormatter.K_UNKNOWN, NO_TRAILING_COMMENT);
switch(this.currentToken = this.scanner.getNextToken()) {
case TerminalTokens.TokenNameEOF :
return;
@@ -4048,151 +4121,6 @@
}
}
- public void printTrailingComment(int numberOfNewLinesToInsert) {
- try {
- // if we have a space between two tokens we ensure it will be dumped in the formatted string
- int currentTokenStartPosition = this.scanner.currentPosition;
- boolean hasWhitespaces = false;
- boolean hasLineComment = false;
- while ((this.currentToken = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
- switch(this.currentToken) {
- case TerminalTokens.TokenNameWHITESPACE :
- int count = 0;
- char[] whiteSpaces = this.scanner.getCurrentTokenSource();
- for (int i = 0, max = whiteSpaces.length; i < max; i++) {
- switch(whiteSpaces[i]) {
- case '\r' :
- if ((i + 1) < max) {
- if (whiteSpaces[i + 1] == '\n') {
- i++;
- }
- }
- count++;
- break;
- case '\n' :
- count++;
- }
- }
- if (hasLineComment) {
- if (count >= 1) {
- currentTokenStartPosition = this.scanner.getCurrentTokenStartPosition();
- preserveEmptyLines(numberOfNewLinesToInsert, currentTokenStartPosition);
- addDeleteEdit(currentTokenStartPosition, this.scanner.getCurrentTokenEndPosition());
- this.scanner.resetTo(this.scanner.currentPosition, this.scannerEndPosition - 1);
- return;
- }
- this.scanner.resetTo(currentTokenStartPosition, this.scannerEndPosition - 1);
- return;
- } else if (count > 1) {
- this.printEmptyLines(numberOfNewLinesToInsert, this.scanner.getCurrentTokenStartPosition());
- this.scanner.resetTo(currentTokenStartPosition, this.scannerEndPosition - 1);
- return;
- } else {
- hasWhitespaces = true;
- currentTokenStartPosition = this.scanner.currentPosition;
- addDeleteEdit(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition());
- }
- break;
- case TerminalTokens.TokenNameCOMMENT_LINE :
- if (hasWhitespaces) {
- space();
- }
- printLineComment();
- currentTokenStartPosition = this.scanner.currentPosition;
- hasLineComment = true;
- break;
- case TerminalTokens.TokenNameCOMMENT_BLOCK :
- if (hasWhitespaces) {
- space();
- }
- printBlockComment(false);
- currentTokenStartPosition = this.scanner.currentPosition;
- break;
- default :
- // step back one token
- this.scanner.resetTo(currentTokenStartPosition, this.scannerEndPosition - 1);
- return;
- }
- }
- } catch (InvalidInputException e) {
- throw new AbortFormatting(e);
- }
- }
- public void printTrailingComment() {
- try {
- // if we have a space between two tokens we ensure it will be dumped in the formatted string
- int currentTokenStartPosition = this.scanner.currentPosition;
- boolean hasWhitespaces = false;
- boolean hasComment = false;
- boolean hasLineComment = false;
- while ((this.currentToken = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
- switch(this.currentToken) {
- case TerminalTokens.TokenNameWHITESPACE :
- int count = 0;
- char[] whiteSpaces = this.scanner.getCurrentTokenSource();
- for (int i = 0, max = whiteSpaces.length; i < max; i++) {
- switch(whiteSpaces[i]) {
- case '\r' :
- if ((i + 1) < max) {
- if (whiteSpaces[i + 1] == '\n') {
- i++;
- }
- }
- count++;
- break;
- case '\n' :
- count++;
- }
- }
- if (hasLineComment) {
- if (count >= 1) {
- currentTokenStartPosition = this.scanner.getCurrentTokenStartPosition();
- preserveEmptyLines(count, currentTokenStartPosition);
- addDeleteEdit(currentTokenStartPosition, this.scanner.getCurrentTokenEndPosition());
- this.scanner.resetTo(this.scanner.currentPosition, this.scannerEndPosition - 1);
- return;
- }
- this.scanner.resetTo(currentTokenStartPosition, this.scannerEndPosition - 1);
- return;
- } else if (count >= 1) {
- if (hasComment) {
- this.printNewLine(this.scanner.getCurrentTokenStartPosition());
- }
- this.scanner.resetTo(currentTokenStartPosition, this.scannerEndPosition - 1);
- return;
- } else {
- hasWhitespaces = true;
- currentTokenStartPosition = this.scanner.currentPosition;
- addDeleteEdit(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition());
- }
- break;
- case TerminalTokens.TokenNameCOMMENT_LINE :
- if (hasWhitespaces) {
- space();
- }
- printLineComment();
- currentTokenStartPosition = this.scanner.currentPosition;
- hasLineComment = true;
- break;
- case TerminalTokens.TokenNameCOMMENT_BLOCK :
- if (hasWhitespaces) {
- space();
- }
- printBlockComment(false);
- currentTokenStartPosition = this.scanner.currentPosition;
- hasComment = true;
- break;
- default :
- // step back one token
- this.scanner.resetTo(currentTokenStartPosition, this.scannerEndPosition - 1);
- return;
- }
- }
- } catch (InvalidInputException e) {
- throw new AbortFormatting(e);
- }
- }
-
void redoAlignment(AlignmentException e){
if (e.relativeDepth > 0) { // if exception targets a distinct context
e.relativeDepth--; // record fact that current context got traversed
#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.5
diff -u -r1.5 FormatterBugsTests.java
--- src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java 28 Oct 2009 09:57:06 -0000 1.5
+++ src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java 5 Nov 2009 14:26:12 -0000
@@ -312,6 +312,148 @@
}
/**
+ * @bug 199265: [formatter] 3.3 Code Formatter mis-places commented-out import statements
+ * @test Ensure that the formatter keep commented import declarations on their lines
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=199265"
+ */
+public void testBug199265a() throws JavaModelException {
+ String source =
+ "import java.util.List;\n" +
+ "//import java.util.HashMap;\n" +
+ "import java.util.Set;\n" +
+ "\n" +
+ "public class X01 {\n" +
+ "}\n";
+ formatSource(source);
+}
+public void testBug199265b() throws JavaModelException {
+ String source =
+ "import java.util.List;\n" +
+ "import java.util.Set;\n" +
+ "//import java.util.HashMap;\n" +
+ "\n" +
+ "public class X02 {\n" +
+ "}\n";
+ formatSource(source);
+}
+public void testBug199265c1() throws JavaModelException {
+ String source =
+ "import java.util.List;\n" +
+ "// CU snippet\n" +
+ "public class X03 {\n" +
+ " List field;\n" +
+ "}\n";
+ formatSource(source,
+ "import java.util.List;\n" +
+ "\n" +
+ "// CU snippet\n" +
+ "public class X03 {\n" +
+ " List field;\n" +
+ "}\n"
+ );
+}
+public void testBug199265c2() throws JavaModelException {
+ this.formatterPrefs.comment_format_header = true;
+ String source =
+ "import java.util.List;\n" +
+ "// CU snippet\n" +
+ "public class X03 {\n" +
+ " List field;\n" +
+ "}\n";
+ formatSource(source,
+ "import java.util.List;\n" +
+ "\n" +
+ "// CU snippet\n" +
+ "public class X03 {\n" +
+ " List field;\n" +
+ "}\n"
+ );
+}
+public void testBug199265c3() throws JavaModelException {
+ String source =
+ "import java.util.List;\n" +
+ "\n" +
+ "// line comment\n" +
+ "public class X03 {\n" +
+ " List field;\n" +
+ "}\n";
+ formatSource(source);
+}
+public void testBug199265_wksp1a() throws JavaModelException {
+ String source =
+ "package wksp1;\n" +
+ "\n" +
+ "import java.util.*;\n" +
+ "import java.util.List; // line comment\n" +
+ "\n" +
+ "/**\n" +
+ " * Javadoc comment\n" +
+ " */\n" +
+ "public class X01 {\n" +
+ "\n" +
+ "}\n";
+ formatSource(source);
+}
+public void testBug199265_wksp1b() throws JavaModelException {
+ String source =
+ "package wksp1;\n" +
+ "\n" +
+ "import java.util.Map;\n" +
+ "\n" +
+ "//==========================\n" +
+ "// Line comment\n" +
+ "//==========================\n" +
+ "\n" +
+ "/**\n" +
+ " * Javadoc comment\n" +
+ " */\n" +
+ "public class X02 {\n" +
+ "\n" +
+ "}\n";
+ formatSource(source);
+}
+public void testBug199265_wksp2a() throws JavaModelException {
+ String source =
+ "package wksp2;\n" +
+ "\n" +
+ "import java.util.Map;\n" +
+ "\n" +
+ "//#if defined(TEST)\n" +
+ "import java.util.Vector;\n" +
+ "//#else\n" +
+ "//##import java.util.Set;\n" +
+ "//#endif\n" +
+ "\n" +
+ "public class X01 {\n" +
+ "\n" +
+ "}\n";
+ formatSource(source);
+}
+public void testBug199265_wksp3a() throws JavaModelException {
+ String source =
+ "package wksp3;\n" +
+ "\n" +
+ "import java.util.Set; // comment 1\n" +
+ "import java.util.Map; // comment 2\n" +
+ "import java.util.List; // comment 3\n" +
+ "\n" +
+ "public class X01 {\n" +
+ "\n" +
+ "}\n";
+ formatSource(source,
+ "package wksp3;\n" +
+ "\n" +
+ "import java.util.Set; // comment 1\n" +
+ "import java.util.Map; // comment 2\n" +
+ "import java.util.List; // comment 3\n" +
+ "\n" +
+ "public class X01 {\n" +
+ "\n" +
+ "}\n"
+ );
+}
+
+/**
* @bug 208541: [formatter] Formatter does not format whole region/selection
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541"
*/
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.6
diff -u -r1.6 FormatterMassiveRegressionTests.java
--- src/org/eclipse/jdt/core/tests/formatter/FormatterMassiveRegressionTests.java 24 Oct 2009 18:49:53 -0000 1.6
+++ src/org/eclipse/jdt/core/tests/formatter/FormatterMassiveRegressionTests.java 5 Nov 2009 14:26:13 -0000
@@ -33,6 +33,7 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
@@ -45,7 +46,6 @@
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter;
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatterOptions;
import org.eclipse.text.edits.TextEdit;
-
import com.ibm.icu.util.StringTokenizer;
/**
@@ -154,6 +154,44 @@
private final static File INPUT_DIR = new File(System.getProperty("inputDir"));
private static File OUTPUT_DIR; // use static to minimize data consumption
private static File WRITE_DIR;
+
+ // Files
+ final static String FILES_FILTER = System.getProperty("filesFilter");
+ final static int FILES_FILTER_KIND;
+ static {
+ int kind = 0; // No filter
+ if (FILES_FILTER != null) {
+ int length = FILES_FILTER.length();
+ int idxQM = FILES_FILTER.indexOf('?');
+ int idxS = FILES_FILTER.indexOf('*');
+ if (idxQM >= 0 && idxS >= 0) {
+ kind = 4; // Pure pattern match
+ } else if (idxQM >= 0) {
+ while (idxQM < length && FILES_FILTER.charAt(idxQM) == '?') {
+ idxQM++;
+ }
+ if (idxQM == length) {
+ kind = 3; // Starts with + same length
+ } else {
+ kind = 4; // Pure pattern match
+ }
+ } else if (idxS >= 0) {
+ while (idxS < length && FILES_FILTER.charAt(idxQM) == '*') {
+ idxS++;
+ }
+ if (idxS == length) {
+ kind = 2; // Starts with
+ } else {
+ kind = 4; // Pure pattern match
+ }
+ } else {
+ kind = 1; // Equals
+ }
+ }
+ FILES_FILTER_KIND = kind;
+ }
+
+ // Log
private static File LOG_FILE;
private static PrintStream LOG_STREAM;
@@ -215,7 +253,7 @@
private static String ECLIPSE_VERSION;
private static String ECLIPSE_MILESTONE;
private static String JDT_CORE_VERSION;
- private static String PATCH_BUG;
+ private static String PATCH_BUG, PATCH_VERSION;
private static boolean JDT_CORE_HEAD;
private final static IPath[] EXPECTED_FAILURES = INPUT_DIR.getPath().indexOf("v34") < 0
? new IPath[] {
@@ -287,7 +325,25 @@
// Get files from input dir
FileFilter filter = new FileFilter() {
public boolean accept(File pathname) {
- return pathname.isDirectory() || pathname.getPath().endsWith(".java");
+ String path = pathname.getPath();
+ boolean accept = pathname.isDirectory() || path.endsWith(".java");
+ if (accept) {
+ switch (FILES_FILTER_KIND) {
+ case 1: // Equals
+ accept = path.equals(FILES_FILTER);
+ break;
+ case 2: // Starts with
+ accept = path.startsWith(FILES_FILTER);
+ break;
+ case 3: // Starts with + same length
+ accept = path.startsWith(FILES_FILTER) && path.length() == FILES_FILTER.length();
+ break;
+ case 4: // Pattern
+ accept = path.matches(FILES_FILTER);
+ break;
+ }
+ }
+ return accept;
}
};
File[] allFiles = ModelTestsUtil.getAllFiles(INPUT_DIR, filter);
@@ -300,8 +356,22 @@
// Init directories
boolean clean = initDirectories(buffer);
- buffer.append("Comparison: "+CAN_COMPARE);
- buffer.append(LINE_SEPARATOR);
+ buffer.append("Compare vs: ");
+ if (CAN_COMPARE) {
+ if (clean) {
+ buffer.append(JDT_CORE_VERSION);
+ } else {
+ File versionFile = new File(OUTPUT_DIR, "version.txt");
+ if (versionFile.exists()) {
+ buffer.append(Util.fileContent(versionFile.getAbsolutePath()));
+ } else {
+ buffer.append("???");
+ }
+ }
+ } else {
+ buffer.append("none");
+ }
+// buffer.append(LINE_SEPARATOR);
// Write logs
System.out.println(buffer.toString());
@@ -385,7 +455,11 @@
clean = true;
}
}
- if (!OUTPUT_DIR.exists() && !clean) {
+ if (clean) {
+ if (PATCH_BUG != null || JDT_CORE_HEAD) {
+ throw new RuntimeException("Reference can only be updated using a version (i.e. with a closed buildnotes_jdt-core.html)!");
+ }
+ } else if (!OUTPUT_DIR.exists()) {
System.err.println(" WARNING: The output directory "+OUTPUT_DIR+" does not exist...");
System.err.println(" => NO comparison could be done!");
CAN_COMPARE = false;
@@ -398,7 +472,11 @@
}
// Get log dir
- setLogDir(buffer);
+ try {
+ setLogDir(buffer);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
// Get write dir
String wdir = System.getProperty("writeDir"); //$NON-NLS-1$
@@ -417,9 +495,12 @@
return clean;
}
-private static void setLogDir(StringBuffer buffer) {
+private static void setLogDir(StringBuffer buffer) throws CoreException {
// Compute log dir
+// IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+// IProject project = root.getProject("Bugs");
+// IFolder rootFolder = project.getFolder("Formatter");
File logDir = new File(System.getProperty("logDir"));
if (!logDir.exists()) {
return;
@@ -427,44 +508,89 @@
// Compute log sub-directories depending on profiles
logDir = new File(logDir, ECLIPSE_VERSION);
+// IFolder folder = rootFolder.getFolder(ECLIPSE_VERSION);
+// if (!folder.exists()) folder.create(true, true, null);
if (PATCH_BUG != null) {
logDir = new File(logDir, "tests");
logDir = new File(logDir, PATCH_BUG);
+ logDir = new File(logDir, PATCH_VERSION);
+// folder = folder.getFolder("tests");
+// if (!folder.exists()) folder.create(true, true, null);
+// folder = folder.getFolder(PATCH_BUG);
+// if (!folder.exists()) folder.create(true, true, null);
+// folder = folder.getFolder(PATCH_VERSION);
+// if (!folder.exists()) folder.create(true, true, null);
} else if (JDT_CORE_HEAD) {
logDir = new File(logDir, "HEAD");
+// folder = folder.getFolder("HEAD");
+// if (!folder.exists()) folder.create(true, true, null);
} else {
logDir = new File(logDir, ECLIPSE_MILESTONE);
logDir = new File(logDir, JDT_CORE_VERSION);
+// folder = folder.getFolder(ECLIPSE_MILESTONE);
+// if (!folder.exists()) folder.create(true, true, null);
+// folder = folder.getFolder(JDT_CORE_VERSION);
+// if (!folder.exists()) folder.create(true, true, null);
}
if (NO_COMMENTS || BRACES != null || JOIN_LINES != null) {
logDir = new File(logDir, "profiles");
+// folder = folder.getFolder("profiles");
+// if (!folder.exists()) folder.create(true, true, null);
if (JOIN_LINES != null) {
logDir = new File(new File(logDir, "join_lines"), JOIN_LINES);
+// folder = folder.getFolder("join_lines");
+// if (!folder.exists()) folder.create(true, true, null);
+// folder = folder.getFolder(JOIN_LINES);
+// if (!folder.exists()) folder.create(true, true, null);
}
if (NO_COMMENTS) {
logDir = new File(logDir, "no_comments");
+// folder = folder.getFolder("no_comments");
+// if (!folder.exists()) folder.create(true, true, null);
}
if (BRACES != null) {
logDir = new File(new File(logDir, "braces"), BRACES);
+// folder = folder.getFolder("braces");
+// if (!folder.exists()) folder.create(true, true, null);
+// folder = folder.getFolder(BRACES);
+// if (!folder.exists()) folder.create(true, true, null);
}
}
// Create log stream
logDir.mkdirs();
- String logFileName = INPUT_DIR.getName().replaceAll("\\.", "")+".txt";
+ String filePrefix = INPUT_DIR.getName().replaceAll("\\.", "");
+ String logFileName = filePrefix+".txt";
LOG_FILE = new File(logDir, logFileName);
+ if (LOG_FILE.exists()) {
+ File saveDir = new File(logDir, "save");
+ saveDir.mkdir();
+ int i=0;
+ while (true) {
+ String newFileName = filePrefix+"_";
+ if (i<10) newFileName += "0";
+ newFileName += i+".text";
+ File renamedFile = new File(saveDir, newFileName);
+ if (LOG_FILE.renameTo(renamedFile)) break;
+ i++;
+ }
+ }
+// LOG_RESOURCE = folder.getFile(logFileName);
buffer.append("Log file : ");
buffer.append(LOG_FILE);
+// buffer.append(LOG_RESOURCE.getFullPath());
buffer.append(LINE_SEPARATOR);
try {
- if (LOG_FILE.exists()) {
- Util.delete(LOG_FILE);
- }
LOG_STREAM = new PrintStream(new BufferedOutputStream(new FileOutputStream(LOG_FILE)));
+ LOG_STREAM.flush();
}
catch (FileNotFoundException fnfe) {
System.err.println("Can't create log file"+LOG_FILE); //$NON-NLS-1$
}
+// if (LOG_RESOURCE.exists()) {
+// Util.delete(LOG_RESOURCE);
+// }
+// LOG_BUFFER = new StringBuffer();
}
private static void setOutputDir(String dir, StringBuffer buffer) {
@@ -546,6 +672,7 @@
patch_line = line;
StringTokenizer tokenizer = new StringTokenizer(line);
tokenizer.nextToken(); // 'Patch'
+ PATCH_VERSION = tokenizer.nextToken();
while (tokenizer.hasMoreTokens()) {
PATCH_BUG = tokenizer.nextToken();
}
@@ -553,7 +680,7 @@
Integer.parseInt(PATCH_BUG);
}
catch (NumberFormatException nfe) {
- System.err.println("Invalid patch bug number noticed in JDT/Core buildnotes:"+PATCH_BUG);
+ System.err.println("Invalid patch bug number noticed in JDT/Core buildnotes: "+PATCH_BUG);
}
}
if (!JDT_CORE_HEAD) break;
@@ -625,7 +752,7 @@
StringBuffer name = new StringBuffer(super.getName());
if (this.testIndex >= 0) {
int n = this.testIndex == 0 ? 0 : (int) (Math.log(this.testIndex)/Math.log(10));
- for (int i=n; i 0) {
- buffer.append(size);
- buffer.append(" file");
+ buffer1.append(size);
+ buffer1.append(" file");
if (size == 1) {
- buffer.append(" has ");
+ buffer1.append(" has ");
} else {
- buffer.append("s have ");
+ buffer1.append("s have ");
}
- buffer.append(FAILURES[i]);
- buffer.append('!');
- buffer.append(LINE_SEPARATOR);
+ buffer1.append(FAILURES[i]);
+ buffer1.append('!');
+ buffer1.append(LINE_SEPARATOR);
}
}
- buffer.append(LINE_SEPARATOR);
+ buffer1.append(LINE_SEPARATOR);
+ StringBuffer buffer2 = new StringBuffer(LINE_SEPARATOR);
for (int i=0; i 0) {
- buffer.append("List of file(s) with ");
- buffer.append(FAILURES[i]);
- buffer.append(':');
- buffer.append(LINE_SEPARATOR);
+ buffer2.append("List of file(s) with ");
+ buffer2.append(FAILURES[i]);
+ buffer2.append(':');
+ buffer2.append(LINE_SEPARATOR);
for (int j=0; j