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 179248 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), 7.54 KB, created by
Rajesh
on 2010-09-20 10:16:10 EDT
(
hide
)
Description:
Fix
Filename:
MIME Type:
Creator:
Rajesh
Created:
2010-09-20 10:16:10 EDT
Size:
7.54 KB
patch
obsolete
>### 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 20 Sep 2010 14:07:32 -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 handleAssignmentAndComparison(); > > 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,66 @@ > } > > /** >+ * Checks if the statement is a continuation and the token at the current position is an assignment or a comparison and sets the >+ * indentation accordingly. >+ * >+ * @return the position of the token >+ * @since 3.7 >+ */ >+ private int handleAssignmentAndComparison() { >+ int tokenAtPreviousChar; >+ >+ try { >+ //If this line is itself continuation of the previous then do nothing >+ IRegion line; >+ line= fDocument.getLineInformationOfOffset(fPosition); >+ int nonWS= fScanner.findNonWhitespaceBackward(line.getOffset(), JavaHeuristicScanner.UNBOUND); >+ tokenAtPreviousChar= fScanner.nextToken(nonWS, nonWS + 1); >+ if (tokenAtPreviousChar != Symbols.TokenSEMICOLON && tokenAtPreviousChar != Symbols.TokenRBRACE && tokenAtPreviousChar != Symbols.TokenEOF) >+ return fPosition; >+ } catch (BadLocationException e) { >+ return fPosition; >+ } >+ >+ tokenAtPreviousChar= fScanner.nextToken(fPosition - 1, fPosition); >+ if (tokenAtPreviousChar == Symbols.TokenEQUAL || fToken == Symbols.TokenGREATERTHAN || fToken == Symbols.TokenLESSTHAN) { >+ fIndent= fPrefs.prefContinuationIndent; >+ fPosition--; >+ } else { >+ fIndent= fPrefs.prefAssignmentIndent; >+ } >+ 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: >+ //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 <code>if</code> >@@ -1235,6 +1303,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 +1317,11 @@ > fIndent= fPrefs.prefTernaryIndent; > return fPosition; > } >+ case Symbols.TokenRETURN: >+ fIndent= fPrefs.prefContinuationIndent; >+ return fPosition; >+ case Symbols.TokenEQUAL: >+ return handleAssignmentAndComparison(); > 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 20 Sep 2010 14:07:33 -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); >+ 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
Actions:
View
|
Diff
Attachments on
bug 65317
:
11464
|
178439
|
179248
|
179443
|
180194
|
187942