### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core 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.238 diff -u -r1.238 CodeFormatterVisitor.java --- formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java 22 Dec 2010 16:34:45 -0000 1.238 +++ formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java 27 Dec 2010 14:09:29 -0000 @@ -172,10 +172,22 @@ TerminalTokens.TokenNameGREATER }; public int lastLocalDeclarationSourceStart; + int lastBinaryExpressionAlignmentBreakIndentation; private Scanner localScanner; public DefaultCodeFormatterOptions preferences; public Scribe scribe; + // Binary expression positions storage + final static long EXPRESSIONS_POS_ENTER_EQUALITY = 1; + final static long EXPRESSIONS_POS_ENTER_TWO = 2; + final static long EXPRESSIONS_POS_BETWEEN_TWO = 3; + final static long EXPRESSIONS_POS_MASK = EXPRESSIONS_POS_BETWEEN_TWO; + long expressionsPos; + int expressionsDepth = -1; + + // Array initializers information + int arrayInitializersDepth = -1; + public CodeFormatterVisitor(DefaultCodeFormatterOptions preferences, Map settings, IRegion[] regions, CodeSnippetParsingUtil codeSnippetParsingUtil, boolean includeComments) { long sourceLevel = settings == null ? ClassFileConstants.JDK1_3 @@ -421,62 +433,90 @@ BinaryExpressionFragmentBuilder builder = buildFragments(binaryExpression, scope); final int fragmentsSize = builder.size(); - if ((builder.realFragmentsSize() > 1 || fragmentsSize > 4) && numberOfParens == 0) { - this.scribe.printComment(); - Alignment binaryExpressionAlignment = this.scribe.createAlignment( - Alignment.BINARY_EXPRESSION, - this.preferences.alignment_for_binary_expression, - Alignment.R_OUTERMOST, - fragmentsSize, - this.scribe.scanner.currentPosition); - this.scribe.enterAlignment(binaryExpressionAlignment); - boolean ok = false; - ASTNode[] fragments = builder.fragments(); - int[] operators = builder.operators(); - do { - try { - for (int i = 0; i < fragmentsSize - 1; i++) { - ASTNode fragment = fragments[i]; - fragment.traverse(this, scope); - this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT); - if (this.scribe.lastNumberOfNewLines == 1) { - // 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) { - this.scribe.alignFragment(binaryExpressionAlignment, i); - this.scribe.printNextToken(operators[i], this.preferences.insert_space_before_binary_operator); - } else { - this.scribe.printNextToken(operators[i], this.preferences.insert_space_before_binary_operator); - this.scribe.alignFragment(binaryExpressionAlignment, i); - } - if (operators[i] == TerminalTokens.TokenNameMINUS && isNextToken(TerminalTokens.TokenNameMINUS)) { - // the next character is a minus (unary operator) - this.scribe.space(); - } - if (this.preferences.insert_space_after_binary_operator) { - this.scribe.space(); + if (this.expressionsDepth < 0) { + this.expressionsDepth = 0; + } else { + this.expressionsDepth++; + this.expressionsPos <<= 2; + } + try { + this.lastBinaryExpressionAlignmentBreakIndentation = 0; + if ((builder.realFragmentsSize() > 1 || fragmentsSize > 4) && numberOfParens == 0) { + int scribeLine = this.scribe.line; + this.scribe.printComment(); + Alignment binaryExpressionAlignment = this.scribe.createAlignment( + Alignment.BINARY_EXPRESSION, + this.preferences.alignment_for_binary_expression, + Alignment.R_OUTERMOST, + fragmentsSize, + this.scribe.scanner.currentPosition); + this.scribe.enterAlignment(binaryExpressionAlignment); + boolean ok = false; + ASTNode[] fragments = builder.fragments(); + int[] operators = builder.operators(); + do { + try { + final int max = fragmentsSize - 1; + for (int i = 0; i < max; i++) { + ASTNode fragment = fragments[i]; + fragment.traverse(this, scope); + this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT); + if (this.scribe.lastNumberOfNewLines == 1) { + // a new line has been inserted while printing the comment + // hence we need to use the break indentation level before printing next token... + this.scribe.indentationLevel = binaryExpressionAlignment.breakIndentationLevel; + } + if (this.preferences.wrap_before_binary_operator) { + this.scribe.alignFragment(binaryExpressionAlignment, i); + this.scribe.printNextToken(operators[i], this.preferences.insert_space_before_binary_operator); + } else { + this.scribe.printNextToken(operators[i], this.preferences.insert_space_before_binary_operator); + this.scribe.alignFragment(binaryExpressionAlignment, i); + } + if (operators[i] == TerminalTokens.TokenNameMINUS && isNextToken(TerminalTokens.TokenNameMINUS)) { + // the next character is a minus (unary operator) + this.scribe.space(); + } + if (this.preferences.insert_space_after_binary_operator) { + this.scribe.space(); + } } + fragments[max].traverse(this, scope); + this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT); + ok = true; + } catch(AlignmentException e){ + this.scribe.redoAlignment(e); } - fragments[fragmentsSize - 1].traverse(this, scope); - this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT); - ok = true; - } catch(AlignmentException e){ - this.scribe.redoAlignment(e); + } while (!ok); + this.scribe.exitAlignment(binaryExpressionAlignment, true); + if (this.scribe.line == scribeLine) { + // The expression was not broken => reset last break indentation + this.lastBinaryExpressionAlignmentBreakIndentation = 0; + } else { + this.lastBinaryExpressionAlignmentBreakIndentation = binaryExpressionAlignment.breakIndentationLevel; } - } while (!ok); - this.scribe.exitAlignment(binaryExpressionAlignment, true); - } else { - binaryExpression.left.traverse(this, scope); - this.scribe.printNextToken(operator, this.preferences.insert_space_before_binary_operator); - if (operator == TerminalTokens.TokenNameMINUS && isNextToken(TerminalTokens.TokenNameMINUS)) { - // the next character is a minus (unary operator) - this.scribe.space(); + } else { + this.expressionsPos |= EXPRESSIONS_POS_ENTER_TWO; + binaryExpression.left.traverse(this, scope); + this.expressionsPos &= ~EXPRESSIONS_POS_MASK; + this.expressionsPos |= EXPRESSIONS_POS_BETWEEN_TWO; + this.scribe.printNextToken(operator, this.preferences.insert_space_before_binary_operator, Scribe.PRESERVE_EMPTY_LINES_IN_BINARY_EXPRESSION); + if (operator == TerminalTokens.TokenNameMINUS && isNextToken(TerminalTokens.TokenNameMINUS)) { + // the next character is a minus (unary operator) + this.scribe.space(); + } + if (this.preferences.insert_space_after_binary_operator) { + this.scribe.space(); + } + binaryExpression.right.traverse(this, scope); } - if (this.preferences.insert_space_after_binary_operator) { - this.scribe.space(); + } + finally { + this.expressionsDepth--; + this.expressionsPos >>= 2; + if (this.expressionsDepth < 0) { + this.lastBinaryExpressionAlignmentBreakIndentation = 0; } - binaryExpression.right.traverse(this, scope); } if (numberOfParens > 0) { manageClosingParenthesizedExpression(binaryExpression, numberOfParens); @@ -494,13 +534,25 @@ if (numberOfParens > 0) { manageOpeningParenthesizedExpression(binaryExpression, numberOfParens); } - binaryExpression.left.traverse(this, scope); - this.scribe.printNextToken(operator, this.preferences.insert_space_before_binary_operator); - if (this.preferences.insert_space_after_binary_operator) { - this.scribe.space(); + if (this.expressionsDepth < 0) { + this.expressionsDepth = 0; + } else { + this.expressionsDepth++; + this.expressionsPos <<= 2; + } + try { + this.expressionsPos |= EXPRESSIONS_POS_ENTER_EQUALITY; + binaryExpression.left.traverse(this, scope); + this.scribe.printNextToken(operator, this.preferences.insert_space_before_binary_operator, Scribe.PRESERVE_EMPTY_LINES_IN_EQUALITY_EXPRESSION); + if (this.preferences.insert_space_after_binary_operator) { + this.scribe.space(); + } + binaryExpression.right.traverse(this, scope); + } + finally { + this.expressionsDepth--; + this.expressionsPos >>= 2; } - binaryExpression.right.traverse(this, scope); - if (numberOfParens > 0) { manageClosingParenthesizedExpression(binaryExpression, numberOfParens); } @@ -1254,7 +1306,7 @@ this.scribe.indent(); } formatStatements(scope, statements, true); - this.scribe.printComment(); + this.scribe.printComment(Scribe.PRESERVE_EMPTY_LINES_AT_END_OF_BLOCK); if (this.preferences.indent_statements_compare_to_block) { this.scribe.unIndent(); @@ -1264,7 +1316,7 @@ if (this.preferences.indent_statements_compare_to_block) { this.scribe.indent(); } - this.scribe.printComment(); + this.scribe.printComment(Scribe.PRESERVE_EMPTY_LINES_AT_END_OF_BLOCK); if (this.preferences.indent_statements_compare_to_block) { this.scribe.unIndent(); @@ -1273,7 +1325,7 @@ if (this.preferences.indent_statements_compare_to_block) { this.scribe.indent(); } - this.scribe.printComment(); + this.scribe.printComment(Scribe.PRESERVE_EMPTY_LINES_AT_END_OF_BLOCK); if (this.preferences.indent_statements_compare_to_block) { this.scribe.unIndent(); @@ -1582,20 +1634,14 @@ } private void formatLeftCurlyBrace(final int line, final String bracePosition) { - this.scribe.formatBrace = true; /* * deal with (quite unexpected) comments right before lcurly */ - try { - this.scribe.printComment(); - if (DefaultCodeFormatterConstants.NEXT_LINE_ON_WRAP.equals(bracePosition) - && (this.scribe.line > line || this.scribe.column >= this.preferences.page_width)) - { - this.scribe.printNewLine(); - } - } - finally { - this.scribe.formatBrace = false; + this.scribe.printComment(Scribe.PRESERVE_EMPTY_LINES_IN_FORMAT_LEFT_CURLY_BRACE); + if (DefaultCodeFormatterConstants.NEXT_LINE_ON_WRAP.equals(bracePosition) + && (this.scribe.line > line || this.scribe.column >= this.preferences.page_width)) + { + this.scribe.printNewLine(); } } @@ -1736,6 +1782,11 @@ if (i > 0) { this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_method_invocation_arguments); this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT); + if (this.scribe.lastNumberOfNewLines == 1) { + // a new line has been inserted while printing the comment + // hence we need to use the break indentation level before printing next token... + this.scribe.indentationLevel = argumentsAlignment.breakIndentationLevel; + } } this.scribe.alignFragment(argumentsAlignment, i); if (i > 0 && this.preferences.insert_space_after_comma_in_method_invocation_arguments) { @@ -1806,6 +1857,11 @@ if (i > 0) { this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, spaceBeforeComma); this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT); + if (this.scribe.lastNumberOfNewLines == 1) { + // a new line has been inserted while printing the comment + // hence we need to use the break indentation level before printing next token... + this.scribe.indentationLevel = argumentsAlignment.breakIndentationLevel; + } } this.scribe.alignFragment(argumentsAlignment, i); if (i == 0) { @@ -1907,7 +1963,7 @@ this.scribe.printNewLine(); this.scribe.indent(); } - this.scribe.printNextToken(TerminalTokens.TokenNameLBRACE, insertSpaceBeforeBrace); + this.scribe.printNextToken(TerminalTokens.TokenNameLBRACE, insertSpaceBeforeBrace, Scribe.PRESERVE_EMPTY_LINES_IN_FORMAT_OPENING_BRACE); this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.UNMODIFIABLE_TRAILING_COMMENT); } private void formatStatements(BlockScope scope, final Statement[] statements, boolean insertNewLineAfterLastStatement) { @@ -2111,7 +2167,7 @@ this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon); this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT); } - this.scribe.printComment(); + this.scribe.printComment(Scribe.DO_NOT_PRESERVE_EMPTY_LINES); this.scribe.exitMemberAlignment(memberAlignment); } @@ -2581,116 +2637,153 @@ /** * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.ArrayInitializer, org.eclipse.jdt.internal.compiler.lookup.BlockScope) */ - public boolean visit(ArrayInitializer arrayInitializer, BlockScope scope) { final int numberOfParens = (arrayInitializer.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT; + public boolean visit(ArrayInitializer arrayInitializer, BlockScope scope) { + final int numberOfParens = (arrayInitializer.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT; if (numberOfParens > 0) { manageOpeningParenthesizedExpression(arrayInitializer, numberOfParens); } - final Expression[] expressions = arrayInitializer.expressions; - if (expressions != null) { - String array_initializer_brace_position = this.preferences.brace_position_for_array_initializer; - formatOpeningBrace(array_initializer_brace_position, this.preferences.insert_space_before_opening_brace_in_array_initializer); - - int expressionsLength = expressions.length; - final boolean insert_new_line_after_opening_brace = this.preferences.insert_new_line_after_opening_brace_in_array_initializer; - if (expressionsLength > 1) { - if (insert_new_line_after_opening_brace) { - this.scribe.printNewLine(); - } - Alignment arrayInitializerAlignment =this.scribe.createAlignment( - Alignment.ARRAY_INITIALIZER, - this.preferences.alignment_for_expressions_in_array_initializer, - Alignment.R_OUTERMOST, - expressionsLength, - this.scribe.scanner.currentPosition, - this.preferences.continuation_indentation_for_array_initializer, - true); - - if (insert_new_line_after_opening_brace) { - arrayInitializerAlignment.fragmentIndentations[0] = arrayInitializerAlignment.breakIndentationLevel; - } + if (this.arrayInitializersDepth < 0) { + this.arrayInitializersDepth = 0; + } else { + this.arrayInitializersDepth++; + } + int arrayInitializerIndentationLevel = this.scribe.indentationLevel; + try { + final Expression[] expressions = arrayInitializer.expressions; + if (expressions != null) { + String array_initializer_brace_position = this.preferences.brace_position_for_array_initializer; + formatOpeningBrace(array_initializer_brace_position, this.preferences.insert_space_before_opening_brace_in_array_initializer); - this.scribe.enterAlignment(arrayInitializerAlignment); + int expressionsLength = expressions.length; + final boolean insert_new_line_after_opening_brace = this.preferences.insert_new_line_after_opening_brace_in_array_initializer; boolean ok = false; - do { - try { - this.scribe.alignFragment(arrayInitializerAlignment, 0); - if (this.preferences.insert_space_after_opening_brace_in_array_initializer) { - this.scribe.space(); - } - 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.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT); - this.scribe.alignFragment(arrayInitializerAlignment, i); - if (this.preferences.insert_space_after_comma_in_array_initializer) { + Alignment arrayInitializerAlignment = null; + if (expressionsLength > 1) { + if (insert_new_line_after_opening_brace) { + this.scribe.printNewLine(); + } + arrayInitializerAlignment = this.scribe.createAlignment( + Alignment.ARRAY_INITIALIZER, + this.preferences.alignment_for_expressions_in_array_initializer, + Alignment.R_OUTERMOST, + expressionsLength, + this.scribe.scanner.currentPosition, + this.preferences.continuation_indentation_for_array_initializer, + true); + + if (insert_new_line_after_opening_brace) { + arrayInitializerAlignment.fragmentIndentations[0] = arrayInitializerAlignment.breakIndentationLevel; + } + + this.scribe.enterAlignment(arrayInitializerAlignment); + do { + try { + this.scribe.alignFragment(arrayInitializerAlignment, 0); + if (this.preferences.insert_space_after_opening_brace_in_array_initializer) { this.scribe.space(); } - expressions[i].traverse(this, scope); - if (i == expressionsLength - 1) { - if (isNextToken(TerminalTokens.TokenNameCOMMA)) { - this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_array_initializer); - this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT); + 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.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(); + } + expressions[i].traverse(this, scope); + if (i == expressionsLength - 1) { + if (isNextToken(TerminalTokens.TokenNameCOMMA)) { + this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_array_initializer); + this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT); + } } } + ok = true; + } catch (AlignmentException e) { + this.scribe.redoAlignment(e); } - ok = true; - } catch (AlignmentException e) { - this.scribe.redoAlignment(e); + } while (!ok); + this.scribe.exitAlignment(arrayInitializerAlignment, true); + } else { + // Use an alignment with no break in case when the array initializer + // is not inside method arguments alignments + if (this.scribe.currentAlignment == null || this.scribe.currentAlignment.kind != Alignment.MESSAGE_ARGUMENTS) { + arrayInitializerAlignment = this.scribe.createAlignment( + Alignment.ARRAY_INITIALIZER, + this.preferences.alignment_for_expressions_in_array_initializer, + Alignment.R_OUTERMOST, + 0, + this.scribe.scanner.currentPosition, + this.preferences.continuation_indentation_for_array_initializer, + true); + this.scribe.enterAlignment(arrayInitializerAlignment); + } + do { + try { + if (insert_new_line_after_opening_brace) { + this.scribe.printNewLine(); + this.scribe.indent(); + } + // we don't need to use an alignment + if (this.preferences.insert_space_after_opening_brace_in_array_initializer) { + this.scribe.space(); + } else { + this.scribe.needSpace = false; + } + 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.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT); + } + if (insert_new_line_after_opening_brace) { + this.scribe.unIndent(); + } + ok = true; + } catch (AlignmentException e) { + if (arrayInitializerAlignment == null) throw e; + this.scribe.redoAlignment(e); + } + } while (!ok); + if (arrayInitializerAlignment != null) { + this.scribe.exitAlignment(arrayInitializerAlignment, true); } - } while (!ok); - this.scribe.exitAlignment(arrayInitializerAlignment, true); - } else { - if (insert_new_line_after_opening_brace) { - this.scribe.printNewLine(); - this.scribe.indent(); } - // we don't need to use an alignment - if (this.preferences.insert_space_after_opening_brace_in_array_initializer) { + if (this.preferences.insert_new_line_before_closing_brace_in_array_initializer) { + this.scribe.printNewLine(); + } else if (this.preferences.insert_space_before_closing_brace_in_array_initializer) { this.scribe.space(); - } else { - this.scribe.needSpace = false; - } - 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.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT); } - if (insert_new_line_after_opening_brace) { + this.scribe.printNextToken(TerminalTokens.TokenNameRBRACE, false, Scribe.PRESERVE_EMPTY_LINES_IN_CLOSING_ARRAY_INITIALIZER + (arrayInitializerIndentationLevel << 16)); + if (array_initializer_brace_position.equals(DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED)) { this.scribe.unIndent(); } - } - if (this.preferences.insert_new_line_before_closing_brace_in_array_initializer) { - this.scribe.printNewLine(); - } else if (this.preferences.insert_space_before_closing_brace_in_array_initializer) { - this.scribe.space(); - } - this.scribe.printNextToken(TerminalTokens.TokenNameRBRACE, false); - if (array_initializer_brace_position.equals(DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED)) { - this.scribe.unIndent(); - } - } else { - boolean keepEmptyArrayInitializerOnTheSameLine = this.preferences.keep_empty_array_initializer_on_one_line; - String array_initializer_brace_position = this.preferences.brace_position_for_array_initializer; - if (keepEmptyArrayInitializerOnTheSameLine) { - 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.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.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)) { - this.scribe.unIndent(); + boolean keepEmptyArrayInitializerOnTheSameLine = this.preferences.keep_empty_array_initializer_on_one_line; + String array_initializer_brace_position = this.preferences.brace_position_for_array_initializer; + if (keepEmptyArrayInitializerOnTheSameLine) { + 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.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.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)) { + this.scribe.unIndent(); + } } } + } finally { + this.arrayInitializersDepth--; } + if (numberOfParens > 0) { manageClosingParenthesizedExpression(arrayInitializer, numberOfParens); @@ -3958,9 +4051,9 @@ if (elseStatement != null) { if (thenStatementIsBlock) { - this.scribe.printNextToken(TerminalTokens.TokenNameelse, this.preferences.insert_space_after_closing_brace_in_block); + this.scribe.printNextToken(TerminalTokens.TokenNameelse, this.preferences.insert_space_after_closing_brace_in_block, Scribe.PRESERVE_EMPTY_LINES_BEFORE_ELSE); } else { - this.scribe.printNextToken(TerminalTokens.TokenNameelse, true); + this.scribe.printNextToken(TerminalTokens.TokenNameelse, true, Scribe.PRESERVE_EMPTY_LINES_BEFORE_ELSE); } if (elseStatement instanceof Block) { elseStatement.traverse(this, scope); @@ -4125,6 +4218,7 @@ pair.value.traverse(this, scope); return false; } + /** * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.MessageSend, org.eclipse.jdt.internal.compiler.lookup.BlockScope) */ @@ -4328,7 +4422,7 @@ this.scribe.indent(); } formatStatements(methodDeclarationScope, statements, true); - this.scribe.printComment(); + this.scribe.printComment(Scribe.PRESERVE_EMPTY_LINES_AT_END_OF_METHOD_DECLARATION); if (this.preferences.indent_statements_compare_to_body) { this.scribe.unIndent(); } @@ -4339,7 +4433,7 @@ if (this.preferences.indent_statements_compare_to_body) { this.scribe.indent(); } - this.scribe.printComment(); + this.scribe.printComment(Scribe.PRESERVE_EMPTY_LINES_AT_END_OF_METHOD_DECLARATION); if (this.preferences.indent_statements_compare_to_body) { this.scribe.unIndent(); } @@ -4975,7 +5069,7 @@ manageOpeningParenthesizedExpression(stringLiteral, numberOfParens); } - this.scribe.printComment(); + this.scribe.printComment(Scribe.PRESERVE_EMPTY_LINES_IN_STRING_LITERAL_CONCATENATION); ASTNode[] fragments = stringLiteral.literals; int fragmentsSize = stringLiteral.counter; Alignment binaryExpressionAlignment = this.scribe.createAlignment( @@ -5044,7 +5138,6 @@ if (this.preferences.insert_space_after_opening_paren_in_switch) { this.scribe.space(); } - switchStatement.expression.traverse(this, scope); this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN, this.preferences.insert_space_before_closing_paren_in_switch); /* @@ -5054,77 +5147,72 @@ formatOpeningBrace(switch_brace, this.preferences.insert_space_before_opening_brace_in_switch); this.scribe.printNewLine(); + final Statement[] statements = switchStatement.statements; + int switchIndentationLevel = this.scribe.indentationLevel; + int caseIndentation = 0; + int statementIndentation = 0; + int breakIndentation = 0; if (this.preferences.indent_switchstatements_compare_to_switch) { - this.scribe.indent(); + caseIndentation++; + statementIndentation++; + breakIndentation++; + } + if (this.preferences.indent_switchstatements_compare_to_cases) { + statementIndentation++; + } + if (this.preferences.indent_breaks_compare_to_cases) { + breakIndentation++; } - final Statement[] statements = switchStatement.statements; boolean wasACase = false; - boolean wasAStatement = false; + boolean wasABreak = false; if (statements != null) { int statementsLength = statements.length; for (int i = 0; i < statementsLength; i++) { final Statement statement = statements[i]; if (statement instanceof CaseStatement) { + if (wasABreak) { + this.scribe.setIndentation(switchIndentationLevel, caseIndentation); + this.scribe.printComment(); + } else { + if (wasACase) { + this.scribe.printComment(Scribe.PRESERVE_EMPTY_LINES_IN_SWITCH_CASE); + } else { + this.scribe.printComment(); + } + this.scribe.setIndentation(switchIndentationLevel, caseIndentation); + } if (wasACase) { this.scribe.printNewLine(); } - if ((wasACase && this.preferences.indent_switchstatements_compare_to_cases) - || (wasAStatement && this.preferences.indent_switchstatements_compare_to_cases)) { - this.scribe.unIndent(); - } statement.traverse(this, scope); - wasACase = true; - wasAStatement = false; - if (this.preferences.indent_switchstatements_compare_to_cases) { - this.scribe.indent(); - } + // Print following trailing (if any) comment at statement indentation + this.scribe.setIndentation(switchIndentationLevel, statementIndentation); this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.COMPLEX_TRAILING_COMMENT); + wasACase = true; + wasABreak = false; } else if (statement instanceof BreakStatement) { - if (this.preferences.indent_breaks_compare_to_cases) { - if (wasAStatement && !this.preferences.indent_switchstatements_compare_to_cases) { - this.scribe.indent(); - } - } else { - if (wasAStatement) { - if (this.preferences.indent_switchstatements_compare_to_cases) { - this.scribe.unIndent(); - } - } - if (wasACase && this.preferences.indent_switchstatements_compare_to_cases) { - this.scribe.unIndent(); - } - } + this.scribe.setIndentation(switchIndentationLevel, breakIndentation); if (wasACase) { this.scribe.printNewLine(); } + this.scribe.printComment(); statement.traverse(this, scope); - if (this.preferences.indent_breaks_compare_to_cases) { - this.scribe.unIndent(); - } wasACase = false; - wasAStatement = false; + wasABreak = true; } else if (statement instanceof Block) { - String bracePosition; - if (wasACase) { - if (this.preferences.indent_switchstatements_compare_to_cases) { - this.scribe.unIndent(); - } - bracePosition = this.preferences.brace_position_for_block_in_case; - formatBlock((Block) statement, scope, bracePosition, this.preferences.insert_space_after_colon_in_case); - if (this.preferences.indent_switchstatements_compare_to_cases) { - this.scribe.indent(); - } - } else { - bracePosition = this.preferences.brace_position_for_block; - formatBlock((Block) statement, scope, bracePosition, this.preferences.insert_space_before_opening_brace_in_block); - } - wasAStatement = true; + this.scribe.setIndentation(switchIndentationLevel, wasACase ? caseIndentation : statementIndentation); + this.scribe.printComment(); + String bracePosition = wasACase ? this.preferences.brace_position_for_block_in_case : this.preferences.brace_position_for_block; + formatBlock((Block) statement, scope, bracePosition, this.preferences.insert_space_before_opening_brace_in_block); wasACase = false; + wasABreak = false; } else { + this.scribe.setIndentation(switchIndentationLevel, statementIndentation); this.scribe.printNewLine(); + this.scribe.printComment(); statement.traverse(this, scope); - wasAStatement = true; wasACase = false; + wasABreak = false; } if (statement instanceof Expression) { /* @@ -5168,17 +5256,16 @@ } else if (!wasACase) { this.scribe.printNewLine(); } - this.scribe.printComment(); } } - - if ((wasACase || wasAStatement) && this.preferences.indent_switchstatements_compare_to_cases) { - this.scribe.unIndent(); - } - if (this.preferences.indent_switchstatements_compare_to_switch) { - this.scribe.unIndent(); - } this.scribe.printNewLine(); + if (wasABreak) { + this.scribe.setIndentation(switchIndentationLevel, 0); + this.scribe.printComment(); + } else { + this.scribe.printComment(); + this.scribe.setIndentation(switchIndentationLevel, 0); + } this.scribe.printNextToken(TerminalTokens.TokenNameRBRACE); this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT); if (switch_brace.equals(DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED)) { 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.223 diff -u -r1.223 Scribe.java --- formatter/org/eclipse/jdt/internal/formatter/Scribe.java 23 Dec 2010 10:35:52 -0000 1.223 +++ formatter/org/eclipse/jdt/internal/formatter/Scribe.java 27 Dec 2010 14:09:31 -0000 @@ -73,7 +73,6 @@ public int indentationLevel; public int lastNumberOfNewLines; private boolean preserveLineBreakIndentation = false; - boolean formatBrace; public int line; private int[] lineEnds; @@ -105,6 +104,23 @@ private final boolean indentEmptyLines; int blank_lines_between_import_groups = -1; + // Preserve empty lines constants + public static final int DO_NOT_PRESERVE_EMPTY_LINES = -1; + public static final int PRESERVE_EMPTY_LINES_KEEP_LAST_NEW_LINES_INDENTATION = 1; + public static final int PRESERVE_EMPTY_LINES_IN_FORMAT_LEFT_CURLY_BRACE = 2; + public static final int PRESERVE_EMPTY_LINES_IN_STRING_LITERAL_CONCATENATION = 3; + public static final int PRESERVE_EMPTY_LINES_IN_CLOSING_ARRAY_INITIALIZER = 4; + public static final int PRESERVE_EMPTY_LINES_IN_FORMAT_OPENING_BRACE = 5; + public static final int PRESERVE_EMPTY_LINES_IN_BINARY_EXPRESSION = 6; + public static final int PRESERVE_EMPTY_LINES_IN_EQUALITY_EXPRESSION = 7; + public static final int PRESERVE_EMPTY_LINES_BEFORE_ELSE = 8; + public static final int PRESERVE_EMPTY_LINES_IN_SWITCH_CASE = 9; + public static final int PRESERVE_EMPTY_LINES_AT_END_OF_METHOD_DECLARATION = 10; + public static final int PRESERVE_EMPTY_LINES_AT_END_OF_BLOCK = 11; + final static int PRESERVE_EMPTY_LINES_DO_NOT_USE_ANY_INDENTATION = -1; + final static int PRESERVE_EMPTY_LINES_USE_CURRENT_INDENTATION = 0; + final static int PRESERVE_EMPTY_LINES_USE_TEMPORARY_INDENTATION = 1; + /** disabling */ boolean editsEnabled; boolean useTags; @@ -696,6 +712,22 @@ public Alignment createAlignment(int kind, int mode, int tieBreakRule, int count, int sourceRestart, int continuationIndent, boolean adjust){ Alignment alignment = new Alignment(kind, mode, tieBreakRule, this, count, sourceRestart, continuationIndent); + // specific break indentation for message arguments inside binary expressions + if ((this.currentAlignment == null && this.formatter.expressionsDepth >= 0) || + (this.currentAlignment != null && this.currentAlignment.kind == Alignment.BINARY_EXPRESSION && + (this.formatter.expressionsPos & CodeFormatterVisitor.EXPRESSIONS_POS_MASK) == CodeFormatterVisitor.EXPRESSIONS_POS_BETWEEN_TWO)) { + switch (kind) { + case Alignment.CONDITIONAL_EXPRESSION: + case Alignment.MESSAGE_ARGUMENTS: + case Alignment.MESSAGE_SEND: + if (this.formatter.lastBinaryExpressionAlignmentBreakIndentation == alignment.breakIndentationLevel) { + alignment.breakIndentationLevel += this.indentationSize; + alignment.shiftBreakIndentationLevel += this.indentationSize; + this.formatter.lastBinaryExpressionAlignmentBreakIndentation = 0; + } + break; + } + } // adjust break indentation if (adjust && this.memberAlignment != null) { Alignment current = this.memberAlignment; @@ -1137,108 +1169,129 @@ /* * Preserve empty lines depending on given count and preferences. */ - private String getPreserveEmptyLines(int count) { + private String getPreserveEmptyLines(int count, int emptyLinesRules) { if (count == 0) { - // preserve line breaks in wrapping if specified - // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=198074 - if (this.currentAlignment != null && !this.formatter.preferences.join_wrapped_lines) { - // Insert a new line only if it has not been already done before - // (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=283476) - // or when there's no direct member alignment - // (additional fix for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=286601) - if (this.lastNumberOfNewLines == 0 || this.memberAlignment == null || this.memberAlignment.location.inputOffset < this.currentAlignment.location.inputOffset) { - - // Debug - if (DefaultCodeFormatter.DEBUG) { - System.out.println("Preserve empty lines:"); //$NON-NLS-1$ - System.out.println(" - indentation level = "+this.indentationLevel); //$NON-NLS-1$ - System.out.println(" - current alignment: "); //$NON-NLS-1$ - System.out.print(this.currentAlignment.toString(new StringBuffer(), 1)); - if (this.memberAlignment != null) { - System.out.println(" - member alignment: "); //$NON-NLS-1$ - System.out.print(this.memberAlignment.toString(new StringBuffer(), 1)); - } - } - - // Reset indentation level to the location output - this.indentationLevel = this.currentAlignment.location.outputIndentationLevel; - - // Create new line - this.tempBuffer.setLength(0); - this.tempBuffer.append(getNewLine()); - - // Look for current indentation - int currentIndentation = getCurrentIndentation(this.scanner.currentPosition); - - // Determine whether the alignment indentation can be used or not - // So far, the best algorithm is to use it when - // 1. this is not the opening brace of a local declaration assignment - // 2. this is not the first opening brace - // or this is an array initializer alignment - // or this is an binary expression alignment - // 3. the indentation level is below the alignment break indentation - int currentTokenStartPosition = this.scanner.currentPosition; - int nextToken = -1; - try { - nextToken = this.scanner.getNextToken(); - } catch (InvalidInputException e) { - // skip - } - this.scanner.resetTo(currentTokenStartPosition, this.scannerEndPosition - 1); - boolean canUseAlignmentIndentation = (nextToken != TerminalTokens.TokenNameLBRACE || this.currentAlignment.kind != Alignment.LOCAL_DECLARATION_ASSIGNMENT); - if (canUseAlignmentIndentation && - (!this.formatBrace || - this.currentAlignment.kind == Alignment.ARRAY_INITIALIZER || - this.currentAlignment.kind == Alignment.BINARY_EXPRESSION) && - this.indentationLevel < this.currentAlignment.breakIndentationLevel) { - this.indentationLevel = this.currentAlignment.breakIndentationLevel; + int currentIndentationLevel = this.indentationLevel; + int useAlignmentBreakIndentation = useAlignmentBreakIndentation(emptyLinesRules); + switch (useAlignmentBreakIndentation) { + case PRESERVE_EMPTY_LINES_DO_NOT_USE_ANY_INDENTATION: + return Util.EMPTY_STRING; + default: + // Return the new indented line + StringBuffer buffer = new StringBuffer(getNewLine()); + printIndentationIfNecessary(buffer); + if (useAlignmentBreakIndentation == PRESERVE_EMPTY_LINES_USE_TEMPORARY_INDENTATION) { + this.indentationLevel = currentIndentationLevel; } - - // Use the current indentation if over the computed indentation - 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 = "+(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); - if (linePtr < 0) { - linePtr = -linePtr - 1; - } - int i = getLineEnd(linePtr)+1; - char[] source = this.scanner.source; - int sourceLength = source.length; - while (i < sourceLength && source[i] != '\r') { - System.out.print(source[i++]); - } - System.out.println(); - System.out.println(" - indentation level = "+this.indentationLevel); //$NON-NLS-1$ - System.out.println(); - } - - // Set the flag to indicate that a specific indentation is currently in used - this.preserveLineBreakIndentation = true; - - // Print the computed indentation in the buffer - printIndentationIfNecessary(this.tempBuffer); - return this.tempBuffer.toString(); - } + return buffer.toString(); } - return Util.EMPTY_STRING; } if (this.blank_lines_between_import_groups >= 0) { + useAlignmentBreakIndentation(emptyLinesRules); return getEmptyLines(this.blank_lines_between_import_groups); } if (this.formatter.preferences.number_of_empty_lines_to_preserve != 0) { + useAlignmentBreakIndentation(emptyLinesRules); int linesToPreserve = Math.min(count, this.formatter.preferences.number_of_empty_lines_to_preserve); return getEmptyLines(linesToPreserve); } return getNewLine(); } + private int useAlignmentBreakIndentation(int emptyLinesRules) { + // preserve line breaks in wrapping if specified + // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=198074 + boolean specificEmptyLinesRule = emptyLinesRules != PRESERVE_EMPTY_LINES_KEEP_LAST_NEW_LINES_INDENTATION; + if ((this.currentAlignment != null || specificEmptyLinesRule) && !this.formatter.preferences.join_wrapped_lines) { + // insert a new line only if it has not been already done before + // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=283476 + if (this.lastNumberOfNewLines == 0 || specificEmptyLinesRule || this.formatter.arrayInitializersDepth >= 0) { + + // Do not use alignment break indentation in specific circumstances + boolean useAlignmentBreakIndentation; + boolean useAlignmentShiftBreakIndentation = false; + boolean useLastBinaryExpressionAlignmentBreakIndentation = false; + switch (emptyLinesRules) { + case DO_NOT_PRESERVE_EMPTY_LINES: + case PRESERVE_EMPTY_LINES_IN_SWITCH_CASE: + case PRESERVE_EMPTY_LINES_AT_END_OF_METHOD_DECLARATION: + case PRESERVE_EMPTY_LINES_AT_END_OF_BLOCK: + return PRESERVE_EMPTY_LINES_DO_NOT_USE_ANY_INDENTATION; + case PRESERVE_EMPTY_LINES_IN_BINARY_EXPRESSION: + useAlignmentBreakIndentation = true; + if ((this.formatter.expressionsPos & CodeFormatterVisitor.EXPRESSIONS_POS_MASK) == CodeFormatterVisitor.EXPRESSIONS_POS_BETWEEN_TWO) { + // we're just before the left expression, try to use the last + // binary expression break indentation if any + useLastBinaryExpressionAlignmentBreakIndentation = true; + } + break; + case PRESERVE_EMPTY_LINES_IN_EQUALITY_EXPRESSION: + useAlignmentShiftBreakIndentation = this.currentAlignment == null || this.currentAlignment.kind == Alignment.BINARY_EXPRESSION; + useAlignmentBreakIndentation = !useAlignmentShiftBreakIndentation; + break; + case PRESERVE_EMPTY_LINES_IN_FORMAT_OPENING_BRACE: + useAlignmentBreakIndentation = this.formatter.arrayInitializersDepth <= 1 + && this.currentAlignment != null + && this.currentAlignment.kind == Alignment.ARRAY_INITIALIZER; + break; + case PRESERVE_EMPTY_LINES_IN_FORMAT_LEFT_CURLY_BRACE: + useAlignmentBreakIndentation = false; + break; + default: + if ((emptyLinesRules & 0xFFFF) == PRESERVE_EMPTY_LINES_IN_CLOSING_ARRAY_INITIALIZER && this.scanner.currentCharacter == '}' ) { + // last array initializer closing brace + this.indentationLevel = emptyLinesRules >> 16; + this.preserveLineBreakIndentation = true; + return PRESERVE_EMPTY_LINES_USE_CURRENT_INDENTATION; + } + useAlignmentBreakIndentation = true; + break; + } + + // If there's an alignment try to align on its break indentation level + Alignment alignment = this.currentAlignment; + if (alignment == null) { + if (useLastBinaryExpressionAlignmentBreakIndentation) { + if (this.indentationLevel < this.formatter.lastBinaryExpressionAlignmentBreakIndentation) { + this.indentationLevel = this.formatter.lastBinaryExpressionAlignmentBreakIndentation; + } + } + if (useAlignmentShiftBreakIndentation && this.memberAlignment != null) { + if (this.indentationLevel < this.memberAlignment.shiftBreakIndentationLevel) { + this.indentationLevel = this.memberAlignment.shiftBreakIndentationLevel; + } + } + } else { + // Use the member alignment break indentation level when + // it's closer from the wrapped line than the current alignment + if (this.memberAlignment != null && this.memberAlignment.location.inputOffset > alignment.location.inputOffset) { + alignment = this.memberAlignment; + } + + // Use the break indentation level if possible... + if (useLastBinaryExpressionAlignmentBreakIndentation) { + if (this.indentationLevel < this.formatter.lastBinaryExpressionAlignmentBreakIndentation) { + this.indentationLevel = this.formatter.lastBinaryExpressionAlignmentBreakIndentation; + } + } + if (useAlignmentBreakIndentation) { + if (this.indentationLevel < alignment.breakIndentationLevel) { + this.indentationLevel = alignment.breakIndentationLevel; + } + } else if (useAlignmentShiftBreakIndentation) { + if (this.indentationLevel < alignment.shiftBreakIndentationLevel) { + this.indentationLevel = alignment.shiftBreakIndentationLevel; + } + } + } + this.preserveLineBreakIndentation = true; + if (useLastBinaryExpressionAlignmentBreakIndentation || useAlignmentShiftBreakIndentation) { + return PRESERVE_EMPTY_LINES_USE_TEMPORARY_INDENTATION; + } + return PRESERVE_EMPTY_LINES_USE_CURRENT_INDENTATION; + } + } + return PRESERVE_EMPTY_LINES_DO_NOT_USE_ANY_INDENTATION; + } public TextEdit getRootEdit() { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541 @@ -1446,6 +1499,11 @@ this.numberOfIndentations++; } + void setIndentation(int level, int n) { + this.indentationLevel = level + n * this.indentationSize; + this.numberOfIndentations = this.indentationLevel / this.indentationSize; + } + private void initializeScanner(long sourceLevel, DefaultCodeFormatterOptions preferences) { this.useTags = preferences.use_tags; this.tagsKind = 0; @@ -2344,13 +2402,21 @@ } void printComment() { - printComment(CodeFormatter.K_UNKNOWN, NO_TRAILING_COMMENT); + printComment(CodeFormatter.K_UNKNOWN, NO_TRAILING_COMMENT, PRESERVE_EMPTY_LINES_KEEP_LAST_NEW_LINES_INDENTATION); + } + + void printComment(int emptyLinesRules) { + printComment(CodeFormatter.K_UNKNOWN, NO_TRAILING_COMMENT, emptyLinesRules); + } + + void printComment(int kind, int trailing) { + printComment(kind, trailing, PRESERVE_EMPTY_LINES_KEEP_LAST_NEW_LINES_INDENTATION); } /* * Main method to print and format comments (javadoc, block and single line comments) */ - void printComment(int kind, int trailing) { + void printComment(int kind, int trailing, int emptyLinesRules) { 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; @@ -2464,12 +2530,18 @@ } else { if (lines == 0) { hasWhitespaces = true; - addDeleteEdit(tokenStartPosition, whitespacesEndPosition); + if (hasLineComment && emptyLinesRules != PRESERVE_EMPTY_LINES_KEEP_LAST_NEW_LINES_INDENTATION) { + addReplaceEdit(tokenStartPosition, whitespacesEndPosition, getPreserveEmptyLines(0, emptyLinesRules)); + } else { + addDeleteEdit(tokenStartPosition, whitespacesEndPosition); + } } else if (hasLineComment) { + useAlignmentBreakIndentation(emptyLinesRules); currentTokenStartPosition = tokenStartPosition; preserveEmptyLines(lines, currentTokenStartPosition); addDeleteEdit(currentTokenStartPosition, whitespacesEndPosition); } else if (hasComment) { + useAlignmentBreakIndentation(emptyLinesRules); if (lines == 1) { this.printNewLine(tokenStartPosition); } else { @@ -2477,8 +2549,9 @@ } addDeleteEdit(tokenStartPosition, whitespacesEndPosition); } else if (lines != 0 && (!this.formatter.preferences.join_wrapped_lines || this.formatter.preferences.number_of_empty_lines_to_preserve != 0 || this.blank_lines_between_import_groups > 0)) { - addReplaceEdit(tokenStartPosition, whitespacesEndPosition, getPreserveEmptyLines(lines-1)); + addReplaceEdit(tokenStartPosition, whitespacesEndPosition, getPreserveEmptyLines(lines-1, emptyLinesRules)); } else { + useAlignmentBreakIndentation(emptyLinesRules); addDeleteEdit(tokenStartPosition, whitespacesEndPosition); } } @@ -2712,6 +2785,7 @@ } } else { if (this.currentAlignment != null && this.currentAlignment.kind == Alignment.ARRAY_INITIALIZER && + this.currentAlignment.fragmentCount > 0 && this.indentationLevel < this.currentAlignment.breakIndentationLevel && this.lastLineComment.lines > 0) { @@ -2782,6 +2856,13 @@ } else if (this.currentAlignment.couldBreak() && this.currentAlignment.wasSplit) { this.currentAlignment.performFragmentEffect(); } + if (this.currentAlignment.kind == Alignment.BINARY_EXPRESSION && + this.currentAlignment.enclosing != null && + this.currentAlignment.enclosing.kind == Alignment.BINARY_EXPRESSION && + this.indentationLevel < this.currentAlignment.breakIndentationLevel) + { + this.indentationLevel = this.currentAlignment.breakIndentationLevel; + } } this.scanner.resetTo(currentTokenEndPosition, this.scannerEndPosition - 1); } @@ -4800,31 +4881,20 @@ } public void printNextToken(int expectedTokenType, boolean considerSpaceIfAny) { + printNextToken(expectedTokenType, considerSpaceIfAny, PRESERVE_EMPTY_LINES_KEEP_LAST_NEW_LINES_INDENTATION); + } + + public void printNextToken(int expectedTokenType, boolean considerSpaceIfAny, int emptyLineRules) { // Set brace flag, it's useful for the scribe while preserving line breaks - switch (expectedTokenType) { - case TerminalTokens.TokenNameRBRACE: - case TerminalTokens.TokenNameLBRACE: - this.formatBrace = true; - } + printComment(CodeFormatter.K_UNKNOWN, NO_TRAILING_COMMENT, emptyLineRules); try { - printComment(CodeFormatter.K_UNKNOWN, NO_TRAILING_COMMENT); - try { - this.currentToken = this.scanner.getNextToken(); - if (expectedTokenType != this.currentToken) { - throw new AbortFormatting("unexpected token type, expecting:"+expectedTokenType+", actual:"+this.currentToken);//$NON-NLS-1$//$NON-NLS-2$ - } - print(this.scanner.currentPosition - this.scanner.startPosition, considerSpaceIfAny); - } catch (InvalidInputException e) { - throw new AbortFormatting(e); - } - } - finally { - // Flush brace flag - switch (expectedTokenType) { - case TerminalTokens.TokenNameRBRACE: - case TerminalTokens.TokenNameLBRACE: - this.formatBrace = false; + this.currentToken = this.scanner.getNextToken(); + if (expectedTokenType != this.currentToken) { + throw new AbortFormatting("unexpected token type, expecting:"+expectedTokenType+", actual:"+this.currentToken);//$NON-NLS-1$//$NON-NLS-2$ } + print(this.scanner.currentPosition - this.scanner.startPosition, considerSpaceIfAny); + } catch (InvalidInputException e) { + throw new AbortFormatting(e); } } Index: formatter/org/eclipse/jdt/internal/formatter/align/Alignment.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/align/Alignment.java,v retrieving revision 1.40 diff -u -r1.40 Alignment.java --- formatter/org/eclipse/jdt/internal/formatter/align/Alignment.java 4 May 2010 08:45:55 -0000 1.40 +++ formatter/org/eclipse/jdt/internal/formatter/align/Alignment.java 27 Dec 2010 14:09:31 -0000 @@ -252,7 +252,7 @@ } public void checkColumn() { - if ((this.mode & M_MULTICOLUMN) != 0) { + if ((this.mode & M_MULTICOLUMN) != 0 && this.fragmentCount > 0) { int currentIndentation = this.scribe.getNextIndentationLevel(this.scribe.column+(this.scribe.needSpace ? 1 : 0)); int fragmentIndentation = this.fragmentIndentations[this.fragmentIndex]; if (currentIndentation > fragmentIndentation) { @@ -351,6 +351,7 @@ } public boolean couldBreak(){ + if (this.fragmentCount == 0) return false; int i; switch(this.mode & SPLIT_MASK){ @@ -445,8 +446,9 @@ } return false; // cannot split better } - + public boolean isWrapped() { + if (this.fragmentCount == 0) return false; return this.fragmentBreaks[this.fragmentIndex] == BREAK; } @@ -461,6 +463,7 @@ // perform alignment effect for current fragment public void performFragmentEffect(){ + if (this.fragmentCount == 0) return; if ((this.mode & M_MULTICOLUMN) == 0) { switch(this.mode & SPLIT_MASK) { case Alignment.M_COMPACT_SPLIT : #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.41 diff -u -r1.41 FormatterBugsTests.java --- src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java 23 Dec 2010 10:35:49 -0000 1.41 +++ src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java 27 Dec 2010 14:09:36 -0000 @@ -1242,7 +1242,8 @@ "public class Test {\n" + "\n" + " String foo(boolean enabled) {\n" + - " if (enabled) {\n" + + " if (enabled)\n" + + " {\n" + " // we need x\n" + " // we need a select\n" + " return \"select x \"\n" + @@ -1272,7 +1273,8 @@ "public class Test {\n" + "\n" + " String foo(boolean enabled) {\n" + - " if (enabled) {\n" + + " if (enabled)\n" + + " {\n" + " // we need x\n" + " // we need a select\n" + " return \"select x \"\n" + @@ -1897,8 +1899,8 @@ formatSource(source, "@MessageDriven(mappedName = \"filiality/SchedulerMQService\",\n" + " activationConfig = {\n" + - " @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" + - " propertyValue = \"0/10 * * * * ?\")\n" + + " @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" + + " propertyValue = \"0/10 * * * * ?\")\n" + " })\n" + "@RunAs(\"admin\")\n" + "@ResourceAdapter(\"quartz-ra.rar\")\n" + @@ -2621,8 +2623,10 @@ " }\n" + "}\n"; formatSource(source, - "public class Test {\n" + - " public void aMethod() {\n" + + "public class Test\n" + + "{\n" + + " public void aMethod()\n" + + " {\n" + " Object anObject = new Object()\n" + " {\n" + " boolean aVariable;\n" + @@ -2689,8 +2693,10 @@ " }\n" + "}\n"; formatSource(source, - "public class Test {\n" + - " public void aMethod() {\n" + + "public class Test\n" + + "{\n" + + " public void aMethod()\n" + + " {\n" + " Object anObject = new Object()\n" + " {\n" + " boolean aVariable;\n" + @@ -2721,398 +2727,232 @@ " }\n" + "}\n"; formatSource(source, - "public class Test {\n" + - " public void aMethod() {\n" + - " Object anObject = new Object() /* comment */\n" + - " {\n" + - " boolean aVariable;\n" + - "\n" + - " void foo() /* comment */\n" + - " {\n" + - " }\n" + - " };\n" + - " }\n" + - "}\n" - ); -} -public void testBug286601e() { - this.formatterPrefs.join_wrapped_lines = false; - setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE); - String source = - "public class Test\n" + - "{\n" + - " public void build(String href) {\n" + - " // set the href on the related topic\n" + - " if (href == null)\n" + - " setHref(\"\"); //$NON-NLS-1$\n" + - " else {\n" + - " if (!href.equals(\"\") // no empty link //$NON-NLS-1$\n" + - " && !href.startsWith(\"/\") // no help url //$NON-NLS-1$\n" + - " && href.indexOf(\':\') == -1) // no other protocols\n" + - " {\n" + - " setHref(\"/test/\" + href); //$NON-NLS-1$ //$NON-NLS-2$\n" + - " }\n" + - " }\n" + - " }\n" + - "}\n"; - formatSource(source, "public class Test\n" + "{\n" + - " public void build(String href)\n" + + " public void aMethod()\n" + " {\n" + - " // set the href on the related topic\n" + - " if (href == null)\n" + - " setHref(\"\"); //$NON-NLS-1$\n" + - " else\n" + + " Object anObject = new Object() /* comment */\n" + " {\n" + - " if (!href.equals(\"\") // no empty link //$NON-NLS-1$\n" + - " && !href.startsWith(\"/\") // no help url //$NON-NLS-1$\n" + - " && href.indexOf(\':\') == -1) // no other protocols\n" + - " {\n" + - " setHref(\"/test/\" + href); //$NON-NLS-1$ //$NON-NLS-2$\n" + - " }\n" + - " }\n" + - " }\n" + - "}\n" - ); -} -public void testBug286601f() { - this.formatterPrefs.join_wrapped_lines = false; - setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE); - String source = - "public class Test\n" + - "{\n" + - " \n" + - " private AntModel getAntModel(final File buildFile) {\n" + - " AntModel model= new AntModel(XMLCore.getDefault(), doc, null, new LocationProvider(null) {\n" + - " /* (non-Javadoc)\n" + - " * @see org.eclipse.ant.internal.ui.editor.outline.ILocationProvider#getLocation()\n" + - " */\n" + - " public IPath getLocation() {\n" + - " return new Path(buildFile.getAbsolutePath());\n" + - " }\n" + - " });\n" + - " model.reconcile(null);\n" + - " return model;\n" + - " }\n" + - "}\n"; - formatSource(source, - "public class Test\n" + - "{\n" + - "\n" + - " private AntModel getAntModel(final File buildFile)\n" + - " {\n" + - " AntModel model = new AntModel(XMLCore.getDefault(), doc, null,\n" + - " new LocationProvider(null)\n" + - " {\n" + - " /*\n" + - " * (non-Javadoc)\n" + - " * \n" + - " * @see\n" + - " * org.eclipse.ant.internal.ui.editor.outline.ILocationProvider\n" + - " * #getLocation()\n" + - " */\n" + - " public IPath getLocation()\n" + - " {\n" + - " return new Path(buildFile.getAbsolutePath());\n" + - " }\n" + - " });\n" + - " model.reconcile(null);\n" + - " return model;\n" + - " }\n" + - "}\n" - ); -} -public void testBug286601g() { - this.formatterPrefs.join_wrapped_lines = false; - String source = - "package massive;\n" + - "\n" + - "public class X05\n" + - "{\n" + - "\n" + - " public void foo() throws NullPointerException {\n" + - "\n" + - " Object body = new Object() {\n" + - " public void run(StringBuffer monitor) throws IllegalArgumentException {\n" + - " IResourceVisitor visitor = new IResourceVisitor() {\n" + - " public boolean visit(String resource) throws IllegalArgumentException {\n" + - " return true;\n" + - " }\n" + - " };\n" + - " }\n" + - " };\n" + - " }\n" + - "\n" + - "}\n" + - "interface IResourceVisitor {\n" + - "}\n"; - formatSource(source, - "package massive;\n" + - "\n" + - "public class X05 {\n" + - "\n" + - " public void foo() throws NullPointerException {\n" + - "\n" + - " Object body = new Object() {\n" + - " public void run(StringBuffer monitor)\n" + - " throws IllegalArgumentException {\n" + - " IResourceVisitor visitor = new IResourceVisitor() {\n" + - " public boolean visit(String resource)\n" + - " throws IllegalArgumentException {\n" + - " return true;\n" + - " }\n" + - " };\n" + - " }\n" + - " };\n" + - " }\n" + - "\n" + - "}\n" + - "\n" + - "interface IResourceVisitor {\n" + - "}\n" - ); -} -public void testBug286601h() { - this.formatterPrefs.join_wrapped_lines = false; - setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE); - String source = - "package massive;\n" + - "\n" + - "public class X05\n" + - "{\n" + - "\n" + - " public void foo() throws NullPointerException {\n" + - "\n" + - " Object body = new Object() {\n" + - " public void run(StringBuffer monitor) throws IllegalArgumentException {\n" + - " IResourceVisitor visitor = new IResourceVisitor() {\n" + - " public boolean visit(String resource) throws IllegalArgumentException {\n" + - " return true;\n" + - " }\n" + - " };\n" + - " }\n" + - " };\n" + - " }\n" + - "\n" + - "}\n" + - "interface IResourceVisitor {\n" + - "}\n"; - formatSource(source, - "package massive;\n" + - "\n" + - "public class X05\n" + - "{\n" + - "\n" + - " public void foo() throws NullPointerException\n" + - " {\n" + + " boolean aVariable;\n" + "\n" + - " Object body = new Object()\n" + - " {\n" + - " public void run(StringBuffer monitor)\n" + - " throws IllegalArgumentException\n" + + " void foo() /* comment */\n" + " {\n" + - " IResourceVisitor visitor = new IResourceVisitor()\n" + - " {\n" + - " public boolean visit(String resource)\n" + - " throws IllegalArgumentException\n" + - " {\n" + - " return true;\n" + - " }\n" + - " };\n" + " }\n" + " };\n" + " }\n" + - "\n" + - "}\n" + - "\n" + - "interface IResourceVisitor\n" + - "{\n" + - "}\n" - ); -} -public void testBug286601i1() { - this.formatterPrefs.join_wrapped_lines = false; - this.formatterPrefs.alignment_for_expressions_in_array_initializer = DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE; - setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE); - String source = - "package massive;\n" + - "\n" + - "public class X06a {\n" + - "\n" + - " \n" + - " // Table to merge access modes for condition statements (e.g branch[x] || branch[y]). \n" + - " private static final String[][] ACCESS_MODE_CONDITIONAL_TABLE= {\n" + - " /* Comment 1 */\n" + - " /* Comment 2 */ { \"1234567890123456789012345678901234567890\", \"1234567890123456789012345678901234567890\" },\n" + - " /* Comment 3 */ { \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\", \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\" },\n" + - " };\n" + - "\n" + - "}\n"; - formatSource(source, - "package massive;\n" + - "\n" + - "public class X06a\n" + - "{\n" + - "\n" + - " // Table to merge access modes for condition statements (e.g branch[x] ||\n" + - " // branch[y]).\n" + - " private static final String[][] ACCESS_MODE_CONDITIONAL_TABLE =\n" + - " {\n" + - " /* Comment 1 */\n" + - " /* Comment 2 */{ \"1234567890123456789012345678901234567890\", \"1234567890123456789012345678901234567890\" },\n" + - " /* Comment 3 */{ \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\", \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\" },\n" + - " };\n" + - "\n" + "}\n" ); } -public void testBug286601i2() { +public void testBug286601_massive_01() { this.formatterPrefs.join_wrapped_lines = false; - this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE; - this.formatterPrefs.alignment_for_expressions_in_array_initializer = DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE; setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE); String source = - "package massive;\n" + - "\n" + - "public class X06a {\n" + - "\n" + - " \n" + - " // Table to merge access modes for condition statements (e.g branch[x] || branch[y]). \n" + - " private static final String[][] ACCESS_MODE_CONDITIONAL_TABLE= {\n" + - " /* Comment 1 */\n" + - " /* Comment 2 */ { \"1234567890123456789012345678901234567890\", \"1234567890123456789012345678901234567890\" },\n" + - " /* Comment 3 */ { \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\", \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\" },\n" + - " };\n" + - "\n" + + "package massive;\n" + + "public class X01 {\n" + + " public void build(String href) {\n" + + " // set the href on the related topic\n" + + " if (href == null)\n" + + " setHref(\"\"); //$NON-NLS-1$\n" + + " else {\n" + + " if (!href.equals(\"\") // no empty link //$NON-NLS-1$\n" + + " && !href.startsWith(\"/\") // no help url //$NON-NLS-1$\n" + + " && href.indexOf(\':\') == -1) // no other protocols\n" + + " {\n" + + " setHref(\"/test/\" + href); //$NON-NLS-1$ //$NON-NLS-2$\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " private void setHref(String string)\n" + + " {\n" + + " \n" + + " }\n" + "}\n"; formatSource(source, - "package massive;\n" + - "\n" + - "public class X06a\n" + - "{\n" + - "\n" + - " // Table to merge access modes for condition statements (e.g branch[x] ||\n" + - " // branch[y]).\n" + - " private static final String[][] ACCESS_MODE_CONDITIONAL_TABLE =\n" + - " {\n" + - " /* Comment 1 */\n" + - " /* Comment 2 */{ \"1234567890123456789012345678901234567890\", \"1234567890123456789012345678901234567890\" },\n" + - " /* Comment 3 */{ \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\", \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\" },\n" + - " };\n" + - "\n" + + "package massive;\n" + + "\n" + + "public class X01\n" + + "{\n" + + " public void build(String href)\n" + + " {\n" + + " // set the href on the related topic\n" + + " if (href == null)\n" + + " setHref(\"\"); //$NON-NLS-1$\n" + + " else\n" + + " {\n" + + " if (!href.equals(\"\") // no empty link //$NON-NLS-1$\n" + + " && !href.startsWith(\"/\") // no help url //$NON-NLS-1$\n" + + " && href.indexOf(\':\') == -1) // no other protocols\n" + + " {\n" + + " setHref(\"/test/\" + href); //$NON-NLS-1$ //$NON-NLS-2$\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " private void setHref(String string)\n" + + " {\n" + + "\n" + + " }\n" + "}\n" ); } -public void testBug286601j1() { +public void testBug286601_massive_02() { this.formatterPrefs.join_wrapped_lines = false; - this.formatterPrefs.alignment_for_expressions_in_array_initializer = DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE; setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE); String source = - "package massive;\n" + - "\n" + - "public class X06b {\n" + - "\n" + - " \n" + - " // Table to merge access modes for condition statements (e.g branch[x] || branch[y]). \n" + - " private static final String[][] ACCESS_MODE_CONDITIONAL_TABLE= {\n" + - " { \"1234567890123456789012345678901234567890\", \"1234567890123456789012345678901234567890\" },\n" + - " { \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\", \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\" },\n" + - " };\n" + - "\n" + + "package massive;\n" + + "\n" + + "public class X02\n" + + "{\n" + + " \n" + + " private AntModel getAntModel(final File buildFile) {\n" + + " AntModel model= new AntModel(XMLCore.getDefault(), doc, null, new LocationProvider(null) {\n" + + " /* (non-Javadoc)\n" + + " * @see org.eclipse.ant.internal.ui.editor.outline.ILocationProvider#getLocation()\n" + + " */\n" + + " public IPath getLocation() {\n" + + " return new Path(buildFile.getAbsolutePath());\n" + + " }\n" + + " });\n" + + " model.reconcile(null);\n" + + " return model;\n" + + " }\n" + "}\n"; formatSource(source, - "package massive;\n" + - "\n" + - "public class X06b\n" + - "{\n" + - "\n" + - " // Table to merge access modes for condition statements (e.g branch[x] ||\n" + - " // branch[y]).\n" + - " private static final String[][] ACCESS_MODE_CONDITIONAL_TABLE =\n" + - " {\n" + - " { \"1234567890123456789012345678901234567890\", \"1234567890123456789012345678901234567890\" },\n" + - " { \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\", \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\" },\n" + - " };\n" + - "\n" + + "package massive;\n" + + "\n" + + "public class X02\n" + + "{\n" + + "\n" + + " private AntModel getAntModel(final File buildFile)\n" + + " {\n" + + " AntModel model = new AntModel(XMLCore.getDefault(), doc, null,\n" + + " new LocationProvider(null)\n" + + " {\n" + + " /*\n" + + " * (non-Javadoc)\n" + + " * \n" + + " * @see\n" + + " * org.eclipse.ant.internal.ui.editor.outline.ILocationProvider\n" + + " * #getLocation()\n" + + " */\n" + + " public IPath getLocation()\n" + + " {\n" + + " return new Path(buildFile.getAbsolutePath());\n" + + " }\n" + + " });\n" + + " model.reconcile(null);\n" + + " return model;\n" + + " }\n" + "}\n" ); } -public void testBug286601j2() { +public void testBug286601_massive_03() { this.formatterPrefs.join_wrapped_lines = false; - this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE; - this.formatterPrefs.alignment_for_expressions_in_array_initializer = DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE; - setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE); String source = - "package massive;\n" + - "\n" + - "public class X06b {\n" + - "\n" + - " \n" + - " // Table to merge access modes for condition statements (e.g branch[x] || branch[y]). \n" + - " private static final String[][] ACCESS_MODE_CONDITIONAL_TABLE= {\n" + - " { \"1234567890123456789012345678901234567890\", \"1234567890123456789012345678901234567890\" },\n" + - " { \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\", \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\" },\n" + - " };\n" + - "\n" + + "package massive;\n" + + "\n" + + "public class X03\n" + + "{\n" + + "\n" + + " public void foo() throws NullPointerException {\n" + + "\n" + + " Object body = new Object() {\n" + + " public void run(StringBuffer monitor) throws IllegalArgumentException {\n" + + " IResourceVisitor visitor = new IResourceVisitor() {\n" + + " public boolean visit(String resource) throws IllegalArgumentException {\n" + + " return true;\n" + + " }\n" + + " };\n" + + " }\n" + + " };\n" + + " }\n" + + "\n" + + "}\n" + + "interface IResourceVisitor {\n" + "}\n"; formatSource(source, - "package massive;\n" + - "\n" + - "public class X06b\n" + - "{\n" + - "\n" + - " // Table to merge access modes for condition statements (e.g branch[x] ||\n" + - " // branch[y]).\n" + - " private static final String[][] ACCESS_MODE_CONDITIONAL_TABLE =\n" + - " {\n" + - " { \"1234567890123456789012345678901234567890\", \"1234567890123456789012345678901234567890\" },\n" + - " { \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\", \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\" },\n" + - " };\n" + - "\n" + + "package massive;\n" + + "\n" + + "public class X03\n" + + "{\n" + + "\n" + + " public void foo() throws NullPointerException {\n" + + "\n" + + " Object body = new Object() {\n" + + " public void run(StringBuffer monitor)\n" + + " throws IllegalArgumentException {\n" + + " IResourceVisitor visitor = new IResourceVisitor() {\n" + + " public boolean visit(String resource)\n" + + " throws IllegalArgumentException {\n" + + " return true;\n" + + " }\n" + + " };\n" + + " }\n" + + " };\n" + + " }\n" + + "\n" + + "}\n" + + "\n" + + "interface IResourceVisitor {\n" + "}\n" ); } -public void testBug286601k() { +public void testBug286601_wksp_03b() { this.formatterPrefs.join_wrapped_lines = false; - this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE; - this.formatterPrefs.alignment_for_expressions_in_array_initializer = DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE; setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE); String source = - "package massive;\n" + - "\n" + - "public class X07 {\n" + - " private MinimizedFileSystemElement selectFiles(final Object rootFileSystemObject, final IImportStructureProvider structureProvider) {\n" + - "\n" + - " BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {\n" + - " public void run() {\n" + - " //Create the root element from the supplied file system object\n" + - " }\n" + - " });\n" + - "\n" + - " return null;\n" + - " }\n" + + "package massive;\n" + + "\n" + + "public class X03\n" + + "{\n" + + "\n" + + " public void foo() throws NullPointerException {\n" + + "\n" + + " Object body = new Object() {\n" + + " public void run(StringBuffer monitor) throws IllegalArgumentException {\n" + + " IResourceVisitor visitor = new IResourceVisitor() {\n" + + " public boolean visit(String resource) throws IllegalArgumentException {\n" + + " return true;\n" + + " }\n" + + " };\n" + + " }\n" + + " };\n" + + " }\n" + + "\n" + + "}\n" + + "interface IResourceVisitor {\n" + "}\n"; formatSource(source, - "package massive;\n" + - "\n" + - "public class X07\n" + - "{\n" + - " private MinimizedFileSystemElement selectFiles(\n" + - " final Object rootFileSystemObject,\n" + - " final IImportStructureProvider structureProvider)\n" + - " {\n" + - "\n" + - " BusyIndicator.showWhile(getShell().getDisplay(), new Runnable()\n" + - " {\n" + - " public void run()\n" + - " {\n" + - " // Create the root element from the supplied file system object\n" + - " }\n" + - " });\n" + - "\n" + - " return null;\n" + - " }\n" + + "package massive;\n" + + "\n" + + "public class X03\n" + + "{\n" + + "\n" + + " public void foo() throws NullPointerException\n" + + " {\n" + + "\n" + + " Object body = new Object()\n" + + " {\n" + + " public void run(StringBuffer monitor)\n" + + " throws IllegalArgumentException\n" + + " {\n" + + " IResourceVisitor visitor = new IResourceVisitor()\n" + + " {\n" + + " public boolean visit(String resource)\n" + + " throws IllegalArgumentException\n" + + " {\n" + + " return true;\n" + + " }\n" + + " };\n" + + " }\n" + + " };\n" + + " }\n" + + "\n" + + "}\n" + + "\n" + + "interface IResourceVisitor\n" + + "{\n" + "}\n" ); } @@ -7019,14 +6859,14 @@ " MessageFormat\n" + " .format(InternalAntMessages\n" + " .getString(\"InternalAntRunner.Buildfile__{0}_does_not_exist_!_1\"), //$NON-NLS-1$\n" + - " new String[] { buildFile.getAbsolutePath() }));\n" + + " new String[] { buildFile.getAbsolutePath() }));\n" + " }\n" + " if (!buildFile.isFile()) {\n" + " throw new BuildException(\n" + " MessageFormat\n" + " .format(InternalAntMessages\n" + " .getString(\"InternalAntRunner.Buildfile__{0}_is_not_a_file_1\"), //$NON-NLS-1$\n" + - " new String[] { buildFile.getAbsolutePath() }));\n" + + " new String[] { buildFile.getAbsolutePath() }));\n" + " }\n" + " }\n" + "}\n" @@ -7630,6 +7470,2851 @@ } /** + * @bug 330313: [formatter] 'Never join already wrapped lines' formatter option does correctly indent + * @test Ensure that indentation is correct when 'Never join already wrapped lines' is set + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=330313" + */ +public void testBug330313() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "public class Test {\n" + + " private void helper2(\n" + + " boolean[] booleans) {\n" + + " if (booleans[0]) {\n" + + "\n" + + " }\n" + + " }\n" + + "}\n"; + formatSource(source, + "public class Test {\n" + + " private void helper2(\n" + + " boolean[] booleans) {\n" + + " if (booleans[0]) {\n" + + "\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313a() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "public class Test {\n" + + " private void helper2(\n" + + " boolean[] booleans) {\n" + + " if (booleans[0]) {\n" + + "\n" + + " }\n" + + " }\n" + + "}\n"; + formatSource(source); +} +public void testBug330313b() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "public class Test {\n" + + " private void helper2(\n" + + " boolean[] booleans) {\n" + + " if (booleans[0]) {\n" + + "\n" + + " }\n" + + " }\n" + + "}\n"; + formatSource(source, + "public class Test {\n" + + " private void helper2(\n" + + " boolean[] booleans) {\n" + + " if (booleans[0]) {\n" + + "\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313c() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "public class Test {\n" + + " private void helper2(\n" + + "boolean[] booleans) {\n" + + " if (booleans[0]) {\n" + + "\n" + + " }\n" + + " }\n" + + "}\n"; + formatSource(source, + "public class Test {\n" + + " private void helper2(\n" + + " boolean[] booleans) {\n" + + " if (booleans[0]) {\n" + + "\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313d() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "public class Test {\n" + + " private void helper2(\n" + + " boolean[] booleans) {\n" + + " if (booleans[0]) {\n" + + "\n" + + " }\n" + + " }\n" + + "}\n"; + formatSource(source, + "public class Test {\n" + + " private void helper2(\n" + + " boolean[] booleans) {\n" + + " if (booleans[0]) {\n" + + "\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_regression_187a() { + String source = + "import java.io.File;\n" + + "\n" + + "public class RegressionTest_187 {\n" + + "\n" + + " private String createC42PDFCommandLine(String documentName) {\n" + + " return (Registry.getConvertToolPath() + File.separator +\n" + + " Registry.getConvertToolName() +\n" + + " \" -o \" + _workingDir + File.separator + documentName +\n" + + " \" -l \" + _workingDir + File.separator + _fileList);\n" + + " }\n" + + "}\n"; + formatSource(source, + "import java.io.File;\n" + + "\n" + + "public class RegressionTest_187 {\n" + + "\n" + + " private String createC42PDFCommandLine(String documentName) {\n" + + " return (Registry.getConvertToolPath() + File.separator\n" + + " + Registry.getConvertToolName() + \" -o \" + _workingDir\n" + + " + File.separator + documentName + \" -l \" + _workingDir\n" + + " + File.separator + _fileList);\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_regression_187b() { + String source = + "import java.io.File;\n" + + "\n" + + "public class RegressionTest_187 {\n" + + "\n" + + " private String createC42PDFCommandLine(String documentName) {\n" + + " return (Registry.getConvertToolPath() + File.separator +\n" + + " Registry.getConvertToolName() +\n" + + " (\" -o \" + _workingDir + File.separator + documentName +\n" + + " (\" -l \" + _workingDir + File.separator + _fileList)));\n" + + " }\n" + + "}\n"; + formatSource(source, + "import java.io.File;\n" + + "\n" + + "public class RegressionTest_187 {\n" + + "\n" + + " private String createC42PDFCommandLine(String documentName) {\n" + + " return (Registry.getConvertToolPath() + File.separator\n" + + " + Registry.getConvertToolName() + (\" -o \" + _workingDir\n" + + " + File.separator + documentName + (\" -l \" + _workingDir\n" + + " + File.separator + _fileList)));\n" + + " }\n" + + "}\n" + ); +} +//static { TESTS_PREFIX = "testBug330313_wksp1"; } +public void testBug330313_wksp1_01_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X01 {\n" + + "\n" + + " protected String getPrefixFromDocument(String aDocumentText, int anOffset) {\n" + + " int startOfWordToken = anOffset;\n" + + " \n" + + " char token= \'a\';\n" + + " if (startOfWordToken > 0) {\n" + + " token= aDocumentText.charAt(startOfWordToken - 1);\n" + + " }\n" + + " \n" + + " while (startOfWordToken > 0 \n" + + " && (Character.isJavaIdentifierPart(token) \n" + + " || \'.\' == token\n" + + " || \'-\' == token\n" + + " || \';\' == token)\n" + + " && !(\'$\' == token)) {\n" + + " startOfWordToken--;\n" + + " if (startOfWordToken == 0) {\n" + + " break; //word goes right to the beginning of the doc\n" + + " }\n" + + " token= aDocumentText.charAt(startOfWordToken - 1);\n" + + " }\n" + + " return \"\";\n" + + " }\n" + + "}\n"; + formatSource(source, + "package wksp1;\n" + + "\n" + + "public class X01 {\n" + + "\n" + + " protected String getPrefixFromDocument(String aDocumentText, int anOffset) {\n" + + " int startOfWordToken = anOffset;\n" + + "\n" + + " char token = \'a\';\n" + + " if (startOfWordToken > 0) {\n" + + " token = aDocumentText.charAt(startOfWordToken - 1);\n" + + " }\n" + + "\n" + + " while (startOfWordToken > 0\n" + + " && (Character.isJavaIdentifierPart(token)\n" + + " || \'.\' == token\n" + + " || \'-\' == token\n" + + " || \';\' == token)\n" + + " && !(\'$\' == token)) {\n" + + " startOfWordToken--;\n" + + " if (startOfWordToken == 0) {\n" + + " break; // word goes right to the beginning of the doc\n" + + " }\n" + + " token = aDocumentText.charAt(startOfWordToken - 1);\n" + + " }\n" + + " return \"\";\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_02_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X02 {\n" + + " public void testMethod(String currentTokenVal,\n" + + " int[][] expectedTokenSequencesVal,\n" + + " String[] tokenImageVal\n" + + " )\n" + + " {\n" + + " }\n" + + "}\n"; + formatSource(source, + "package wksp1;\n" + + "\n" + + "public class X02 {\n" + + " public void testMethod(String currentTokenVal,\n" + + " int[][] expectedTokenSequencesVal,\n" + + " String[] tokenImageVal\n" + + " )\n" + + " {\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_03_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X03 {\n" + + "\n" + + " void foo() {\n" + + " if (declaringClass.isNestedType()){\n" + + " NestedTypeBinding nestedType = (NestedTypeBinding) declaringClass;\n" + + " this.scope.extraSyntheticArguments = nestedType.syntheticOuterLocalVariables();\n" + + " scope.computeLocalVariablePositions(// consider synthetic arguments if any\n" + + " nestedType.enclosingInstancesSlotSize + 1,\n" + + " codeStream);\n" + + " argSlotSize += nestedType.enclosingInstancesSlotSize;\n" + + " argSlotSize += nestedType.outerLocalVariablesSlotSize;\n" + + " } else {\n" + + " scope.computeLocalVariablePositions(1, codeStream);\n" + + " }\n" + + " }\n" + + "}\n"; + formatSource(source, + "package wksp1;\n" + + "\n" + + "public class X03 {\n" + + "\n" + + " void foo() {\n" + + " if (declaringClass.isNestedType()) {\n" + + " NestedTypeBinding nestedType = (NestedTypeBinding) declaringClass;\n" + + " this.scope.extraSyntheticArguments = nestedType\n" + + " .syntheticOuterLocalVariables();\n" + + " scope.computeLocalVariablePositions(// consider synthetic arguments\n" + + " // if any\n" + + " nestedType.enclosingInstancesSlotSize + 1,\n" + + " codeStream);\n" + + " argSlotSize += nestedType.enclosingInstancesSlotSize;\n" + + " argSlotSize += nestedType.outerLocalVariablesSlotSize;\n" + + " } else {\n" + + " scope.computeLocalVariablePositions(1, codeStream);\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_04() { + String source = + "package wksp1;\n" + + "\n" + + "public class X04 {\n" + + "\n" + + " void foo() {\n" + + " for (;;) {\n" + + " if (act <= NUM_RULES) { // reduce action\n" + + " tempStackTop--;\n" + + " } else if (act < ACCEPT_ACTION || // shift action\n" + + " act > ERROR_ACTION) { // shift-reduce action\n" + + " if (indx == MAX_DISTANCE)\n" + + " return indx;\n" + + " indx++;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"; + formatSource(source, + "package wksp1;\n" + + "\n" + + "public class X04 {\n" + + "\n" + + " void foo() {\n" + + " for (;;) {\n" + + " if (act <= NUM_RULES) { // reduce action\n" + + " tempStackTop--;\n" + + " } else if (act < ACCEPT_ACTION || // shift action\n" + + " act > ERROR_ACTION) { // shift-reduce action\n" + + " if (indx == MAX_DISTANCE)\n" + + " return indx;\n" + + " indx++;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_04_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X04 {\n" + + "\n" + + " void foo() {\n" + + " for (;;) {\n" + + " if (act <= NUM_RULES) { // reduce action\n" + + " tempStackTop--;\n" + + " } else if (act < ACCEPT_ACTION || // shift action\n" + + " act > ERROR_ACTION) { // shift-reduce action\n" + + " if (indx == MAX_DISTANCE)\n" + + " return indx;\n" + + " indx++;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"; + formatSource(source, + "package wksp1;\n" + + "\n" + + "public class X04 {\n" + + "\n" + + " void foo() {\n" + + " for (;;) {\n" + + " if (act <= NUM_RULES) { // reduce action\n" + + " tempStackTop--;\n" + + " } else if (act < ACCEPT_ACTION || // shift action\n" + + " act > ERROR_ACTION) { // shift-reduce action\n" + + " if (indx == MAX_DISTANCE)\n" + + " return indx;\n" + + " indx++;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_05_njl() { + this.formatterPrefs.join_wrapped_lines = false; + setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE); + String source = + "package wksp1;\n" + + "\n" + + "public class X05 {\n" + + "\n" + + " private void foo() {\n" + + " setBuildFileLocation.invoke(runner, new Object[] { buildFileLocation });\n" + + " }\n" + + "}\n"; + formatSource(source, + "package wksp1;\n" + + "\n" + + "public class X05\n" + + "{\n" + + "\n" + + " private void foo()\n" + + " {\n" + + " setBuildFileLocation.invoke(runner, new Object[]\n" + + " { buildFileLocation });\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_06_njl() { + this.formatterPrefs.join_wrapped_lines = false; + setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE); + String source = + "package wksp1;\n" + + "\n" + + "public class X06 {\n" + + "\n" + + " public void foo(Object index) {\n" + + "\n" + + " try {\n" + + " index = this.manager.getIndexForUpdate(this.containerPath, true, /*reuse index file*/ true /*create if none*/);\n" + + " }\n" + + " finally {}\n" + + " }\n" + + "}\n"; + formatSource(source, + "package wksp1;\n" + + "\n" + + "public class X06\n" + + "{\n" + + "\n" + + " public void foo(Object index)\n" + + " {\n" + + "\n" + + " try\n" + + " {\n" + + " index = this.manager.getIndexForUpdate(this.containerPath, true, /*\n" + + " * reuse\n" + + " * index\n" + + " * file\n" + + " */\n" + + " true /* create if none */);\n" + + " } finally\n" + + " {\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_07() { + String source = + "package wksp1;\n" + + "\n" + + "public class X07 {\n" + + "\n" + + "static final long[] jjtoToken = {\n" + + " 0x7fbfecffL, \n" + + "};\n" + + "static final long[] jjtoSkip = {\n" + + " 0x400000L, \n" + + "};\n" + + "\n" + + "}\n"; + formatSource(source, + "package wksp1;\n" + + "\n" + + "public class X07 {\n" + + "\n" + + " static final long[] jjtoToken = { 0x7fbfecffL, };\n" + + " static final long[] jjtoSkip = { 0x400000L, };\n" + + "\n" + + "}\n" + ); +} +public void testBug330313_wksp1_07_bnl() { + setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE); + String source = + "package wksp1;\n" + + "\n" + + "public class X07 {\n" + + "\n" + + "static final long[] jjtoToken = {\n" + + " 0x7fbfecffL, \n" + + "};\n" + + "static final long[] jjtoSkip = {\n" + + " 0x400000L, \n" + + "};\n" + + "\n" + + "}\n"; + formatSource(source, + "package wksp1;\n" + + "\n" + + "public class X07\n" + + "{\n" + + "\n" + + " static final long[] jjtoToken =\n" + + " { 0x7fbfecffL, };\n" + + " static final long[] jjtoSkip =\n" + + " { 0x400000L, };\n" + + "\n" + + "}\n" + ); +} +public void testBug330313_wksp1_07_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X07 {\n" + + "\n" + + "static final long[] jjtoToken = {\n" + + " 0x7fbfecffL, \n" + + "};\n" + + "static final long[] jjtoSkip = {\n" + + " 0x400000L, \n" + + "};\n" + + "\n" + + "}\n"; + formatSource(source, + "package wksp1;\n" + + "\n" + + "public class X07 {\n" + + "\n" + + " static final long[] jjtoToken = {\n" + + " 0x7fbfecffL,\n" + + " };\n" + + " static final long[] jjtoSkip = {\n" + + " 0x400000L,\n" + + " };\n" + + "\n" + + "}\n" + ); +} +public void testBug330313_wksp1_07_njl_bnl() { + this.formatterPrefs.join_wrapped_lines = false; + setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE); + String source = + "package wksp1;\n" + + "\n" + + "public class X07 {\n" + + "\n" + + "static final long[] jjtoToken = {\n" + + " 0x7fbfecffL, \n" + + "};\n" + + "static final long[] jjtoSkip = {\n" + + " 0x400000L, \n" + + "};\n" + + "\n" + + "}\n"; + formatSource(source, + "package wksp1;\n" + + "\n" + + "public class X07\n" + + "{\n" + + "\n" + + " static final long[] jjtoToken =\n" + + " {\n" + + " 0x7fbfecffL,\n" + + " };\n" + + " static final long[] jjtoSkip =\n" + + " {\n" + + " 0x400000L,\n" + + " };\n" + + "\n" + + "}\n" + ); +} +public void testBug330313_wksp1_08_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X08 {\n" + + "\n" + + " void foo() {\n" + + " MinimizedFileSystemElement dummyParent =\n" + + " new MinimizedFileSystemElement(\"\", null, true);//$NON-NLS-1$\n" + + " }\n" + + "}\n"; + formatSource(source, + "package wksp1;\n" + + "\n" + + "public class X08 {\n" + + "\n" + + " void foo() {\n" + + " MinimizedFileSystemElement dummyParent =\n" + + " new MinimizedFileSystemElement(\"\", null, true);//$NON-NLS-1$\n" + + " }\n" + + "}\n" + ); +} +// testCompare1159_1: org.eclipse.debug.internal.ui.DebugUIPropertiesAdapterFactory +public void testBug330313_wksp1_09_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X09 {\n" + + " public Class[] getAdapterList() {\n" + + " return new Class[] {\n" + + " IWorkbenchAdapter.class\n" + + " };\n" + + " }\n" + + "}\n"; + formatSource(source, + "package wksp1;\n" + + "\n" + + "public class X09 {\n" + + " public Class[] getAdapterList() {\n" + + " return new Class[] {\n" + + " IWorkbenchAdapter.class\n" + + " };\n" + + " }\n" + + "}\n" + ); +} +// testCompare1723_1: org.eclipse.jdt.internal.compiler.ast.DoubleLiteral +public void testBug330313_wksp1_10_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X10 {\n" + + "\n" + + "public void computeConstant() {\n" + + "\n" + + " if (true)\n" + + " { //only a true 0 can be made of zeros\n" + + " //2.00000000000000000e-324 is illegal .... \n" + + " }}\n" + + "}\n"; + formatSource(source, + "package wksp1;\n" + + "\n" + + "public class X10 {\n" + + "\n" + + " public void computeConstant() {\n" + + "\n" + + " if (true)\n" + + " { // only a true 0 can be made of zeros\n" + + " // 2.00000000000000000e-324 is illegal ....\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +// testCompare1794_1: org.eclipse.jdt.internal.compiler.ast.ClassFile +public void testBug330313_wksp1_11_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X11 {\n" + + " X11() {\n" + + " accessFlags\n" + + " &= ~(\n" + + " AccStrictfp\n" + + " | AccProtected\n" + + " | AccPrivate\n" + + " | AccStatic\n" + + " | AccSynchronized\n" + + " | AccNative);\n" + + " }\n" + + "}\n"; + formatSource(source, + "package wksp1;\n" + + "\n" + + "public class X11 {\n" + + " X11() {\n" + + " accessFlags &= ~(\n" + + " AccStrictfp\n" + + " | AccProtected\n" + + " | AccPrivate\n" + + " | AccStatic\n" + + " | AccSynchronized\n" + + " | AccNative);\n" + + " }\n" + + "}\n" + ); +} +// rg.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/XmlFormatter.java +public void testBug330313_wksp1_12() { + String source = + "package wksp1;\n" + + "\n" + + "public class X12 {\n" + + "\n" + + " private static Document createDocument(String string, Position[] positions) throws IllegalArgumentException {\n" + + " Document doc= new Document(string);\n" + + " try {\n" + + " if (positions != null) {\n" + + " doc.addPositionUpdater(new DefaultPositionUpdater(POS_CATEGORY) {\n" + + " protected boolean notDeleted() {\n" + + " if (fOffset < fPosition.offset && (fPosition.offset + fPosition.length < fOffset + fLength)) {\n" + + " return false;\n" + + " }\n" + + " return true;\n" + + " }\n" + + " });\n" + + " }\n" + + " } catch (BadPositionCategoryException cannotHappen) {\n" + + " // can not happen: category is correctly set up\n" + + " }\n" + + " return doc;\n" + + " }\n" + + "}\n"; + formatSource(source, + "package wksp1;\n" + + "\n" + + "public class X12 {\n" + + "\n" + + " private static Document createDocument(String string, Position[] positions)\n" + + " throws IllegalArgumentException {\n" + + " Document doc = new Document(string);\n" + + " try {\n" + + " if (positions != null) {\n" + + " doc.addPositionUpdater(new DefaultPositionUpdater(POS_CATEGORY) {\n" + + " protected boolean notDeleted() {\n" + + " if (fOffset < fPosition.offset\n" + + " && (fPosition.offset + fPosition.length < fOffset\n" + + " + fLength)) {\n" + + " return false;\n" + + " }\n" + + " return true;\n" + + " }\n" + + " });\n" + + " }\n" + + " } catch (BadPositionCategoryException cannotHappen) {\n" + + " // can not happen: category is correctly set up\n" + + " }\n" + + " return doc;\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_12_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X12 {\n" + + "\n" + + " private static Document createDocument(String string, Position[] positions) throws IllegalArgumentException {\n" + + " Document doc= new Document(string);\n" + + " try {\n" + + " if (positions != null) {\n" + + " doc.addPositionUpdater(new DefaultPositionUpdater(POS_CATEGORY) {\n" + + " protected boolean notDeleted() {\n" + + " if (fOffset < fPosition.offset && (fPosition.offset + fPosition.length < fOffset + fLength)) {\n" + + " return false;\n" + + " }\n" + + " return true;\n" + + " }\n" + + " });\n" + + " }\n" + + " } catch (BadPositionCategoryException cannotHappen) {\n" + + " // can not happen: category is correctly set up\n" + + " }\n" + + " return doc;\n" + + " }\n" + + "}\n"; + formatSource(source, + "package wksp1;\n" + + "\n" + + "public class X12 {\n" + + "\n" + + " private static Document createDocument(String string, Position[] positions)\n" + + " throws IllegalArgumentException {\n" + + " Document doc = new Document(string);\n" + + " try {\n" + + " if (positions != null) {\n" + + " doc.addPositionUpdater(new DefaultPositionUpdater(POS_CATEGORY) {\n" + + " protected boolean notDeleted() {\n" + + " if (fOffset < fPosition.offset\n" + + " && (fPosition.offset + fPosition.length < fOffset\n" + + " + fLength)) {\n" + + " return false;\n" + + " }\n" + + " return true;\n" + + " }\n" + + " });\n" + + " }\n" + + " } catch (BadPositionCategoryException cannotHappen) {\n" + + " // can not happen: category is correctly set up\n" + + " }\n" + + " return doc;\n" + + " }\n" + + "}\n" + ); +} +// Test case extracted from org.eclipse.ant.ui/org/eclipse/core/internal/dtree/NodeInfo.java +public void testBug330313_wksp1_13() { + String source = + "package wksp1;\n" + + "\n" + + "public class X13 {\n" + + "\n" + + " public boolean isEmptyDelta() {\n" + + " return (this.getType() == AbstractDataTreeNode.T_NO_DATA_DELTA_NODE && this.getNamesOfChildren().length == 0 && this.getNamesOfDeletedChildren().length == 0);\n" + + " }\n" + + "}\n"; + formatSource(source, + "package wksp1;\n" + + "\n" + + "public class X13 {\n" + + "\n" + + " public boolean isEmptyDelta() {\n" + + " return (this.getType() == AbstractDataTreeNode.T_NO_DATA_DELTA_NODE\n" + + " && this.getNamesOfChildren().length == 0 && this\n" + + " .getNamesOfDeletedChildren().length == 0);\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_13_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X13 {\n" + + "\n" + + " public boolean isEmptyDelta() {\n" + + " return (this.getType() == AbstractDataTreeNode.T_NO_DATA_DELTA_NODE && this.getNamesOfChildren().length == 0 && this.getNamesOfDeletedChildren().length == 0);\n" + + " }\n" + + "}\n"; + formatSource(source, + "package wksp1;\n" + + "\n" + + "public class X13 {\n" + + "\n" + + " public boolean isEmptyDelta() {\n" + + " return (this.getType() == AbstractDataTreeNode.T_NO_DATA_DELTA_NODE\n" + + " && this.getNamesOfChildren().length == 0 && this\n" + + " .getNamesOfDeletedChildren().length == 0);\n" + + " }\n" + + "}\n" + ); +} +// Test case extracted from org.eclipse.jdt.core/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java +public void testBug330313_wksp1_14() { + String source = + "package wksp1;\n" + + "\n" + + "public class X14 {\n" + + " public void foo() {\n" + + " if (true) {\n" + + " if (((bits & DepthMASK) != 0)\n" + + " && (fieldBinding.isPrivate() // private access\n" + + " || (fieldBinding.isProtected() // implicit protected access\n" + + " && fieldBinding.declaringClass.getPackage() \n" + + " != currentScope.enclosingSourceType().getPackage()))) {\n" + + " return;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"; + formatSource(source, + "package wksp1;\n" + + "\n" + + "public class X14 {\n" + + " public void foo() {\n" + + " if (true) {\n" + + " if (((bits & DepthMASK) != 0) && (fieldBinding.isPrivate() // private\n" + + " // access\n" + + " || (fieldBinding.isProtected() // implicit protected access\n" + + " && fieldBinding.declaringClass.getPackage() != currentScope\n" + + " .enclosingSourceType().getPackage()))) {\n" + + " return;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_14_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X14 {\n" + + " public void foo() {\n" + + " if (true) {\n" + + " if (((bits & DepthMASK) != 0)\n" + + " && (fieldBinding.isPrivate() // private access\n" + + " || (fieldBinding.isProtected() // implicit protected access\n" + + " && fieldBinding.declaringClass.getPackage() \n" + + " != currentScope.enclosingSourceType().getPackage()))) {\n" + + " return;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"; + formatSource(source, + "package wksp1;\n" + + "\n" + + "public class X14 {\n" + + " public void foo() {\n" + + " if (true) {\n" + + " if (((bits & DepthMASK) != 0)\n" + + " && (fieldBinding.isPrivate() // private access\n" + + " || (fieldBinding.isProtected() // implicit protected access\n" + + " && fieldBinding.declaringClass.getPackage()\n" + + " != currentScope.enclosingSourceType().getPackage()))) {\n" + + " return;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +// Test case extracted from org.eclipse.jdt.core/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java +public void testBug330313_wksp1_15_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X15 {\n" + + " public void foo() {\n" + + " if (true) {\n" + + " if (fieldBinding.declaringClass != this.actualReceiverType\n" + + " && !this.actualReceiverType.isArrayType() \n" + + " && fieldBinding.declaringClass != null\n" + + " && fieldBinding.constant == NotAConstant\n" + + " && ((currentScope.environment().options.targetJDK >= ClassFileConstants.JDK1_2 \n" + + " && !fieldBinding.isStatic()\n" + + " && fieldBinding.declaringClass.id != T_Object) // no change for Object fields (if there was any)\n" + + " || !fieldBinding.declaringClass.canBeSeenBy(currentScope))){\n" + + " this.codegenBinding = currentScope.enclosingSourceType().getUpdatedFieldBinding(fieldBinding, (ReferenceBinding)this.actualReceiverType);\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"; + formatSource(source, + "package wksp1;\n" + + "\n" + + "public class X15 {\n" + + " public void foo() {\n" + + " if (true) {\n" + + " if (fieldBinding.declaringClass != this.actualReceiverType\n" + + " && !this.actualReceiverType.isArrayType()\n" + + " && fieldBinding.declaringClass != null\n" + + " && fieldBinding.constant == NotAConstant\n" + + " && ((currentScope.environment().options.targetJDK >= ClassFileConstants.JDK1_2\n" + + " && !fieldBinding.isStatic()\n" + + " && fieldBinding.declaringClass.id != T_Object) // no\n" + + " // change\n" + + " // for\n" + + " // Object\n" + + " // fields\n" + + " // (if\n" + + " // there\n" + + " // was\n" + + " // any)\n" + + " || !fieldBinding.declaringClass\n" + + " .canBeSeenBy(currentScope))) {\n" + + " this.codegenBinding = currentScope.enclosingSourceType()\n" + + " .getUpdatedFieldBinding(fieldBinding,\n" + + " (ReferenceBinding) this.actualReceiverType);\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +// Test case 1941_1 (extracted from org.eclipse.jdt.core/org/eclipse/jdt/internal/compiler/ast/Parser.java) +public void testBug330313_wksp1_16() { + String source = + "package wksp1;\n" + + "\n" + + "public class X16 {\n" + + "void foo() {\n" + + " // recovery\n" + + " if (this.currentElement != null) {\n" + + " if (!(this.currentElement instanceof RecoveredType)\n" + + " && (this.currentToken == TokenNameDOT\n" + + " //|| declaration.modifiers != 0\n" + + " || (this.scanner.getLineNumber(declaration.type.sourceStart)\n" + + " != this.scanner.getLineNumber((int) (namePosition >>> 32))))){\n" + + " return;\n" + + " }\n" + + " }\n" + + "}\n" + + "}\n"; + formatSource(source, + "package wksp1;\n" + + "\n" + + "public class X16 {\n" + + " void foo() {\n" + + " // recovery\n" + + " if (this.currentElement != null) {\n" + + " if (!(this.currentElement instanceof RecoveredType)\n" + + " && (this.currentToken == TokenNameDOT\n" + + " // || declaration.modifiers != 0\n" + + " || (this.scanner\n" + + " .getLineNumber(declaration.type.sourceStart) != this.scanner\n" + + " .getLineNumber((int) (namePosition >>> 32))))) {\n" + + " return;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_16_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X16 {\n" + + "void foo() {\n" + + " // recovery\n" + + " if (this.currentElement != null) {\n" + + " if (!(this.currentElement instanceof RecoveredType)\n" + + " && (this.currentToken == TokenNameDOT\n" + + " //|| declaration.modifiers != 0\n" + + " || (this.scanner.getLineNumber(declaration.type.sourceStart)\n" + + " != this.scanner.getLineNumber((int) (namePosition >>> 32))))){\n" + + " return;\n" + + " }\n" + + " }\n" + + "}\n" + + "}\n"; + formatSource(source, + "package wksp1;\n" + + "\n" + + "public class X16 {\n" + + " void foo() {\n" + + " // recovery\n" + + " if (this.currentElement != null) {\n" + + " if (!(this.currentElement instanceof RecoveredType)\n" + + " && (this.currentToken == TokenNameDOT\n" + + " // || declaration.modifiers != 0\n" + + " || (this.scanner\n" + + " .getLineNumber(declaration.type.sourceStart)\n" + + " != this.scanner\n" + + " .getLineNumber((int) (namePosition >>> 32))))) {\n" + + " return;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +// Test case 1872_1 (extracted from org.eclipse.jdt.core/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java) +public void testBug330313_wksp1_17_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X17 {\n" + + " void foo() {\n" + + " if ((currentMethodScope = this.methodScope())\n" + + " != outerLocalVariable.declaringScope.methodScope()) {\n" + + " return;\n" + + " }\n" + + " }\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X17 {\n" + + " void foo() {\n" + + " if ((currentMethodScope = this.methodScope())\n" + + " != outerLocalVariable.declaringScope.methodScope()) {\n" + + " return;\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +// Test case 1964_1 (extracted from org.eclipse.jdt.core/org/eclipse/jdt/core/dom/ASTMatcher.java) +public void testBug330313_wksp1_18_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X18 {\n" + + " public boolean foo() {\n" + + " return (\n" + + " safeSubtreeMatch(node.getJavadoc(), o.getJavadoc())\n" + + " && safeSubtreeListMatch(node.modifiers(), o.modifiers())\n" + + " && safeSubtreeMatch(node.getName(), o.getName())\n" + + " && safeSubtreeListMatch(node.arguments(), o.arguments())\n" + + " && safeSubtreeListMatch(\n" + + " node.bodyDeclarations(),\n" + + " o.bodyDeclarations()));\n" + + " }\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X18 {\n" + + " public boolean foo() {\n" + + " return (safeSubtreeMatch(node.getJavadoc(), o.getJavadoc())\n" + + " && safeSubtreeListMatch(node.modifiers(), o.modifiers())\n" + + " && safeSubtreeMatch(node.getName(), o.getName())\n" + + " && safeSubtreeListMatch(node.arguments(), o.arguments())\n" + + " && safeSubtreeListMatch(\n" + + " node.bodyDeclarations(),\n" + + " o.bodyDeclarations()));\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_19_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X19 {\n" + + " public boolean foo() {\n" + + " return (\n" + + " safeSubtreeMatch(node.getJavadoc(), o.getJavadoc())\n" + + " && safeSubtreeListMatch(node.modifiers(), o.modifiers())\n" + + " && safeSubtreeMatch(node.getName(), o.getName())\n" + + " && safeSubtreeListMatch(node.superInterfaceTypes(), o.superInterfaceTypes())\n" + + " && safeSubtreeListMatch(\n" + + " node.bodyDeclarations(),\n" + + " o.bodyDeclarations()));\n" + + " }\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X19 {\n" + + " public boolean foo() {\n" + + " return (safeSubtreeMatch(node.getJavadoc(), o.getJavadoc())\n" + + " && safeSubtreeListMatch(node.modifiers(), o.modifiers())\n" + + " && safeSubtreeMatch(node.getName(), o.getName())\n" + + " && safeSubtreeListMatch(node.superInterfaceTypes(),\n" + + " o.superInterfaceTypes())\n" + + " && safeSubtreeListMatch(\n" + + " node.bodyDeclarations(),\n" + + " o.bodyDeclarations()));\n" + + " }\n" + + "}\n" + ); +} +// Test case extracted from org.eclipse.debug.ui/ui/org/eclipse/debug/ui/AbstractDebugView.java +public void testBug330313_wksp1_20_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X20 {\n" + + "\n" + + " static final String decode(String entity) {\n" + + " if (true) {\n" + + " if (entity.charAt(2) == \'X\' || entity.charAt(2) == \'x\') {\n" + + " }\n" + + " Character c =\n" + + " new Character((char)Integer.parseInt(entity.substring(start), radix));\n" + + " return c.toString();\n" + + " }\n" + + " return \"\";\n" + + " }\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X20 {\n" + + "\n" + + " static final String decode(String entity) {\n" + + " if (true) {\n" + + " if (entity.charAt(2) == \'X\' || entity.charAt(2) == \'x\') {\n" + + " }\n" + + " Character c =\n" + + " new Character((char) Integer.parseInt(\n" + + " entity.substring(start), radix));\n" + + " return c.toString();\n" + + " }\n" + + " return \"\";\n" + + " }\n" + + "}\n" + ); +} +// Test case extracted from org.apache.lucene/src/org/apache/lucene/demo/html/Entities.java +public void testBug330313_wksp1_21_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X21 {\n" + + " public boolean isAvailable() {\n" + + " return !(getViewer() == null || getViewer().getControl() == null || getViewer().getControl().isDisposed());\n" + + " } \n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X21 {\n" + + " public boolean isAvailable() {\n" + + " return !(getViewer() == null || getViewer().getControl() == null || getViewer()\n" + + " .getControl().isDisposed());\n" + + " }\n" + + "}\n" + ); +} +// Test case extracted from differences noticed with patch v27.txt +public void testBug330313_wksp1_22_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X22 {\n" + + " public boolean foo() {\n" + + " return (\n" + + " (node.isInterface() == o.isInterface())\n" + + " && safeSubtreeMatch(node.getJavadoc(), o.getJavadoc())\n" + + " && safeSubtreeMatch(node.getName(), o.getName())\n" + + " && safeSubtreeListMatch(node.bodyDeclarations(), o.bodyDeclarations()));\n" + + " }\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X22 {\n" + + " public boolean foo() {\n" + + " return ((node.isInterface() == o.isInterface())\n" + + " && safeSubtreeMatch(node.getJavadoc(), o.getJavadoc())\n" + + " && safeSubtreeMatch(node.getName(), o.getName())\n" + + " && safeSubtreeListMatch(node.bodyDeclarations(),\n" + + " o.bodyDeclarations()));\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_23_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X23 {\n" + + " void foo() {\n" + + " boolean wasError = IMarker.SEVERITY_ERROR\n" + + " == pb.getAttribute(IMarker.SEVERITY,\n" + + " IMarker.SEVERITY_ERROR);\n" + + " }\n" + + "}\n"; + formatSource(source ); +} +public void testBug330313_wksp1_24_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X24 {\n" + + "\n" + + " protected boolean canRunEvaluation() {\n" + + " // NOTE similar to #canStep, except a quiet suspend state is OK\n" + + " try {\n" + + " return isSuspendedQuiet() || (isSuspended()\n" + + " && !(isPerformingEvaluation() || isInvokingMethod())\n" + + " && !isStepping()\n" + + " && getTopStackFrame() != null\n" + + " && !getJavaDebugTarget().isPerformingHotCodeReplace());\n" + + " } catch (DebugException e) {\n" + + " return false;\n" + + " }\n" + + " }\n" + + "}\n"; + formatSource(source ); +} +public void testBug330313_wksp1_25_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X25 {\n" + + "\n" + + " void unloadIcon(ImageData icon) {\n" + + " int sizeImage = (((icon.width * icon.depth + 31) / 32 * 4) +\n" + + " ((icon.width + 31) / 32 * 4)) * icon.height;\n" + + " }\n" + + "}\n"; + formatSource(source ); +} +public void testBug330313_wksp1_26_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X26 {\n" + + "\n" + + "void foo() {\n" + + " for (int i = 0; i < data.length; i++) {\n" + + " byte s = data[i];\n" + + " sourceData[i] = (byte)(((s & 0x80) >> 7) |\n" + + " ((s & 0x40) >> 5) |\n" + + " ((s & 0x20) >> 3) |\n" + + " ((s & 0x10) >> 1) |\n" + + " ((s & 0x08) << 1) |\n" + + " ((s & 0x04) << 3) |\n" + + " ((s & 0x02) << 5) |\n" + + " ((s & 0x01) << 7));\n" + + " }\n" + + "}\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X26 {\n" + + "\n" + + " void foo() {\n" + + " for (int i = 0; i < data.length; i++) {\n" + + " byte s = data[i];\n" + + " sourceData[i] = (byte) (((s & 0x80) >> 7) |\n" + + " ((s & 0x40) >> 5) |\n" + + " ((s & 0x20) >> 3) |\n" + + " ((s & 0x10) >> 1) |\n" + + " ((s & 0x08) << 1) |\n" + + " ((s & 0x04) << 3) |\n" + + " ((s & 0x02) << 5) |\n" + + " ((s & 0x01) << 7));\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_27_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X27 {\n" + + " private void foo() {\n" + + "\n" + + " if (_VerificationResult.getVerificationCode()\n" + + " == IVerificationResult.TYPE_ENTRY_SIGNED_UNRECOGNIZED\n" + + " || _VerificationResult.getVerificationCode()\n" + + " == IVerificationResult.TYPE_ENTRY_SIGNED_RECOGNIZED) {\n" + + " // Group box\n" + + " }\n" + + " }\n" + + "\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X27 {\n" + + " private void foo() {\n" + + "\n" + + " if (_VerificationResult.getVerificationCode()\n" + + " == IVerificationResult.TYPE_ENTRY_SIGNED_UNRECOGNIZED\n" + + " || _VerificationResult.getVerificationCode()\n" + + " == IVerificationResult.TYPE_ENTRY_SIGNED_RECOGNIZED) {\n" + + " // Group box\n" + + " }\n" + + " }\n" + + "\n" + + "}\n" + ); +} +public void testBug330313_wksp1_28_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X28 {\n" + + "\n" + + " void foo() {\n" + + " if (fieldBinding.declaringClass != lastReceiverType\n" + + " && !lastReceiverType.isArrayType() \n" + + " && fieldBinding.declaringClass != null\n" + + " && fieldBinding.constant == NotAConstant\n" + + " && ((currentScope.environment().options.targetJDK >= ClassFileConstants.JDK1_2\n" + + " && (fieldBinding != this.binding || this.indexOfFirstFieldBinding > 1 || !fieldBinding.isStatic())\n" + + " && fieldBinding.declaringClass.id != T_Object)\n" + + " || !(useDelegate\n" + + " ? new CodeSnippetScope(currentScope).canBeSeenByForCodeSnippet(fieldBinding.declaringClass, (ReferenceBinding) this.delegateThis.type)\n" + + " : fieldBinding.declaringClass.canBeSeenBy(currentScope)))){\n" + + " // code\n" + + " }\n" + + " }\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X28 {\n" + + "\n" + + " void foo() {\n" + + " if (fieldBinding.declaringClass != lastReceiverType\n" + + " && !lastReceiverType.isArrayType()\n" + + " && fieldBinding.declaringClass != null\n" + + " && fieldBinding.constant == NotAConstant\n" + + " && ((currentScope.environment().options.targetJDK >= ClassFileConstants.JDK1_2\n" + + " && (fieldBinding != this.binding\n" + + " || this.indexOfFirstFieldBinding > 1 || !fieldBinding\n" + + " .isStatic())\n" + + " && fieldBinding.declaringClass.id != T_Object)\n" + + " || !(useDelegate\n" + + " ? new CodeSnippetScope(currentScope)\n" + + " .canBeSeenByForCodeSnippet(\n" + + " fieldBinding.declaringClass,\n" + + " (ReferenceBinding) this.delegateThis.type)\n" + + " : fieldBinding.declaringClass\n" + + " .canBeSeenBy(currentScope)))) {\n" + + " // code\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_29_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X29 {\n" + + "\n" + + " boolean foo() {\n" + + " return (pack != null && otherpack != null && isSamePackage(pack, otherpack));\n" + + " }\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X29 {\n" + + "\n" + + " boolean foo() {\n" + + " return (pack != null && otherpack != null && isSamePackage(pack,\n" + + " otherpack));\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_30_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X30 {\n" + + " private boolean isInTypeNestedInInputType(ASTNode node, TypeDeclaration inputType){\n" + + " return (isInAnonymousTypeInsideInputType(node, inputType) ||\n" + + " isInLocalTypeInsideInputType(node, inputType) ||\n" + + " isInNonStaticMemberTypeInsideInputType(node, inputType));\n" + + " }\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X30 {\n" + + " private boolean isInTypeNestedInInputType(ASTNode node,\n" + + " TypeDeclaration inputType) {\n" + + " return (isInAnonymousTypeInsideInputType(node, inputType) ||\n" + + " isInLocalTypeInsideInputType(node, inputType) || isInNonStaticMemberTypeInsideInputType(\n" + + " node, inputType));\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_31_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X31 {\n" + + " void foo(int i) {\n" + + " if (true) {\n" + + " switch (i) {\n" + + " case 0:\n" + + " if (!((offset == (hashable.length - 1)) && !has95 && hasOneOf(meta63, hashable, offset - 2, 2) && !hasOneOf(meta64, hashable, offset - 4, 2)))\n" + + " buffer.append(\'R\');\n" + + " break;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X31 {\n" + + " void foo(int i) {\n" + + " if (true) {\n" + + " switch (i) {\n" + + " case 0:\n" + + " if (!((offset == (hashable.length - 1)) && !has95\n" + + " && hasOneOf(meta63, hashable, offset - 2, 2) && !hasOneOf(\n" + + " meta64, hashable, offset - 4, 2)))\n" + + " buffer.append(\'R\');\n" + + " break;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_32_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X32 {\n" + + " public boolean equals(Object object) {\n" + + " TextAttribute a= (TextAttribute) object;\n" + + " return (a.style == style && equals(a.foreground, foreground) && equals(a.background, background));\n" + + " }\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X32 {\n" + + " public boolean equals(Object object) {\n" + + " TextAttribute a = (TextAttribute) object;\n" + + " return (a.style == style && equals(a.foreground, foreground) && equals(\n" + + " a.background, background));\n" + + " }\n" + + "}\n" + ); +} +// Test case extracted from differences noticed with patch v29.txt +public void testBug330313_wksp1_33() { + String source = + "package wksp1;\n" + + "\n" + + "public class X33 {\n" + + " void foo() {\n" + + " if(inMetaTag &&\n" + + " ( t1.image.equalsIgnoreCase(\"name\") ||\n" + + " t1.image.equalsIgnoreCase(\"HTTP-EQUIV\")\n" + + " )\n" + + " && t2 != null)\n" + + " {\n" + + " currentMetaTag=t2.image.toLowerCase();\n" + + " }\n" + + " }\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X33 {\n" + + " void foo() {\n" + + " if (inMetaTag\n" + + " && (t1.image.equalsIgnoreCase(\"name\") || t1.image\n" + + " .equalsIgnoreCase(\"HTTP-EQUIV\")) && t2 != null) {\n" + + " currentMetaTag = t2.image.toLowerCase();\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_33_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X33 {\n" + + " void foo() {\n" + + " if(inMetaTag &&\n" + + " ( t1.image.equalsIgnoreCase(\"name\") ||\n" + + " t1.image.equalsIgnoreCase(\"HTTP-EQUIV\")\n" + + " )\n" + + " && t2 != null)\n" + + " {\n" + + " currentMetaTag=t2.image.toLowerCase();\n" + + " }\n" + + " }\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X33 {\n" + + " void foo() {\n" + + " if (inMetaTag &&\n" + + " (t1.image.equalsIgnoreCase(\"name\") ||\n" + + " t1.image.equalsIgnoreCase(\"HTTP-EQUIV\")\n" + + " )\n" + + " && t2 != null)\n" + + " {\n" + + " currentMetaTag = t2.image.toLowerCase();\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_34_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X34 {\n" + + " private boolean compareMarkers(ResourceInfo oldElement, ResourceInfo newElement) {\n" + + " boolean bothNull = oldElement.getMarkers(false) == null && newElement.getMarkers(false) == null;\n" + + " return bothNull || oldElement.getMarkerGenerationCount() == newElement.getMarkerGenerationCount();\n" + + " }\n" + + " private boolean compareSync(ResourceInfo oldElement, ResourceInfo newElement) {\n" + + " return oldElement.getSyncInfoGenerationCount() == newElement.getSyncInfoGenerationCount();\n" + + " }\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X34 {\n" + + " private boolean compareMarkers(ResourceInfo oldElement,\n" + + " ResourceInfo newElement) {\n" + + " boolean bothNull = oldElement.getMarkers(false) == null\n" + + " && newElement.getMarkers(false) == null;\n" + + " return bothNull\n" + + " || oldElement.getMarkerGenerationCount() == newElement\n" + + " .getMarkerGenerationCount();\n" + + " }\n" + + "\n" + + " private boolean compareSync(ResourceInfo oldElement, ResourceInfo newElement) {\n" + + " return oldElement.getSyncInfoGenerationCount() == newElement\n" + + " .getSyncInfoGenerationCount();\n" + + " }\n" + + "}\n" + ); +} +// Test case extracted from differences noticed with patch v30.txt +public void testBug330313_wksp1_35_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X35 {\n" + + " void foo() {\n" + + " if (true) {\n" + + " if (20+lineNum*printGC.getFontMetrics().getHeight() > printer.getClientArea().height) {\n" + + " //\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X35 {\n" + + " void foo() {\n" + + " if (true) {\n" + + " if (20 + lineNum * printGC.getFontMetrics().getHeight() > printer\n" + + " .getClientArea().height) {\n" + + " //\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +// Test case extracted from differences noticed with patch v32.txt +public void testBug330313_wksp1_36_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X36 {\n" + + " public static boolean isRuntimeException(ITypeBinding thrownException) {\n" + + " if (thrownException == null || thrownException.isPrimitive() || thrownException.isArray())\n" + + " return false;\n" + + " return findTypeInHierarchy(thrownException, \"java.lang.RuntimeException\") != null; //$NON-NLS-1$\n" + + " }\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X36 {\n" + + " public static boolean isRuntimeException(ITypeBinding thrownException) {\n" + + " if (thrownException == null || thrownException.isPrimitive()\n" + + " || thrownException.isArray())\n" + + " return false;\n" + + " return findTypeInHierarchy(thrownException,\n" + + " \"java.lang.RuntimeException\") != null; //$NON-NLS-1$\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_37_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X37 {\n" + + " void foo() {\n" + + " if (true) {\n" + + " if (ignoreQuickDiffPrefPage && (info.getAnnotationType().equals(\"org.eclipse.ui.workbench.texteditor.quickdiffChange\") //$NON-NLS-1$\n" + + " || (info.getAnnotationType().equals(\"org.eclipse.ui.workbench.texteditor.quickdiffAddition\")) //$NON-NLS-1$\n" + + " || (info.getAnnotationType().equals(\"org.eclipse.ui.workbench.texteditor.quickdiffDeletion\")) //$NON-NLS-1$\n" + + " )) \n" + + " continue;\n" + + " }\n" + + " }\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X37 {\n" + + " void foo() {\n" + + " if (true) {\n" + + " if (ignoreQuickDiffPrefPage\n" + + " && (info.getAnnotationType()\n" + + " .equals(\"org.eclipse.ui.workbench.texteditor.quickdiffChange\") //$NON-NLS-1$\n" + + " || (info.getAnnotationType()\n" + + " .equals(\"org.eclipse.ui.workbench.texteditor.quickdiffAddition\")) //$NON-NLS-1$\n" + + " || (info.getAnnotationType()\n" + + " .equals(\"org.eclipse.ui.workbench.texteditor.quickdiffDeletion\")) //$NON-NLS-1$\n" + + " ))\n" + + " continue;\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +// Test case extracted from differences noticed with patch v33.txt +public void testBug330313_wksp1_38_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X38 {\n" + + " void foo(boolean condition) {\n" + + " if (condition)\n" + + " {\n" + + " // block 1\n" + + " }\n" + + " else\n" + + " {\n" + + " // block 2\n" + + " }\n" + + " }\n" + + "}\n"; + formatSource(source ); +} +public void testBug330313_wksp1_39_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X39 {\n" + + "/**\n" + + " *
\n" + 
+		" *		RadioGroupFieldEditor editor= new RadioGroupFieldEditor(\n" + 
+		" *			\"GeneralPage.DoubleClick\", resName, 1,\n" + 
+		" *			new String[][] {\n" + 
+		" *				{\"Open Browser\", \"open\"},\n" + 
+		" *				{\"Expand Tree\", \"expand\"}\n" + 
+		" *			},\n" + 
+		" *          parent);	\n" + 
+		" * 
\n" + + " */\n" + + "public void foo() {\n" + + "}\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X39 {\n" + + " /**\n" + + " *
\n" + 
+		"	 * RadioGroupFieldEditor editor = new RadioGroupFieldEditor(\n" + 
+		"	 * 		"GeneralPage.DoubleClick", resName, 1,\n" + 
+		"	 * 		new String[][] {\n" + 
+		"	 * 				{ "Open Browser", "open" },\n" + 
+		"	 * 				{ "Expand Tree", "expand" }\n" + 
+		"	 * 		},\n" + 
+		"	 * 		parent);\n" + 
+		"	 * 
\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_40_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X40 {\n" + + " protected final static String[][] TABLE= new String[][] {\n" + + " /*INACTIVE*/ /*PARTLY_ACTIVE */ /*ACTIVE */\n" + + " /* INACTIVE */ { \"INACTIVE\", \"PARTLY_ACTIVE\", \"PARTLY_ACTIVE\" },\n" + + " /* PARTLY_ACTIVE*/ { \"PARTLY_ACTIVE\", \"PARTLY_ACTIVE\", \"PARTLY_ACTIVE\" },\n" + + " /* ACTIVE */ { \"PARTLY_ACTIVE\", \"PARTLY_ACTIVE\", \"ACTIVE\"}\n" + + " };\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X40 {\n" + + " protected final static String[][] TABLE = new String[][] {\n" + + " /* INACTIVE *//* PARTLY_ACTIVE *//* ACTIVE */\n" + + " /* INACTIVE */{ \"INACTIVE\", \"PARTLY_ACTIVE\", \"PARTLY_ACTIVE\" },\n" + + " /* PARTLY_ACTIVE */{ \"PARTLY_ACTIVE\", \"PARTLY_ACTIVE\",\n" + + " \"PARTLY_ACTIVE\" },\n" + + " /* ACTIVE */{ \"PARTLY_ACTIVE\", \"PARTLY_ACTIVE\", \"ACTIVE\" }\n" + + " };\n" + + "}\n" + ); +} +public void testBug330313_wksp1_41_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X41 {\n" + + " static final int [][] TABLE = {\n" + + " \n" + + " /* First */\n" + + " {1, 2},\n" + + " {3, 4},\n" + + " {5, 6},\n" + + "// {7????, 8},\n" + + "\n" + + " /* Second */ \n" + + "// {11, 12},\n" + + "// {13, 14},\n" + + "// {15, 16},\n" + + " \n" + + " \n" + + " /* Third */\n" + + " {21, 22},\n" + + " {23, 24},\n" + + " {25, 26},\n" + + "// {27????, 28},\n" + + "\n" + + " /* Others */\n" + + " {31, 32},\n" + + " {33, 34},\n" + + " {35, 36},\n" + + "// {37????, 38},\n" + + " \n" + + " };\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X41 {\n" + + " static final int[][] TABLE = {\n" + + "\n" + + " /* First */\n" + + " { 1, 2 },\n" + + " { 3, 4 },\n" + + " { 5, 6 },\n" + + " // {7????, 8},\n" + + "\n" + + " /* Second */\n" + + " // {11, 12},\n" + + " // {13, 14},\n" + + " // {15, 16},\n" + + "\n" + + " /* Third */\n" + + " { 21, 22 },\n" + + " { 23, 24 },\n" + + " { 25, 26 },\n" + + " // {27????, 28},\n" + + "\n" + + " /* Others */\n" + + " { 31, 32 },\n" + + " { 33, 34 },\n" + + " { 35, 36 },\n" + + " // {37????, 38},\n" + + "\n" + + " };\n" + + "}\n" + ); +} +public void testBug330313_wksp1_42_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X42 {\n" + + " static final byte[][] DashList = {\n" + + " { }, // SWT.LINE_SOLID\n" + + " { 10, 4 }, // SWT.LINE_DASH\n" + + " { 2, 2 }, // SWT.LINE_DOT\n" + + " { 10, 4, 2, 4 }, // SWT.LINE_DASHDOT\n" + + " { 10, 4, 2, 4, 2, 4 } // SWT.LINE_DASHDOTDOT\n" + + " };\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X42 {\n" + + " static final byte[][] DashList = {\n" + + " {}, // SWT.LINE_SOLID\n" + + " { 10, 4 }, // SWT.LINE_DASH\n" + + " { 2, 2 }, // SWT.LINE_DOT\n" + + " { 10, 4, 2, 4 }, // SWT.LINE_DASHDOT\n" + + " { 10, 4, 2, 4, 2, 4 } // SWT.LINE_DASHDOTDOT\n" + + " };\n" + + "}\n" + ); +} +public void testBug330313_wksp1_43_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X43 {\n" + + " Cloneable clone;\n" + + "X43() {\n" + + " this.clone = new Cloneable() {\n" + + " void foo(int x) {\n" + + " switch (x) {\n" + + " case 1:\n" + + " case 2:\n" + + " if (true) break;\n" + + " // FALL THROUGH\n" + + " case 3:\n" + + " case 4:\n" + + " break;\n" + + " }\n" + + " }\n" + + " };\n" + + "}\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X43 {\n" + + " Cloneable clone;\n" + + "\n" + + " X43() {\n" + + " this.clone = new Cloneable() {\n" + + " void foo(int x) {\n" + + " switch (x) {\n" + + " case 1:\n" + + " case 2:\n" + + " if (true)\n" + + " break;\n" + + " // FALL THROUGH\n" + + " case 3:\n" + + " case 4:\n" + + " break;\n" + + " }\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_44_njl() { + // TODO Could be improved to put the all array statements at the same indentation... + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X44 {\n" + + " String foo() {\n" + + " return Policy.bind(\"CVSAnnotateBlock.6\", new Object[] { //$NON-NLS-1$\n" + + " user,\n" + + " revision,\n" + + " String.valueOf(delta),\n" + + " line\n" + + " });\n" + + " }\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X44 {\n" + + " String foo() {\n" + + " return Policy.bind(\"CVSAnnotateBlock.6\", new Object[] { //$NON-NLS-1$\n" + + " user,\n" + + " revision,\n" + + " String.valueOf(delta),\n" + + " line\n" + + " });\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_45_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X45 {\n" + + " private String[][] TABLE = {\n" + + " {\"COL_REVISION\", \"COL_DATE\", \"COL_AUTHOR\", \"COL_COMMENT\", \"COL_TAGS\"}, /* revision */ \n" + + " {\"COL_TAGS\", \"COL_REVISION\", \"COL_DATE\", \"COL_AUTHOR\", \"COL_COMMENT\"}, /* tags */\n" + + " {\"COL_DATE\", \"COL_REVISION\", \"COL_AUTHOR\", \"COL_COMMENT\", \"COL_TAGS\"}, /* date */\n" + + " {\"COL_AUTHOR\", \"COL_REVISION\", \"COL_DATE\", \"COL_COMMENT\", \"COL_TAGS\"}, /* author */\n" + + " {\"COL_COMMENT\", \"COL_REVISION\", \"COL_DATE\", \"COL_AUTHOR\", \"COL_TAGS\"} /* comment */\n" + + " };\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X45 {\n" + + " private String[][] TABLE = {\n" + + " { \"COL_REVISION\", \"COL_DATE\", \"COL_AUTHOR\", \"COL_COMMENT\",\n" + + " \"COL_TAGS\" }, /* revision */\n" + + " { \"COL_TAGS\", \"COL_REVISION\", \"COL_DATE\", \"COL_AUTHOR\",\n" + + " \"COL_COMMENT\" }, /* tags */\n" + + " { \"COL_DATE\", \"COL_REVISION\", \"COL_AUTHOR\", \"COL_COMMENT\",\n" + + " \"COL_TAGS\" }, /* date */\n" + + " { \"COL_AUTHOR\", \"COL_REVISION\", \"COL_DATE\", \"COL_COMMENT\",\n" + + " \"COL_TAGS\" }, /* author */\n" + + " { \"COL_COMMENT\", \"COL_REVISION\", \"COL_DATE\", \"COL_AUTHOR\",\n" + + " \"COL_TAGS\" } /* comment */\n" + + " };\n" + + "}\n" + ); +} +public void testBug330313_wksp1_46_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X46 {\n" + + " void foo() {\n" + + " if (getActive() == StackPresentation.AS_ACTIVE_NOFOCUS) {\n" + + " drawGradient(\n" + + " colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_TEXT_COLOR), \n" + + " new Color [] {\n" + + " colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START) \n" + + " }, \n" + + " new int [0],\n" + + " true); \n" + + " }\n" + + " }\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X46 {\n" + + " void foo() {\n" + + " if (getActive() == StackPresentation.AS_ACTIVE_NOFOCUS) {\n" + + " drawGradient(\n" + + " colorRegistry\n" + + " .get(IWorkbenchThemeConstants.INACTIVE_TAB_TEXT_COLOR),\n" + + " new Color[] {\n" + + " colorRegistry\n" + + " .get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START)\n" + + " },\n" + + " new int[0],\n" + + " true);\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_47_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X47 {\n" + + " void foo(int x) {\n" + + " switch (x) {\n" + + " case 0 :\n" + + " // case 0\n" + + " break;\n" + + " case 3 :\n" + + " // case 3\n" + + " break;\n" + + " //case -1 :\n" + + " // internal failure: trying to load variable not supposed to be generated\n" + + " // break;\n" + + " default :\n" + + " // default\n" + + " }\n" + + " // last comment\n" + + " }\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X47 {\n" + + " void foo(int x) {\n" + + " switch (x) {\n" + + " case 0:\n" + + " // case 0\n" + + " break;\n" + + " case 3:\n" + + " // case 3\n" + + " break;\n" + + " // case -1 :\n" + + " // internal failure: trying to load variable not supposed to be\n" + + " // generated\n" + + " // break;\n" + + " default:\n" + + " // default\n" + + " }\n" + + " // last comment\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_48_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X48 {\n" + + " void foo(int x) {\n" + + " switch (x) {\n" + + " case 0 :\n" + + " // case 0\n" + + " break;\n" + + " case 3 :\n" + + " // case 3\n" + + " break;\n" + + " //case -1 :\n" + + " // internal failure: trying to load variable not supposed to be generated\n" + + " // break;\n" + + " }\n" + + " // last comment\n" + + " }\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X48 {\n" + + " void foo(int x) {\n" + + " switch (x) {\n" + + " case 0:\n" + + " // case 0\n" + + " break;\n" + + " case 3:\n" + + " // case 3\n" + + " break;\n" + + " // case -1 :\n" + + " // internal failure: trying to load variable not supposed to be\n" + + " // generated\n" + + " // break;\n" + + " }\n" + + " // last comment\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_49_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X49 {\n" + + " void foo(int i) {\n" + + " if (true) {\n" + + " if (true) {\n" + + " this.foundTaskPositions[this.foundTaskCount] = new int[] { i, i + tagLength - 1 };\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X49 {\n" + + " void foo(int i) {\n" + + " if (true) {\n" + + " if (true) {\n" + + " this.foundTaskPositions[this.foundTaskCount] = new int[] { i,\n" + + " i + tagLength - 1 };\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_50_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X50 {\n" + + "private void deployCodeSnippetClassIfNeeded(IRequestor requestor) {\n" + + " if (this.codeSnippetBinary == null) {\n" + + " // Deploy CodeSnippet class (only once)\n" + + " requestor.acceptClassFiles(\n" + + " new ClassFile[] {\n" + + " new ClassFile() {\n" + + " public byte[] getBytes() {\n" + + " return getCodeSnippetBytes();\n" + + " }\n" + + " public char[][] getCompoundName() {\n" + + " return EvaluationConstants.ROOT_COMPOUND_NAME;\n" + + " }\n" + + " }\n" + + " }, \n" + + " null);\n" + + " }\n" + + "}\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X50 {\n" + + " private void deployCodeSnippetClassIfNeeded(IRequestor requestor) {\n" + + " if (this.codeSnippetBinary == null) {\n" + + " // Deploy CodeSnippet class (only once)\n" + + " requestor.acceptClassFiles(\n" + + " new ClassFile[] {\n" + + " new ClassFile() {\n" + + " public byte[] getBytes() {\n" + + " return getCodeSnippetBytes();\n" + + " }\n" + + "\n" + + " public char[][] getCompoundName() {\n" + + " return EvaluationConstants.ROOT_COMPOUND_NAME;\n" + + " }\n" + + " }\n" + + " },\n" + + " null);\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_51_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X51 {\n" + + "\n" + + "protected void addAllSourceFiles(final ArrayList sourceFiles) throws CoreException {\n" + + " for (int i = 0, l = sourceLocations.length; i < l; i++) {\n" + + " sourceLocation.sourceFolder.accept(\n" + + " new IResourceProxyVisitor() {\n" + + " public boolean visit(IResourceProxy proxy) throws CoreException {\n" + + " IResource resource = null;\n" + + " switch(proxy.getType()) {\n" + + " case IResource.FILE :\n" + + " if (exclusionPatterns != null || inclusionPatterns != null) {\n" + + " resource = proxy.requestResource();\n" + + " if (Util.isExcluded(resource, inclusionPatterns, exclusionPatterns)) return false;\n" + + " }\n" + + " if (org.eclipse.jdt.internal.compiler.util.Util.isJavaFileName(proxy.getName())) {\n" + + " if (resource == null)\n" + + " resource = proxy.requestResource();\n" + + " sourceFiles.add(new SourceFile((IFile) resource, sourceLocation));\n" + + " }\n" + + " return false;\n" + + " case IResource.FOLDER :\n" + + " if (exclusionPatterns != null && inclusionPatterns == null) {\n" + + " // if there are inclusion patterns then we must walk the children\n" + + " resource = proxy.requestResource();\n" + + " if (Util.isExcluded(resource, inclusionPatterns, exclusionPatterns)) return false;\n" + + " }\n" + + " if (isAlsoProject && isExcludedFromProject(proxy.requestFullPath())) return false;\n" + + " }\n" + + " return true;\n" + + " }\n" + + " },\n" + + " IResource.NONE\n" + + " );\n" + + " notifier.checkCancel();\n" + + " }\n" + + "}\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X51 {\n" + + "\n" + + " protected void addAllSourceFiles(final ArrayList sourceFiles)\n" + + " throws CoreException {\n" + + " for (int i = 0, l = sourceLocations.length; i < l; i++) {\n" + + " sourceLocation.sourceFolder.accept(\n" + + " new IResourceProxyVisitor() {\n" + + " public boolean visit(IResourceProxy proxy)\n" + + " throws CoreException {\n" + + " IResource resource = null;\n" + + " switch (proxy.getType()) {\n" + + " case IResource.FILE:\n" + + " if (exclusionPatterns != null\n" + + " || inclusionPatterns != null) {\n" + + " resource = proxy.requestResource();\n" + + " if (Util.isExcluded(resource,\n" + + " inclusionPatterns,\n" + + " exclusionPatterns))\n" + + " return false;\n" + + " }\n" + + " if (org.eclipse.jdt.internal.compiler.util.Util\n" + + " .isJavaFileName(proxy.getName())) {\n" + + " if (resource == null)\n" + + " resource = proxy.requestResource();\n" + + " sourceFiles.add(new SourceFile(\n" + + " (IFile) resource, sourceLocation));\n" + + " }\n" + + " return false;\n" + + " case IResource.FOLDER:\n" + + " if (exclusionPatterns != null\n" + + " && inclusionPatterns == null) {\n" + + " // if there are inclusion patterns then we\n" + + " // must walk the children\n" + + " resource = proxy.requestResource();\n" + + " if (Util.isExcluded(resource,\n" + + " inclusionPatterns,\n" + + " exclusionPatterns))\n" + + " return false;\n" + + " }\n" + + " if (isAlsoProject\n" + + " && isExcludedFromProject(proxy\n" + + " .requestFullPath()))\n" + + " return false;\n" + + " }\n" + + " return true;\n" + + " }\n" + + " },\n" + + " IResource.NONE\n" + + " );\n" + + " notifier.checkCancel();\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_52_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp1;\n" + + "\n" + + "public class X52 {\n" + + " protected FastSyncInfoFilter getKnownFailureCases() {\n" + + " return new OrSyncInfoFilter(new FastSyncInfoFilter[] {\n" + + " // Conflicting additions of files will fail\n" + + " new AndSyncInfoFilter(new FastSyncInfoFilter[] {\n" + + " FastSyncInfoFilter.getDirectionAndChangeFilter(SyncInfo.CONFLICTING, SyncInfo.ADDITION),\n" + + " new FastSyncInfoFilter() {\n" + + " public boolean select(SyncInfo info) {\n" + + " return info.getLocal().getType() == IResource.FILE;\n" + + " }\n" + + " }\n" + + " }),\n" + + " // Conflicting changes of files will fail if the local is not managed\n" + + " // or is an addition\n" + + " new AndSyncInfoFilter(new FastSyncInfoFilter[] {\n" + + " FastSyncInfoFilter.getDirectionAndChangeFilter(SyncInfo.CONFLICTING, SyncInfo.CHANGE),\n" + + " new FastSyncInfoFilter() {\n" + + " public boolean select(SyncInfo info) {\n" + + " if (info.getLocal().getType() == IResource.FILE) {\n" + + " try {\n" + + " ICVSFile cvsFile = CVSWorkspaceRoot.getCVSFileFor((IFile)info.getLocal());\n" + + " byte[] syncBytes = cvsFile.getSyncBytes();\n" + + " return (syncBytes == null || ResourceSyncInfo.isAddition(syncBytes));\n" + + " } catch (CVSException e) {\n" + + " CVSUIPlugin.log(e);\n" + + " // Fall though and try to update\n" + + " }\n" + + " }\n" + + " return false;\n" + + " }\n" + + " }\n" + + " }),\n" + + " // Conflicting changes involving a deletion on one side will aways fail\n" + + " new AndSyncInfoFilter(new FastSyncInfoFilter[] {\n" + + " FastSyncInfoFilter.getDirectionAndChangeFilter(SyncInfo.CONFLICTING, SyncInfo.CHANGE),\n" + + " new FastSyncInfoFilter() {\n" + + " public boolean select(SyncInfo info) {\n" + + " IResourceVariant remote = info.getRemote();\n" + + " IResourceVariant base = info.getBase();\n" + + " if (info.getLocal().exists()) {\n" + + " // local != base and no remote will fail\n" + + " return (base != null && remote == null);\n" + + " } else {\n" + + " // no local and base != remote\n" + + " return (base != null && remote != null && !base.equals(remote));\n" + + " }\n" + + " }\n" + + " }\n" + + " }),\n" + + " // Conflicts where the file type is binary will work but are not merged\n" + + " // so they should be skipped\n" + + " new AndSyncInfoFilter(new FastSyncInfoFilter[] {\n" + + " FastSyncInfoFilter.getDirectionAndChangeFilter(SyncInfo.CONFLICTING, SyncInfo.CHANGE),\n" + + " new FastSyncInfoFilter() {\n" + + " public boolean select(SyncInfo info) {\n" + + " IResource local = info.getLocal();\n" + + " if (local.getType() == IResource.FILE) {\n" + + " try {\n" + + " ICVSFile file = CVSWorkspaceRoot.getCVSFileFor((IFile)local);\n" + + " byte[] syncBytes = file.getSyncBytes();\n" + + " if (syncBytes != null) {\n" + + " return ResourceSyncInfo.isBinary(syncBytes);\n" + + " }\n" + + " } catch (CVSException e) {\n" + + " // There was an error obtaining or interpreting the sync bytes\n" + + " // Log it and skip the file\n" + + " CVSProviderPlugin.log(e);\n" + + " return true;\n" + + " }\n" + + " }\n" + + " return false;\n" + + " }\n" + + " }\n" + + " }),\n" + + " // Outgoing changes may not fail but they are skipped as well\n" + + " new SyncInfoDirectionFilter(SyncInfo.OUTGOING)\n" + + " });\n" + + " }\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X52 {\n" + + " protected FastSyncInfoFilter getKnownFailureCases() {\n" + + " return new OrSyncInfoFilter(new FastSyncInfoFilter[] {\n" + + " // Conflicting additions of files will fail\n" + + " new AndSyncInfoFilter(new FastSyncInfoFilter[] {\n" + + " FastSyncInfoFilter.getDirectionAndChangeFilter(\n" + + " SyncInfo.CONFLICTING, SyncInfo.ADDITION),\n" + + " new FastSyncInfoFilter() {\n" + + " public boolean select(SyncInfo info) {\n" + + " return info.getLocal().getType() == IResource.FILE;\n" + + " }\n" + + " }\n" + + " }),\n" + + " // Conflicting changes of files will fail if the local is not\n" + + " // managed\n" + + " // or is an addition\n" + + " new AndSyncInfoFilter(new FastSyncInfoFilter[] {\n" + + " FastSyncInfoFilter.getDirectionAndChangeFilter(\n" + + " SyncInfo.CONFLICTING, SyncInfo.CHANGE),\n" + + " new FastSyncInfoFilter() {\n" + + " public boolean select(SyncInfo info) {\n" + + " if (info.getLocal().getType() == IResource.FILE) {\n" + + " try {\n" + + " ICVSFile cvsFile = CVSWorkspaceRoot\n" + + " .getCVSFileFor((IFile) info\n" + + " .getLocal());\n" + + " byte[] syncBytes = cvsFile\n" + + " .getSyncBytes();\n" + + " return (syncBytes == null || ResourceSyncInfo\n" + + " .isAddition(syncBytes));\n" + + " } catch (CVSException e) {\n" + + " CVSUIPlugin.log(e);\n" + + " // Fall though and try to update\n" + + " }\n" + + " }\n" + + " return false;\n" + + " }\n" + + " }\n" + + " }),\n" + + " // Conflicting changes involving a deletion on one side will\n" + + " // aways fail\n" + + " new AndSyncInfoFilter(new FastSyncInfoFilter[] {\n" + + " FastSyncInfoFilter.getDirectionAndChangeFilter(\n" + + " SyncInfo.CONFLICTING, SyncInfo.CHANGE),\n" + + " new FastSyncInfoFilter() {\n" + + " public boolean select(SyncInfo info) {\n" + + " IResourceVariant remote = info.getRemote();\n" + + " IResourceVariant base = info.getBase();\n" + + " if (info.getLocal().exists()) {\n" + + " // local != base and no remote will fail\n" + + " return (base != null && remote == null);\n" + + " } else {\n" + + " // no local and base != remote\n" + + " return (base != null && remote != null && !base\n" + + " .equals(remote));\n" + + " }\n" + + " }\n" + + " }\n" + + " }),\n" + + " // Conflicts where the file type is binary will work but are not\n" + + " // merged\n" + + " // so they should be skipped\n" + + " new AndSyncInfoFilter(new FastSyncInfoFilter[] {\n" + + " FastSyncInfoFilter.getDirectionAndChangeFilter(\n" + + " SyncInfo.CONFLICTING, SyncInfo.CHANGE),\n" + + " new FastSyncInfoFilter() {\n" + + " public boolean select(SyncInfo info) {\n" + + " IResource local = info.getLocal();\n" + + " if (local.getType() == IResource.FILE) {\n" + + " try {\n" + + " ICVSFile file = CVSWorkspaceRoot\n" + + " .getCVSFileFor((IFile) local);\n" + + " byte[] syncBytes = file.getSyncBytes();\n" + + " if (syncBytes != null) {\n" + + " return ResourceSyncInfo\n" + + " .isBinary(syncBytes);\n" + + " }\n" + + " } catch (CVSException e) {\n" + + " // There was an error obtaining or\n" + + " // interpreting the sync bytes\n" + + " // Log it and skip the file\n" + + " CVSProviderPlugin.log(e);\n" + + " return true;\n" + + " }\n" + + " }\n" + + " return false;\n" + + " }\n" + + " }\n" + + " }),\n" + + " // Outgoing changes may not fail but they are skipped as well\n" + + " new SyncInfoDirectionFilter(SyncInfo.OUTGOING)\n" + + " });\n" + + " }\n" + + "}\n" + ); +} +public void testBug330313_wksp1_53_njl_bnl() { + this.formatterPrefs.join_wrapped_lines = false; + setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE); + String source = + "package wksp1;\n" + + "\n" + + "public class X53 {\n" + + " static final short[][][] BLACK_CODE = {\n" + + " /* 9 bits */\n" + + " {{24, 15}},\n" + + " /* 10 bits */\n" + + " {{8, 18}, {15, 64}, {23, 16}, {24, 17}, {55, 0}},\n" + + " /* 11 bits */\n" + + " {/* EOL */{0, -1}, {8, 1792}, {23, 24}, {24, 25}, {40, 23}, {55, 22}, {103, 19},\n" + + " {104, 20}, {108, 21}, {12, 1856}, {13, 1920}},\n" + + " };\n" + + "}\n"; + formatSource(source , + "package wksp1;\n" + + "\n" + + "public class X53\n" + + "{\n" + + " static final short[][][] BLACK_CODE =\n" + + " {\n" + + " /* 9 bits */\n" + + " {\n" + + " { 24, 15 } },\n" + + " /* 10 bits */\n" + + " {\n" + + " { 8, 18 },\n" + + " { 15, 64 },\n" + + " { 23, 16 },\n" + + " { 24, 17 },\n" + + " { 55, 0 } },\n" + + " /* 11 bits */\n" + + " {/* EOL */\n" + + " { 0, -1 },\n" + + " { 8, 1792 },\n" + + " { 23, 24 },\n" + + " { 24, 25 },\n" + + " { 40, 23 },\n" + + " { 55, 22 },\n" + + " { 103, 19 },\n" + + " { 104, 20 },\n" + + " { 108, 21 },\n" + + " { 12, 1856 },\n" + + " { 13, 1920 } },\n" + + " };\n" + + "}\n" + ); +} +public void testBug330313_wksp2_01 () { + String source = + "package wksp2;\n" + + "\n" + + "public class X01 {\n" + + "\n" + + " static final Object[][] contents = {\n" + + " // comment\n" + + " { \"STR1\",\n" + + " // comment\n" + + " new String[] { \"STR\", // comment\n" + + " \"STR\", // comment\n" + + " \"STR\"} // comment\n" + + " }\n" + + "\n" + + " };\n" + + "\n" + + "}\n"; + formatSource(source, + "package wksp2;\n" + + "\n" + + "public class X01 {\n" + + "\n" + + " static final Object[][] contents = {\n" + + " // comment\n" + + " { \"STR1\",\n" + + " // comment\n" + + " new String[] { \"STR\", // comment\n" + + " \"STR\", // comment\n" + + " \"STR\" } // comment\n" + + " }\n" + + "\n" + + " };\n" + + "\n" + + "}\n" + ); +} +public void testBug330313_wksp3_X01_njl() { + this.formatterPrefs.join_wrapped_lines = false; + String source = + "package wksp3;\n" + + "\n" + + "public class X01 {\n" + + " private static final String foo[][] = {\n" + + " // line 1\n" + + " // line 2\n" + + " {\"A\", \"B\", \"C\", \"D\", \"E\"} // comment\n" + + " };\n" + + "}\n"; + formatSource(source , + "package wksp3;\n" + + "\n" + + "public class X01 {\n" + + " private static final String foo[][] = {\n" + + " // line 1\n" + + " // line 2\n" + + " { \"A\", \"B\", \"C\", \"D\", \"E\" } // comment\n" + + " };\n" + + "}\n" + ); +} +// Test cases added from bug 286601 +public void testBug330313_b286601_04() { + this.formatterPrefs.join_wrapped_lines = false; + this.formatterPrefs.alignment_for_expressions_in_array_initializer = Alignment.M_ONE_PER_LINE_SPLIT; + setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE); + String source = + "package b286601;\n" + + "\n" + + "public class X04 {\n" + + "\n" + + " \n" + + " // Table to merge access modes for condition statements (e.g branch[x] || branch[y]). \n" + + " private static final int[][] ACCESS_MODE_CONDITIONAL_TABLE= {\n" + + " /* UNUSED READ READ_POTENTIAL WRTIE WRITE_POTENTIAL UNKNOWN */\n" + + " /* UNUSED */ { UNUSED, READ_POTENTIAL, READ_POTENTIAL, WRITE_POTENTIAL, WRITE_POTENTIAL, UNKNOWN },\n" + + " /* READ */ { READ_POTENTIAL, READ, READ_POTENTIAL, UNKNOWN, UNKNOWN, UNKNOWN },\n" + + " /* READ_POTENTIAL */ { READ_POTENTIAL, READ_POTENTIAL, READ_POTENTIAL, UNKNOWN, UNKNOWN, UNKNOWN },\n" + + " /* WRITE */ { WRITE_POTENTIAL, UNKNOWN, UNKNOWN, WRITE, WRITE_POTENTIAL, UNKNOWN },\n" + + " /* WRITE_POTENTIAL */ { WRITE_POTENTIAL, UNKNOWN, UNKNOWN, WRITE_POTENTIAL, WRITE_POTENTIAL, UNKNOWN },\n" + + " /* UNKNOWN */ { UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN }\n" + + " };\n" + + "\n" + + "}\n"; + formatSource(source, + "package b286601;\n" + + "\n" + + "public class X04\n" + + "{\n" + + "\n" + + " // Table to merge access modes for condition statements (e.g branch[x] ||\n" + + " // branch[y]).\n" + + " private static final int[][] ACCESS_MODE_CONDITIONAL_TABLE =\n" + + " {\n" + + " /* UNUSED READ READ_POTENTIAL WRTIE WRITE_POTENTIAL UNKNOWN */\n" + + " /* UNUSED */{\n" + + " UNUSED,\n" + + " READ_POTENTIAL,\n" + + " READ_POTENTIAL,\n" + + " WRITE_POTENTIAL,\n" + + " WRITE_POTENTIAL,\n" + + " UNKNOWN },\n" + + " /* READ */{\n" + + " READ_POTENTIAL,\n" + + " READ,\n" + + " READ_POTENTIAL,\n" + + " UNKNOWN,\n" + + " UNKNOWN,\n" + + " UNKNOWN },\n" + + " /* READ_POTENTIAL */{\n" + + " READ_POTENTIAL,\n" + + " READ_POTENTIAL,\n" + + " READ_POTENTIAL,\n" + + " UNKNOWN,\n" + + " UNKNOWN,\n" + + " UNKNOWN },\n" + + " /* WRITE */{\n" + + " WRITE_POTENTIAL,\n" + + " UNKNOWN,\n" + + " UNKNOWN,\n" + + " WRITE,\n" + + " WRITE_POTENTIAL,\n" + + " UNKNOWN },\n" + + " /* WRITE_POTENTIAL */{\n" + + " WRITE_POTENTIAL,\n" + + " UNKNOWN,\n" + + " UNKNOWN,\n" + + " WRITE_POTENTIAL,\n" + + " WRITE_POTENTIAL,\n" + + " UNKNOWN },\n" + + " /* UNKNOWN */{ UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN }\n" + + // Should be slip but that has been broken since 3.4.2 (i.e. 3.3.2 is OK) +// " /* UNKNOWN */{\n" + +// " UNKNOWN,\n" + +// " UNKNOWN,\n" + +// " UNKNOWN,\n" + +// " UNKNOWN,\n" + +// " UNKNOWN,\n" + +// " UNKNOWN }\n" + + " };\n" + + "\n" + + "}\n" + ); +} +public void testBug330313_b286601_05() { + this.formatterPrefs.join_wrapped_lines = false; + this.formatterPrefs.alignment_for_expressions_in_array_initializer = Alignment.M_ONE_PER_LINE_SPLIT; + setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE); + String source = + "package b286601;\n" + + "\n" + + "public class X05 {\n" + + "\n" + + " \n" + + " // Table to merge access modes for condition statements (e.g branch[x] || branch[y]). \n" + + " static final String[][] ACCESS_MODE_CONDITIONAL_TABLE= {\n" + + " { \"UNUSED\", \"READ_POTENTIAL\", \"READ_POTENTIAL\", \"WRITE_POTENTIAL\", \"WRITE_POTENTIAL\", \"UNKNOWN\" },\n" + + " { \"READ_POTENTIAL\", \"READ\", \"READ_POTENTIAL\", \"UNKNOWN\", \"UNKNOWN\", \"UNKNOWN\" },\n" + + " };\n" + + "\n" + + "}\n"; + formatSource(source, + "package b286601;\n" + + "\n" + + "public class X05\n" + + "{\n" + + "\n" + + " // Table to merge access modes for condition statements (e.g branch[x] ||\n" + + " // branch[y]).\n" + + " static final String[][] ACCESS_MODE_CONDITIONAL_TABLE =\n" + + " {\n" + + " {\n" + + " \"UNUSED\",\n" + + " \"READ_POTENTIAL\",\n" + + " \"READ_POTENTIAL\",\n" + + " \"WRITE_POTENTIAL\",\n" + + " \"WRITE_POTENTIAL\",\n" + + " \"UNKNOWN\" },\n" + + " {\n" + + " \"READ_POTENTIAL\",\n" + + " \"READ\",\n" + + " \"READ_POTENTIAL\",\n" + + " \"UNKNOWN\",\n" + + " \"UNKNOWN\",\n" + + " \"UNKNOWN\" },\n" + + " };\n" + + "\n" + + "}\n" + ); +} +public void testBug330313_b286601_06() { + this.formatterPrefs.join_wrapped_lines = false; + this.formatterPrefs.alignment_for_expressions_in_array_initializer = Alignment.M_ONE_PER_LINE_SPLIT; + setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE); + String source = + "package b286601;\n" + + "\n" + + "public class X06 {\n" + + "\n" + + " \n" + + " // Table to merge access modes for condition statements (e.g branch[x] || branch[y]). \n" + + " static final String[][] ACCESS_MODE_CONDITIONAL_TABLE= {\n" + + " /* Comment 1 */\n" + + " /* Comment 2 */ { \"UNUSED\", \"READ_POTENTIAL\", \"READ_POTENTIAL\", \"WRITE_POTENTIAL\", \"WRITE_POTENTIAL\", \"UNKNOWN\" },\n" + + " /* Comment 3 */ { \"READ_POTENTIAL\", \"READ\", \"READ_POTENTIAL\", \"UNKNOWN\", \"UNKNOWN\", \"UNKNOWN\" },\n" + + " };\n" + + "\n" + + "}\n"; + formatSource(source, + "package b286601;\n" + + "\n" + + "public class X06\n" + + "{\n" + + "\n" + + " // Table to merge access modes for condition statements (e.g branch[x] ||\n" + + " // branch[y]).\n" + + " static final String[][] ACCESS_MODE_CONDITIONAL_TABLE =\n" + + " {\n" + + " /* Comment 1 */\n" + + " /* Comment 2 */{\n" + + " \"UNUSED\",\n" + + " \"READ_POTENTIAL\",\n" + + " \"READ_POTENTIAL\",\n" + + " \"WRITE_POTENTIAL\",\n" + + " \"WRITE_POTENTIAL\",\n" + + " \"UNKNOWN\" },\n" + + " /* Comment 3 */{\n" + + " \"READ_POTENTIAL\",\n" + + " \"READ\",\n" + + " \"READ_POTENTIAL\",\n" + + " \"UNKNOWN\",\n" + + " \"UNKNOWN\",\n" + + " \"UNKNOWN\" },\n" + + " };\n" + + "\n" + + "}\n" + ); +} +public void testBug330313_b286601_07() { + this.formatterPrefs.join_wrapped_lines = false; + this.formatterPrefs.tab_char = DefaultCodeFormatterOptions.SPACE; + this.formatterPrefs.alignment_for_expressions_in_array_initializer = Alignment.M_ONE_PER_LINE_SPLIT; + setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE); + String source = + "package b286601;\n" + + "\n" + + "public class X07 {\n" + + "\n" + + " \n" + + " // Table to merge access modes for condition statements (e.g branch[x] || branch[y]). \n" + + " static final String[][] ACCESS_MODE_CONDITIONAL_TABLE= {\n" + + " /* Comment 1 */\n" + + " /* Comment 2 */ { \"1234567890123456789012345678901234567890\", \"1234567890123456789012345678901234567890\" },\n" + + " /* Comment 3 */ { \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\", \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\" },\n" + + " };\n" + + "\n" + + "}\n"; + formatSource(source, + "package b286601;\n" + + "\n" + + "public class X07\n" + + "{\n" + + "\n" + + " // Table to merge access modes for condition statements (e.g branch[x] ||\n" + + " // branch[y]).\n" + + " static final String[][] ACCESS_MODE_CONDITIONAL_TABLE =\n" + + " {\n" + + " /* Comment 1 */\n" + + " /* Comment 2 */{\n" + + " \"1234567890123456789012345678901234567890\",\n" + + " \"1234567890123456789012345678901234567890\" },\n" + + " /* Comment 3 */{\n" + + " \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\",\n" + + " \"ABCDEFGHIJKLMNOPQRSTUVWXYZ______________\" },\n" + + " };\n" + + "\n" + + "}\n" + ); +} +public void testBug330313_b286601_08() { + this.formatterPrefs.join_wrapped_lines = false; + this.formatterPrefs.alignment_for_expressions_in_array_initializer = Alignment.M_ONE_PER_LINE_SPLIT; + setUpBracesPreferences(DefaultCodeFormatterConstants.NEXT_LINE); + String source = + "package b286601;\n" + + "\n" + + "public class X08 {\n" + + " private MinimizedFileSystemElement selectFiles(final Object rootFileSystemObject, final IImportStructureProvider structureProvider) {\n" + + "\n" + + " BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {\n" + + " public void run() {\n" + + " //Create the root element from the supplied file system object\n" + + " }\n" + + " });\n" + + "\n" + + " return null;\n" + + " }\n" + + "}\n"; + formatSource(source, + "package b286601;\n" + + "\n" + + "public class X08\n" + + "{\n" + + " private MinimizedFileSystemElement selectFiles(\n" + + " final Object rootFileSystemObject,\n" + + " final IImportStructureProvider structureProvider)\n" + + " {\n" + + "\n" + + " BusyIndicator.showWhile(getShell().getDisplay(), new Runnable()\n" + + " {\n" + + " public void run()\n" + + " {\n" + + " // Create the root element from the supplied file system object\n" + + " }\n" + + " });\n" + + "\n" + + " return null;\n" + + " }\n" + + "}\n" + ); +} + +/** * @bug 332818: [formatter] Java formatter, Blank Lines tab, only 1st line indented when multiple lines is set * @test Ensure that the indentation is set on all blank lines * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=332818" 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.28 diff -u -r1.28 FormatterMassiveRegressionTests.java --- src/org/eclipse/jdt/core/tests/formatter/FormatterMassiveRegressionTests.java 7 Dec 2010 15:45:29 -0000 1.28 +++ src/org/eclipse/jdt/core/tests/formatter/FormatterMassiveRegressionTests.java 27 Dec 2010 14:09:37 -0000 @@ -569,7 +569,7 @@ separator = ","; } if (NO_COMMENTS) { - buffer.append(separator+"no_comments"); + buffer.append(separator+"no_comments=true"); separator = ","; } if (BRACES != null) { @@ -660,14 +660,17 @@ } else if (token.equals("list")) { LIST = true; } else if (token.equals("tmp")) { - if (JDT_CORE_HEAD) { - TEMP_OUTPUT = "HEAD"; + if (PATCH_BUG != null) { + TEMP_OUTPUT = "patch"; + } + else if (JDT_CORE_HEAD) { + TEMP_OUTPUT = "head"; } } } setOutputDir(inputDir, outputDir, profiles); if (CLEAN) { - if (PATCH_BUG != null || (TEMP_OUTPUT == null && JDT_CORE_HEAD)) { + if ((PATCH_BUG != null || JDT_CORE_HEAD) && TEMP_OUTPUT == null) { System.err.println("Reference can only be updated using a version (i.e. with a closed buildnotes_jdt-core.html)!"); System.exit(1); } @@ -705,51 +708,55 @@ private static void setLogDir(File inputDir, int profiles, boolean verify) throws CoreException { // Compute log dir - File logDir = new File(System.getProperty("logDir")); - if (!logDir.exists()) { - if (!logDir.mkdirs()) { - System.err.println("Cannot create specified log directory: "+logDir+"!!!"); + File rootLogDir = new File(System.getProperty("logDir")); + if (!rootLogDir.exists()) { + if (!rootLogDir.mkdirs()) { + System.err.println("Cannot create specified log directory: "+rootLogDir+"!!!"); return; } } // Compute log sub-directories depending on version - logDir = new File(logDir, ECLIPSE_VERSION); + rootLogDir = new File(rootLogDir, ECLIPSE_VERSION); + String subRootDir; if (PATCH_BUG != null) { - logDir = new File(logDir, "tests"); - logDir = new File(logDir, PATCH_BUG); - logDir = new File(logDir, PATCH_VERSION); + rootLogDir = new File(rootLogDir, "tests"); + rootLogDir = new File(rootLogDir, PATCH_BUG); + subRootDir = PATCH_VERSION; } else if (JDT_CORE_HEAD) { - logDir = new File(logDir, "HEAD"); + subRootDir = "HEAD"; } else { - logDir = new File(logDir, ECLIPSE_MILESTONE); - logDir = new File(logDir, JDT_CORE_VERSION); + rootLogDir = new File(rootLogDir, ECLIPSE_MILESTONE); + subRootDir = JDT_CORE_VERSION; } // Compute log sub-directories depending on profiles + List subDirs = new ArrayList(); if (profiles > 0) { - logDir = new File(logDir, "profiles"); - logDir = setProfilesDir(profiles, logDir); + subDirs.add("profiles"); + setProfilesDir(profiles, subDirs); } if (FILES_FILTER_KIND > 0) { - logDir = new File(new File(logDir, "filter"), FILES_FILTER.replace('?', '_').replace('*', '%')); + subDirs.add("filter"); + subDirs.add(FILES_FILTER.replace('?', '_').replace('*', '%')); } // Create log stream - logDir.mkdirs(); + File logDir = createDir(new File (rootLogDir, subRootDir), subDirs); String filePrefix = inputDir.getName().replaceAll("\\.", ""); String logFileName = filePrefix+".txt"; LOG_FILE = new File(logDir, logFileName); if (verify && LOG_FILE.exists()) { - File saveDir = new File(logDir, "save"); - saveDir.mkdir(); + File saveDir = new File(new File(rootLogDir, "save"), subRootDir); + saveDir.mkdirs(); int i=0; while (true) { - String newFileName = filePrefix+"_"; - if (i<10) newFileName += "0"; - newFileName += i+".txt"; - File renamedFile = new File(saveDir, newFileName); + String dirN = Integer.toString(i); + if (i<10) dirN = "0" + dirN; + saveDir = new File(saveDir, dirN); + logDir = createDir(saveDir, subDirs); + File renamedFile = new File(logDir, logFileName); if (LOG_FILE.renameTo(renamedFile)) break; i++; } @@ -768,7 +775,22 @@ // LOG_BUFFER = new StringBuffer(); } +private static File createDir(File rootDir, List subDirs) { + File dir = rootDir; + for (int i=0, s=subDirs.size(); i> 5; - dir = new File(new File(dir, "preserved_lines"), Integer.toString(lines)); + subDirs.add("preserved_lines"); + subDirs.add(Integer.toString(lines)); } - return dir; } private static void appendProfiles(int profiles, StringBuffer buffer) { @@ -1135,9 +1159,18 @@ } // Dump the version - File versionFile = new Path(OUTPUT_DIR.getPath()).append("version.txt").toFile(); - OUTPUT_DIR.mkdirs(); - Util.writeToFile(JDT_CORE_VERSION, versionFile.getAbsolutePath()); + if (CLEAN) { + File versionFile = new Path(OUTPUT_DIR.getPath()).append("version.txt").toFile(); + OUTPUT_DIR.mkdirs(); + String version = JDT_CORE_VERSION; + if (TEMP_OUTPUT != null) { + version += " + " + TEMP_OUTPUT; + if (PATCH_BUG != null) { + version += " " + PATCH_VERSION + " of " + PATCH_BUG; + } + } + Util.writeToFile(version, versionFile.getAbsolutePath()); + } // Init time measuring TIME_MEASURES = new TimeMeasuring(); Index: workspace/Formatter/test488/A_out.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/workspace/Formatter/test488/A_out.java,v retrieving revision 1.1 diff -u -r1.1 A_out.java --- workspace/Formatter/test488/A_out.java 19 Apr 2004 20:50:48 -0000 1.1 +++ workspace/Formatter/test488/A_out.java 27 Dec 2010 14:09:37 -0000 @@ -4,14 +4,14 @@ case VALUE0 : doCase0(); break; - case VALUE1 :{ + case VALUE1 : { doCase1(); break; } case VALUE2 : doCase2(); break; - default :{ + default : { doDefault(); } }