View | Details | Raw Unified | Return to bug 49896 | Differences between
and this patch

Collapse All | Expand All

(-)formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java (-1 / +9 lines)
Lines 286-292 Link Here
286
	public final char filling_space = ' ';
286
	public final char filling_space = ' ';
287
	public int page_width;
287
	public int page_width;
288
	public int tab_char;
288
	public int tab_char;
289
289
	public boolean use_tabs_only_for_leading_indentations;
290
	
290
	public int initial_indentation_level;
291
	public int initial_indentation_level;
291
	public String line_separator;
292
	public String line_separator;
292
	
293
	
Lines 555-560 Link Here
555
				break;
556
				break;
556
		}
557
		}
557
		options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, Integer.toString(this.tab_size));
558
		options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, Integer.toString(this.tab_size));
559
		options.put(DefaultCodeFormatterConstants.FORMATTER_USE_TABS_ONLY_FOR_LEADING_INDENTATIONS, this.use_tabs_only_for_leading_indentations ?  DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
558
		return options;
560
		return options;
559
	}
561
	}
560
562
Lines 1761-1766 Link Here
1761
				this.tab_size = 4;
1763
				this.tab_size = 4;
1762
			}
1764
			}
1763
		}
1765
		}
1766
		final Object useTabsOnlyForLeadingIndentationsOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_USE_TABS_ONLY_FOR_LEADING_INDENTATIONS);
1767
		if (useTabsOnlyForLeadingIndentationsOption != null) {
1768
			this.use_tabs_only_for_leading_indentations = DefaultCodeFormatterConstants.TRUE.equals(useTabsOnlyForLeadingIndentationsOption);
1769
		}
1764
		final Object pageWidthOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT);
1770
		final Object pageWidthOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT);
1765
		if (pageWidthOption != null) {
1771
		if (pageWidthOption != null) {
1766
			try {
1772
			try {
Lines 2022-2027 Link Here
2022
		this.tab_size = 4;
2028
		this.tab_size = 4;
2023
		this.page_width = 80;
2029
		this.page_width = 80;
2024
		this.tab_char = TAB; // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=49081
2030
		this.tab_char = TAB; // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=49081
2031
		this.use_tabs_only_for_leading_indentations = false;
2025
	}
2032
	}
2026
	
2033
	
2027
	public void setJavaConventionsSettings() {
2034
	public void setJavaConventionsSettings() {
Lines 2263-2267 Link Here
2263
		this.tab_size = 4;
2270
		this.tab_size = 4;
2264
		this.page_width = 80;
2271
		this.page_width = 80;
2265
		this.tab_char = SPACE;
2272
		this.tab_char = SPACE;
2273
		this.use_tabs_only_for_leading_indentations = false;
2266
	}
2274
	}
2267
}
2275
}
(-)formatter/org/eclipse/jdt/internal/formatter/Location.java (+2 lines)
Lines 25-30 Link Here
25
	public boolean pendingSpace;
25
	public boolean pendingSpace;
26
	public int nlsTagCounter;
26
	public int nlsTagCounter;
27
	public int lastLocalDeclarationSourceStart;
27
	public int lastLocalDeclarationSourceStart;
28
	public int numberOfIndentations;
28
29
29
	// chunk management
30
	// chunk management
30
	public int lastNumberOfNewLines;
31
	public int lastNumberOfNewLines;
Lines 47-52 Link Here
47
		this.pendingSpace = scribe.pendingSpace;
48
		this.pendingSpace = scribe.pendingSpace;
48
		this.editsIndex = scribe.editsIndex;
49
		this.editsIndex = scribe.editsIndex;
49
		this.nlsTagCounter = scribe.nlsTagCounter;
50
		this.nlsTagCounter = scribe.nlsTagCounter;
51
		this.numberOfIndentations = scribe.numberOfIndentations;
50
		textEdit = scribe.getLastEdit();
52
		textEdit = scribe.getLastEdit();
51
	}
53
	}
52
}
54
}
(-)formatter/org/eclipse/jdt/internal/formatter/Scribe.java (-5 / +32 lines)
Lines 72-77 Link Here
72
	private int textRegionEnd;
72
	private int textRegionEnd;
73
	private int textRegionStart;
73
	private int textRegionStart;
74
	public int tabChar;
74
	public int tabChar;
75
	public int numberOfIndentations;
76
	private boolean useTabsOnlyForLeadingIndents;
