From ad6efbc424c034cb842a0b03cd3a2fac5bb442b4 Mon Sep 17 00:00:00 2001 From: toshihiro Date: Wed, 4 Apr 2007 05:53:00 +0000 Subject: [PATCH 1/1] Fix #1475484 - code formatter: bad result for array() embedding func calls --- .../phpdt/internal/formatter/CodeFormatter.java | 20 ++++++++++++++------ 1 files changed, 14 insertions(+), 6 deletions(-) diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/formatter/CodeFormatter.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/formatter/CodeFormatter.java index 986398f..c65a883 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/formatter/CodeFormatter.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/formatter/CodeFormatter.java @@ -795,7 +795,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter { // recognize array declaration for nice output if (previousCompilableToken == TokenNamearray) { arrayDeclarationCount++; - arrayDeclarationParenthesis[arrayDeclarationCount] = openParenthesis[openParenthesisCount]; + arrayDeclarationParenthesis[arrayDeclarationCount] = openParenthesis[openParenthesisCount - 1]; indentationLevel++; pendingNewLines = 1; } @@ -804,9 +804,14 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter { case TokenNameRPAREN: // check for closing array declaration if (arrayDeclarationCount > 0) { - if (arrayDeclarationParenthesis[arrayDeclarationCount] == openParenthesis[openParenthesisCount]) { + if (arrayDeclarationParenthesis[arrayDeclarationCount] == openParenthesis[openParenthesisCount - 1]) { if (previousCompilableToken != TokenNameLPAREN) { newLine(1); + } else if (previousToken == TokenNameCOMMENT_LINE + || previousToken == TokenNameCOMMENT_BLOCK + || previousToken == TokenNameCOMMENT_PHPDOC) { + // prevent to combine comment line and statement line (#1475484) + newLine(1); } indentationLevel--; currentLineIndentationLevel = indentationLevel; @@ -913,7 +918,10 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter { case TokenNameCOMMA: pendingSpace = false; if (arrayDeclarationCount > 0) { - pendingNewLines = 1; + if (arrayDeclarationParenthesis[arrayDeclarationCount] == openParenthesis[openParenthesisCount - 1]) { + // there is no left parenthesis to close in current array declaration (#1475484) + pendingNewLines = 1; + } } break; case TokenNameDOT: @@ -975,9 +983,9 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter { break; case Scanner.TokenNameCOMMENT_LINE: pendingNewLines = 1; - if (inAssignment) { - currentLineIndentationLevel++; - } + //if (inAssignment) { + // currentLineIndentationLevel++; + //} break; // a line is always inserted after a one-line // comment case Scanner.TokenNameCOMMENT_PHPDOC: -- 1.7.1