import net.sourceforge.phpdt.core.compiler.InvalidInputException;
import net.sourceforge.phpdt.internal.compiler.ConfigurableOption;
import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
-
import net.sourceforge.phpdt.internal.formatter.impl.FormatterOptions;
import net.sourceforge.phpdt.internal.formatter.impl.SplitLine;
boolean inArrayAssignment = false;
boolean inThrowsClause = false;
boolean inClassOrInterfaceHeader = false;
+ int dollarBraceCount = 0;
// openBracketCount is used to count the number of open brackets not closed yet.
int openBracketCount = 0;
// exit the loop.
try {
token = scanner.getNextToken();
+ if (Scanner.DEBUG) {
+ int currentEndPosition = scanner.getCurrentTokenEndPosition();
+ int currentStartPosition = scanner.getCurrentTokenStartPosition();
+
+ System.out.print(currentStartPosition + "," + currentEndPosition + ": ");
+ System.out.println(scanner.toStringAction(token));
+ }
// Patch for line comment
// See PR http://dev.eclipse.org/bugs/show_bug.cgi?id=23096
}
}
switch (token) {
+ case TokenNameDOLLAR_LBRACE :
+ dollarBraceCount++;
+ break;
case TokenNameelse :
// case TokenNamefinally :
expectingOpenBrace = true;
}
break;
case TokenNameRBRACE :
+ if (dollarBraceCount > 0) {
+ dollarBraceCount--;
+ break;
+ }
if (previousCompilableToken == TokenNameRPAREN) {
pendingSpace = false;
}
}
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;
+ // 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
// (eg: ++, --, +, -) and the identifier being modified.
if (previousToken == TokenNamePLUS_PLUS
|| previousToken == TokenNameMINUS_MINUS
+ || (previousToken == TokenNameMINUS_GREATER &&
+ options.compactDereferencingMode) // ->
|| (previousToken == TokenNamePLUS && unarySignModifier > 0)
|| (previousToken == TokenNameMINUS && unarySignModifier > 0)) {
pendingSpace = false;
7) in an assignment statement, if the previous token is an
open brace or the current token is a close brace
8) previous token is a single line comment
+ 9) current token is a '->'
*/
+ if (token == TokenNameMINUS_GREATER &&
+ options.compactDereferencingMode) pendingSpace = false;
+
boolean openAndCloseBrace = previousCompilableToken == TokenNameLBRACE && token == TokenNameRBRACE;
if (pendingSpace
case TokenNameCOLON : // :
return 50; // it's better cutting on ?: than on ;
case TokenNameEQUAL_EQUAL : // ==
+ case TokenNameEQUAL_EQUAL_EQUAL : // ===
case TokenNameNOT_EQUAL : // !=
+ case TokenNameNOT_EQUAL_EQUAL : // !=
return 60;
case TokenNameLESS : // <
case TokenNameLESS_EQUAL : // <=
case TokenNameCOLON : // : (15.24)
return ":"; //$NON-NLS-1$
+ case TokenNameCOLON_COLON : // : (15.24)
+ return "::"; //$NON-NLS-1$
+
case TokenNameEQUAL_EQUAL : // == (15.20, 15.20.1, 15.20.2, 15.20.3)
return "=="; //$NON-NLS-1$
+ case TokenNameEQUAL_EQUAL_EQUAL : // == (15.20, 15.20.1, 15.20.2, 15.20.3)
+ return "==="; //$NON-NLS-1$
+
+ case TokenNameEQUAL_GREATER : // -= (15.25.2)
+ return "=>"; //$NON-NLS-1$
+
case TokenNameNOT_EQUAL : // != (15.20, 15.20.1, 15.20.2, 15.20.3)
return "!="; //$NON-NLS-1$
+ case TokenNameNOT_EQUAL_EQUAL : // != (15.20, 15.20.1, 15.20.2, 15.20.3)
+ return "!=="; //$NON-NLS-1$
+
case TokenNameLESS : // < (15.19.1)
return "<"; //$NON-NLS-1$
case TokenNameMINUS_EQUAL : // -= (15.25.2)
return "-="; //$NON-NLS-1$
+ case TokenNameMINUS_GREATER : // -= (15.25.2)
+ return "->"; //$NON-NLS-1$
+
case TokenNameLEFT_SHIFT_EQUAL : // <<= (15.25.2)
return "<<="; //$NON-NLS-1$
if (currentToken != Scanner.TokenNameWHITESPACE)
previousToken = currentToken;
currentToken = splitScanner.getNextToken();
+ if (Scanner.DEBUG) {
+ int currentEndPosition = splitScanner.getCurrentTokenEndPosition();
+ int currentStartPosition = splitScanner.getCurrentTokenStartPosition();
+
+ System.out.print(currentStartPosition + "," + currentEndPosition + ": ");
+ System.out.println(scanner.toStringAction(currentToken));
+ }
} catch (InvalidInputException e) {
if (!handleInvalidToken(e))
throw e;
case TokenNameGREATER_EQUAL : // >= (15.19.1)
// case TokenNameinstanceof : // instanceof
case TokenNameEQUAL_EQUAL : // == (15.20, 15.20.1, 15.20.2, 15.20.3)
+ case TokenNameEQUAL_EQUAL_EQUAL : // == (15.20, 15.20.1, 15.20.2, 15.20.3)
case TokenNameNOT_EQUAL : // != (15.20, 15.20.1, 15.20.2, 15.20.3)
+ case TokenNameNOT_EQUAL_EQUAL : // != (15.20, 15.20.1, 15.20.2, 15.20.3)
case TokenNameAND : // & (15.21, 15.21.1, 15.21.2)
case TokenNameOR : // | (15.21, 15.21.1, 15.21.2)
case TokenNameXOR : // ^ (15.21, 15.21.1, 15.21.2)