75
77
76
	Scribe(CodeFormatterVisitor formatter, Map settings, int offset, int length, CodeSnippetParsingUtil codeSnippetParsingUtil) {
78
	Scribe(CodeFormatterVisitor formatter, Map settings, int offset, int length, CodeSnippetParsingUtil codeSnippetParsingUtil) {
77
		if (settings != null) {
79
		if (settings != null) {
Lines 90-95 Link Here
90
		this.pageWidth = formatter.preferences.page_width;
92
		this.pageWidth = formatter.preferences.page_width;
91
		this.tabLength = formatter.preferences.tab_size;
93
		this.tabLength = formatter.preferences.tab_size;
92
		this.indentationLevel= 0; // initialize properly
94
		this.indentationLevel= 0; // initialize properly
95
		this.numberOfIndentations = 0;
96
		this.useTabsOnlyForLeadingIndents = formatter.preferences.use_tabs_only_for_leading_indentations;
93
		this.tabChar = formatter.preferences.tab_char;
97
		this.tabChar = formatter.preferences.tab_char;
94
		if (this.tabChar == DefaultCodeFormatterOptions.MIXED) {
98
		if (this.tabChar == DefaultCodeFormatterOptions.MIXED) {
95
			this.indentationSize = formatter.preferences.indentation_size;
99
			this.indentationSize = formatter.preferences.indentation_size;
Lines 322-327 Link Here
322
			throw new AbortFormatting("could not find matching alignment: "+alignment); //$NON-NLS-1$
326
			throw new AbortFormatting("could not find matching alignment: "+alignment); //$NON-NLS-1$
323
		}
327
		}
324
		this.indentationLevel = alignment.location.outputIndentationLevel;
328
		this.indentationLevel = alignment.location.outputIndentationLevel;
329
		this.numberOfIndentations = alignment.location.numberOfIndentations;
325
		this.formatter.lastLocalDeclarationSourceStart = alignment.location.lastLocalDeclarationSourceStart;	
330
		this.formatter.lastLocalDeclarationSourceStart = alignment.location.lastLocalDeclarationSourceStart;	
326
		if (discardAlignment){ 
331
		if (discardAlignment){ 
327
			this.currentAlignment = alignment.enclosing;
332
			this.currentAlignment = alignment.enclosing;
Lines 338-343 Link Here
338
			throw new AbortFormatting("could not find matching alignment: "+alignment); //$NON-NLS-1$
343
			throw new AbortFormatting("could not find matching alignment: "+alignment); //$NON-NLS-1$
339
		}
344
		}
340
		this.indentationLevel = current.location.outputIndentationLevel;
345
		this.indentationLevel = current.location.outputIndentationLevel;
346
		this.numberOfIndentations = current.location.numberOfIndentations;
341
		this.formatter.lastLocalDeclarationSourceStart = alignment.location.lastLocalDeclarationSourceStart;	
347
		this.formatter.lastLocalDeclarationSourceStart = alignment.location.lastLocalDeclarationSourceStart;	
342
		this.memberAlignment = current.enclosing;
348
		this.memberAlignment = current.enclosing;
343
	}
349
	}
Lines 571-576 Link Here
571
	
577
	
572
	public void indent() {
578
	public void indent() {
573
		this.indentationLevel += this.indentationSize;
579
		this.indentationLevel += this.indentationSize;
580
		this.numberOfIndentations++;
574
	}	
581
	}	
575
582
576
	private int indexOf(char[] toBeFound, char[] source, int start, int end) {
583
	private int indexOf(char[] toBeFound, char[] source, int start, int end) {
Lines 1086-1097 Link Here
1086
	private void printIndentationIfNecessary(StringBuffer buffer) {
1093
	private void printIndentationIfNecessary(StringBuffer buffer) {
1087
		switch(this.tabChar) {
1094
		switch(this.tabChar) {
1088
			case DefaultCodeFormatterOptions.TAB :
1095
			case DefaultCodeFormatterOptions.TAB :
1096
				final boolean useTabsForLeadingIndents = this.useTabsOnlyForLeadingIndents;
1097
				final int numberOfLeadingIndents = this.numberOfIndentations;
1098
				int indentationsAsTab = 0;
1089
				while (this.column <= this.indentationLevel) {
1099
				while (this.column <= this.indentationLevel) {
1090
					buffer.append('\t');
1100
					if (useTabsForLeadingIndents) {
1091
					this.lastNumberOfNewLines = 0;
1101
						if (indentationsAsTab < numberOfLeadingIndents) {
1092
					int complement = this.tabLength - ((this.column - 1) % this.tabLength); // amount of space
1102
							buffer.append('\t');
1093
					this.column += complement;
1103
							indentationsAsTab++;
1094
					this.needSpace = false;
1104
							this.lastNumberOfNewLines = 0;
1105
							int complement = this.tabLength - ((this.column - 1) % this.tabLength); // amount of space
1106
							this.column += complement;
1107
							this.needSpace = false;
1108
						} else {
1109
							buffer.append(' ');
1110
							this.column++;
1111
							this.needSpace = false;
1112
						}
1113
					} else {
1114
						buffer.append('\t');
1115
						this.lastNumberOfNewLines = 0;
1116
						int complement = this.tabLength - ((this.column - 1) % this.tabLength); // amount of space
1117
						this.column += complement;
1118
						this.needSpace = false;
1119
					}
1095
				}
1120
				}
1096
				break;
1121
				break;
1097
			case DefaultCodeFormatterOptions.SPACE :
1122
			case DefaultCodeFormatterOptions.SPACE :
Lines 1453-1458 Link Here
1453
		this.line = location.outputLine;
1478
		this.line = location.outputLine;
1454
		this.column = location.outputColumn;
1479
		this.column = location.outputColumn;
1455
		this.indentationLevel = location.outputIndentationLevel;
1480
		this.indentationLevel = location.outputIndentationLevel;
1481
		this.numberOfIndentations = location.numberOfIndentations;
1456
		this.lastNumberOfNewLines = location.lastNumberOfNewLines;
1482
		this.lastNumberOfNewLines = location.lastNumberOfNewLines;
1457
		this.needSpace = location.needSpace;
1483
		this.needSpace = location.needSpace;
1458
		this.pendingSpace = location.pendingSpace;
1484
		this.pendingSpace = location.pendingSpace;
Lines 1505-1509 Link Here
1505
	
1531
	
1506
	public void unIndent() {
1532
	public void unIndent() {
1507
		this.indentationLevel -= this.indentationSize;
1533
		this.indentationLevel -= this.indentationSize;
1534
		this.numberOfIndentations--;
1508
	}
1535
	}
1509
}
1536
}

Return to bug 49896