Link Here
|
14 |
import java.util.Iterator; |
14 |
import java.util.Iterator; |
15 |
import java.util.LinkedList; |
15 |
import java.util.LinkedList; |
16 |
|
16 |
|
|
|
17 |
import org.eclipse.core.runtime.Assert; |
18 |
|
17 |
import org.eclipse.text.edits.MalformedTreeException; |
19 |
import org.eclipse.text.edits.MalformedTreeException; |
18 |
import org.eclipse.text.edits.TextEdit; |
20 |
import org.eclipse.text.edits.TextEdit; |
19 |
|
21 |
|
Link Here
|
69 |
/** Number of spaces representing tabulator */ |
71 |
/** Number of spaces representing tabulator */ |
70 |
private int fTabSize; |
72 |
private int fTabSize; |
71 |
|
73 |
|
72 |
/** |
|
|
73 |
* <code>true</code> if tabs, not spaces, should be used for indentation |
74 |
* @since 3.1 |
75 |
*/ |
76 |
private boolean fUseTab; |
77 |
|
78 |
/** the scribe used to create edits */ |
74 |
/** the scribe used to create edits */ |
79 |
protected Scribe scribe; |
75 |
protected Scribe scribe; |
80 |
|
76 |
|
Link Here
|
94 |
|
90 |
|
95 |
fClear= this.preferences.comment_clear_blank_lines; |
91 |
fClear= this.preferences.comment_clear_blank_lines; |
96 |
|
92 |
|
97 |
fTabSize= this.preferences.tab_size; |
93 |
fTabSize= DefaultCodeFormatterOptions.SPACE == this.preferences.tab_char ? this.preferences.indentation_size : this.preferences.tab_size; |
98 |
fUseTab = this.preferences.tab_char == DefaultCodeFormatterOptions.TAB; |
|
|
99 |
|
94 |
|
100 |
this.scribe = formatter.scribe; |
95 |
this.scribe = formatter.scribe; |
101 |
|
96 |
|
Link Here
|
426 |
* @since 3.1 |
421 |
* @since 3.1 |
427 |
*/ |
422 |
*/ |
428 |
private String computeIndentation(int indentationLevel) { |
423 |
private String computeIndentation(int indentationLevel) { |
429 |
return replicate(fUseTab ? "\t" : replicate(" ", fTabSize), indentationLevel); //$NON-NLS-1$//$NON-NLS-2$ |
424 |
if (DefaultCodeFormatterOptions.TAB == this.preferences.tab_char) |
|
|
425 |
return replicate("\t", indentationLevel); //$NON-NLS-1$ |
426 |
|
427 |
if (DefaultCodeFormatterOptions.SPACE == this.preferences.tab_char) |
428 |
return replicate(" ", indentationLevel * this.preferences.tab_size); //$NON-NLS-1$ |
429 |
|
430 |
if (DefaultCodeFormatterOptions.MIXED == this.preferences.tab_char) { |
431 |
int tabSize= this.preferences.tab_size; |
432 |
int indentSize= this.preferences.indentation_size; |
433 |
int spaceEquivalents= indentationLevel * indentSize; |
434 |
return replicate("\t", spaceEquivalents / tabSize) + replicate(" ", spaceEquivalents % tabSize); //$NON-NLS-1$ //$NON-NLS-2$ |
435 |
} |
436 |
|
437 |
Assert.isTrue(false); |
438 |
return null; |
430 |
} |
439 |
} |
431 |
|
440 |
|
432 |
/** |
441 |
/** |
Link Here
|
448 |
* Computes the equivalent indentation for a string |
457 |
* Computes the equivalent indentation for a string |
449 |
* |
458 |
* |
450 |
* @param reference the string to compute the indentation for |
459 |
* @param reference the string to compute the indentation for |
451 |
* @param tabs <code>true</code> iff the indentation should use tabs, |
|
|
452 |
* <code>false</code> otherwise. |
453 |
* @return the indentation string |
460 |
* @return the indentation string |
454 |
*/ |
461 |
*/ |
455 |
protected final String stringToIndent(final String reference, final boolean tabs) { |
462 |
protected final String stringToIndent(final String reference) { |
456 |
|
463 |
return replicate(" ", stringToLength(reference)); //$NON-NLS-1$ |
457 |
int spaceWidth= 1; |
|
|
458 |
int referenceWidth= expandTabs(reference).length(); |
459 |
|
460 |
final StringBuffer buffer= new StringBuffer(); |
461 |
final int spaces= referenceWidth / spaceWidth; |
462 |
|
463 |
if (tabs) { |
464 |
|
465 |
final int count= spaces / fTabSize; |
466 |
final int modulo= spaces % fTabSize; |
467 |
|
468 |
for (int index= 0; index < count; index++) |
469 |
buffer.append('\t'); |
470 |
|
471 |
for (int index= 0; index < modulo; index++) |
472 |
buffer.append(' '); |
473 |
|
474 |
} else { |
475 |
|
476 |
for (int index= 0; index < spaces; index++) |
477 |
buffer.append(' '); |
478 |
} |
479 |
return buffer.toString(); |
480 |
} |
464 |
} |
481 |
|
465 |
|
482 |
/** |
466 |
/** |