don't insert a line break when formatting an empty array declaration
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / formatter / CodeFormatter.java
index 434287e..09e3add 100644 (file)
@@ -511,6 +511,12 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
             pendingSpace = false;
           }
         }
+        // don't linebreak empty array declarations
+        if (token == TokenNameRPAREN && arrayDeclarationCount > 0) {
+               if (previousCompilableToken == TokenNameLPAREN) {
+                       pendingNewLines = 0;
+               }
+        }
         // Add pending new lines to the formatted source string.
         // Note: pending new lines are not added if the current token
         // is a single line comment or whitespace.
@@ -690,7 +696,9 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
             // check for closing array declaration
             if (arrayDeclarationCount>0) {
                if (arrayDeclarationParenthesis[arrayDeclarationCount]==openParenthesis[openParenthesisCount]) {
-                       newLine(1);
+                       if (previousCompilableToken != TokenNameLPAREN) {
+                               newLine(1);
+                       }
                        indentationLevel--;
                        currentLineIndentationLevel = indentationLevel;
                     pendingNewLines = 0;
@@ -1108,6 +1116,13 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
    * @deprecated There is no need to retrieve the mapped positions anymore.
    */
   public int[] getMappedPositions() {
+       if (null!=mappedPositions) {
+               for (int i=0;i<mappedPositions.length;i++) {
+                       if (mappedPositions[i]>=formattedSource.length()) {
+                               mappedPositions[i]=formattedSource.length()-1;
+                       }
+               }
+       }
     return mappedPositions;
   }
 
@@ -2479,7 +2494,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
       if (posToMap < 0 || posToMap >= sourceLength) {
         // protection against out of bounds position
         if (posToMap == sourceLength) {
-          mappedPositions[indexToMap] = formattedSource.length()-1;
+          mappedPositions[indexToMap] = formattedSource.length();
         }
         indexToMap = positionsToMap.length; // no more mapping
         return;
@@ -2492,9 +2507,6 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
         } else {
           mappedPositions[indexToMap] = posToMap + globalDelta + lineDelta;
         }
-        if (mappedPositions[indexToMap]>=formattedSource.length()) {
-               mappedPositions[indexToMap]=formattedSource.length()-1;
-        }
       }
       indexToMap++;
     }
@@ -2506,9 +2518,6 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
     while (indexInMap < mappedPositions.length && startPosition <= mappedPositions[indexInMap]
         && mappedPositions[indexInMap] < endPosition && indexInMap < indexToMap) {
       mappedPositions[indexInMap] += splitDelta;
-      if (mappedPositions[indexInMap]>=formattedSource.length()) {
-       mappedPositions[indexInMap]=formattedSource.length()-1;
-      }
       indexInMap++;
     }
   }