Search in sources :

Example 6 with IPreferenceValues

use of org.eclipse.xtext.preferences.IPreferenceValues in project n4js by eclipse.

the class N4JSPreferenceAccess method getPreference.

/**
 * @param resource
 *            the current resource, this will be used to calculate the preference store to access (e.g. if there are
 *            project specific preferences configured).
 * @param compilerID
 *            the compiler id
 * @param compilerProperty
 *            the compiler property to ask for
 * @param defaultDescriptor
 *            the descriptor containing the default values to be used as fall back if there isn't a value in the
 *            preference store
 * @return the preference value found in the preference store or any other values provider or the default value out
 *         of the default descriptor
 */
public String getPreference(Resource resource, String compilerID, CompilerProperties compilerProperty, CompilerDescriptor defaultDescriptor) {
    IPreferenceValues preferences = valuesProvider.getPreferenceValues(resource);
    PreferenceKey key = new PreferenceKey(compilerProperty.getKey(compilerID), String.valueOf(compilerProperty.getValueInCompilerDescriptor(defaultDescriptor, compilerID)));
    return preferences.getPreference(key);
}
Also used : IPreferenceValues(org.eclipse.xtext.preferences.IPreferenceValues) PreferenceKey(org.eclipse.xtext.preferences.PreferenceKey)

Example 7 with IPreferenceValues

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

the class FormatterPreferenceValuesProvider method getPreferenceValues.

@Override
public IPreferenceValues getPreferenceValues(final Resource resource) {
    final IPreferenceValues preferenceValues = internalGetRawPreferenceValues(resource);
    final String indent = whitespaceInfo.getIndentationInformation(resource.getURI()).getIndentString();
    final String lineSep = whitespaceInfo.getLineSeparatorInformation(resource.getURI()).getLineSeparator();
    return new IPreferenceValues() {

        @Override
        public String getPreference(PreferenceKey key) {
            if (key == FormatterPreferenceKeys.indentation) {
                return indent;
            }
            if (key == FormatterPreferenceKeys.lineSeparator) {
                return lineSep;
            }
            return preferenceValues.getPreference(key);
        }
    };
}
Also used : IPreferenceValues(org.eclipse.xtext.preferences.IPreferenceValues) PreferenceKey(org.eclipse.xtext.preferences.PreferenceKey)

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