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 184390 Details for
Bug 330556
[typing] Indentation is messed up on paste
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
patch
330556 (text/plain), 10.45 KB, created by
Rajesh
on 2010-12-02 14:49:20 EST
(
hide
)
Description:
patch
Filename:
MIME Type:
Creator:
Rajesh
Created:
2010-12-02 14:49:20 EST
Size:
10.45 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.23 >diff -u -r1.23 JavaHeuristicScannerTest.java >--- src/org/eclipse/jdt/text/tests/JavaHeuristicScannerTest.java 1 Dec 2010 15:44:37 -0000 1.23 >+++ src/org/eclipse/jdt/text/tests/JavaHeuristicScannerTest.java 2 Dec 2010 19:43:29 -0000 >@@ -916,6 +916,21 @@ > Assert.assertEquals("\t\t\t", indent); > } > >+ public void testContinuationIndentationOfStrings() throws Exception { >+ fDocument.set("\tString[] i = new String[] {\n\t\t\"X.java\",\n\t\t\"public class X extends B{\"\n\t\t+ \"test\"\n\t\t+ \" public \"};"); >+ >+ String indent= fScanner.computeIndentation(73).toString(); >+ Assert.assertEquals("\t\t\t", indent); >+ indent= fScanner.computeIndentation(84).toString(); >+ Assert.assertEquals("\t\t\t", indent); >+ >+ fDocument.set("\tString[] i = new String[] {\n\t\t\"X.java\",\n\t\t\"public class X extends B{\" +\n\t\t\"test\" +\n\t\t\" public\"\n};"); >+ >+ indent= fScanner.computeIndentation(75).toString(); >+ Assert.assertEquals("\t\t\t", indent); >+ } >+ >+ > public void testContinuationIndentation1() throws Exception { > fDocument.set("\treturn (thisIsAVeryLongName == 1 && anotherVeryLongName == 1)\n" + > "\t\t|| thisIsAVeryLongName == 2;"); >#P org.eclipse.jdt.ui >Index: ui/org/eclipse/jdt/internal/ui/text/JavaHeuristicScanner.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/JavaHeuristicScanner.java,v >retrieving revision 1.28 >diff -u -r1.28 JavaHeuristicScanner.java >--- ui/org/eclipse/jdt/internal/ui/text/JavaHeuristicScanner.java 4 Nov 2010 16:35:20 -0000 1.28 >+++ ui/org/eclipse/jdt/internal/ui/text/JavaHeuristicScanner.java 2 Dec 2010 19:43:35 -0000 >@@ -61,6 +61,8 @@ > private static final char LANGLE= '<'; > private static final char RANGLE= '>'; > >+ private static final char PLUS= '+'; >+ > /** > * Specifies the stop condition, upon which the <code>scanXXX</code> methods will decide whether > * to keep scanning or not. This interface may implemented by clients. >@@ -334,6 +336,8 @@ > return TokenLESSTHAN; > case RANGLE: > return TokenGREATERTHAN; >+ case PLUS: >+ return TokenPLUS; > } > > // else >@@ -406,6 +410,8 @@ > return TokenLESSTHAN; > case RANGLE: > return TokenGREATERTHAN; >+ case PLUS: >+ return TokenPLUS; > } > > // else >@@ -675,6 +681,24 @@ > } > > /** >+ * Finds the highest position in <code>fDocument</code> such that the position is <= >+ * <code>position</code> and > <code>bound</code> and >+ * <code>Character.isWhitespace(fDocument.getChar(pos))</code> evaluates to <code>false</code> >+ * and the position can be in any partition. >+ * >+ * @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>NOT_FOUND</code> if >+ * none can be found >+ * @since 3.7 >+ */ >+ public int findNonWhitespaceBackwardInAnyPartition(int position, int bound) { >+ return scanBackward(position, bound, fNonWS); >+ } >+ >+ /** > * Finds the lowest position <code>p</code> in <code>fDocument</code> such that <code>start</code> <= p < > * <code>bound</code> and <code>condition.stop(fDocument.getChar(p), p)</code> evaluates to <code>true</code>. > * >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.65 >diff -u -r1.65 JavaIndenter.java >--- ui/org/eclipse/jdt/internal/ui/text/JavaIndenter.java 1 Dec 2010 15:44:37 -0000 1.65 >+++ ui/org/eclipse/jdt/internal/ui/text/JavaIndenter.java 2 Dec 2010 19:43:36 -0000 >@@ -22,6 +22,7 @@ > > import org.eclipse.jdt.internal.corext.util.CodeFormatterUtil; > >+import org.eclipse.jdt.internal.ui.JavaPlugin; > > /** > * Uses the {@link org.eclipse.jdt.internal.ui.text.JavaHeuristicScanner} to >@@ -787,6 +788,14 @@ > case Symbols.TokenTHROWS: > throwsClause= true; > break; >+ case Symbols.TokenPLUS: >+ int position= handleStringContinuation(offset); >+ if (position != JavaHeuristicScanner.NOT_FOUND) { >+ fAlign= JavaHeuristicScanner.NOT_FOUND; >+ fIndent= fPrefs.prefContinuationIndent; >+ return position; >+ } >+ break; > } > } catch (BadLocationException e) { > } >@@ -804,6 +813,44 @@ > } > > /** >+ * Specifically handles the case of extra indentation for second line of string continuation. >+ * >+ * @param offset the offset for which the reference is computed >+ * @return the reference statement relative to which <code>offset</code> should be indented, or >+ * {@link JavaHeuristicScanner#NOT_FOUND} >+ * @since 3.7 >+ */ >+ private int handleStringContinuation(int offset) { >+ int prevNonWSCharPosition= fScanner.findNonWhitespaceBackwardInAnyPartition(offset - 1, JavaHeuristicScanner.UNBOUND); >+ if (prevNonWSCharPosition != JavaHeuristicScanner.NOT_FOUND) { >+ try { >+ char c= fDocument.getChar(prevNonWSCharPosition); >+ if (c == '"' || c == '+') { >+ int initialLine= fDocument.getLineOfOffset(offset); >+ nextToken(offset); >+ while (fToken == Symbols.TokenPLUS) { >+ if ((initialLine - fLine) > 1) >+ return JavaHeuristicScanner.NOT_FOUND; >+ nextToken(); >+ } >+ int lineDiff= initialLine - fLine; >+ if (lineDiff > 0) { >+ int bound= fDocument.getLineOffset(fLine) + fDocument.getLineLength(fLine) - 1; >+ int nextNonWSCharPosition= fScanner.findNonWhitespaceForwardInAnyPartition(fPosition + 1, bound); >+ if (lineDiff < 3 && fPreviousPos != offset && nextNonWSCharPosition != JavaHeuristicScanner.NOT_FOUND && fDocument.getChar(nextNonWSCharPosition) != '"') >+ return fPreviousPos; >+ else >+ return fPosition; >+ } >+ } >+ } catch (BadLocationException e) { >+ JavaPlugin.log(e); >+ } >+ } >+ return JavaHeuristicScanner.NOT_FOUND; >+ } >+ >+ /** > * Returns the reference position regarding to indentation for <code>position</code>, or > * <code>NOT_FOUND</code>.<code>fIndent</code> will contain the relative indentation (in > * indentation units, not characters) after the call. If there is a special alignment (e.g. for >Index: ui/org/eclipse/jdt/internal/ui/text/Symbols.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/Symbols.java,v >retrieving revision 1.11 >diff -u -r1.11 Symbols.java >--- ui/org/eclipse/jdt/internal/ui/text/Symbols.java 4 Nov 2010 16:35:20 -0000 1.11 >+++ ui/org/eclipse/jdt/internal/ui/text/Symbols.java 2 Dec 2010 19:43:36 -0000 >@@ -32,6 +32,7 @@ > int TokenEQUAL= 12; > int TokenLESSTHAN= 13; > int TokenGREATERTHAN= 14; >+ int TokenPLUS= 15; > int TokenIF= 109; > int TokenDO= 1010; > int TokenFOR= 1011; >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.123 >diff -u -r1.123 JavaAutoIndentStrategy.java >--- ui/org/eclipse/jdt/internal/ui/text/java/JavaAutoIndentStrategy.java 6 Oct 2010 09:54:40 -0000 1.123 >+++ ui/org/eclipse/jdt/internal/ui/text/java/JavaAutoIndentStrategy.java 2 Dec 2010 19:43:37 -0000 >@@ -686,37 +686,38 @@ > boolean changed= false; > for (int l= first; l < lines; l++) { // we don't change the number of lines while adding indents > >- IRegion r= temp.getLineInformation(l); >- int lineOffset= r.getOffset(); >- int lineLength= r.getLength(); >- >- if (lineLength == 0) // don't modify empty lines >- continue; >- >- >- // 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 >+ if (!isIndentDetected) { >+ IRegion r= temp.getLineInformation(l); >+ int lineOffset= r.getOffset(); >+ int lineLength= r.getLength(); >+ >+ if (lineLength == 0) // don't modify empty lines >+ continue; >+ >+ >+ // 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; > } >- return; >+ } else { >+ changed= insertLength != 0; > } >- removeJavaStuff(temp); >- } else { >- changed= insertLength != 0; > } > > // relatively indent all pasted lines >@@ -727,6 +728,7 @@ > > } > >+ removeJavaStuff(temp); > temp.stopRewriteSession(session); > newText= temp.get(prefix.length(), temp.getLength() - prefix.length()); >
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 330556
:
183376
|
183642
|
183875
|
184050
|
184229
| 184390