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();
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') {
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;
}
// 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;
*/
// 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;
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
// 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
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
// 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)) {
}
} 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);
}
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;
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;
// 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;
pendingSpace = false;
break;
case TokenNameLBRACE :
- if ((previousCompilableToken == TokenNameRBRACKET)
- || (previousCompilableToken == TokenNameEQUAL)) {
+ if ((previousCompilableToken == TokenNameRBRACKET) || (previousCompilableToken == TokenNameEQUAL)) {
// if (previousCompilableToken == TokenNameRBRACKET) {
inArrayAssignment = true;
inAssignment = false;
// 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;
// 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--;
// 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') {
}
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
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);
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);
}
*
* @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);
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$
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;
}
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++) {
}
// 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);
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) {
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);
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);
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) {
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) {
// 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?
}
// 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);
formattedSource.append(lastOperatorString);
increaseSplitDelta(lastOperatorString.length());
- if (insertSpaceAfter(lastOperator)
- // && lastOperator != TokenNameimplements
+ if (insertSpaceAfter(lastOperator) // && lastOperator != TokenNameimplements
&& lastOperator != TokenNameextends) {
// && lastOperator != TokenNamethrows) {
formattedSource.append(' ');
*/
private int pop(int token) {
int delta = 0;
- if ((constructionsCount > 0)
- && (constructions[constructionsCount - 1] == token)) {
+ if ((constructionsCount > 0) && (constructions[constructionsCount - 1] == token)) {
delta--;
constructionsCount--;
}
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--;
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--;
}
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--;
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--;
}
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)
*/
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;
}
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;
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
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;
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
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
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 :
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
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;
}
} 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.
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
&& 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(
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
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) == ' ') {
}
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()) {
(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;
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;
}
}
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();
}
}
- private void updateMappedPositionsWhileSplitting(
- int startPosition,
- int endPosition) {
+ private void updateMappedPositionsWhileSplitting(int startPosition, int endPosition) {
if (mappedPositions == null || mappedPositions.length == indexInMap)
return;
* @deprecated
*/
public void setInitialIndentationLevel(int newIndentationLevel) {
- this.initialIndentationLevel =
- currentLineIndentationLevel = indentationLevel = newIndentationLevel;
+ this.initialIndentationLevel = currentLineIndentationLevel = indentationLevel = newIndentationLevel;
}
}
\ No newline at end of file