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 67908 Details for
Bug 185712
Invalid indenting of code template
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix
patch_185712.txt (text/plain), 6.33 KB, created by
Sergey Prigogin
on 2007-05-19 22:39:41 EDT
(
hide
)
Description:
Proposed fix
Filename:
MIME Type:
Creator:
Sergey Prigogin
Created:
2007-05-19 22:39:41 EDT
Size:
6.33 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.cdt.ui >Index: src/org/eclipse/cdt/internal/ui/editor/IndentUtil.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/IndentUtil.java,v >retrieving revision 1.3 >diff -u -r1.3 IndentUtil.java >--- src/org/eclipse/cdt/internal/ui/editor/IndentUtil.java 21 Nov 2006 10:23:22 -0000 1.3 >+++ src/org/eclipse/cdt/internal/ui/editor/IndentUtil.java 20 May 2007 02:30:02 -0000 >@@ -17,6 +17,7 @@ > import org.eclipse.jface.text.ITypedRegion; > import org.eclipse.jface.text.TextUtilities; > import org.eclipse.jface.text.source.ILineRange; >+import org.eclipse.jface.text.source.LineRange; > > import org.eclipse.cdt.core.CCorePlugin; > import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants; >@@ -103,6 +104,22 @@ > } > > /** >+ * Inserts <code>indent</code> string at the beginning of each line in <code>lines</code>. >+ * @param document the document to be changed. >+ * @param lines the line range to be indented. >+ * @param indent the indent string to be inserted. >+ * @throws BadLocationException if <code>lines</code> is not a valid line >+ * range on <code>document</code> >+ */ >+ public static void indentLines(IDocument document, LineRange lines, String indent) throws BadLocationException { >+ int numberOfLines= lines.getNumberOfLines(); >+ for (int line= lines.getStartLine(), last= line + numberOfLines; line < last; line++) { >+ int offset= document.getLineOffset(line); >+ document.replace(offset, 0, indent); >+ } >+ } >+ >+ /** > * Returns <code>true</code> if line comments at column 0 should be indented inside, <code>false</code> otherwise. > * > * @param project the project to get project specific options from >@@ -580,5 +597,4 @@ > computed= new StringBuffer(previousIndent); > return computed.toString(); > } >- > } >Index: src/org/eclipse/cdt/internal/corext/template/c/CFormatter.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/template/c/CFormatter.java,v >retrieving revision 1.9 >diff -u -r1.9 CFormatter.java >--- src/org/eclipse/cdt/internal/corext/template/c/CFormatter.java 2 Feb 2007 14:38:29 -0000 1.9 >+++ src/org/eclipse/cdt/internal/corext/template/c/CFormatter.java 20 May 2007 02:30:02 -0000 >@@ -14,6 +14,7 @@ > package org.eclipse.cdt.internal.corext.template.c; > > import java.util.ArrayList; >+import java.util.Arrays; > import java.util.HashMap; > import java.util.Iterator; > import java.util.List; >@@ -41,6 +42,7 @@ > > import org.eclipse.cdt.core.CCorePlugin; > import org.eclipse.cdt.core.formatter.CodeFormatter; >+import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants; > import org.eclipse.cdt.core.model.ICProject; > import org.eclipse.cdt.ui.text.ICPartitions; > >@@ -95,6 +97,7 @@ > > internalFormat(document, context); > convertLineDelimiters(document); >+ convertTabs(document); > if (isReplacedAreaEmpty(context)) > trimStart(document); > >@@ -134,6 +137,50 @@ > } > } > >+ /** >+ * Converts tabs into spaces if such conversion is required according >+ * to the current code style. >+ * >+ * @param document the document to process. >+ * @throws BadLocationException >+ */ >+ private void convertTabs(IDocument document) throws BadLocationException { >+ int lines= document.getNumberOfLines(); >+ if (lines == 0) >+ return; >+ >+ String option; >+ if (fProject == null) >+ option= CCorePlugin.getOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR); >+ else >+ option= fProject.getOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, true); >+ >+ if (!CCorePlugin.SPACE.equals(option)) >+ return; >+ >+ int tabWidth= CodeFormatterUtil.getTabWidth(fProject); >+ char[] spaces= null; >+ for (int line= 0; line < lines; line++) { >+ IRegion region= document.getLineInformation(line); >+ int offset= region.getOffset(); >+ int length = region.getLength(); >+ for (int i= 0; i < length; i++) { >+ char c= document.getChar(offset + i); >+ if (c == '\t') { >+ int numSpaces= tabWidth - i % tabWidth; >+ if (spaces == null) { >+ spaces= new char[tabWidth]; >+ Arrays.fill(spaces, ' '); >+ } >+ document.replace(offset + i, 1, String.valueOf(spaces, 0, numSpaces)); >+ numSpaces--; >+ i += numSpaces; >+ length += numSpaces; >+ } >+ } >+ } >+ } >+ > private void trimStart(IDocument document) throws BadLocationException { > int i= 0; > while ((i != document.getLength()) && Character.isWhitespace(document.getChar(i))) >@@ -175,13 +222,9 @@ > } > > private void indent(IDocument document) throws BadLocationException, MalformedTreeException { >- // first line >- int offset= document.getLineOffset(0); >- document.replace(offset, 0, CodeFormatterUtil.createIndentString(fInitialIndentLevel, fProject)); >- >- // following lines >+ String indent = CodeFormatterUtil.createIndentString(fInitialIndentLevel, fProject); > int lineCount= document.getNumberOfLines(); >- IndentUtil.indentLines(document, new LineRange(1, lineCount - 1), fProject, null); >+ IndentUtil.indentLines(document, new LineRange(0, lineCount), indent); > } > > /** >Index: src/org/eclipse/cdt/internal/corext/template/c/CContext.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/template/c/CContext.java,v >retrieving revision 1.9 >diff -u -r1.9 CContext.java >--- src/org/eclipse/cdt/internal/corext/template/c/CContext.java 2 Feb 2007 14:38:29 -0000 1.9 >+++ src/org/eclipse/cdt/internal/corext/template/c/CContext.java 20 May 2007 02:30:02 -0000 >@@ -126,7 +126,8 @@ > boolean useCodeFormatter= prefs.getBoolean(PreferenceConstants.TEMPLATES_USE_CODEFORMATTER); > > ICProject project= getCProject(); >- CFormatter formatter= new CFormatter(TextUtilities.getDefaultLineDelimiter(getDocument()), getIndentationLevel(), useCodeFormatter, project); >+ int indentationLevel = isReadOnly() ? 0 : getIndentationLevel(); >+ CFormatter formatter= new CFormatter(TextUtilities.getDefaultLineDelimiter(getDocument()), indentationLevel, useCodeFormatter, project); > formatter.format(buffer, this); > > return buffer;
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:
bjorn.freeman-benson
:
iplog+
Actions:
View
|
Diff
Attachments on
bug 185712
: 67908