aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzzhongwei2012-10-24 01:13:59 (EDT)
committerzzhongwei2012-10-24 01:13:59 (EDT)
commit1e952b363394006ce460262d4a112604487868b9 (patch)
tree44fdee86104e45eff168c8cdb887a149314fb75d
parent8d39fb0cf71f8efa8a037621e29bfe050f59dd87 (diff)
downloadorg.eclipse.pdt-1e952b363394006ce460262d4a112604487868b9.zip
org.eclipse.pdt-1e952b363394006ce460262d4a112604487868b9.tar.gz
org.eclipse.pdt-1e952b363394006ce460262d4a112604487868b9.tar.bz2
388960: Incorrect indentation for nested braceless if statement
https://bugs.eclipse.org/bugs/show_bug.cgi?id=388960 contributed by Itay
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/format/PHPHeuristicScanner.java6
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/util/text/PHPTextSequenceUtilities.java11
-rw-r--r--tests/org.eclipse.php.ui.tests/workspace/formatter-autoedit/bracelessOuterIfStatement.pdtt14
-rw-r--r--tests/org.eclipse.php.ui.tests/workspace/formatter-autoedit/twoBracelessIfStatements.pdtt13
4 files changed, 39 insertions, 5 deletions
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/format/PHPHeuristicScanner.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/format/PHPHeuristicScanner.java
index e0aa6c0..4eac235 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/format/PHPHeuristicScanner.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/format/PHPHeuristicScanner.java
@@ -1091,6 +1091,12 @@ public final class PHPHeuristicScanner implements Symbols {
public boolean isBracelessBlockStart(int position, int bound) {
if (position < 1)
return false;
+ switch (nextToken(position, PHPHeuristicScanner.UNBOUND)) {
+ case TokenIF:
+ case TokenFOR:
+ case TokenWHILE:
+ return false;
+ }
switch (previousToken(position, bound)) {
case TokenDO:
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/util/text/PHPTextSequenceUtilities.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/util/text/PHPTextSequenceUtilities.java
index 84b556a..8720449 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/util/text/PHPTextSequenceUtilities.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/util/text/PHPTextSequenceUtilities.java
@@ -74,8 +74,7 @@ public class PHPTextSequenceUtilities {
}
if (tRegion != null && tRegion.getType() == PHPRegionContext.PHP_CLOSE) {
tRegion = container.getRegionAtCharacterOffset(container
- .getStartOffset()
- + tRegion.getStart() - 1);
+ .getStartOffset() + tRegion.getStart() - 1);
}
// This text region must be of type PhpScriptRegion:
@@ -106,7 +105,8 @@ public class PHPTextSequenceUtilities {
}
if (startTokenRegion.getType() == PHPRegionTypes.PHP_CURLY_CLOSE
|| startTokenRegion.getType() == PHPRegionTypes.PHP_CURLY_OPEN
- || startTokenRegion.getType() == PHPRegionTypes.PHP_SEMICOLON) {
+ || startTokenRegion.getType() == PHPRegionTypes.PHP_SEMICOLON
+ || startTokenRegion.getType() == PHPRegionTypes.PHP_IF) {
// Calculate starting position of the statement (it
// should go right after this startTokenRegion):
startOffset += startTokenRegion.getEnd();
@@ -128,8 +128,9 @@ public class PHPTextSequenceUtilities {
}
// remove spaces from start.
- textSequence = textSequence.subTextSequence(readForwardSpaces(
- textSequence, 0), textSequence.length());
+ textSequence = textSequence.subTextSequence(
+ readForwardSpaces(textSequence, 0),
+ textSequence.length());
return textSequence;
diff --git a/tests/org.eclipse.php.ui.tests/workspace/formatter-autoedit/bracelessOuterIfStatement.pdtt b/tests/org.eclipse.php.ui.tests/workspace/formatter-autoedit/bracelessOuterIfStatement.pdtt
new file mode 100644
index 0000000..c86d109
--- /dev/null
+++ b/tests/org.eclipse.php.ui.tests/workspace/formatter-autoedit/bracelessOuterIfStatement.pdtt
@@ -0,0 +1,14 @@
+--TEST--
+Tests auto editing multiline statements.
+--FILE--
+<?php
+if ($validator instanceof ValidatorInterface)
+ if (! $validator->isValid($param)) {|}
+?>
+--EXPECT--
+<?php
+if ($validator instanceof ValidatorInterface)
+ if (! $validator->isValid($param)) {
+
+ }
+?> \ No newline at end of file
diff --git a/tests/org.eclipse.php.ui.tests/workspace/formatter-autoedit/twoBracelessIfStatements.pdtt b/tests/org.eclipse.php.ui.tests/workspace/formatter-autoedit/twoBracelessIfStatements.pdtt
new file mode 100644
index 0000000..9258bcc
--- /dev/null
+++ b/tests/org.eclipse.php.ui.tests/workspace/formatter-autoedit/twoBracelessIfStatements.pdtt
@@ -0,0 +1,13 @@
+--TEST--
+Tests auto editing multiline statements.
+--FILE--
+<?php
+if ($validator instanceof ValidatorInterface)
+ if (! $validator->isValid($param)) |
+?>
+--EXPECT--
+<?php
+if ($validator instanceof ValidatorInterface)
+ if (! $validator->isValid($param))
+
+?> \ No newline at end of file