use of org.eclipse.xtext.preferences.IPreferenceValues in project xtext-eclipse by eclipse.
the class ContentFormatter method initRequest.
protected void initRequest(IXtextDocument document, IRegion region, XtextResource resource, FormatterRequest request) {
ITextRegion textRegion = new TextRegion(region.getOffset(), region.getLength());
request.setAllowIdentityEdits(false);
request.setFormatUndefinedHiddenRegionsOnly(false);
request.setRegions(singletonList(textRegion));
ITextRegionAccess tokenAccess = regionBuilder.forNodeModel(resource).create();
IPreferenceValues preferenceValues = preferencesProvider.getPreferenceValues(resource);
request.setPreferences(TypedPreferenceValues.castOrWrap(preferenceValues));
request.setTextRegionAccess(tokenAccess);
if (tokenAccess.hasSyntaxError())
request.setExceptionHandler(ExceptionAcceptor.IGNORING);
else
request.setExceptionHandler(ExceptionAcceptor.LOGGING);
}
use of org.eclipse.xtext.preferences.IPreferenceValues in project xtext-eclipse by eclipse.
the class EclipsePreferencesProvider method getPreferenceValues.
@Override
public IPreferenceValues getPreferenceValues(Resource context) {
final IProject project = getProject(context);
final IPreferenceStore store = project != null ? access.getContextPreferenceStore(project) : access.getPreferenceStore();
final Map<String, String> preferenceCache = Maps.newHashMap();
return new IPreferenceValues() {
@Override
public String getPreference(PreferenceKey key) {
try {
String id = key.getId();
String string = preferenceCache.get(id);
if (string == null) {
string = store.getString(id);
preferenceCache.put(id, string);
}
return org.eclipse.jface.preference.IPreferenceStore.STRING_DEFAULT_DEFAULT.equals(string) ? key.getDefaultValue() : string;
} catch (Exception e) {
log.error("Error getting preference for key '" + key.getId() + "'.", e);
return key.getDefaultValue();
}
}
};
}
use of org.eclipse.xtext.preferences.IPreferenceValues in project n4js by eclipse.
the class ImportSpacerUserPreferenceHelper method getSpacingPreference.
/**
* Compute user preference regarding space between import specifiers and curly brace.
*/
public String getSpacingPreference(Resource resource) {
IPreferenceValues prefValues = formattingPreferenceProvider.getPreferenceValues(resource);
String spacePreference = prefValues.getPreference(N4JSFormatterPreferenceKeys.FORMAT_SURROUND_IMPORT_LIST_WITH_SPACE);
return Boolean.valueOf(spacePreference) ? " " : "";
}
use of org.eclipse.xtext.preferences.IPreferenceValues in project xtext-xtend by eclipse.
the class XtendTaskTagProvider method getTaskTags.
@Override
public TaskTags getTaskTags(final Resource resource) {
TaskTags _xblockexpression = null;
{
final IPreferenceValues prefs = this.preferenceValuesProvider.getPreferenceValues(resource);
PreferenceKey _preferenceKey = new PreferenceKey(JavaCore.COMPILER_TASK_TAGS, "TODO,FIXME,XXX");
final String namePref = prefs.getPreference(_preferenceKey);
PreferenceKey _preferenceKey_1 = new PreferenceKey(JavaCore.COMPILER_TASK_PRIORITIES, "NORMAL,HIGH,NORMAL");
final String prioritiesPref = prefs.getPreference(_preferenceKey_1);
PreferenceKey _preferenceKey_2 = new PreferenceKey(JavaCore.COMPILER_TASK_CASE_SENSITIVE, JavaCore.ENABLED);
final String caseSensitivePref = prefs.getPreference(_preferenceKey_2);
final List<TaskTag> tags = PreferenceTaskTagProvider.parseTags(namePref, prioritiesPref);
TaskTags _taskTags = new TaskTags();
final Procedure1<TaskTags> _function = (TaskTags it) -> {
List<TaskTag> _taskTags_1 = it.getTaskTags();
Iterables.<TaskTag>addAll(_taskTags_1, tags);
it.setCaseSensitive(caseSensitivePref.equals(JavaCore.ENABLED));
};
_xblockexpression = ObjectExtensions.<TaskTags>operator_doubleArrow(_taskTags, _function);
}
return _xblockexpression;
}
use of org.eclipse.xtext.preferences.IPreferenceValues in project xtext-core by eclipse.
the class PreferenceTaskTagProvider method getTaskTags.
@Override
public TaskTags getTaskTags(Resource resource) {
IPreferenceValues prefs = this.preferenceValuesProvider.getPreferenceValues(resource);
String names = prefs.getPreference(PreferenceTaskTagProvider.TAGS_KEY);
String priorities = prefs.getPreference(PreferenceTaskTagProvider.PRIORITIES_KEY);
TaskTags taskTags = new TaskTags();
taskTags.setCaseSensitive(Boolean.valueOf(prefs.getPreference(PreferenceTaskTagProvider.CASE_SENSITIVE_KEY)));
List<TaskTag> tags = PreferenceTaskTagProvider.parseTags(names, priorities);
taskTags.getTaskTags().addAll(tags);
return taskTags;
}
Aggregations