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.56 diff -u -r1.56 DefaultCodeFormatterConstants.java --- formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 28 Mar 2005 21:15:56 -0000 1.56 +++ formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 29 Mar 2005 19:13:38 -0000 @@ -2912,6 +2912,20 @@ /** *
+	 * FORMATTER / Option to use tabulations only for leading indentations 
+	 *     - option id:         "org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations"
+	 *     - possible values:   { TRUE, FALSE }
+	 *     - default:           FALSE
+	 * 
+ *

This is used only if the {@link #FORMATTER_TAB_CHAR } is set to {@link JavaCore#TAB}.

+ * @see #TRUE + * @see #FALSE + * @since 3.1 + */ + public static final String FORMATTER_USE_TABS_ONLY_FOR_LEADING_INDENTATIONS = JavaCore.PLUGIN_ID + ".formatter.use_tabs_only_for_leading_indentations"; //$NON-NLS-1$ + + /** + *
 	 * FORMATTER / The wrapping is done by indenting by one compare to the current indentation.
 	 * 
* @since 3.0 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.59 diff -u -r1.59 DefaultCodeFormatterOptions.java --- formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 28 Mar 2005 21:15:56 -0000 1.59 +++ formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 29 Mar 2005 19:13:38 -0000 @@ -286,7 +286,8 @@ public final char filling_space = ' '; public int page_width; public int tab_char; - + public boolean use_tabs_only_for_leading_indentations; + public int initial_indentation_level; public String line_separator; @@ -555,6 +556,7 @@ break; } options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, Integer.toString(this.tab_size)); + options.put(DefaultCodeFormatterConstants.FORMATTER_USE_TABS_ONLY_FOR_LEADING_INDENTATIONS, this.use_tabs_only_for_leading_indentations ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); return options; } @@ -1761,6 +1763,10 @@ this.tab_size = 4; } } + final Object useTabsOnlyForLeadingIndentationsOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_USE_TABS_ONLY_FOR_LEADING_INDENTATIONS); + if (useTabsOnlyForLeadingIndentationsOption != null) { + this.use_tabs_only_for_leading_indentations = DefaultCodeFormatterConstants.TRUE.equals(useTabsOnlyForLeadingIndentationsOption); + } final Object pageWidthOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT); if (pageWidthOption != null) { try { @@ -2022,6 +2028,7 @@ this.tab_size = 4; this.page_width = 80; this.tab_char = TAB; // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=49081 + this.use_tabs_only_for_leading_indentations = false; } public void setJavaConventionsSettings() { @@ -2263,5 +2270,6 @@ this.tab_size = 4; this.page_width = 80; this.tab_char = SPACE; + this.use_tabs_only_for_leading_indentations = false; } } Index: formatter/org/eclipse/jdt/internal/formatter/Location.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/Location.java,v retrieving revision 1.10 diff -u -r1.10 Location.java --- formatter/org/eclipse/jdt/internal/formatter/Location.java 23 Feb 2005 02:47:58 -0000 1.10 +++ formatter/org/eclipse/jdt/internal/formatter/Location.java 29 Mar 2005 19:13:38 -0000 @@ -25,6 +25,7 @@ public boolean pendingSpace; public int nlsTagCounter; public int lastLocalDeclarationSourceStart; + public int numberOfIndentations; // chunk management public int lastNumberOfNewLines; @@ -47,6 +48,7 @@ this.pendingSpace = scribe.pendingSpace; this.editsIndex = scribe.editsIndex; this.nlsTagCounter = scribe.nlsTagCounter; + this.numberOfIndentations = scribe.numberOfIndentations; textEdit = scribe.getLastEdit(); } } 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.85 diff -u -r1.85 Scribe.java --- formatter/org/eclipse/jdt/internal/formatter/Scribe.java 28 Mar 2005 23:22:11 -0000 1.85 +++ formatter/org/eclipse/jdt/internal/formatter/Scribe.java 29 Mar 2005 19:13:39 -0000 @@ -72,6 +72,8 @@ private int textRegionEnd; private int textRegionStart; public int tabChar; + public int numberOfIndentations; + private boolean useTabsOnlyForLeadingIndents; Scribe(CodeFormatterVisitor formatter, Map settings, int offset, int length, CodeSnippetParsingUtil codeSnippetParsingUtil) { if (settings != null) { @@ -90,6 +92,8 @@ this.pageWidth = formatter.preferences.page_width; this.tabLength = formatter.preferences.tab_size; this.indentationLevel= 0; // initialize properly + this.numberOfIndentations = 0; + this.useTabsOnlyForLeadingIndents = formatter.preferences.use_tabs_only_for_leading_indentations; this.tabChar = formatter.preferences.tab_char; if (this.tabChar == DefaultCodeFormatterOptions.MIXED) { this.indentationSize = formatter.preferences.indentation_size; @@ -322,6 +326,7 @@ throw new AbortFormatting("could not find matching alignment: "+alignment); //$NON-NLS-1$ } this.indentationLevel = alignment.location.outputIndentationLevel; + this.numberOfIndentations = alignment.location.numberOfIndentations; this.formatter.lastLocalDeclarationSourceStart = alignment.location.lastLocalDeclarationSourceStart; if (discardAlignment){ this.currentAlignment = alignment.enclosing; @@ -338,6 +343,7 @@ throw new AbortFormatting("could not find matching alignment: "+alignment); //$NON-NLS-1$ } this.indentationLevel = current.location.outputIndentationLevel; + this.numberOfIndentations = current.location.numberOfIndentations; this.formatter.lastLocalDeclarationSourceStart = alignment.location.lastLocalDeclarationSourceStart; this.memberAlignment = current.enclosing; } @@ -571,6 +577,7 @@ public void indent() { this.indentationLevel += this.indentationSize; + this.numberOfIndentations++; } private int indexOf(char[] toBeFound, char[] source, int start, int end) { @@ -1086,12 +1093,30 @@ private void printIndentationIfNecessary(StringBuffer buffer) { switch(this.tabChar) { case DefaultCodeFormatterOptions.TAB : + final boolean useTabsForLeadingIndents = this.useTabsOnlyForLeadingIndents; + final int numberOfLeadingIndents = this.numberOfIndentations; + int indentationsAsTab = 0; while (this.column <= this.indentationLevel) { - buffer.append('\t'); - this.lastNumberOfNewLines = 0; - int complement = this.tabLength - ((this.column - 1) % this.tabLength); // amount of space - this.column += complement; - this.needSpace = false; + if (useTabsForLeadingIndents) { + if (indentationsAsTab < numberOfLeadingIndents) { + buffer.append('\t'); + indentationsAsTab++; + this.lastNumberOfNewLines = 0; + int complement = this.tabLength - ((this.column - 1) % this.tabLength); // amount of space + this.column += complement; + this.needSpace = false; + } else { + buffer.append(' '); + this.column++; + this.needSpace = false; + } + } else { + buffer.append('\t'); + this.lastNumberOfNewLines = 0; + int complement = this.tabLength - ((this.column - 1) % this.tabLength); // amount of space + this.column += complement; + this.needSpace = false; + } } break; case DefaultCodeFormatterOptions.SPACE : @@ -1453,6 +1478,7 @@ this.line = location.outputLine; this.column = location.outputColumn; this.indentationLevel = location.outputIndentationLevel; + this.numberOfIndentations = location.numberOfIndentations; this.lastNumberOfNewLines = location.lastNumberOfNewLines; this.needSpace = location.needSpace; this.pendingSpace = location.pendingSpace; @@ -1505,5 +1531,6 @@ public void unIndent() { this.indentationLevel -= this.indentationSize; + this.numberOfIndentations--; } } \ No newline at end of file