aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacek Pospychala2012-10-31 04:36:32 (EDT)
committerJacek Pospychala2012-10-31 04:36:32 (EDT)
commitfd66523260daefb6c77051e004e647c3afc8e4ce (patch)
tree79c8eced2c98b906285176e882ae34c582b188e6
parentf99df1e9da170370ae08f097e3abe91bdc7b533f (diff)
downloadorg.eclipse.pdt-fd66523260daefb6c77051e004e647c3afc8e4ce.zip
org.eclipse.pdt-fd66523260daefb6c77051e004e647c3afc8e4ce.tar.gz
org.eclipse.pdt-fd66523260daefb6c77051e004e647c3afc8e4ce.tar.bz2
Bug 386550 - Incorrect array indentation cases
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/format/DefaultIndentationStrategy.java55
1 files changed, 38 insertions, 17 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 a3f2714..e558f35 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
@@ -595,23 +595,44 @@ 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) {
return;
}
- int lastNonEmptyLineIndex = getIndentationBaseLine(document,
- lineNumber, forOffset, false);
- final int indentationBaseLineIndex = getIndentationBaseLine(document,
- lineNumber, forOffset, true);
+
+ int lineOfOffset = document.getLineOfOffset(forOffset);
+ IRegion lineInformationOfOffset = document
+ .getLineInformation(lineOfOffset);
+ final String lineText = document.get(
+ lineInformationOfOffset.getOffset(),
+ lineInformationOfOffset.getLength());
+
+ int lastNonEmptyLineIndex;
+ final int indentationBaseLineIndex;
+ final int newForOffset;
+
+ // code for not formatting comments
+ if (lineText.trim().startsWith("//")) {
+ lastNonEmptyLineIndex = lineOfOffset;
+ indentationBaseLineIndex = lineOfOffset;
+ int i = lineInformationOfOffset.getOffset();
+ for (; i < lineInformationOfOffset.getOffset()
+ + lineInformationOfOffset.getLength()
+ && document.getChar(i) != '/'; i++)
+ ;
+ newForOffset = (forOffset < i) ? i : forOffset;
+
+ }
+ // end
+ else {
+ newForOffset = forOffset;
+ lastNonEmptyLineIndex = getIndentationBaseLine(document,
+ lineNumber, newForOffset, false);
+ indentationBaseLineIndex = getIndentationBaseLine(document,
+ lineNumber, newForOffset, true);
+ }
+
final IRegion lastNonEmptyLine = document
.getLineInformation(lastNonEmptyLineIndex);
final IRegion indentationBaseLine = document
@@ -623,8 +644,8 @@ public class DefaultIndentationStrategy implements IIndentationStrategy {
+ lastNonEmptyLine.getLength();
int offset;
int line;
- if (forOffset < lastLineEndOffset) {
- offset = forOffset;
+ if (newForOffset < lastLineEndOffset) {
+ offset = newForOffset;
line = lineNumber;
} else {
offset = lastLineEndOffset;
@@ -634,7 +655,7 @@ public class DefaultIndentationStrategy implements IIndentationStrategy {
indent(document, result, indentationChar, indentationSize);
} else {
boolean intended = indentMultiLineCase(document, lineNumber,
- forOffset, enterKeyPressed, result, blanks, commandText,
+ newForOffset, enterKeyPressed, result, blanks, commandText,
indentationObject);
if (!intended) {
lastNonEmptyLineIndex = lineNumber;
@@ -666,10 +687,10 @@ public class DefaultIndentationStrategy implements IIndentationStrategy {
// we use the same indentation of the last non-empty
// line.
boolean shouldNotChangeIndent = false;
- if (forOffset != document.getLength()) {
+ if (newForOffset != document.getLength()) {
final IRegion lineInfo = document
.getLineInformation(lineNumber);
- int nonEmptyOffset = forOffset;
+ int nonEmptyOffset = newForOffset;
if (!enterKeyPressed) {
if (nonEmptyOffset == lineInfo.getOffset()) {
nonEmptyOffset = moveLineStartToNonBlankChar(