### Eclipse Workspace Patch 1.0
#P org.eclipse.jdt.ui
Index: ui/org/eclipse/jdt/internal/ui/text/JavaIndenter.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/JavaIndenter.java,v
retrieving revision 1.62
diff -u -r1.62 JavaIndenter.java
--- ui/org/eclipse/jdt/internal/ui/text/JavaIndenter.java 18 Feb 2009 17:15:41 -0000 1.62
+++ ui/org/eclipse/jdt/internal/ui/text/JavaIndenter.java 23 Sep 2010 10:21:34 -0000
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -887,13 +887,19 @@
int pos= fPosition;
if (!skipScope())
fPosition= pos;
- //$FALL-THROUGH$
+ return skipToStatementStart(danglingElse, false);
case Symbols.TokenSEMICOLON:
// this is the 90% case: after a statement block
// the end of the previous statement / block previous.end
// search to the end of the statement / block before the previous; the token just after that is previous.start
- return skipToStatementStart(danglingElse, false);
-
+ pos= fPosition;
+ if (isForStatement()) {
+ fIndent= fPrefs.prefContinuationIndent;
+ return fPosition;
+ } else {
+ fPosition= pos;
+ return skipToStatementStart(danglingElse, false);
+ }
// scope introduction: special treat who special is
case Symbols.TokenLPAREN:
case Symbols.TokenLBRACE:
@@ -906,8 +912,7 @@
case Symbols.TokenEQUAL:
// indent assignments
- fIndent= fPrefs.prefAssignmentIndent;
- return fPosition;
+ return handleEqual();
case Symbols.TokenCOLON:
// TODO handle ternary deep indentation
@@ -958,6 +963,9 @@
fLine= line;
return skipToPreviousListItemOrListStart();
+ case Symbols.TokenRETURN:
+ fIndent= fPrefs.prefContinuationIndent;
+ return fPosition;
case Symbols.TokenCOMMA:
// inside a list of some type
// easy if there is already a list item before with its own indentation - we just align
@@ -972,6 +980,57 @@
}
/**
+ * Checks if the statement at position is itself a continuation of the previous, else sets the
+ * indentation to Continuation Indent.
+ *
+ * @return the position of the token
+ * @since 3.7
+ */
+ private int handleEqual() {
+ try {
+ //If this line is itself continuation of the previous then do nothing
+ IRegion line= fDocument.getLineInformationOfOffset(fPosition);
+ int nonWS= fScanner.findNonWhitespaceBackward(line.getOffset(), JavaHeuristicScanner.UNBOUND);
+ int tokenAtPreviousLine= fScanner.nextToken(nonWS, nonWS + 1);
+ if (tokenAtPreviousLine != Symbols.TokenSEMICOLON && tokenAtPreviousLine != Symbols.TokenRBRACE && tokenAtPreviousLine != Symbols.TokenLBRACE && tokenAtPreviousLine != Symbols.TokenEOF)
+ return fPosition;
+ } catch (BadLocationException e) {
+ return fPosition;
+ }
+
+ fIndent= fPrefs.prefContinuationIndent;
+ return fPosition;
+ }
+
+ /**
+ * Checks if the semicolon at the current position is part of a for statement.
+ *
+ * @return returns true
if current position is part of for statement
+ * @since 3.7
+ */
+ private boolean isForStatement() {
+ int semiColonCount= 1;
+ while (true) {
+ nextToken();
+ switch (fToken) {
+ case Symbols.TokenFOR:
+ //case Symbols.TokenLPAREN:
+ return true;
+ case Symbols.TokenRPAREN:
+ skipScope();
+ break;
+ case Symbols.TokenSEMICOLON:
+ semiColonCount++;
+ if (semiColonCount > 2)
+ return false;
+ break;
+ case Symbols.TokenEOF:
+ return false;
+ }
+ }
+ }
+
+ /**
* Skips to the start of a statement that ends at the current position.
*
* @param danglingElse whether to indent aligned with the last if
@@ -1235,6 +1294,11 @@
return handleScopeIntroduction(startPosition + 1);
case Symbols.TokenSEMICOLON:
+ int savedPosition= fPosition;
+ if (isForStatement())
+ fIndent= fPrefs.prefContinuationIndent;
+ else
+ fPosition= savedPosition;
return fPosition;
case Symbols.TokenQUESTIONMARK:
if (fPrefs.prefTernaryDeepAlign) {
@@ -1244,6 +1308,11 @@
fIndent= fPrefs.prefTernaryIndent;
return fPosition;
}
+ case Symbols.TokenRETURN:
+ fIndent= fPrefs.prefContinuationIndent;
+ return fPosition;
+ case Symbols.TokenEQUAL:
+ return handleEqual();
case Symbols.TokenEOF:
return 0;
Index: ui/org/eclipse/jdt/internal/ui/text/java/JavaAutoIndentStrategy.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaAutoIndentStrategy.java,v
retrieving revision 1.122
diff -u -r1.122 JavaAutoIndentStrategy.java
--- ui/org/eclipse/jdt/internal/ui/text/java/JavaAutoIndentStrategy.java 3 Sep 2010 09:23:02 -0000 1.122
+++ ui/org/eclipse/jdt/internal/ui/text/java/JavaAutoIndentStrategy.java 23 Sep 2010 10:21:35 -0000
@@ -693,32 +693,30 @@
if (lineLength == 0) // don't modify empty lines
continue;
- if (!isIndentDetected) {
- // indent the first pasted line
- String current= getCurrentIndent(temp, l);
- StringBuffer correct= indenter.computeIndentation(lineOffset);
- if (correct == null)
- return; // bail out
-
- insertLength= subtractIndent(correct, current, addition, tabLength);
- if (l != first && temp.get(lineOffset, lineLength).trim().length() != 0) {
- isIndentDetected= true;
- if (insertLength == 0) {
- // no adjustment needed, bail out
- if (firstLine == 0) {
- // but we still need to adjust the first line
- command.offset= newOffset;
- command.length= newLength;
- if (changed)
- break; // still need to get the leading indent of the first line
- }
- return;
+ // indent the first pasted line
+ String current= getCurrentIndent(temp, l); //$NON-NLS-1$
+ StringBuffer correct= indenter.computeIndentation(lineOffset);
+ if (correct == null)
+ return; // bail out
+
+ insertLength= subtractIndent(correct, current, addition, tabLength);
+ if (!isIndentDetected && l != first && temp.get(lineOffset, lineLength).trim().length() != 0) {
+ isIndentDetected= true;
+ if (insertLength == 0) {
+ // no adjustment needed, bail out
+ if (firstLine == 0) {
+ // but we still need to adjust the first line
+ command.offset= newOffset;
+ command.length= newLength;
+ if (changed)
+ break; // still need to get the leading indent of the first line
}
- removeJavaStuff(temp);
- } else {
- changed= insertLength != 0;
+ return;
}
+ removeJavaStuff(temp);
+ } else {
+ changed= insertLength != 0;
}
// relatively indent all pasted lines