1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-21 21:52:10 +02:00

Bug 564274 - Switch CDT cmake to use new Equinox preferences API

Replace "org.eclipse.cdt.core.options" with
"org.eclipse.core.runtime.preferences"

Change-Id: I6ac4813b680ebf34336c85bfd3bc1721d6656dc4
Signed-off-by: Alexander Fedorov <alexander.fedorov@arsysop.ru>
This commit is contained in:
Alexander Fedorov 2020-06-14 14:31:28 +03:00
parent fe2daff197
commit a5dce82d54
7 changed files with 38 additions and 27 deletions

View file

@ -16,7 +16,7 @@ import java.util.regex.PatternSyntaxException;
import org.eclipse.cdt.cmake.is.core.IParserPreferences;
import org.eclipse.cdt.cmake.is.core.IParserPreferencesAccess;
import org.eclipse.cdt.cmake.is.core.IParserPreferencesMetadata;
import org.eclipse.cdt.core.options.OptionMetadata;
import org.eclipse.core.runtime.preferences.PreferenceMetadata;
import org.eclipse.e4.core.contexts.EclipseContextFactory;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.preference.PreferencePage;
@ -155,7 +155,7 @@ public class IndexerSupportPreferencePage extends PreferencePage implements IWor
* @param text text to display on the check-box
*/
private static Button createCheckbox(Composite parent, int horizontalAlignment, int horizontalSpan,
OptionMetadata<Boolean> option) {
PreferenceMetadata<Boolean> option) {
Button b = new Button(parent, SWT.CHECK);
b.setText(option.name());
b.setToolTipText(option.description());

View file

@ -11,7 +11,7 @@
package org.eclipse.cdt.cmake.is.core;
import org.eclipse.cdt.core.options.OptionMetadata;
import org.eclipse.core.runtime.preferences.PreferenceMetadata;
/**
* The metadata for options to configure the {@code compile_commands.json} parser.
@ -24,19 +24,19 @@ public interface IParserPreferencesMetadata {
*
* @return the metadata for the preference option, never {@null}
*/
OptionMetadata<Boolean> tryVersionSuffix();
PreferenceMetadata<Boolean> tryVersionSuffix();
/**
* Returns the metadata for the {@link IParserPreferences#getVersionSuffixPattern()} preference.
*
* @return the metadata for the preference option, never {@null}
*/
OptionMetadata<String> versionSuffixPattern();
PreferenceMetadata<String> versionSuffixPattern();
/**
* Returns the metadata for the {@link IParserPreferences#getAllocateConsole()} preference.
*
* @return the metadata for the preference option, never {@null}
*/
OptionMetadata<Boolean> allocateConsole();
PreferenceMetadata<Boolean> allocateConsole();
}

View file

@ -19,6 +19,7 @@ import org.eclipse.osgi.util.NLS;
*/
public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.cdt.cmake.is.core.internal.messages"; //$NON-NLS-1$
public static String ParserPreferencesAccess_e_get_preferences;
public static String ParserPreferencesMetadata_label_console;
public static String ParserPreferencesMetadata_label_suffix;
public static String ParserPreferencesMetadata_label_try_suffix;

View file

