Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 180194 Details for
Bug 65317
[typing] Auto-indent does not handle continuation properly
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Fix
Patch 65317 (text/plain), 12.30 KB, created by
Rajesh
on 2010-10-04 14:27:06 EDT
(
hide
)
Description:
Fix
Filename:
MIME Type:
Creator:
Rajesh
Created:
2010-10-04 14:27:06 EDT
Size:
12.30 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.text.tests >Index: src/org/eclipse/jdt/text/tests/JavaHeuristicScannerTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaHeuristicScannerTest.java,v >retrieving revision 1.20 >diff -u -r1.20 JavaHeuristicScannerTest.java >--- src/org/eclipse/jdt/text/tests/JavaHeuristicScannerTest.java 31 Dec 2008 21:14:07 -0000 1.20 >+++ src/org/eclipse/jdt/text/tests/JavaHeuristicScannerTest.java 4 Oct 2010 18:22:31 -0000 >@@ -110,15 +110,6 @@ > Assert.assertEquals(21, pos); > } > >- public void testPrevIndentationUnit4() { >- fDocument.set("\tint a;\n" + >- "\tif (true)\n" + >- "\t\treturn a\n" + >- ""); >- >- int pos= fScanner.findReferencePosition(29); >- Assert.assertEquals(28, pos); >- } > > public void testPrevIndentationUnit5() { > fDocument.set("\tint a;\n" + >@@ -325,34 +316,6 @@ > Assert.assertEquals("\t\t", indent); > } > >- public void testIndentation2() { >- fDocument.set("\tint a;\n" + >- "\tif (true)\n" + >- "\t\treturn a"); >- >- String indent= fScanner.computeIndentation(28).toString(); >- Assert.assertEquals("\t\t", indent); >- } >- >- public void testIndentation3() { >- fDocument.set("\tint a;\n" + >- "\tif (true)\n" + >- "\t\treturn a;"); >- >- String indent= fScanner.computeIndentation(29).toString(); >- Assert.assertEquals("\t\t", indent); >- } >- >- public void testIndentation4() { >- fDocument.set("\tint a;\n" + >- "\tif (true)\n" + >- "\t\treturn a\n" + >- ""); >- >- String indent= fScanner.computeIndentation(29).toString(); >- Assert.assertEquals("\t\t", indent); >- } >- > public void testIndentation5() { > fDocument.set("\tint a;\n" + > "\tif (true)\n" + >@@ -873,4 +836,100 @@ > Assert.assertEquals(" ", indent); > > } >+ >+ public void testContinuationIndentationOfForStatement() throws Exception { >+ fDocument.set("\tfor (int i = (2 * 2); i < array.length; i++) {\n" + >+ "\t\t}"); >+ >+ String indent= fScanner.computeIndentation(22).toString(); >+ Assert.assertEquals("\t\t", indent); >+ indent= fScanner.computeIndentation(27).toString(); >+ Assert.assertEquals("\t\t", indent); >+ indent= fScanner.computeIndentation(39).toString(); >+ Assert.assertEquals("\t\t", indent); >+ indent= fScanner.computeIndentation(40).toString(); >+ Assert.assertEquals("\t\t", indent); >+ indent= fScanner.computeIndentation(5).toString(); >+ Assert.assertEquals("\t", indent); >+ indent= fScanner.computeIndentation(45).toString(); >+ Assert.assertEquals("\t", indent); >+ } >+ >+ public void testContinuationIndentationOfBooleanExpression() throws Exception { >+ fDocument.set("\tboolean a = true || false;\n" + >+ "\tboolean b = a || false;\n"); >+ >+ String indent= fScanner.computeIndentation(20).toString(); >+ Assert.assertEquals("\t\t", indent); >+ indent= fScanner.computeIndentation(40).toString(); >+ Assert.assertEquals("\t\t", indent); >+ } >+ >+ public void testContinuationIndentationOfReturnStatement() throws Exception { >+ fDocument.set("\t\treturn \"I'm such a long string that you have to split me to see the whole line without scrolling around\"\n"); >+ >+ String indent= fScanner.computeIndentation(8).toString(); >+ Assert.assertEquals("\t\t\t", indent); >+ indent= fScanner.computeIndentation(21).toString(); >+ Assert.assertEquals("\t\t\t", indent); >+ indent= fScanner.computeIndentation(38).toString(); >+ Assert.assertEquals("\t\t\t", indent); >+ } >+ >+ public void testContinuationIndentationOfAssignmentStatement() throws Exception { >+ fDocument.set("\tint i= 5+"); >+ >+ String indent= fScanner.computeIndentation(7).toString(); >+ Assert.assertEquals("\t\t", indent); >+ indent= fScanner.computeIndentation(10).toString(); >+ Assert.assertEquals("\t\t", indent); >+ } >+ >+ public void testContinuationIndentation1() throws Exception { >+ fDocument.set("\treturn (thisIsAVeryLongName == 1 && anotherVeryLongName == 1)\n" + >+ "\t\t|| thisIsAVeryLongName == 2;"); >+ >+ String indent= fScanner.computeIndentation(68).toString(); >+ Assert.assertEquals("\t\t", indent); >+ indent= fScanner.computeIndentation(88).toString(); >+ Assert.assertEquals("\t\t", indent); >+ } >+ >+ public void testContinuationIndentation2() { >+ fDocument.set("\tint a;\n" + >+ "\tif (true)\n" + >+ "\t\treturn a\n" + >+ ""); >+ >+ int pos= fScanner.findReferencePosition(29); >+ Assert.assertEquals(21, pos); >+ } >+ >+ public void testContinuationIndentation3() { >+ fDocument.set("\tint a;\n" + >+ "\tif (true)\n" + >+ "\t\treturn a"); >+ >+ String indent= fScanner.computeIndentation(28).toString(); >+ Assert.assertEquals("\t\t\t", indent); >+ } >+ >+ public void testContinuationIndentation4() { >+ fDocument.set("\tint a;\n" + >+ "\tif (true)\n" + >+ "\t\treturn a;"); >+ >+ String indent= fScanner.computeIndentation(29).toString(); >+ Assert.assertEquals("\t\t\t", indent); >+ } >+ >+ public void testContinuationIndentation5() { >+ fDocument.set("\tint a;\n" + >+ "\tif (true)\n" + >+ "\t\treturn a\n" + >+ ""); >+ >+ String indent= fScanner.computeIndentation(29).toString(); >+ Assert.assertEquals("\t\t\t", indent); >+ } > } >#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 4 Oct 2010 18:22:38 -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,56 @@ > } > > /** >+ * 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); >+ if (nonWS != Symbols.TokenEOF) { >+ 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 <code>true</code> 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: >+ return true; >+ 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 <code>if</code> >@@ -1235,6 +1293,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 +1307,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 4 Oct 2010 18:22:39 -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
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
daniel_megert
:
review+
Actions:
View
|
Diff
Attachments on
bug 65317
:
11464
|
178439
|
179248
|
179443
|
180194
|
187942