Search in sources :

Example 1 with IPreferenceValues

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);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) IPreferenceValues(org.eclipse.xtext.preferences.IPreferenceValues) ITextRegion(org.eclipse.xtext.util.ITextRegion)

Example 2 with IPreferenceValues

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();
            }
        }
    };
}
Also used : IPreferenceValues(org.eclipse.xtext.preferences.IPreferenceValues) PreferenceKey(org.eclipse.xtext.preferences.PreferenceKey) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) IProject(org.eclipse.core.resources.IProject)

Example 3 with IPreferenceValues

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) ? " " : "";
}
Also used : IPreferenceValues(org.eclipse.xtext.preferences.IPreferenceValues)

Example 4 with IPreferenceValues

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;
}
Also used : TaskTag(org.eclipse.xtext.tasks.TaskTag) IPreferenceValues(org.eclipse.xtext.preferences.IPreferenceValues) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) TaskTags(org.eclipse.xtext.tasks.TaskTags) PreferenceKey(org.eclipse.xtext.preferences.PreferenceKey) List(java.util.List)

Example 5 with IPreferenceValues

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;
}
Also used : IPreferenceValues(org.eclipse.xtext.preferences.IPreferenceValues)

Aggregations

IPreferenceValues (org.eclipse.xtext.preferences.IPreferenceValues)7 PreferenceKey (org.eclipse.xtext.preferences.PreferenceKey)4 List (java.util.List)1 IProject (org.eclipse.core.resources.IProject)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)1 TaskTag (org.eclipse.xtext.tasks.TaskTag)1 TaskTags (org.eclipse.xtext.tasks.TaskTags)1 ITextRegion (org.eclipse.xtext.util.ITextRegion)1 TextRegion (org.eclipse.xtext.util.TextRegion)1 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)1