Search in sources :

Example 1 with ITypedPreferenceValues

use of org.eclipse.xtext.preferences.ITypedPreferenceValues in project xtext-core by eclipse.

the class FormatterTestRequest method getOrCreateMapBasedPreferences.

public MapBasedPreferenceValues getOrCreateMapBasedPreferences() {
    ITypedPreferenceValues preferences = request.getPreferences();
    if (preferences instanceof MapBasedPreferenceValues)
        return (MapBasedPreferenceValues) preferences;
    LinkedHashMap<String, String> newMap = Maps.<String, String>newLinkedHashMap();
    MapBasedPreferenceValues result = new MapBasedPreferenceValues(preferences, newMap);
    request.setPreferences(result);
    return result;
}
Also used : ITypedPreferenceValues(org.eclipse.xtext.preferences.ITypedPreferenceValues) MapBasedPreferenceValues(org.eclipse.xtext.preferences.MapBasedPreferenceValues)

Example 2 with ITypedPreferenceValues

use of org.eclipse.xtext.preferences.ITypedPreferenceValues in project xtext-core by eclipse.

the class TextReplacerContext method logicalLength.

protected int logicalLength(String text) {
    ITypedPreferenceValues preferences = getDocument().getRequest().getPreferences();
    String indentation = preferences.getPreference(FormatterPreferenceKeys.indentation);
    if (!"\t".equals(indentation))
        return text.length();
    @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 += tabWidth;
    else
        length++;
    return length;
}
Also used : ITypedPreferenceValues(org.eclipse.xtext.preferences.ITypedPreferenceValues) String(java.lang.String)

Aggregations

ITypedPreferenceValues (org.eclipse.xtext.preferences.ITypedPreferenceValues)2 String (java.lang.String)1 MapBasedPreferenceValues (org.eclipse.xtext.preferences.MapBasedPreferenceValues)1