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 17059 Details for
Bug 73104
[format] indentation amount tied to tab size
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
jdt-core_mixed-indents.diff
jdt-core_mixed-indents.diff (text/plain), 15.73 KB, created by
Tom Hofmann
on 2005-01-10 16:23:49 EST
(
hide
)
Description:
jdt-core_mixed-indents.diff
Filename:
MIME Type:
Creator:
Tom Hofmann
Created:
2005-01-10 16:23:49 EST
Size:
15.73 KB
patch
obsolete
>Index: formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java,v >retrieving revision 1.49 >diff -u -r1.49 DefaultCodeFormatterConstants.java >--- formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 6 Oct 2004 17:40:09 -0000 1.49 >+++ formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 10 Jan 2005 21:20:47 -0000 >@@ -2868,14 +2868,37 @@ > public static final String FORMATTER_TAB_CHAR = JavaCore.PLUGIN_ID + ".formatter.tabulation.char"; //$NON-NLS-1$ > /** > * <pre> >+ * FORMATTER / Option to specify the indentation size >+ * - option id: "org.eclipse.jdt.core.formatter.tabulation.size" >+ * - possible values: "<n>", where n is zero or a positive integer >+ * - default: "4" >+ * </pre> >+ * @since 3.1 >+ */ >+ public static final String FORMATTER_INDENTATION_SIZE = JavaCore.PLUGIN_ID + ".formatter.tabulation.size"; //$NON-NLS-1$ >+ >+ /** >+ * <pre> > * FORMATTER / Option to specify the tabulation size > * - option id: "org.eclipse.jdt.core.formatter.tabulation.size" > * - possible values: "<n>", where n is zero or a positive integer > * - default: "4" > * </pre> > * @since 3.0 >+ * @deprecated as of 3.1 use DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE >+ */ >+ public static final String FORMATTER_TAB_SIZE = FORMATTER_INDENTATION_SIZE; >+ >+ /** >+ * <pre> >+ * FORMATTER / Option to specify the equivalent number of spaces that represents one tab >+ * - option id: "org.eclipse.jdt.core.formatter.indentation.size" >+ * - possible values: "<n>", where n is zero or a positive integer >+ * - default: "4" >+ * </pre> >+ * @since 3.1 > */ >- public static final String FORMATTER_TAB_SIZE = JavaCore.PLUGIN_ID + ".formatter.tabulation.size"; //$NON-NLS-1$ >+ public static final String FORMATTER_TAB_LENGTH = JavaCore.PLUGIN_ID + ".formatter.tab.length"; //$NON-NLS-1$ > > /** > * Returns the formatter settings that most closely approximate >Index: formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java,v >retrieving revision 1.52 >diff -u -r1.52 DefaultCodeFormatterOptions.java >--- formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 5 Jan 2005 16:11:52 -0000 1.52 >+++ formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 10 Jan 2005 21:20:50 -0000 >@@ -266,6 +266,7 @@ > public int number_of_empty_lines_to_preserve; > public boolean put_empty_statement_on_new_line; > public int tab_size; >+ public int indentation_size; > public final char filling_space = ' '; > public int page_width; > public boolean use_tab; >@@ -515,7 +516,8 @@ > options.put(DefaultCodeFormatterConstants.FORMATTER_PUT_EMPTY_STATEMENT_ON_NEW_LINE, this.put_empty_statement_on_new_line ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); > options.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, Integer.toString(this.page_width)); > options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, this.use_tab ? JavaCore.TAB: JavaCore.SPACE); >- options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, Integer.toString(this.tab_size)); >+ options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_LENGTH, Integer.toString(this.tab_size)); >+ options.put(DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE, Integer.toString(this.indentation_size)); > return options; > } > >@@ -1652,14 +1654,27 @@ > if (putEmptyStatementOnNewLineOption != null) { > this.put_empty_statement_on_new_line = DefaultCodeFormatterConstants.TRUE.equals(putEmptyStatementOnNewLineOption); > } >- final Object tabSizeOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE); >+ final Object tabSizeOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_TAB_LENGTH); > if (tabSizeOption != null) { > try { > this.tab_size = Integer.parseInt((String) tabSizeOption); > } catch (NumberFormatException e) { >- this.tab_size = 4; >+ this.tab_size = this.indentation_size; > } catch(ClassCastException e) { >- this.tab_size = 4; >+ this.tab_size = this.indentation_size; >+ } >+ } else { >+ // compatibility code >+ this.tab_size = this.indentation_size; >+ } >+ final Object indentationSizeOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE); >+ if (indentationSizeOption != null) { >+ try { >+ this.indentation_size = Integer.parseInt((String) indentationSizeOption); >+ } catch (NumberFormatException e) { >+ this.indentation_size = this.tab_size; >+ } catch(ClassCastException e) { >+ this.indentation_size = this.tab_size; > } > } > final Object pageWidthOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT); >@@ -1903,6 +1918,7 @@ > this.number_of_empty_lines_to_preserve = 1; > this.put_empty_statement_on_new_line = false; > this.tab_size = 4; >+ this.indentation_size = 4; > this.page_width = 80; > this.use_tab = true; // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=49081 > } >@@ -2131,7 +2147,9 @@ > this.keep_then_statement_on_same_line = false; > this.number_of_empty_lines_to_preserve = 1; > this.put_empty_statement_on_new_line = true; >+// this.tab_size = 8; > this.tab_size = 4; >+ this.indentation_size = 4; > this.page_width = 80; > this.use_tab = false; > } >Index: formatter/org/eclipse/jdt/internal/formatter/Scribe.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/Scribe.java,v >retrieving revision 1.76 >diff -u -r1.76 Scribe.java >--- formatter/org/eclipse/jdt/internal/formatter/Scribe.java 21 Sep 2004 17:39:24 -0000 1.76 >+++ formatter/org/eclipse/jdt/internal/formatter/Scribe.java 10 Jan 2005 21:20:51 -0000 >@@ -39,6 +39,7 @@ > private static final int INITIAL_SIZE = 100; > > private boolean checkLineWrapping; >+ /** one-based column */ > public int column; > private int[][] commentPositions; > >@@ -69,9 +70,11 @@ > public Scanner scanner; > public int scannerEndPosition; > public int tabSize; >+ public int indentationSize; > private int textRegionEnd; > private int textRegionStart; > public boolean useTab; >+ private boolean snapToTabs; > > Scribe(CodeFormatterVisitor formatter, Map settings, int offset, int length, CodeSnippetParsingUtil codeSnippetParsingUtil) { > if (settings != null) { >@@ -89,7 +92,11 @@ > this.formatter = formatter; > this.pageWidth = formatter.preferences.page_width; > this.tabSize = formatter.preferences.tab_size; >+ this.indentationLevel= 0; // initialize properly >+ this.indentationSize = formatter.preferences.indentation_size; > this.useTab = formatter.preferences.use_tab; >+ this.snapToTabs= this.useTab && this.tabSize == this.indentationSize; >+// this.snapToTabs= false; > this.fillingSpace = formatter.preferences.filling_space; > setLineSeparatorAndIdentationLevel(formatter.preferences); > this.textRegionStart = offset; >@@ -234,7 +241,7 @@ > current = current.enclosing; > } > if ((current.mode & Alignment.M_MULTICOLUMN) != 0) { >- final int indentSize = this.useTab ? 1 : this.tabSize; >+ final int indentSize = this.indentationSize; > switch(current.chunkKind) { > case Alignment.CHUNK_METHOD : > case Alignment.CHUNK_TYPE : >@@ -261,7 +268,7 @@ > case Alignment.M_NEXT_PER_LINE_SPLIT : > case Alignment.M_NEXT_SHIFTED_SPLIT : > case Alignment.M_ONE_PER_LINE_SPLIT : >- final int indentSize = this.useTab ? 1 : this.tabSize; >+ final int indentSize = this.indentationSize; > switch(current.chunkKind) { > case Alignment.CHUNK_METHOD : > case Alignment.CHUNK_TYPE : >@@ -348,11 +355,7 @@ > * @return int > */ > public int getColumnIndentationLevel() { >- if (this.useTab) { >- return (this.column - 1)/ this.tabSize; >- } else { >- return this.column - 1; >- } >+ return this.column - 1; > } > > public final int getCommentIndex(int position) { >@@ -419,18 +422,6 @@ > } > return String.valueOf(buffer); > } >- /** >- * Answer indentation level based on column estimated position >- * (if column is not indented, then use indentationLevel) >- */ >- public int getIndentationLevel(int someColumn) { >- if (someColumn == 1) return this.indentationLevel; >- if (this.useTab) { >- return (someColumn - 1) / this.tabSize; >- } else { >- return someColumn - 1; >- } >- } > > public OptimizedReplaceEdit getLastEdit() { > if (this.editsIndex > 0) { >@@ -473,12 +464,14 @@ > * (if column is not indented, then use indentationLevel) > */ > public int getNextIndentationLevel(int someColumn) { >- if (someColumn == 1) return this.indentationLevel; >- if (this.useTab) { >- int rem = (someColumn - 1)% this.tabSize; // round to superior >- return rem == 0 ? (someColumn - 1)/ this.tabSize : ((someColumn - 1)/ this.tabSize)+1; >+ int indent= someColumn - 1; >+ if (indent == 0) return this.indentationLevel; >+ if (snapToTabs) { >+ int rem= indent % this.tabSize; >+ int addition= rem == 0 ? 0 : this.tabSize - rem; // round to superior >+ return indent + addition; > } else { >- return someColumn - 1; >+ return indent; > } > } > >@@ -572,11 +565,7 @@ > } > > public void indent() { >- if (this.useTab) { >- this.indentationLevel++; >- } else { >- this.indentationLevel += tabSize; >- } >+ this.indentationLevel += indentationSize; > } > > private int indexOf(char[] toBeFound, char[] source, int start, int end) { >@@ -1077,36 +1066,30 @@ > } > > private void printIndentationIfNecessary() { >- int indentationColumn = (this.useTab ? this.indentationLevel * this.tabSize : this.indentationLevel)+1; >- if (this.column < indentationColumn) { >- StringBuffer buffer = new StringBuffer(); >- for (int i = getColumnIndentationLevel(), max = this.indentationLevel; i < max; i++) { >- if (this.useTab) { >- this.tab(buffer); >- } else { >- this.column++; >- buffer.append(this.fillingSpace); >- this.needSpace = false; >- } >- } >+ StringBuffer buffer = new StringBuffer(); >+ printIndentationIfNecessary(buffer); >+ if (buffer.length() > 0) { > addInsertEdit(this.scanner.getCurrentTokenStartPosition(), buffer.toString()); > this.pendingSpace = false; > } > } > >- > private void printIndentationIfNecessary(StringBuffer buffer) { >- int indentationColumn = (this.useTab ? this.indentationLevel * this.tabSize : this.indentationLevel)+1; >- if (this.column < indentationColumn) { >- for (int i = getColumnIndentationLevel(), max = this.indentationLevel; i < max; i++) { >- if (this.useTab) { >- this.tab(buffer); >- } else { >- this.column++; >- buffer.append(this.fillingSpace); >- this.needSpace = false; >- } >+ // where do we want to go (will round up to the next tab stop if snapToTabs == true) >+ int wantedIndentation= getNextIndentationLevel(this.indentationLevel + 1); >+ while (this.column - 1 < this.indentationLevel) { >+ // where would we get by appending a tab? >+ int nextTabIndentation= this.column - 1 + (this.tabSize - ((this.column - 1) % this.tabSize)); >+ if (this.useTab && nextTabIndentation <= wantedIndentation) { >+ buffer.append('\t'); >+ this.lastNumberOfNewLines = 0; >+ int complement = this.tabSize - ((this.column - 1) % this.tabSize); // amount of space >+ this.column += complement; >+ } else { >+ buffer.append(this.fillingSpace); >+ this.column++; > } >+ this.needSpace = false; > } > } > >@@ -1447,11 +1430,7 @@ > > public void setLineSeparatorAndIdentationLevel(DefaultCodeFormatterOptions preferences) { > this.lineSeparator = preferences.line_separator; >- if (this.useTab) { >- this.indentationLevel = preferences.initial_indentation_level; >- } else { >- this.indentationLevel = preferences.initial_indentation_level * this.tabSize; >- } >+ this.indentationLevel = preferences.initial_indentation_level * this.indentationSize; > } > > public void space() { >@@ -1462,24 +1441,10 @@ > this.needSpace = false; > } > >- private void tab(StringBuffer buffer) { >- this.lastNumberOfNewLines = 0; >- int complement = this.tabSize - ((this.column - 1)% this.tabSize); // amount of space >- if (this.useTab) { >- buffer.append('\t'); >- } else { >- for (int i = 0; i < complement; i++) { >- buffer.append(this.fillingSpace); >- } >- } >- this.column += complement; >- this.needSpace = false; >- } >- > public String toString() { > StringBuffer stringBuffer = new StringBuffer(); > stringBuffer >- .append("(page witdh = " + this.pageWidth + ") - (useTab = " + this.useTab + ") - (tabSize = " + this.tabSize + ")") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ >+ .append("(page width = " + this.pageWidth + ") - (useTab = " + this.useTab + ") - (tabSize = " + this.tabSize + ")") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ > .append(this.lineSeparator) > .append("(line = " + this.line + ") - (column = " + this.column + ") - (identationLevel = " + this.indentationLevel + ")") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ > .append(this.lineSeparator) >@@ -1492,10 +1457,6 @@ > } > > public void unIndent() { >- if (this.useTab) { >- this.indentationLevel--; >- } else { >- this.indentationLevel -= tabSize; >- } >+ this.indentationLevel -= indentationSize; > } > } >Index: formatter/org/eclipse/jdt/internal/formatter/align/Alignment.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/align/Alignment.java,v >retrieving revision 1.18 >diff -u -r1.18 Alignment.java >--- formatter/org/eclipse/jdt/internal/formatter/align/Alignment.java 25 Jul 2004 01:53:01 -0000 1.18 >+++ formatter/org/eclipse/jdt/internal/formatter/align/Alignment.java 10 Jan 2005 21:20:51 -0000 >@@ -144,10 +144,10 @@ > this.wasSplit = false; > > // initialize the break indentation level, using modes and continuationIndentationLevel preference >- final int indentSize = this.scribe.useTab ? 1 : this.scribe.tabSize; >+ final int indentSize = this.scribe.indentationSize; > int currentColumn = this.location.outputColumn; > if (currentColumn == 1) { >- currentColumn = this.location.outputIndentationLevel * indentSize + 1; >+ currentColumn = this.location.outputIndentationLevel + 1; > } > > if ((mode & M_INDENT_ON_COLUMN) != 0) { >Index: formatter/org/eclipse/jdt/internal/formatter/old/CodeFormatter.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/old/CodeFormatter.java,v >retrieving revision 1.5 >diff -u -r1.5 CodeFormatter.java >--- formatter/org/eclipse/jdt/internal/formatter/old/CodeFormatter.java 7 Jun 2004 15:46:28 -0000 1.5 >+++ formatter/org/eclipse/jdt/internal/formatter/old/CodeFormatter.java 10 Jan 2005 21:20:52 -0000 >@@ -114,7 +114,8 @@ > } > } > newOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, this.options.get(JavaCore.FORMATTER_TAB_CHAR)); >- newOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, this.options.get(JavaCore.FORMATTER_TAB_SIZE)); >+ newOptions.put(DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE, this.options.get(JavaCore.FORMATTER_TAB_SIZE)); >+ newOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_LENGTH, this.options.get(JavaCore.FORMATTER_TAB_SIZE)); > newOptions.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, this.options.get(JavaCore.FORMATTER_LINE_SPLIT)); > newOptions.put(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_ARRAY_INITIALIZER, DefaultCodeFormatterConstants.END_OF_LINE); > newOptions.put(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION, "1");//$NON-NLS-1$
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 Raw
Actions:
View
Attachments on
bug 73104
: 17059 |
17060
|
17061
|
17818
|
18667