[formatterPreferences] deprecated indentationLength in favor of tabWidth

Signed-off-by: Moritz Eysholdt <moritz.eysholdt@typefox.io>
This commit is contained in:
Moritz Eysholdt 2016-04-19 14:24:28 +02:00
parent 6a810ea3e7
commit 9eac8bc70b
2 changed files with 33 additions and 17 deletions

View file

@ -17,14 +17,21 @@ import org.eclipse.xtext.preferences.TypedPreferenceKey;
import org.eclipse.xtext.preferences.TypedPreferenceValues;
/**
* <p>General preference keys used by this formatting infrastructure. Formatters based on this infrastructure should honor
* these keys as well.</p>
* <p>
* General preference keys used by this formatting infrastructure. Formatters based on this infrastructure should honor these keys as well.
* </p>
*
* <p>To set a values for one of these keys, use {@link FormatterRequest#setPreferences(ITypedPreferenceValues)}.</p>
* <p>
* To set a values for one of these keys, use {@link FormatterRequest#setPreferences(ITypedPreferenceValues)}.
* </p>
*
* <p>To access a value for one of these keys, use {@link AbstractFormatter2#getPreference(TypedPreferenceKey)}.</p>
* <p>
* To access a value for one of these keys, use {@link AbstractFormatter2#getPreference(TypedPreferenceKey)}.
* </p>
*
* <p>To introduce new keys, subclass this class (see also {@link PreferenceKeysProvider#allConstantKeys(Class...)}.</p>
* <p>
* To introduce new keys, subclass this class (see also {@link PreferenceKeysProvider#allConstantKeys(Class...)}.
* </p>
*
* @author Moritz Eysholdt - Initial contribution and API
* @since 2.8
@ -43,11 +50,18 @@ public class FormatterPreferenceKeys {
public static StringKey indentation = new StringKey("indentation", "\t");
/**
* The width of one level of indentation counted in characters. If {@link #indentation} is {@code \t} and the
* display-width of one tab is fours, then this values should be four. The formatter uses this value to compute when
* {@link #maxLineWidth} has been exceeded.
* @deprecated use {@link #tabWidth}
*/
public static IntegerKey indentationLength = new IntegerKey("indentation.length", 4);
@Deprecated
public static IntegerKey indentationLength = new IntegerKey("indentation.length", -1);
/**
* The display-width of one tab character.
*
* If {@link #indentation} is {@code \t} and the display-width of one tab is fours, then this values should be four. The formatter uses
* this value to compute when {@link #maxLineWidth} has been exceeded.
*/
public static IntegerKey tabWidth = new IntegerKey("tab.width", 4);
/**
* The maximum of characters that may fit into one line.

View file

@ -43,8 +43,7 @@ public class TextReplacerContext implements ITextReplacerContext {
this(document, null, 0, null);
}
protected TextReplacerContext(IFormattableDocument document, ITextReplacerContext previous, int indentation,
ITextReplacer replacer) {
protected TextReplacerContext(IFormattableDocument document, ITextReplacerContext previous, int indentation, ITextReplacer replacer) {
super();
this.document = document;
this.indentation = indentation;
@ -198,11 +197,15 @@ public class TextReplacerContext implements ITextReplacerContext {
String indentation = preferences.getPreference(FormatterPreferenceKeys.indentation);
if (!"\t".equals(indentation))
return text.length();
int indentationLength = preferences.getPreference(FormatterPreferenceKeys.indentationLength);
@SuppressWarnings("deprecation")
int tabWidth = preferences.getPreference(FormatterPreferenceKeys.indentationLength);
if (tabWidth < 0) {
tabWidth = preferences.getPreference(FormatterPreferenceKeys.tabWidth);
}
int length = 0;
for (int i = 0; i < text.length(); i++)
if (text.charAt(i) == '\t')
length += indentationLength;
length += tabWidth;
else
length++;
return length;
@ -280,8 +283,8 @@ public class TextReplacerContext implements ITextReplacerContext {
items.add("canAutowrap");
if (replacer != null) {
ITextSegment region = replacer.getRegion();
items.add(format("replacer=[%d-%d-%s|%s]", region.getOffset(), region.getLength(),
replacer.getClass().getSimpleName(), replacer.toString()));
items.add(format("replacer=[%d-%d-%s|%s]", region.getOffset(), region.getLength(), replacer.getClass().getSimpleName(),
replacer.toString()));
}
if (replacements != null)
for (ITextReplacement r : replacements) {
@ -313,8 +316,7 @@ public class TextReplacerContext implements ITextReplacerContext {
if (nextReplacerIsChild) {
Preconditions.checkArgument(lastReplacer.getRegion().contains(replacer.getRegion()));
} else {
Preconditions
.checkArgument(lastReplacer.getRegion().getEndOffset() <= replacer.getRegion().getOffset());
Preconditions.checkArgument(lastReplacer.getRegion().getEndOffset() <= replacer.getRegion().getOffset());
}
break;
}