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 184229 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.25 KB, created by
Rajesh
on 2010-12-01 04:38:57 EST
(
hide
)
Description:
patch
Filename:
MIME Type:
Creator:
Rajesh
Created:
2010-12-01 04:38:57 EST
Size:
10.25 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.22 >diff -u -r1.22 JavaHeuristicScannerTest.java >--- src/org/eclipse/jdt/text/tests/JavaHeuristicScannerTest.java 4 Nov 2010 16:35:20 -0000 1.22 >+++ src/org/eclipse/jdt/text/tests/JavaHeuristicScannerTest.java 1 Dec 2010 09:36:00 -0000 >@@ -895,6 +895,41 @@ > Assert.assertEquals("\t\t", indent); > } > >+ public void testContinuationIndentationOfBrackets() throws Exception { >+ fDocument.set("\tprivate void helper2(boolean[] booleans) {\n\t}"); >+ >+ String indent= fScanner.computeIndentation(31).toString(); >+ Assert.assertEquals("\t\t", indent); >+ indent= fScanner.computeIndentation(30).toString(); >+ Assert.assertEquals("\t ", indent); >+ >+ fDocument.set("\tif (booleans[0]) {\n\t\tString[] aString= new String[]{\"a\", \"b\"};\n\t\tbooleans[5]= true;\n\t}"); >+ indent= fScanner.computeIndentation(16).toString(); >+ Assert.assertEquals("\t\t", indent); >+ indent= fScanner.computeIndentation(14).toString(); >+ Assert.assertEquals("\t ", indent); >+ indent= fScanner.computeIndentation(30).toString(); >+ Assert.assertEquals("\t\t\t", indent); >+ indent= fScanner.computeIndentation(52).toString(); >+ Assert.assertEquals("\t\t\t", indent); >+ indent= fScanner.computeIndentation(77).toString(); >+ 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 1 Dec 2010 09:36:04 -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.64 >diff -u -r1.64 JavaIndenter.java >--- ui/org/eclipse/jdt/internal/ui/text/JavaIndenter.java 4 Nov 2010 16:35:20 -0000 1.64 >+++ ui/org/eclipse/jdt/internal/ui/text/JavaIndenter.java 1 Dec 2010 09:36:05 -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 >@@ -771,7 +772,8 @@ > case Symbols.TokenLBRACE: // for opening-brace-on-new-line style > if (bracelessBlockStart && !fPrefs.prefIndentBracesForBlocks) > unindent= true; >- else if ((prevToken == Symbols.TokenCOLON || prevToken == Symbols.TokenEQUAL || prevToken == Symbols.TokenRBRACKET) && !fPrefs.prefIndentBracesForArrays) >+ //Bracket Indentation Fix >+ else if ((prevToken == Symbols.TokenCOLON || prevToken == Symbols.TokenEQUAL) && !fPrefs.prefIndentBracesForArrays) > unindent= true; > else if (!bracelessBlockStart && fPrefs.prefIndentBracesForMethods) > indent= true; >@@ -787,6 +789,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 +814,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 >@@ -961,6 +1009,11 @@ > > case Symbols.TokenTRY: > return skipToStatementStart(danglingElse, false); >+ //Bracket Indentation Fix >+ case Symbols.TokenRBRACKET: >+ fIndent= fPrefs.prefContinuationIndent; >+ return fPosition; >+ > case Symbols.TokenRPAREN: > if (throwsClause) { > fIndent= fPrefs.prefContinuationIndent; >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 1 Dec 2010 09:36:05 -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 1 Dec 2010 09:36:06 -0000 >@@ -714,7 +714,6 @@ > } > return; > } >- removeJavaStuff(temp); > } else { > changed= insertLength != 0; > } >@@ -727,6 +726,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
Flags:
daniel_megert
:
review-
Actions:
View
|
Diff
Attachments on
bug 330556
:
183376
|
183642
|
183875
|
184050
|
184229
|
184390