Fix #1475484 - code formatter: bad result for array() embedding func calls
authortoshihiro <toshihiro>
Wed, 4 Apr 2007 05:53:00 +0000 (05:53 +0000)
committertoshihiro <toshihiro>
Wed, 4 Apr 2007 05:53:00 +0000 (05:53 +0000)
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/formatter/CodeFormatter.java

index 986398f..c65a883 100644 (file)
@@ -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: