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.
// 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))
+ if ((
+ (pendingNewLines > 0 && (!isComment(token)))
+ || (newLinesInWhitespace > 0 && (openParenthesisCount <= 1 && isComment(token)))
+ || (previousCompilableToken == TokenNameLBRACE && token == TokenNameRBRACE)
+ || (newLinesInWhitespace > 0 && previousCompilableToken == TokenNameDOT)
+ )
&& token != Scanner.TokenNameWHITESPACE) {
// Do not add newline & indent between an adjoining close brace and
// close paren. Anonymous inner classes may use this form.
// 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;
// Add new line and increase indentation level after open brace.
pendingNewLines = 1;
indentationLevel += pushBlock();
+ inAssignment = false;
}
}
break;
}
break;
case TokenNameDOT:
+ space();
pendingSpace = false;
break;
case TokenNameSEMICOLON:
* @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;
}
case TokenNameLPAREN:
case TokenNameNOT:
case TokenNameTWIDDLE:
- case TokenNameDOT:
case 0:
// no token
case TokenNameWHITESPACE:
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;
} else {
mappedPositions[indexToMap] = posToMap + globalDelta + lineDelta;
}
- if (mappedPositions[indexToMap]>=formattedSource.length()) {
- mappedPositions[indexToMap]=formattedSource.length()-1;
- }
}
indexToMap++;
}
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++;
}
}