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 |
} |