misc
authorkhartlage <khartlage>
Mon, 28 Apr 2003 20:03:24 +0000 (20:03 +0000)
committerkhartlage <khartlage>
Mon, 28 Apr 2003 20:03:24 +0000 (20:03 +0000)
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/formatter/CodeFormatter.java

index 8d764c4..516c7de 100644 (file)
@@ -194,9 +194,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
     Hashtable options = new Hashtable(10);
 
     for (int i = 0; i < settings.length; i++) {
-      if (settings[i]
-        .getComponentName()
-        .equals(CodeFormatter.class.getName())) {
+      if (settings[i].getComponentName().equals(CodeFormatter.class.getName())) {
         String optionName = settings[i].getOptionName();
         int valueIndex = settings[i].getCurrentValueIndex();
 
@@ -273,29 +271,14 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
     beginningOfLineIndex = formattedSource.length();
     if (containsOpenCloseBraces) {
       containsOpenCloseBraces = false;
-      outputLine(
-        currentString,
-        false,
-        indentationLevelForOpenCloseBraces,
-        0,
-        -1,
-        null,
-        0);
+      outputLine(currentString, false, indentationLevelForOpenCloseBraces, 0, -1, null, 0);
       indentationLevelForOpenCloseBraces = currentLineIndentationLevel;
     } else {
-      outputLine(
-        currentString,
-        false,
-        currentLineIndentationLevel,
-        0,
-        -1,
-        null,
-        0);
+      outputLine(currentString, false, currentLineIndentationLevel, 0, -1, null, 0);
     }
     int scannerSourceLength = scanner.source.length;
     if (scannerSourceLength > 2) {
-      if (scanner.source[scannerSourceLength - 1] == '\n'
-        && scanner.source[scannerSourceLength - 2] == '\r') {
+      if (scanner.source[scannerSourceLength - 1] == '\n' && scanner.source[scannerSourceLength - 2] == '\r') {
         formattedSource.append(options.lineSeparatorSequence);
         increaseGlobalDelta(options.lineSeparatorSequence.length - 2);
       } else if (scanner.source[scannerSourceLength - 1] == '\n') {
@@ -400,8 +383,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
         if (clearNonBlockIndents && (token != Scanner.TokenNameWHITESPACE)) {
           switch (token) {
             case TokenNameelse :
-              if (constructionsCount > 0
-                && constructions[constructionsCount - 1] == TokenNameelse) {
+              if (constructionsCount > 0 && constructions[constructionsCount - 1] == TokenNameelse) {
                 pendingNewLines = 1;
                 specialElse = true;
               }
@@ -434,8 +416,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
         //                             if (token == Scanner.TokenNamethrows) {
         //                                     inThrowsClause = true;
         //                             }
-        if ((token
-          == Scanner.TokenNameclass // || token == Scanner.TokenNameinterface
+        if ((token == Scanner.TokenNameclass // || token == Scanner.TokenNameinterface
         )
           && previousToken != Scanner.TokenNameDOT) {
           inClassOrInterfaceHeader = true;
@@ -445,24 +426,22 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
         */
         // Do not add a new line between ELSE and IF, if the option elseIfOnSameLine is true.
         // Fix for 1ETLWPZ: IVJCOM:ALL - incorrect "else if" formatting
-//        if (pendingNewlineAfterParen
-//          && previousCompilableToken == TokenNameelse
-//          && token == TokenNameif
-//          && options.compactElseIfMode) {
-//          pendingNewlineAfterParen = false;
-//          pendingNewLines = 0;
-//          indentationLevel += pop(TokenNameelse);
-//          // because else if is now one single statement,
-//          // the indentation level after it is increased by one and not by 2
-//          // (else = 1 indent, if = 1 indent, but else if = 1 indent, not 2).
-//        }
+        //        if (pendingNewlineAfterParen
+        //          && previousCompilableToken == TokenNameelse
+        //          && token == TokenNameif
+        //          && options.compactElseIfMode) {
+        //          pendingNewlineAfterParen = false;
+        //          pendingNewLines = 0;
+        //          indentationLevel += pop(TokenNameelse);
+        //          // because else if is now one single statement,
+        //          // the indentation level after it is increased by one and not by 2
+        //          // (else = 1 indent, if = 1 indent, but else if = 1 indent, not 2).
+        //        }
         // Add a newline & indent to the formatted source string if
         // a for/if-else/while statement was scanned and there is no block
         // following it.
         pendingNewlineAfterParen =
-          pendingNewlineAfterParen
-            || (previousCompilableToken == TokenNameRPAREN
-              && token == TokenNameLBRACE);
+          pendingNewlineAfterParen || (previousCompilableToken == TokenNameRPAREN && token == TokenNameLBRACE);
         if (pendingNewlineAfterParen && token != Scanner.TokenNameWHITESPACE) {
           pendingNewlineAfterParen = false;
 
@@ -474,15 +453,13 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
           if (token != TokenNameLBRACE
             && !isComment(token) // to avoid adding new line between else and a comment
             && token != TokenNameDOT
-            && !(previousCompilableToken == TokenNameRPAREN
-              && token == TokenNameSEMICOLON)) {
+            && !(previousCompilableToken == TokenNameRPAREN && token == TokenNameSEMICOLON)) {
             newLine(1);
             currentLineIndentationLevel = indentationLevel;
             pendingNewLines = 0;
             pendingSpace = false;
           } else {
-            if (token == TokenNameLBRACE
-              && options.newLineBeforeOpeningBraceMode) {
+            if (token == TokenNameLBRACE && options.newLineBeforeOpeningBraceMode) {
               newLine(1);
               if (constructionsCount > 0
                 && constructions[constructionsCount - 1] != BLOCK
@@ -531,16 +508,13 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
         // if the comment is between parenthesis, there is no blank line preservation
         // (if it's a one-line comment, a blank line is added after it).
         if (((pendingNewLines > 0 && (!isComment(token)))
-          || (newLinesInWhitespace > 0
-            && (openParenthesisCount <= 1 && isComment(token)))
-          || (previousCompilableToken == TokenNameLBRACE
-            && token == TokenNameRBRACE))
+          || (newLinesInWhitespace > 0 && (openParenthesisCount <= 1 && isComment(token)))
+          || (previousCompilableToken == TokenNameLBRACE && token == TokenNameRBRACE))
           && token != Scanner.TokenNameWHITESPACE) {
 
           // Do not add newline & indent between an adjoining close brace and
           // close paren.  Anonymous inner classes may use this form.
-          boolean closeBraceAndCloseParen =
-            previousToken == TokenNameRBRACE && token == TokenNameRPAREN;
+          boolean closeBraceAndCloseParen = previousToken == TokenNameRBRACE && token == TokenNameRPAREN;
 
           // OPTION (NewLineInCompoundStatement): do not add newline & indent
           // between close brace and else, (do) while, catch, and finally if
@@ -548,31 +522,22 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
           boolean nlicsOption =
             previousToken == TokenNameRBRACE
               && !options.newlineInControlStatementMode
-              && (token == TokenNameelse
-                || (token == TokenNamewhile && nlicsToken == TokenNamedo));
+              && (token == TokenNameelse || (token == TokenNamewhile && nlicsToken == TokenNamedo));
           //                                                           || token == TokenNamecatch
           //                                                           || token == TokenNamefinally);
 
           // Do not add a newline & indent between a close brace and semi-colon.
-          boolean semiColonAndCloseBrace =
-            previousToken == TokenNameRBRACE && token == TokenNameSEMICOLON;
+          boolean semiColonAndCloseBrace = previousToken == TokenNameRBRACE && token == TokenNameSEMICOLON;
 
           // Do not add a new line & indent between a multiline comment and a opening brace
-          boolean commentAndOpenBrace =
-            previousToken == Scanner.TokenNameCOMMENT_BLOCK
-              && token == TokenNameLBRACE;
+          boolean commentAndOpenBrace = previousToken == Scanner.TokenNameCOMMENT_BLOCK && token == TokenNameLBRACE;
 
           // Do not add a newline & indent between a close brace and a colon (in array assignments, for example).
-          boolean commaAndCloseBrace =
-            previousToken == TokenNameRBRACE && token == TokenNameCOMMA;
+          boolean commaAndCloseBrace = previousToken == TokenNameRBRACE && token == TokenNameCOMMA;
 
           // Add a newline and indent, if appropriate.
           if (specialElse
-            || (!commentAndOpenBrace
-              && !closeBraceAndCloseParen
-              && !nlicsOption
-              && !semiColonAndCloseBrace
-              && !commaAndCloseBrace)) {
+            || (!commentAndOpenBrace && !closeBraceAndCloseParen && !nlicsOption && !semiColonAndCloseBrace && !commaAndCloseBrace)) {
 
             // if clearAllBlankLinesMode=false, leaves the blank lines
             // inserted by the user
@@ -580,14 +545,10 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
             // and insert only blank lines required by the formatting.
             if (!options.clearAllBlankLinesMode) {
               //  (isComment(token))
-              pendingNewLines =
-                (pendingNewLines < newLinesInWhitespace)
-                  ? newLinesInWhitespace
-                  : pendingNewLines;
+              pendingNewLines = (pendingNewLines < newLinesInWhitespace) ? newLinesInWhitespace : pendingNewLines;
               pendingNewLines = (pendingNewLines > 2) ? 2 : pendingNewLines;
             }
-            if (previousCompilableToken == TokenNameLBRACE
-              && token == TokenNameRBRACE) {
+            if (previousCompilableToken == TokenNameLBRACE && token == TokenNameRBRACE) {
               containsOpenCloseBraces = true;
               indentationLevelForOpenCloseBraces = currentLineIndentationLevel;
               if (isComment(previousToken)) {
@@ -608,8 +569,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
               }
             } else {
               // see PR 1FKKC3U: LFCOM:WINNT - Format problem with a comment before the ';'
-              if (!((previousToken == Scanner.TokenNameCOMMENT_BLOCK
-                || previousToken == Scanner.TokenNameCOMMENT_PHPDOC)
+              if (!((previousToken == Scanner.TokenNameCOMMENT_BLOCK || previousToken == Scanner.TokenNameCOMMENT_PHPDOC)
                 && token == TokenNameSEMICOLON)) {
                 newLine(pendingNewLines);
               }
@@ -622,13 +582,11 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
               indentationOffset = -1;
               indentationLevel += popExclusiveUntilBlock();
             }
-            if (previousToken == Scanner.TokenNameCOMMENT_LINE
-              && inAssignment) {
+            if (previousToken == Scanner.TokenNameCOMMENT_LINE && inAssignment) {
               // PR 1FI5IPO
               currentLineIndentationLevel++;
             } else {
-              currentLineIndentationLevel =
-                indentationLevel + indentationOffset;
+              currentLineIndentationLevel = indentationLevel + indentationOffset;
             }
             pendingSpace = false;
             indentationOffset = 0;
@@ -677,12 +635,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
           case TokenNameif :
           case TokenNamewhile :
             if (openParenthesisCount == openParenthesis.length) {
-              System.arraycopy(
-                openParenthesis,
-                0,
-                (openParenthesis = new int[openParenthesisCount * 2]),
-                0,
-                openParenthesisCount);
+              System.arraycopy(openParenthesis, 0, (openParenthesis = new int[openParenthesisCount * 2]), 0, openParenthesisCount);
             }
             openParenthesis[openParenthesisCount++] = 0;
             expectingOpenBrace = true;
@@ -743,8 +696,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
             // Decrease the parenthesis count
             // if there is no more unclosed parenthesis,
             // a new line and indent may be append (depending on the next token).
-            if ((openParenthesisCount > 1)
-              && (openParenthesis[openParenthesisCount - 1] > 0)) {
+            if ((openParenthesisCount > 1) && (openParenthesis[openParenthesisCount - 1] > 0)) {
               openParenthesis[openParenthesisCount - 1]--;
               if (openParenthesis[openParenthesisCount - 1] <= 0) {
                 pendingNewlineAfterParen = true;
@@ -757,8 +709,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
             pendingSpace = false;
             break;
           case TokenNameLBRACE :
-            if ((previousCompilableToken == TokenNameRBRACKET)
-              || (previousCompilableToken == TokenNameEQUAL)) {
+            if ((previousCompilableToken == TokenNameRBRACKET) || (previousCompilableToken == TokenNameEQUAL)) {
               //                  if (previousCompilableToken == TokenNameRBRACKET) {
               inArrayAssignment = true;
               inAssignment = false;
@@ -843,8 +794,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
 
             // Do not put a space between a post-increment/decrement
             // and the identifier being modified.
-            if (previousToken == TokenNameIdentifier
-              || previousToken == TokenNameRBRACKET) {
+            if (previousToken == TokenNameIdentifier || previousToken == TokenNameRBRACKET) {
               pendingSpace = false;
             }
             break;
@@ -863,8 +813,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
             // In a switch/case statement, add a newline & indent
             // when a colon is encountered.
             if (tokenBeforeColonCount > 0) {
-              if (tokenBeforeColon[tokenBeforeColonCount - 1]
-                == TokenNamecase) {
+              if (tokenBeforeColon[tokenBeforeColonCount - 1] == TokenNamecase) {
                 pendingNewLines = 1;
               }
               tokenBeforeColonCount--;
@@ -890,9 +839,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
             // line spacing can be preserved near comments.
             char[] source = scanner.source;
             newLinesInWhitespace = 0;
-            for (int i = scanner.startPosition, max = scanner.currentPosition;
-              i < max;
-              i++) {
+            for (int i = scanner.startPosition, max = scanner.currentPosition; i < max; i++) {
               if (source[i] == '\r') {
                 if (i < max - 1) {
                   if (source[++i] == '\n') {
@@ -909,6 +856,17 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
             }
             increaseLineDelta(scanner.startPosition - scanner.currentPosition);
             break;
+//          case TokenNameHTML :
+//            // Add the next token to the formatted source string.
+//            // outputCurrentToken(token);
+//            int startPosition = scanner.startPosition;
+//            flushBuffer();
+//            for (int i = startPosition, max = scanner.currentPosition; i < max; i++) {
+//              char currentCharacter = scanner.source[i];
+//              updateMappedPositions(i);
+//              currentLineBuffer.append(currentCharacter);
+//            }
+//            break;
           default :
             if ((token == TokenNameIdentifier) || isLiteralToken(token)) {
               //                                                       || token == TokenNamesuper
@@ -941,23 +899,18 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
           open brace or the current token is a close brace
           8) previous token is a single line comment
           */
-          boolean openAndCloseBrace =
-            previousCompilableToken == TokenNameLBRACE
-              && token == TokenNameRBRACE;
+          boolean openAndCloseBrace = previousCompilableToken == TokenNameLBRACE && token == TokenNameRBRACE;
 
           if (pendingSpace
             && insertSpaceAfter(previousToken)
-            && !(inAssignment
-              && (previousToken == TokenNameLBRACE || token == TokenNameRBRACE))
+            && !(inAssignment && (previousToken == TokenNameLBRACE || token == TokenNameRBRACE))
             && previousToken != Scanner.TokenNameCOMMENT_LINE) {
-            if ((!(options.compactAssignmentMode && token == TokenNameEQUAL))
-              && !openAndCloseBrace)
+            if ((!(options.compactAssignmentMode && token == TokenNameEQUAL)) && !openAndCloseBrace)
               space();
           }
           // Add the next token to the formatted source string.
           outputCurrentToken(token);
-          if (token == Scanner.TokenNameCOMMENT_LINE
-            && openParenthesisCount > 1) {
+          if (token == Scanner.TokenNameCOMMENT_LINE && openParenthesisCount > 1) {
             pendingNewLines = 0;
             currentLineBuffer.append(options.lineSeparatorSequence);
             increaseLineDelta(options.lineSeparatorSequence.length);
@@ -1021,11 +974,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
     return this.format(string, indentationLevel, positions, null);
   }
 
-  public String format(
-    String string,
-    int indentationLevel,
-    int[] positions,
-    String lineSeparator) {
+  public String format(String string, int indentationLevel, int[] positions, String lineSeparator) {
     if (lineSeparator != null) {
       this.options.setLineSeparator(lineSeparator);
     }
@@ -1057,10 +1006,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
    * 
    * @deprecated backport 1.0 internal functionality
    */
-  public static String format(
-    String sourceString,
-    int initialIndentationLevel,
-    ConfigurableOption[] options) {
+  public static String format(String sourceString, int initialIndentationLevel, ConfigurableOption[] options) {
     CodeFormatter formatter = new CodeFormatter(options);
     formatter.setInitialIndentationLevel(initialIndentationLevel);
     return formatter.formatSourceString(sourceString);
@@ -1121,7 +1067,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
     return new ConfigurableOption[] { new ConfigurableOption(componentName, "newline.openingBrace", locale, options.newLineBeforeOpeningBraceMode ? 0 : 1), //$NON-NLS-1$
       new ConfigurableOption(componentName, "newline.controlStatement", locale, options.newlineInControlStatementMode ? 0 : 1), //$NON-NLS-1$
       new ConfigurableOption(componentName, "newline.clearAll", locale, options.clearAllBlankLinesMode ? 0 : 1), //$NON-NLS-1$
-//      new ConfigurableOption(componentName, "newline.elseIf", locale, options.compactElseIfMode ? 0 : 1), //$NON-NLS-1$
+      //      new ConfigurableOption(componentName, "newline.elseIf", locale, options.compactElseIfMode ? 0 : 1), //$NON-NLS-1$
       new ConfigurableOption(componentName, "newline.emptyBlock", locale, options.newLineInEmptyBlockMode ? 0 : 1), //$NON-NLS-1$
       new ConfigurableOption(componentName, "line.split", locale, options.maxLineLength), //$NON-NLS-1$
       new ConfigurableOption(componentName, "style.compactAssignment", locale, options.compactAssignmentMode ? 0 : 1), //$NON-NLS-1$
@@ -1268,9 +1214,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
 
   private static boolean isComment(int token) {
     boolean result =
-      token == Scanner.TokenNameCOMMENT_BLOCK
-        || token == Scanner.TokenNameCOMMENT_LINE
-        || token == Scanner.TokenNameCOMMENT_PHPDOC;
+      token == Scanner.TokenNameCOMMENT_BLOCK || token == Scanner.TokenNameCOMMENT_LINE || token == Scanner.TokenNameCOMMENT_PHPDOC;
     return result;
   }
 
@@ -1297,24 +1241,10 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
     String currentLine = currentLineBuffer.toString();
     if (containsOpenCloseBraces) {
       containsOpenCloseBraces = false;
-      outputLine(
-        currentLine,
-        false,
-        indentationLevelForOpenCloseBraces,
-        0,
-        -1,
-        null,
-        0);
+      outputLine(currentLine, false, indentationLevelForOpenCloseBraces, 0, -1, null, 0);
       indentationLevelForOpenCloseBraces = currentLineIndentationLevel;
     } else {
-      outputLine(
-        currentLine,
-        false,
-        currentLineIndentationLevel,
-        0,
-        -1,
-        null,
-        0);
+      outputLine(currentLine, false, currentLineIndentationLevel, 0, -1, null, 0);
     }
     // dump line break(s)
     for (int i = 0; i < newLineCount; i++) {
@@ -1323,10 +1253,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
     }
     // reset formatter for next line
     int currentLength = currentLine.length();
-    currentLineBuffer =
-      new StringBuffer(
-        currentLength > maxLineSize ? maxLineSize =
-          currentLength : maxLineSize);
+    currentLineBuffer = new StringBuffer(currentLength > maxLineSize ? maxLineSize = currentLength : maxLineSize);
 
     increaseGlobalDelta(splitDelta);
     increaseGlobalDelta(lineDelta);
@@ -1494,9 +1421,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
         currentCommentOffset = getCurrentCommentOffset();
         beginningOfLineSpaces = 0;
         boolean pendingCarriageReturn = false;
-        for (int i = startPosition, max = scanner.currentPosition;
-          i < max;
-          i++) {
+        for (int i = startPosition, max = scanner.currentPosition; i < max; i++) {
           char currentCharacter = source[i];
           updateMappedPositions(i);
           switch (currentCharacter) {
@@ -1573,9 +1498,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
         multipleLineCommentCounter++;
         break;
       default :
-        for (int i = startPosition, max = scanner.currentPosition;
-          i < max;
-          i++) {
+        for (int i = startPosition, max = scanner.currentPosition; i < max; i++) {
           char currentCharacter = source[i];
           updateMappedPositions(i);
           currentLineBuffer.append(currentCharacter);
@@ -1620,9 +1543,8 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
         formattedSource.append(operatorString);
         increaseSplitDelta(operatorString.length());
 
-        if (insertSpaceAfter(operator)
-          //                   && operator != TokenNameimplements
-          && operator != TokenNameextends) {
+        if (insertSpaceAfter(operator) //                      && operator != TokenNameimplements
+        && operator != TokenNameextends) {
           //                   && operator != TokenNamethrows) {
           formattedSource.append(' ');
           increaseSplitDelta(1);
@@ -1651,15 +1573,12 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
       int max = currentString.length();
       if (multipleLineCommentCounter != 0) {
         try {
-          BufferedReader reader =
-            new BufferedReader(new StringReader(currentString));
+          BufferedReader reader = new BufferedReader(new StringReader(currentString));
           String line = reader.readLine();
           while (line != null) {
             updateMappedPositionsWhileSplitting(
               beginningOfLineIndex,
-              beginningOfLineIndex
-                + line.length()
-                + options.lineSeparatorSequence.length);
+              beginningOfLineIndex + line.length() + options.lineSeparatorSequence.length);
             formattedSource.append(line);
             beginningOfLineIndex = beginningOfLineIndex + line.length();
             if ((line = reader.readLine()) != null) {
@@ -1673,9 +1592,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
           e.printStackTrace();
         }
       } else {
-        updateMappedPositionsWhileSplitting(
-          beginningOfLineIndex,
-          beginningOfLineIndex + max);
+        updateMappedPositionsWhileSplitting(beginningOfLineIndex, beginningOfLineIndex + max);
         for (int i = 0; i < max; i++) {
           char currentChar = currentString.charAt(i);
           switch (currentChar) {
@@ -1700,20 +1617,13 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
       // update positions inside the mappedPositions table
       if (substringIndex != -1) {
         if (multipleLineCommentCounter == 0) {
-          int startPosition =
-            beginningOfLineIndex + startSubstringIndexes[substringIndex];
-          updateMappedPositionsWhileSplitting(
-            startPosition,
-            startPosition + max);
+          int startPosition = beginningOfLineIndex + startSubstringIndexes[substringIndex];
+          updateMappedPositionsWhileSplitting(startPosition, startPosition + max);
         }
 
         // compute the splitDelta resulting with the operator and blank removal
         if (substringIndex + 1 != startSubstringIndexes.length) {
-          increaseSplitDelta(
-            startSubstringIndexes[substringIndex]
-              + max
-              - startSubstringIndexes[substringIndex
-              + 1]);
+          increaseSplitDelta(startSubstringIndexes[substringIndex] + max - startSubstringIndexes[substringIndex + 1]);
         }
       }
       // dump postfix operator?
@@ -1733,9 +1643,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
     }
     // fix for 1FG0BA3: LFCOM:WIN98 - Weird splitting on interfaces
     // extends has to stand alone on a line when currentString has been split.
-    if (options.maxLineLength != 0
-      && splitLine != null
-      && (operator == TokenNameextends)) {
+    if (options.maxLineLength != 0 && splitLine != null && (operator == TokenNameextends)) {
       //                               || operator == TokenNameimplements
       //                               || operator == TokenNamethrows)) {
       formattedSource.append(options.lineSeparatorSequence);
@@ -1801,8 +1709,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
           formattedSource.append(lastOperatorString);
           increaseSplitDelta(lastOperatorString.length());
 
-          if (insertSpaceAfter(lastOperator)
-            //                                 && lastOperator != TokenNameimplements
+          if (insertSpaceAfter(lastOperator) //                                        && lastOperator != TokenNameimplements
             && lastOperator != TokenNameextends) {
             //                                 && lastOperator != TokenNamethrows) {
             formattedSource.append(' ');
@@ -1826,8 +1733,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
    */
   private int pop(int token) {
     int delta = 0;
-    if ((constructionsCount > 0)
-      && (constructions[constructionsCount - 1] == token)) {
+    if ((constructionsCount > 0) && (constructions[constructionsCount - 1] == token)) {
       delta--;
       constructionsCount--;
     }
@@ -1840,8 +1746,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
   private int popBlock() {
     int delta = 0;
     if ((constructionsCount > 0)
-      && ((constructions[constructionsCount - 1] == BLOCK)
-        || (constructions[constructionsCount - 1] == NONINDENT_BLOCK))) {
+      && ((constructions[constructionsCount - 1] == BLOCK) || (constructions[constructionsCount - 1] == NONINDENT_BLOCK))) {
       if (constructions[constructionsCount - 1] == BLOCK)
         delta--;
       constructionsCount--;
@@ -1873,11 +1778,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
   private int popExclusiveUntilBlock() {
     int startCount = constructionsCount;
     int delta = 0;
-    for (int i = startCount - 1;
-      i >= 0
-        && constructions[i] != BLOCK
-        && constructions[i] != NONINDENT_BLOCK;
-      i--) {
+    for (int i = startCount - 1; i >= 0 && constructions[i] != BLOCK && constructions[i] != NONINDENT_BLOCK; i--) {
       constructionsCount--;
       delta--;
     }
@@ -1893,10 +1794,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
     int startCount = constructionsCount;
     int delta = 0;
     for (int i = startCount - 1;
-      i >= 0
-        && constructions[i] != BLOCK
-        && constructions[i] != NONINDENT_BLOCK
-        && constructions[i] != TokenNamecase;
+      i >= 0 && constructions[i] != BLOCK && constructions[i] != NONINDENT_BLOCK && constructions[i] != TokenNamecase;
       i--) {
       constructionsCount--;
       delta--;
@@ -1933,10 +1831,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
   private int popInclusiveUntilBlock() {
     int startCount = constructionsCount;
     int delta = 0;
-    for (int i = startCount - 1;
-      i >= 0
-        && (constructions[i] != BLOCK && constructions[i] != NONINDENT_BLOCK);
-      i--) {
+    for (int i = startCount - 1; i >= 0 && (constructions[i] != BLOCK && constructions[i] != NONINDENT_BLOCK); i--) {
       delta--;
       constructionsCount--;
     }
@@ -1957,12 +1852,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
   private int pushBlock() {
     int delta = 0;
     if (constructionsCount == constructions.length)
-      System.arraycopy(
-        constructions,
-        0,
-        (constructions = new int[constructionsCount * 2]),
-        0,
-        constructionsCount);
+      System.arraycopy(constructions, 0, (constructions = new int[constructionsCount * 2]), 0, constructionsCount);
 
     if ((constructionsCount == 0)
       || (constructions[constructionsCount - 1] == BLOCK)
@@ -1982,12 +1872,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
    */
   private int pushControlStatement(int token) {
     if (constructionsCount == constructions.length)
-      System.arraycopy(
-        constructions,
-        0,
-        (constructions = new int[constructionsCount * 2]),
-        0,
-        constructionsCount);
+      System.arraycopy(constructions, 0, (constructions = new int[constructionsCount * 2]), 0, constructionsCount);
     constructions[constructionsCount++] = token;
     return 1;
   }
@@ -2104,13 +1989,11 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
           case TokenNameRBRACE :
           case TokenNameRPAREN :
             if (openParenthesisPositionCount > 0) {
-              if (openParenthesisPositionCount == 1
-                && lastOpenParenthesisPosition < openParenthesisPosition[0]) {
+              if (openParenthesisPositionCount == 1 && lastOpenParenthesisPosition < openParenthesisPosition[0]) {
                 lastOpenParenthesisPosition = openParenthesisPosition[0];
               } else if (
                 (splitTokenDepth == Integer.MAX_VALUE)
-                  || (splitTokenDepth > openParenthesisPositionCount
-                    && openParenthesisPositionCount == 1)) {
+                  || (splitTokenDepth > openParenthesisPositionCount && openParenthesisPositionCount == 1)) {
                 splitTokenType = 0;
                 splitTokenDepth = openParenthesisPositionCount;
                 splitTokenPriority = Integer.MAX_VALUE;
@@ -2129,30 +2012,24 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
             break;
           case TokenNameLBRACE :
           case TokenNameLPAREN :
-            if (openParenthesisPositionCount
-              == openParenthesisPosition.length) {
+            if (openParenthesisPositionCount == openParenthesisPosition.length) {
               System.arraycopy(
                 openParenthesisPosition,
                 0,
-                (openParenthesisPosition =
-                  new int[openParenthesisPositionCount * 2]),
+                (openParenthesisPosition = new int[openParenthesisPositionCount * 2]),
                 0,
                 openParenthesisPositionCount);
             }
-            openParenthesisPosition[openParenthesisPositionCount++] =
-              splitScanner.currentPosition;
-            if (currentToken == TokenNameLPAREN
-              && previousToken == TokenNameRPAREN) {
-              openParenthesisPosition[openParenthesisPositionCount - 1] =
-                splitScanner.startPosition;
+            openParenthesisPosition[openParenthesisPositionCount++] = splitScanner.currentPosition;
+            if (currentToken == TokenNameLPAREN && previousToken == TokenNameRPAREN) {
+              openParenthesisPosition[openParenthesisPositionCount - 1] = splitScanner.startPosition;
             }
             break;
           case TokenNameSEMICOLON : // ;
           case TokenNameCOMMA : // ,
           case TokenNameEQUAL : // =
             if (openParenthesisPositionCount < splitTokenDepth
-              || (openParenthesisPositionCount == splitTokenDepth
-                && splitTokenPriority > getTokenPriority(currentToken))) {
+              || (openParenthesisPositionCount == splitTokenDepth && splitTokenPriority > getTokenPriority(currentToken))) {
               // the current token is better than the one we currently have
               // (in level or in priority if same level)
               // reset the substringsCount
@@ -2162,14 +2039,11 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
               substringsStartPositions[0] = 0;
               // better token means the whole line until now is the first substring
 
-              if (separateFirstArgumentOn(firstTokenOnLine)
-                && openParenthesisPositionCount > 0) {
+              if (separateFirstArgumentOn(firstTokenOnLine) && openParenthesisPositionCount > 0) {
                 substringsCount = 2; // resets the count of substrings
 
-                substringsEndPositions[0] =
-                  openParenthesisPosition[splitTokenDepth - 1];
-                substringsStartPositions[1] =
-                  openParenthesisPosition[splitTokenDepth - 1];
+                substringsEndPositions[0] = openParenthesisPosition[splitTokenDepth - 1];
+                substringsStartPositions[1] = openParenthesisPosition[splitTokenDepth - 1];
                 substringsEndPositions[1] = splitScanner.startPosition;
                 splitOperatorsCount = 2; // resets the count of split operators
                 splitOperators[0] = 0;
@@ -2187,8 +2061,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
                 splitOperators[0] = currentToken;
               }
             } else {
-              if ((openParenthesisPositionCount == splitTokenDepth
-                && splitTokenPriority == getTokenPriority(currentToken))
+              if ((openParenthesisPositionCount == splitTokenDepth && splitTokenPriority == getTokenPriority(currentToken))
                 && splitTokenType != TokenNameEQUAL
                 && currentToken != TokenNameEQUAL) {
                 // fix for 1FG0BCN: LFCOM:WIN98 - Missing one indentation after split
@@ -2212,16 +2085,10 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
                     substringsCount);
                 }
                 if (splitOperatorsCount == splitOperators.length) {
-                  System.arraycopy(
-                    splitOperators,
-                    0,
-                    (splitOperators = new int[splitOperatorsCount * 2]),
-                    0,
-                    splitOperatorsCount);
+                  System.arraycopy(splitOperators, 0, (splitOperators = new int[splitOperatorsCount * 2]), 0, splitOperatorsCount);
                 }
                 substringsStartPositions[substringsCount] = position;
-                substringsEndPositions[substringsCount++] =
-                  splitScanner.startPosition;
+                substringsEndPositions[substringsCount++] = splitScanner.startPosition;
                 // substring ends on operator start
                 position = splitScanner.currentPosition;
                 // next substring will start from operator end
@@ -2233,8 +2100,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
           case TokenNameCOLON : // : (15.24)
             // see 1FK7C5R, we only split on a colon, when it is associated with a question-mark.
             // indeed it might appear also behind a case statement, and we do not to break at this point.
-            if ((splitOperatorsCount == 0)
-              || splitOperators[splitOperatorsCount - 1] != TokenNameQUESTION) {
+            if ((splitOperatorsCount == 0) || splitOperators[splitOperatorsCount - 1] != TokenNameQUESTION) {
               break;
             }
           case TokenNameextends :
@@ -2276,13 +2142,9 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
           case TokenNameOR_EQUAL : // |= (15.25.2)
 
             if ((openParenthesisPositionCount < splitTokenDepth
-              || (openParenthesisPositionCount == splitTokenDepth
-                && splitTokenPriority > getTokenPriority(currentToken)))
-              && !((currentToken == TokenNamePLUS
-                || currentToken == TokenNameMINUS)
-                && (previousToken == TokenNameLBRACE
-                  || previousToken == TokenNameLBRACKET
-                  || splitScanner.startPosition == 0))) {
+              || (openParenthesisPositionCount == splitTokenDepth && splitTokenPriority > getTokenPriority(currentToken)))
+              && !((currentToken == TokenNamePLUS || currentToken == TokenNameMINUS)
+                && (previousToken == TokenNameLBRACE || previousToken == TokenNameLBRACKET || splitScanner.startPosition == 0))) {
               // the current token is better than the one we currently have
               // (in level or in priority if same level)
               // reset the substringsCount
@@ -2292,14 +2154,11 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
               substringsStartPositions[0] = 0;
               // better token means the whole line until now is the first substring
 
-              if (separateFirstArgumentOn(firstTokenOnLine)
-                && openParenthesisPositionCount > 0) {
+              if (separateFirstArgumentOn(firstTokenOnLine) && openParenthesisPositionCount > 0) {
                 substringsCount = 2; // resets the count of substrings
 
-                substringsEndPositions[0] =
-                  openParenthesisPosition[splitTokenDepth - 1];
-                substringsStartPositions[1] =
-                  openParenthesisPosition[splitTokenDepth - 1];
+                substringsEndPositions[0] = openParenthesisPosition[splitTokenDepth - 1];
+                substringsStartPositions[1] = openParenthesisPosition[splitTokenDepth - 1];
                 substringsEndPositions[1] = splitScanner.startPosition;
                 splitOperatorsCount = 3; // resets the count of split operators
                 splitOperators[0] = 0;
@@ -2321,8 +2180,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
 
               }
             } else {
-              if (openParenthesisPositionCount == splitTokenDepth
-                && splitTokenPriority == getTokenPriority(currentToken)) {
+              if (openParenthesisPositionCount == splitTokenDepth && splitTokenPriority == getTokenPriority(currentToken)) {
                 // if another token with the same priority is found,
                 // push the start position of the substring and
                 // push the token into the stack.
@@ -2342,16 +2200,10 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
                     substringsCount);
                 }
                 if (splitOperatorsCount == splitOperators.length) {
-                  System.arraycopy(
-                    splitOperators,
-                    0,
-                    (splitOperators = new int[splitOperatorsCount * 2]),
-                    0,
-                    splitOperatorsCount);
+                  System.arraycopy(splitOperators, 0, (splitOperators = new int[splitOperatorsCount * 2]), 0, splitOperatorsCount);
                 }
                 substringsStartPositions[substringsCount] = position;
-                substringsEndPositions[substringsCount++] =
-                  splitScanner.startPosition;
+                substringsEndPositions[substringsCount++] = splitScanner.startPosition;
                 // substring ends on operator start
                 position = splitScanner.currentPosition;
                 // next substring will start from operator end
@@ -2384,19 +2236,13 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
         && splitTokenDepth == 0
         && lastOpenParenthesisPosition > -1
         && lastOpenParenthesisPosition <= options.maxLineLength)
-      || (separateFirstArgumentOn(firstTokenOnLine)
-        && splitTokenDepth > 0
-        && lastOpenParenthesisPosition > -1))
-      && (lastOpenParenthesisPosition < splitScanner.source.length
-        && splitScanner.source[lastOpenParenthesisPosition] != ')')) {
+      || (separateFirstArgumentOn(firstTokenOnLine) && splitTokenDepth > 0 && lastOpenParenthesisPosition > -1))
+      && (lastOpenParenthesisPosition < splitScanner.source.length && splitScanner.source[lastOpenParenthesisPosition] != ')')) {
       // fix for 1FH4J2H: LFCOM:WINNT - Formatter - Empty parenthesis should not be broken on two lines
       // only one split on a top level .
       // or more than one split on . and substring before open parenthesis fits one line.
       // or split inside parenthesis and first token is not a for/while/if
-      SplitLine sl =
-        split(
-          stringToSplit.substring(lastOpenParenthesisPosition),
-          lastOpenParenthesisPosition);
+      SplitLine sl = split(stringToSplit.substring(lastOpenParenthesisPosition), lastOpenParenthesisPosition);
       if (sl == null || sl.operators[0] != TokenNameCOMMA) {
         // trim() is used to remove the extra blanks at the end of the substring. See PR 1FGYPI1
         return new SplitLine(
@@ -2404,9 +2250,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
           new String[] {
             stringToSplit.substring(0, lastOpenParenthesisPosition).trim(),
             stringToSplit.substring(lastOpenParenthesisPosition)},
-          new int[] {
-            offsetInGlobalLine,
-            lastOpenParenthesisPosition + offsetInGlobalLine });
+          new int[] { offsetInGlobalLine, lastOpenParenthesisPosition + offsetInGlobalLine });
       } else {
         // right substring can be split and is split on comma
         // copy substrings and operators
@@ -2421,36 +2265,19 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
         result[0] = stringToSplit.substring(0, lastOpenParenthesisPosition);
         operators[0] = 0;
 
-        System.arraycopy(
-          sl.startSubstringsIndexes,
-          startIndex,
-          startIndexes,
-          1,
-          subStringsLength - 1);
+        System.arraycopy(sl.startSubstringsIndexes, startIndex, startIndexes, 1, subStringsLength - 1);
         for (int i = subStringsLength - 1; i >= 0; i--) {
           startIndexes[i] += offsetInGlobalLine;
         }
-        System.arraycopy(
-          sl.substrings,
-          startIndex,
-          result,
-          1,
-          subStringsLength - 1);
-        System.arraycopy(
-          sl.operators,
-          startIndex,
-          operators,
-          1,
-          operatorsLength - 1);
+        System.arraycopy(sl.substrings, startIndex, result, 1, subStringsLength - 1);
+        System.arraycopy(sl.operators, startIndex, operators, 1, operatorsLength - 1);
 
         return new SplitLine(operators, result, startIndexes);
       }
     }
     // if the last token is a comment and the substring before the comment fits on a line,
     // split before the comment and return the result.
-    if (lastCommentStartPosition > -1
-      && lastCommentStartPosition < options.maxLineLength
-      && splitTokenPriority > 50) {
+    if (lastCommentStartPosition > -1 && lastCommentStartPosition < options.maxLineLength && splitTokenPriority > 50) {
       int end = lastCommentStartPosition;
       int start = lastCommentStartPosition;
       if (stringToSplit.charAt(end - 1) == ' ') {
@@ -2461,9 +2288,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
       }
       return new SplitLine(
         new int[] { 0, 0 },
-        new String[] {
-          stringToSplit.substring(0, end),
-          stringToSplit.substring(start)},
+        new String[] { stringToSplit.substring(0, end), stringToSplit.substring(start)},
         new int[] { 0, start });
     }
     if (position != stringToSplit.length()) {
@@ -2474,24 +2299,14 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
           (substringsStartPositions = new int[substringsCount * 2]),
           0,
           substringsCount);
-        System.arraycopy(
-          substringsEndPositions,
-          0,
-          (substringsEndPositions = new int[substringsCount * 2]),
-          0,
-          substringsCount);
+        System.arraycopy(substringsEndPositions, 0, (substringsEndPositions = new int[substringsCount * 2]), 0, substringsCount);
       }
       // avoid empty extra substring, e.g. line terminated with a semi-colon
       substringsStartPositions[substringsCount] = position;
       substringsEndPositions[substringsCount++] = stringToSplit.length();
     }
     if (splitOperatorsCount == splitOperators.length) {
-      System.arraycopy(
-        splitOperators,
-        0,
-        (splitOperators = new int[splitOperatorsCount * 2]),
-        0,
-        splitOperatorsCount);
+      System.arraycopy(splitOperators, 0, (splitOperators = new int[splitOperatorsCount * 2]), 0, splitOperatorsCount);
     }
     splitOperators[splitOperatorsCount] = 0;
 
@@ -2512,50 +2327,19 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
       substringsStartPositions[i] += offsetInGlobalLine;
     }
     if (splitOperatorsCount > substringsCount) {
-      System.arraycopy(
-        substringsStartPositions,
-        0,
-        (substringsStartPositions = new int[splitOperatorsCount]),
-        0,
-        substringsCount);
-      System.arraycopy(
-        substringsEndPositions,
-        0,
-        (substringsEndPositions = new int[splitOperatorsCount]),
-        0,
-        substringsCount);
+      System.arraycopy(substringsStartPositions, 0, (substringsStartPositions = new int[splitOperatorsCount]), 0, substringsCount);
+      System.arraycopy(substringsEndPositions, 0, (substringsEndPositions = new int[splitOperatorsCount]), 0, substringsCount);
       for (int i = substringsCount; i < splitOperatorsCount; i++) {
         substringsStartPositions[i] = position;
         substringsEndPositions[i] = position;
       }
-      System.arraycopy(
-        splitOperators,
-        0,
-        (splitOperators = new int[splitOperatorsCount]),
-        0,
-        splitOperatorsCount);
+      System.arraycopy(splitOperators, 0, (splitOperators = new int[splitOperatorsCount]), 0, splitOperatorsCount);
     } else {
-      System.arraycopy(
-        substringsStartPositions,
-        0,
-        (substringsStartPositions = new int[substringsCount]),
-        0,
-        substringsCount);
-      System.arraycopy(
-        substringsEndPositions,
-        0,
-        (substringsEndPositions = new int[substringsCount]),
-        0,
-        substringsCount);
-      System.arraycopy(
-        splitOperators,
-        0,
-        (splitOperators = new int[substringsCount]),
-        0,
-        substringsCount);
+      System.arraycopy(substringsStartPositions, 0, (substringsStartPositions = new int[substringsCount]), 0, substringsCount);
+      System.arraycopy(substringsEndPositions, 0, (substringsEndPositions = new int[substringsCount]), 0, substringsCount);
+      System.arraycopy(splitOperators, 0, (splitOperators = new int[substringsCount]), 0, substringsCount);
     }
-    SplitLine splitLine =
-      new SplitLine(splitOperators, result, substringsStartPositions);
+    SplitLine splitLine = new SplitLine(splitOperators, result, substringsStartPositions);
     return splitLine;
   }
 
@@ -2565,11 +2349,9 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
     }
     char[] source = scanner.source;
     int sourceLength = source.length;
-    while (indexToMap < positionsToMap.length
-      && positionsToMap[indexToMap] <= startPosition) {
+    while (indexToMap < positionsToMap.length && positionsToMap[indexToMap] <= startPosition) {
       int posToMap = positionsToMap[indexToMap];
-      if (posToMap < 0
-        || posToMap >= sourceLength) {
+      if (posToMap < 0 || posToMap >= sourceLength) {
         // protection against out of bounds position
         if (posToMap == sourceLength) {
           mappedPositions[indexToMap] = formattedSource.length();
@@ -2590,9 +2372,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
     }
   }
 
-  private void updateMappedPositionsWhileSplitting(
-    int startPosition,
-    int endPosition) {
+  private void updateMappedPositionsWhileSplitting(int startPosition, int endPosition) {
     if (mappedPositions == null || mappedPositions.length == indexInMap)
       return;
 
@@ -2630,7 +2410,6 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
   * @deprecated
   */
   public void setInitialIndentationLevel(int newIndentationLevel) {
-    this.initialIndentationLevel =
-      currentLineIndentationLevel = indentationLevel = newIndentationLevel;
+    this.initialIndentationLevel = currentLineIndentationLevel = indentationLevel = newIndentationLevel;
   }
 }
\ No newline at end of file