aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzzhongwei2012-10-14 09:20:50 (EDT)
committerzzhongwei2012-10-14 22:54:53 (EDT)
commit80cb4b618417aa441030ff3431aa5c3b3ac4e8e5 (patch)
treed36b365e1bdc9fbca82324d789129c63996a5daa
parenta4e918343ca9143a751f39c6d36d792af452d290 (diff)
downloadorg.eclipse.pdt-80cb4b618417aa441030ff3431aa5c3b3ac4e8e5.zip
org.eclipse.pdt-80cb4b618417aa441030ff3431aa5c3b3ac4e8e5.tar.gz
org.eclipse.pdt-80cb4b618417aa441030ff3431aa5c3b3ac4e8e5.tar.bz2
https://bugs.eclipse.org/bugs/show_bug.cgi?id=386550 case 1
contributed by Itay
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/format/DefaultIndentationStrategy.java63
1 files changed, 53 insertions, 10 deletions
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/format/DefaultIndentationStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/format/DefaultIndentationStrategy.java
index 1c3607b..79a420f 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/format/DefaultIndentationStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/format/DefaultIndentationStrategy.java
@@ -577,6 +577,8 @@ public class DefaultIndentationStrategy implements IIndentationStrategy {
final int lineNumber, final int forOffset, String commandText)
throws BadLocationException {
+ IFormatterCommonPrferences formatterCommonPrferences = FormatterUtils
+ .getFormatterCommonPrferences();
int indentationWrappedLineSize = FormatterUtils
.getFormatterCommonPrferences().getIndentationWrappedLineSize(
document);
@@ -593,6 +595,14 @@ public class DefaultIndentationStrategy implements IIndentationStrategy {
indentationObject.indentationSize = indentationSize;
indentationObject.indentationChar = indentationChar;
+ // remove this
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ // indentationObject.indentationWrappedLineSize = 0;
+ // indentationObject.indentationArrayInitSize = 0;
+ // indentationObject.indentationSize = 0;
+ // remove this
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
boolean enterKeyPressed = document.getLineDelimiter().equals(
result.toString());
if (forOffset == 0) {
@@ -787,6 +797,7 @@ public class DefaultIndentationStrategy implements IIndentationStrategy {
return true;
}
}
+
} else if (inMultiLine(scanner, document, lineNumber, offset)) {
// lineState.inBracelessBlock = true;
int peer = scanner.findOpeningPeer(offset - 1,
@@ -794,8 +805,27 @@ public class DefaultIndentationStrategy implements IIndentationStrategy {
PHPHeuristicScanner.LPAREN, PHPHeuristicScanner.RPAREN);
if (peer != PHPHeuristicScanner.NOT_FOUND) {
- int token = scanner.previousToken(peer - 1,
+ // search for assignment (i.e. "=>")
+ int position = peer - 1;
+ int token = scanner.previousToken(position,
+ PHPHeuristicScanner.UNBOUND);
+ // scan tokens backwards until reaching a PHP token
+ while (token > 100
+ || token == PHPHeuristicScanner.TokenOTHER) {
+ position--;
+ token = scanner.previousToken(position,
+ PHPHeuristicScanner.UNBOUND);
+ }
+
+ position--;
+ boolean isAssignment = scanner.previousToken(position,
+ PHPHeuristicScanner.UNBOUND) == PHPHeuristicScanner.TokenGREATERTHAN
+ && scanner.previousToken(position - 1,
+ PHPHeuristicScanner.UNBOUND) == PHPHeuristicScanner.TokenEQUAL;
+
+ token = scanner.previousToken(peer - 1,
PHPHeuristicScanner.UNBOUND);
+
boolean isArray = token == Symbols.TokenARRAY;
// lineState.indent.setLength(0)
// int baseLine = document.getLineOfOffset(peer);
@@ -814,10 +844,21 @@ public class DefaultIndentationStrategy implements IIndentationStrategy {
.startsWith(
BLANK + PHPHeuristicScanner.RPAREN)) {
if (isArray) {
- indent(document, newBuffer,
- indentationObject.indentationArrayInitSize,
- indentationObject.indentationChar,
- indentationObject.indentationSize);
+ region = document
+ .getLineInformationOfOffset(offset);
+ if (scanner.nextToken(offset, region.getOffset()
+ + region.getLength()) == PHPHeuristicScanner.TokenRPAREN
+ && isAssignment) {
+ indent(document, newBuffer, 0,
+ indentationObject.indentationChar,
+ indentationObject.indentationSize);
+ } else {
+ indent(document,
+ newBuffer,
+ indentationObject.indentationArrayInitSize,
+ indentationObject.indentationChar,
+ indentationObject.indentationSize);
+ }
} else {
indent(document,
newBuffer,
@@ -949,11 +990,13 @@ public class DefaultIndentationStrategy implements IIndentationStrategy {
if (isBracelessBlock) {
try {
IRegion region = document.getLineInformationOfOffset(offset);
- if (!document
- .get(offset,
- region.getOffset() + region.getLength()
- - offset).trim()
- .startsWith(BLANK + PHPHeuristicScanner.LBRACE)) {
+ String trimedLine = document.get(offset,
+ region.getOffset() + region.getLength() - offset)
+ .trim();
+ if (!(trimedLine.startsWith(BLANK// + PHPHeuristicScanner.LBRACE
+ ))
+ && trimedLine.contains(Character
+ .toString(PHPHeuristicScanner.LBRACE))) {
return true;
}
} catch (BadLocationException e) {