@ -15,17 +15,17 @@ import java.util.Objects;
import org.eclipse.cdt.cmake.is.core.IParserPreferences;
import org.eclipse.cdt.cmake.is.core.IParserPreferencesMetadata;
import org.eclipse.cdt.core.options.OptionStorage;
import org.eclipse.core.runtime.preferences.IPreferenceMetadataStore;
/**
* @author weber
*/
final class ParserPreferences implements IParserPreferences {
private final OptionStorage optionStorage;
private final IPreferenceMetadataStore optionStorage;
private final IParserPreferencesMetadata metadata;
public ParserPreferences(OptionStorage optionStorage, IParserPreferencesMetadata metadata) {
public ParserPreferences(IPreferenceMetadataStore optionStorage, IParserPreferencesMetadata metadata) {
this.optionStorage = Objects.requireNonNull(optionStorage, "optionStorage"); //$NON-NLS-1$
this.metadata = Objects.requireNonNull(metadata, "metadata"); //$NON-NLS-1$
}

View file

@ -11,15 +11,18 @@
package org.eclipse.cdt.cmake.is.core.internal;
import java.util.Optional;
import org.eclipse.cdt.cmake.is.core.IParserPreferences;
import org.eclipse.cdt.cmake.is.core.IParserPreferencesAccess;
import org.eclipse.cdt.cmake.is.core.IParserPreferencesMetadata;
import org.eclipse.cdt.core.options.OptionStorage;
import org.eclipse.cdt.core.options.OsgiPreferenceStorage;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IPreferenceMetadataStore;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.core.runtime.preferences.OsgiPreferenceMetadataStore;
import org.eclipse.osgi.util.NLS;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.prefs.Preferences;
/**
* @author weber
@ -33,8 +36,8 @@ public class ParserPreferencesAccess implements IParserPreferencesAccess {
this.metadata = new ParserPreferencesMetadata();
}
private OptionStorage workspaceStorage() {
return new OsgiPreferenceStorage(preferences(InstanceScope.INSTANCE));
private IPreferenceMetadataStore workspaceStorage() {
return new OsgiPreferenceMetadataStore(preferences(InstanceScope.INSTANCE));
}
@Override
@ -47,8 +50,14 @@ public class ParserPreferencesAccess implements IParserPreferencesAccess {
return metadata;
}
private Preferences preferences(IScopeContext scope) {
return scope.getNode(nodeQualifier()).node(nodePath());
private IEclipsePreferences preferences(IScopeContext scope) {
return Optional.ofNullable(scope.getNode(nodeQualifier()))//
.map(n -> n.node(nodePath()))//
.filter(IEclipsePreferences.class::isInstance)//
.map(IEclipsePreferences.class::cast)//
.orElseThrow(() -> new IllegalStateException(//
NLS.bind(Messages.ParserPreferencesAccess_e_get_preferences, //
nodeQualifier(), nodePath())));
}
private String nodeQualifier() {

View file

@ -12,40 +12,40 @@
package org.eclipse.cdt.cmake.is.core.internal;
import org.eclipse.cdt.cmake.is.core.IParserPreferencesMetadata;
import org.eclipse.cdt.core.options.BaseOption;
import org.eclipse.cdt.core.options.OptionMetadata;
import org.eclipse.core.runtime.preferences.PreferenceMetadata;
/**
* @author weber
*/
final class ParserPreferencesMetadata implements IParserPreferencesMetadata {
private final OptionMetadata<Boolean> tryVersionSuffixOption;
private final OptionMetadata<String> versionSuffixPatternOption;
private final OptionMetadata<Boolean> allocateConsoleOption;
private final PreferenceMetadata<Boolean> tryVersionSuffixOption;
private final PreferenceMetadata<String> versionSuffixPatternOption;
private final PreferenceMetadata<Boolean> allocateConsoleOption;
public ParserPreferencesMetadata() {
this.tryVersionSuffixOption = new BaseOption<>(Boolean.class, "versionSuffixPatternEnabled", false, //$NON-NLS-1$
this.tryVersionSuffixOption = new PreferenceMetadata<>(Boolean.class, "versionSuffixPatternEnabled", false, //$NON-NLS-1$
Messages.ParserPreferencesMetadata_label_try_suffix,
Messages.ParserPreferencesMetadata_ttip_try_suffix);
this.versionSuffixPatternOption = new BaseOption<>(String.class, "versionSuffixPattern", "-?\\d+(\\.\\d+)*", //$NON-NLS-1$ //$NON-NLS-2$
this.versionSuffixPatternOption = new PreferenceMetadata<>(String.class, "versionSuffixPattern", //$NON-NLS-1$
"-?\\d+(\\.\\d+)*", //$NON-NLS-1$
Messages.ParserPreferencesMetadata_label_suffix, Messages.ParserPreferencesMetadata_ttip_suffix);
this.allocateConsoleOption = new BaseOption<>(Boolean.class, "allocateConsole", false, //$NON-NLS-1$
this.allocateConsoleOption = new PreferenceMetadata<>(Boolean.class, "allocateConsole", false, //$NON-NLS-1$
Messages.ParserPreferencesMetadata_label_console);
}
@Override
public OptionMetadata<Boolean> tryVersionSuffix() {
public PreferenceMetadata<Boolean> tryVersionSuffix() {
return tryVersionSuffixOption;
}
@Override
public OptionMetadata<String> versionSuffixPattern() {
public PreferenceMetadata<String> versionSuffixPattern() {
return versionSuffixPatternOption;
}
@Override
public OptionMetadata<Boolean> allocateConsole() {
public PreferenceMetadata<Boolean> allocateConsole() {
return allocateConsoleOption;
}
}

View file

@ -11,6 +11,7 @@
# Contributors:
# Martin Weber - initial API and implementation
###############################################################################
ParserPreferencesAccess_e_get_preferences=Unable to get preferences for node: {0}.{1}
ParserPreferencesMetadata_label_console=&Show output of compiler built-in detection in a console in the Console View
ParserPreferencesMetadata_label_suffix=&Suffix pattern:
ParserPreferencesMetadata_label_try_suffix=&Also try with version suffix