*** empty log message ***
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/JavaHeuristicScanner.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/JavaHeuristicScanner.java
index fb5fbf2..37339eb 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/JavaHeuristicScanner.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/JavaHeuristicScanner.java
@@ -589,7 +589,7 @@
*
* @param position the first character position in <code>fDocument</code> to be considered
* @param bound the first position in <code>fDocument</code> to not consider any more, with <code>bound</code> > <code>position</code>, or <code>UNBOUND</code>
- * @return the smallest position of a non-whitespace character in [<code>position</code>, <code>bound</code>) that resides in a Java partition, or <code>-1</code> if none can be found
+ * @return the smallest position of a non-whitespace character in [<code>position</code>, <code>bound</code>) that resides in a Java partition, or <code>NOT_FOUND</code> if none can be found
*/
public int findNonWhitespaceForward(int position, int bound) {
return scanForward(position, bound, fNonWSDefaultPart);
@@ -601,7 +601,7 @@
*
* @param position the first character position in <code>fDocument</code> to be considered
* @param bound the first position in <code>fDocument</code> to not consider any more, with <code>bound</code> > <code>position</code>, or <code>UNBOUND</code>
- * @return the smallest position of a non-whitespace character in [<code>position</code>, <code>bound</code>), or <code>-1</code> if none can be found
+ * @return the smallest position of a non-whitespace character in [<code>position</code>, <code>bound</code>), or <code>NOT_FOUND</code> if none can be found
*/
public int findNonWhitespaceForwardInAnyPartition(int position, int bound) {
return scanForward(position, bound, fNonWS);
@@ -614,7 +614,7 @@
*
* @param position the first character position in <code>fDocument</code> to be considered
* @param bound the first position in <code>fDocument</code> to not consider any more, with <code>bound</code> < <code>position</code>, or <code>UNBOUND</code>
- * @return the highest position of a non-whitespace character in (<code>bound</code>, <code>position</code>] that resides in a Java partition, or <code>-1</code> if none can be found
+ * @return the highest position of a non-whitespace character in (<code>bound</code>, <code>position</code>] that resides in a Java partition, or <code>NOT_FOUND</code> if none can be found
*/
public int findNonWhitespaceBackward(int position, int bound) {
return scanBackward(position, bound, fNonWSDefaultPart);
@@ -627,7 +627,7 @@
* @param start the first character position in <code>fDocument</code> to be considered
* @param bound the first position in <code>fDocument</code> to not consider any more, with <code>bound</code> > <code>start</code>, or <code>UNBOUND</code>
* @param condition the <code>StopCondition</code> to check
- * @return the lowest position in [<code>start</code>, <code>bound</code>) for which <code>condition</code> holds, or <code>-1</code> if none can be found
+ * @return the lowest position in [<code>start</code>, <code>bound</code>) for which <code>condition</code> holds, or <code>NOT_FOUND</code> if none can be found
*/
public int scanForward(int start, int bound, StopCondition condition) {
Assert.isTrue(start >= 0);
@@ -661,7 +661,7 @@
* @param position the first character position in <code>fDocument</code> to be considered
* @param bound the first position in <code>fDocument</code> to not consider any more, with <code>bound</code> > <code>position</code>, or <code>UNBOUND</code>
* @param ch the <code>char</code> to search for
- * @return the lowest position of <code>ch</code> in (<code>bound</code>, <code>position</code>] that resides in a Java partition, or <code>-1</code> if none can be found
+ * @return the lowest position of <code>ch</code> in (<code>bound</code>, <code>position</code>] that resides in a Java partition, or <code>NOT_FOUND</code> if none can be found
*/
public int scanForward(int position, int bound, char ch) {
return scanForward(position, bound, new CharacterMatch(ch));
@@ -675,7 +675,7 @@
* @param position the first character position in <code>fDocument</code> to be considered
* @param bound the first position in <code>fDocument</code> to not consider any more, with <code>bound</code> > <code>position</code>, or <code>UNBOUND</code>
* @param chars an array of <code>char</code> to search for
- * @return the lowest position of a non-whitespace character in [<code>position</code>, <code>bound</code>) that resides in a Java partition, or <code>-1</code> if none can be found
+ * @return the lowest position of a non-whitespace character in [<code>position</code>, <code>bound</code>) that resides in a Java partition, or <code>NOT_FOUND</code> if none can be found
*/
public int scanForward(int position, int bound, char[] chars) {
return scanForward(position, bound, new CharacterMatch(chars));
@@ -688,7 +688,7 @@
* @param start the first character position in <code>fDocument</code> to be considered
* @param bound the first position in <code>fDocument</code> to not consider any more, with <code>bound</code> < <code>start</code>, or <code>UNBOUND</code>
* @param condition the <code>StopCondition</code> to check
- * @return the highest position in (<code>bound</code>, <code>start</code> for which <code>condition</code> holds, or <code>-1</code> if none can be found
+ * @return the highest position in (<code>bound</code>, <code>start</code> for which <code>condition</code> holds, or <code>NOT_FOUND</code> if none can be found
*/
public int scanBackward(int start, int bound, StopCondition condition) {
if (bound == UNBOUND)
@@ -720,7 +720,7 @@
* @param position the first character position in <code>fDocument</code> to be considered
* @param bound the first position in <code>fDocument</code> to not consider any more, with <code>bound</code> < <code>position</code>, or <code>UNBOUND</code>
* @param ch the <code>char</code> to search for
- * @return the highest position of one element in <code>chars</code> in (<code>bound</code>, <code>position</code>] that resides in a Java partition, or <code>-1</code> if none can be found
+ * @return the highest position of one element in <code>chars</code> in (<code>bound</code>, <code>position</code>] that resides in a Java partition, or <code>NOT_FOUND</code> if none can be found
*/
public int scanBackward(int position, int bound, char ch) {
return scanBackward(position, bound, new CharacterMatch(ch));
@@ -734,7 +734,7 @@
* @param position the first character position in <code>fDocument</code> to be considered
* @param bound the first position in <code>fDocument</code> to not consider any more, with <code>bound</code> < <code>position</code>, or <code>UNBOUND</code>
* @param chars an array of <code>char</code> to search for
- * @return the highest position of one element in <code>chars</code> in (<code>bound</code>, <code>position</code>] that resides in a Java partition, or <code>-1</code> if none can be found
+ * @return the highest position of one element in <code>chars</code> in (<code>bound</code>, <code>position</code>] that resides in a Java partition, or <code>NOT_FOUND</code> if none can be found
*/
public int scanBackward(int position, int bound, char[] chars) {
return scanBackward(position, bound, new CharacterMatch(chars));
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/JavaIndenter.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/JavaIndenter.java
index 2d610de..f1e4636 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/JavaIndenter.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/JavaIndenter.java
@@ -37,14 +37,14 @@
* (method defs, array initializers)
*/
private int fAlign;
- /** Whether to add one space to the absolute indentation. */
- private boolean fAlignPlusOne;
/** The stateful scanpositionf or the indentation methods. */
private int fPosition;
/** The previous position. */
private int fPreviousPos;
/** The most recent token. */
private int fToken;
+ /** The line of <code>fPosition</code>. */
+ private int fLine;
/**
* The scanner we will use to scan the document. It has to be installed on the same document
* as the one we get.
@@ -79,6 +79,7 @@
boolean danglingElse= false;
boolean matchBrace= false;
+ boolean matchParen= false;
if (position < fDocument.getLength()) {
IRegion line= fDocument.getLineInformationOfOffset(position);
@@ -96,7 +97,7 @@
}
// find the base position
- int unit= findReferencePosition(position, danglingElse, matchBrace);
+ int unit= findReferencePosition(position, danglingElse, matchBrace, matchParen);
// if we were unable to find anything, return null
if (unit == JavaHeuristicScanner.NOT_FOUND)
@@ -133,6 +134,7 @@
boolean danglingElse= false;
boolean unindent= false;
boolean matchBrace= false;
+ boolean matchParen= false;
if (position < fDocument.getLength()) {
IRegion line= fDocument.getLineInformationOfOffset(position);
@@ -158,13 +160,16 @@
break;
case Symbols.TokenWHILE:
break;
+ case Symbols.TokenRPAREN:
+ matchParen= true;
+ break;
}
} else {
danglingElse= true; // assume an else could come - align with 'if'
}
// find the base position
- int unit= findReferencePosition(position, danglingElse, matchBrace);
+ int unit= findReferencePosition(position, danglingElse, matchBrace, matchParen);
// handle special alignment
if (fAlign != JavaHeuristicScanner.NOT_FOUND) {
@@ -247,9 +252,6 @@
start++;
}
- if (fAlignPlusOne)
- spaces++;
-
if (spaces == tabLen)
ret.append('\t');
else
@@ -293,7 +295,7 @@
* @return the reference statement relative to which <code>position</code> should be indented, or {@link JavaHeuristicScanner#NOT_FOUND}
*/
public int findReferencePosition(int position) {
- return findReferencePosition(position, false, false);
+ return findReferencePosition(position, false, false, false);
}
/**
@@ -307,9 +309,10 @@
* @param position the position for which the reference is computed
* @param danglingElse whether a dangling else should be assumed at <code>position</code>
* @param matchBrace whether the position of the matching brace should be returned instead of doing code analysis
+ * @param matchBrace whether the position of the matching parenthesis should be returned instead of doing code analysis
* @return the reference statement relative to which <code>position</code> should be indented, or {@link JavaHeuristicScanner#NOT_FOUND}
*/
- private int findReferencePosition(int position, boolean danglingElse, boolean matchBrace) {
+ private int findReferencePosition(int position, boolean danglingElse, boolean matchBrace, boolean matchParen) {
fIndent= 0; // the indentation modification
fAlign= JavaHeuristicScanner.NOT_FOUND;
fPosition= position;
@@ -317,18 +320,38 @@
boolean indentBlockLess= true; // whether to indent after an if / while / for without block (set false by semicolons and braces)
boolean takeNextExit= true; // whether the next possible exit should be taken (instead of looking for the base; see blockless stuff)
boolean found= false; // whether we have found anything at all. If we have, we'll trace back to it once we have a hoist point
- boolean hasBrace= false;
+ boolean hasBrace= false; // whether we have found a left brace
+ boolean longIndentSet= false; // whehter we have already added a deep indentation (to avoid multiple deep / double indents for multiple calls)
+ int listItemPos= JavaHeuristicScanner.NOT_FOUND; // position of the alignment element in a comma separated list
+ int listItemLine= -1; // line of listItemPos
if (matchBrace) {
if (!skipScope(Symbols.TokenLBRACE, Symbols.TokenRBRACE)) {
fPosition= position;
- fIndent= -1;
+ fIndent= -1; // handle alignment of closing braces
} else {
indentBlockLess= false;
hasBrace= true;
}
}
+ if (matchParen) {
+ if (!skipScope(Symbols.TokenLPAREN, Symbols.TokenRPAREN)) {
+ fPosition= position;
+ fIndent= 0;
+ } else {
+ int pos= fPosition;
+ fPosition= position;
+ nextToken();
+ if (fToken != Symbols.TokenCOMMA)
+ return pos;
+
+ fPosition= position;
+ fIndent= 0;
+ }
+ }
+
+
nextToken();
while (true) {
@@ -401,7 +424,7 @@
break;
case Symbols.TokenQUESTIONMARK: // ternary expressions
- if (takeNextExit && prefTenaryDeepAlign())
+ if (fAlign == JavaHeuristicScanner.NOT_FOUND && takeNextExit && prefTenaryDeepAlign())
fAlign= fPosition;
nextToken();
break;
@@ -418,10 +441,21 @@
if (fToken == Symbols.TokenEQUAL || skipBrackets()) {
int first= fScanner.findNonWhitespaceForwardInAnyPartition(searchPos, position);
// ... with a first element already defined - take its offset
- if (prefArrayDeepIndent() && first != JavaHeuristicScanner.NOT_FOUND) {
+ if (fAlign == JavaHeuristicScanner.NOT_FOUND && listItemLine > fLine) {
+ // there are more list items later on - adjust to current usage
+ int lineOffset;
+ try {
+ lineOffset= fDocument.getLineOffset(listItemLine);
+ fAlign= fScanner.findNonWhitespaceForwardInAnyPartition(lineOffset, listItemPos + 1);
+ } catch (BadLocationException e) {
+ }
+ }
+ if (fAlign == JavaHeuristicScanner.NOT_FOUND && prefArrayDeepIndent() && first != JavaHeuristicScanner.NOT_FOUND) {
fAlign= first;
- } else
+ } else if (!longIndentSet) {
fIndent += prefArrayIndent();
+ longIndentSet= true;
+ }
}
hasBrace= true;
@@ -448,6 +482,14 @@
nextToken();
break;
+ case Symbols.TokenNEW:
+ if (hasBrace && takeNextExit && found) {
+ // we're probably in an array or anonymous class
+ return fScanner.findNonWhitespaceForward(fPreviousPos, position);
+ }
+ nextToken();
+ break;
+
case Symbols.TokenEOF:
if (found)
return fScanner.findNonWhitespaceForward(0, position);
@@ -472,30 +514,51 @@
// handle method definitions separately
case Symbols.TokenLPAREN:
// TODO differentiate between conditional continuation and calls
- if (!hasBrace)
+
+ // handle list items.
+ if (listItemLine > fLine && fAlign == JavaHeuristicScanner.NOT_FOUND) {
+ // there are more list items later on - adjust to current usage
+ int lineOffset;
+ try {
+ lineOffset= fDocument.getLineOffset(listItemLine);
+ fAlign= fScanner.findNonWhitespaceForwardInAnyPartition(lineOffset, listItemPos + 1);
+ } catch (BadLocationException e) {
+ }
+ }
+
+ if (!hasBrace && !longIndentSet) {
fIndent += prefCallContinuationIndent();
+ longIndentSet= true;
+ }
searchPos= fPreviousPos;
- if (prefMethodDeclDeepIndent() && looksLikeMethodDecl() && found) {
+ if (looksLikeMethodDecl() && found && fAlign == JavaHeuristicScanner.NOT_FOUND && prefMethodDeclDeepIndent()) {
fAlign= fScanner.findNonWhitespaceForward(searchPos, position);
}
-
+
break;
// array dimensions
case Symbols.TokenLBRACKET:
- if (prefArrayDimensionsDeepIndent() && found)
+ if (fAlign == JavaHeuristicScanner.NOT_FOUND && prefArrayDimensionsDeepIndent() && found)
fAlign= fScanner.findNonWhitespaceForward(fPreviousPos, position);
- fIndent+= prefArrayDimensionIndent();
+ if (!longIndentSet) {
+ fIndent+= prefArrayDimensionIndent();
+ longIndentSet= true;
+ }
nextToken();
break;
case Symbols.TokenCOMMA:
- if (found)
- fScanner.findNonWhitespaceForward(fPreviousPos, position);
+ // align with comma list except for when in a method declaration
+ if (found && listItemPos == JavaHeuristicScanner.NOT_FOUND) {
+ listItemPos= fScanner.findNonWhitespaceForwardInAnyPartition(fPreviousPos, position);
+ listItemLine= fLine;
+ }
+
nextToken();
break;
@@ -676,6 +739,11 @@
fToken= fScanner.previousToken(start - 1, JavaHeuristicScanner.UNBOUND);
fPreviousPos= start;
fPosition= fScanner.getPosition() + 1;
+ try {
+ fLine= fDocument.getLineOfOffset(fPosition);
+ } catch (BadLocationException e) {
+ fLine= -1;
+ }
}
/**