mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 565154 - Delete CDT Core Options API
Removed org.eclipse.cdt.core.options package Removed org.eclipse.cdt.internal.core.options package Removed corresponding tests Updated documentation Change-Id: Iac3ae1328e9eec3c8db0a633de68bde71573b736 Signed-off-by: Alexander Fedorov <alexander.fedorov@arsysop.ru>
This commit is contained in:
parent
45c979c400
commit
76497af249
14 changed files with 14 additions and 646 deletions
|
@ -11,5 +11,4 @@ Require-Bundle: org.eclipse.core.runtime,
|
|||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Automatic-Module-Name: org.eclipse.cdt.cmake.is.core.ui
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Import-Package: org.eclipse.cdt.core.options,
|
||||
org.eclipse.e4.core.contexts
|
||||
Import-Package: org.eclipse.e4.core.contexts
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2020 ArSysOp and others.
|
||||
*
|
||||
* This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License 2.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.internal.tests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.eclipse.cdt.core.options.BaseOption;
|
||||
import org.junit.Test;
|
||||
|
||||
public class BaseOptionTest {
|
||||
|
||||
@Test
|
||||
public void testBaseOption() {
|
||||
BaseOption<String> option = new BaseOption<>(String.class, "identifier", "default", "name", "description");
|
||||
assertEquals("identifier", option.identifer());
|
||||
assertEquals("default", option.defaultValue());
|
||||
assertEquals("name", option.name());
|
||||
assertEquals("description", option.description());
|
||||
assertEquals(String.class, option.valueClass());
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testBaseOptionNullValueType() {
|
||||
new BaseOption<>(null, "identifier", "default", "name", "description");
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testBaseOptionNullIdentifier() {
|
||||
new BaseOption<>(Object.class, null, "default", "name", "description");
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testBaseOptionNullDefaultValue() {
|
||||
new BaseOption<>(Object.class, "identifier", null, "name", "description");
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testBaseOptionNullName() {
|
||||
new BaseOption<>(Object.class, "identifier", "default", null, "description");
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testBaseOptionNullDescription() {
|
||||
new BaseOption<>(Object.class, "identifier", "default", "name", null);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,195 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2020 ArSysOp and others.
|
||||
*
|
||||
* This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License 2.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.internal.tests;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.eclipse.cdt.core.options.BaseOption;
|
||||
import org.eclipse.cdt.core.options.OsgiPreferenceStorage;
|
||||
import org.junit.Test;
|
||||
import org.osgi.service.prefs.Preferences;
|
||||
|
||||
public class OsgiPreferenceStorageTest {
|
||||
|
||||
private final BaseOption<Object> unknown = new BaseOption<>(Object.class, "unknown", "", "Unknown",
|
||||
"An option with unclear semantic, i.e. typical one");
|
||||
private final BaseOption<String> string2020 = new BaseOption<>(String.class, "string2020", "2020", "String 2020");
|
||||
private final BaseOption<Boolean> negative = new BaseOption<>(Boolean.class, "negative", false, "Negative");
|
||||
private final BaseOption<Boolean> positive = new BaseOption<>(Boolean.class, "positive", true, "Positive");
|
||||
private final BaseOption<byte[]> bytes2020 = new BaseOption<>(byte[].class, "bytes2020", new byte[] { 20, 20 },
|
||||
"Bytes 2020");
|
||||
private final BaseOption<Double> double2020 = new BaseOption<>(Double.class, "double2020", 2020d, "Double 2020");
|
||||
private final BaseOption<Float> float2020 = new BaseOption<>(Float.class, "float2020", 2020f, "Float 2020");
|
||||
private final BaseOption<Integer> int2020 = new BaseOption<>(Integer.class, "int2020", 2020, "Int 2020");
|
||||
private final BaseOption<Long> long2020 = new BaseOption<>(Long.class, "long2020", 2020l, "Long 2020");
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testNullPreferences() {
|
||||
OsgiPreferenceStorage storage = new OsgiPreferenceStorage(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConsumable() {
|
||||
Preferences preferences = anyPreferences();
|
||||
OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
|
||||
assertFalse(storage.consumable(Object.class));
|
||||
assertTrue(storage.consumable(String.class));
|
||||
assertTrue(storage.consumable(Boolean.class));
|
||||
assertTrue(storage.consumable(byte[].class));
|
||||
assertFalse(storage.consumable(Byte[].class));
|
||||
assertTrue(storage.consumable(Double.class));
|
||||
assertTrue(storage.consumable(Float.class));
|
||||
assertTrue(storage.consumable(Integer.class));
|
||||
assertTrue(storage.consumable(Long.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadString() {
|
||||
Preferences preferences = anyPreferences();
|
||||
OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
|
||||
preferences.put(string2020.identifer(), "2002");
|
||||
assertEquals("2002", storage.load(string2020));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadBoolean() {
|
||||
Preferences preferences = anyPreferences();
|
||||
OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
|
||||
preferences.putBoolean(negative.identifer(), true);
|
||||
assertEquals(true, storage.load(negative));
|
||||
preferences.putBoolean(positive.identifer(), false);
|
||||
assertEquals(false, storage.load(positive));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadByteArray() {
|
||||
Preferences preferences = anyPreferences();
|
||||
OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
|
||||
preferences.putByteArray(bytes2020.identifer(), new byte[] { 20, 02 });
|
||||
assertArrayEquals(new byte[] { 20, 02 }, storage.load(bytes2020));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadDouble() {
|
||||
Preferences preferences = anyPreferences();
|
||||
OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
|
||||
preferences.putDouble(double2020.identifer(), 2002d);
|
||||
assertEquals(2002d, storage.load(double2020), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadFloat() {
|
||||
Preferences preferences = anyPreferences();
|
||||
OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
|
||||
preferences.putFloat(float2020.identifer(), 2002f);
|
||||
assertEquals(2002f, storage.load(float2020), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadInt() {
|
||||
Preferences preferences = anyPreferences();
|
||||
OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
|
||||
preferences.putLong(int2020.identifer(), 2002l);
|
||||
assertEquals(2002l, (long) storage.load(int2020));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadLong() {
|
||||
Preferences preferences = anyPreferences();
|
||||
OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
|
||||
preferences.putLong(long2020.identifer(), 2002l);
|
||||
assertEquals(2002l, (long) storage.load(long2020));
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testLoadUnknown() {
|
||||
Preferences preferences = anyPreferences();
|
||||
OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
|
||||
assertEquals(new Object(), storage.load(unknown));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveString() {
|
||||
Preferences anyPreferences = anyPreferences();
|
||||
OsgiPreferenceStorage storage = new OsgiPreferenceStorage(anyPreferences);
|
||||
storage.save("2002", string2020);
|
||||
assertEquals("2002", anyPreferences.get(string2020.identifer(), string2020.defaultValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveBoolean() {
|
||||
Preferences anyPreferences = anyPreferences();
|
||||
OsgiPreferenceStorage storage = new OsgiPreferenceStorage(anyPreferences);
|
||||
storage.save(true, negative);
|
||||
assertEquals(true, anyPreferences.getBoolean(negative.identifer(), negative.defaultValue()));
|
||||
storage.save(false, positive);
|
||||
assertEquals(false, anyPreferences.getBoolean(positive.identifer(), positive.defaultValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveByteArray() {
|
||||
Preferences anyPreferences = anyPreferences();
|
||||
OsgiPreferenceStorage storage = new OsgiPreferenceStorage(anyPreferences);
|
||||
storage.save(new byte[] { 20, 02 }, bytes2020);
|
||||
assertArrayEquals(new byte[] { 20, 02 },
|
||||
anyPreferences.getByteArray(bytes2020.identifer(), bytes2020.defaultValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveDouble() {
|
||||
Preferences preferences = anyPreferences();
|
||||
OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
|
||||
storage.save(2002d, double2020);
|
||||
assertEquals(2002d, preferences.getDouble(double2020.identifer(), double2020.defaultValue()), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveFloat() {
|
||||
Preferences preferences = anyPreferences();
|
||||
OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
|
||||
storage.save(2002f, float2020);
|
||||
assertEquals(2002f, preferences.getDouble(float2020.identifer(), float2020.defaultValue()), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveInt() {
|
||||
Preferences preferences = anyPreferences();
|
||||
OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
|
||||
storage.save(2002, int2020);
|
||||
assertEquals(2002, preferences.getInt(int2020.identifer(), int2020.defaultValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveLong() {
|
||||
Preferences preferences = anyPreferences();
|
||||
OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
|
||||
storage.save(2002l, long2020);
|
||||
assertEquals(2002l, preferences.getLong(long2020.identifer(), long2020.defaultValue()));
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testSaveUnknown() {
|
||||
Preferences preferences = anyPreferences();
|
||||
OsgiPreferenceStorage storage = new OsgiPreferenceStorage(preferences);
|
||||
storage.save(new Object(), unknown);
|
||||
}
|
||||
|
||||
private Preferences anyPreferences() {
|
||||
return new org.eclipse.core.internal.preferences.EclipsePreferences();
|
||||
}
|
||||
|
||||
}
|
|
@ -21,8 +21,6 @@ import org.eclipse.cdt.core.cdescriptor.tests.CDescriptorTests;
|
|||
import org.eclipse.cdt.core.envvar.IEnvironmentVariableManagerTests;
|
||||
import org.eclipse.cdt.core.internal.efsextension.tests.EFSExtensionTests;
|
||||
import org.eclipse.cdt.core.internal.errorparsers.tests.ErrorParserTests;
|
||||
import org.eclipse.cdt.core.internal.tests.BaseOptionTest;
|
||||
import org.eclipse.cdt.core.internal.tests.OsgiPreferenceStorageTest;
|
||||
import org.eclipse.cdt.core.internal.tests.PositionTrackerTests;
|
||||
import org.eclipse.cdt.core.internal.tests.ResourceLookupTests;
|
||||
import org.eclipse.cdt.core.internal.tests.StringBuilderTest;
|
||||
|
@ -87,8 +85,6 @@ public class AutomatedIntegrationSuite extends TestSuite {
|
|||
suite.addTest(AllCoreTests.suite());
|
||||
suite.addTest(ElementDeltaTests.suite());
|
||||
suite.addTest(WorkingCopyTests.suite());
|
||||
suite.addTest(new JUnit4TestAdapter(BaseOptionTest.class));
|
||||
suite.addTest(new JUnit4TestAdapter(OsgiPreferenceStorageTest.class));
|
||||
suite.addTest(PositionTrackerTests.suite());
|
||||
suite.addTest(ResourceLookupTests.suite());
|
||||
suite.addTest(StringBuilderTest.suite());
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
<classpathentry kind="src" path="utils"/>
|
||||
<classpathentry kind="src" path="parser"/>
|
||||
<classpathentry kind="src" path="templateengine"/>
|
||||
<classpathentry kind="src" path="options"/>
|
||||
<classpathentry kind="src" path="doxygen"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
|
@ -33,7 +33,6 @@ Export-Package: org.eclipse.cdt.core,
|
|||
org.eclipse.cdt.core.language.settings.providers,
|
||||
org.eclipse.cdt.core.model,
|
||||
org.eclipse.cdt.core.model.util,
|
||||
org.eclipse.cdt.core.options;x-friends:="org.eclipse.cdt.ui",
|
||||
org.eclipse.cdt.core.parser,
|
||||
org.eclipse.cdt.core.parser.ast,
|
||||
org.eclipse.cdt.core.parser.util,
|
||||
|
@ -84,7 +83,6 @@ Export-Package: org.eclipse.cdt.core,
|
|||
org.eclipse.cdt.debug.ui,
|
||||
org.eclipse.cdt.codan.ui",
|
||||
org.eclipse.cdt.internal.core.model.ext;x-friends:="org.eclipse.cdt.ui",
|
||||
org.eclipse.cdt.internal.core.options;x-internal:=true,
|
||||
org.eclipse.cdt.internal.core.parser;x-internal:=true,
|
||||
org.eclipse.cdt.internal.core.parser.problem;x-internal:=true,
|
||||
org.eclipse.cdt.internal.core.parser.scanner;x-friends:="org.eclipse.cdt.ui",
|
||||
|
|
|
@ -34,6 +34,5 @@ source.. = src/,\
|
|||
parser/,\
|
||||
browser/,\
|
||||
templateengine/,\
|
||||
options/,\
|
||||
doxygen/,\
|
||||
utils/
|
||||
|
|
|
@ -1,99 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2020 ArSysOp and others.
|
||||
*
|
||||
* This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License 2.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.options;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.eclipse.cdt.internal.core.options.OptionMessages;
|
||||
|
||||
/**
|
||||
* The base implementation for option metadata
|
||||
*
|
||||
* @param <V> the value type for the option
|
||||
*
|
||||
* @see OptionMetadata
|
||||
* @see OptionStorage
|
||||
*/
|
||||
public final class BaseOption<V> implements OptionMetadata<V> {
|
||||
|
||||
private final Class<V> clazz;
|
||||
private final String identifier;
|
||||
private final V defaultValue;
|
||||
private final String name;
|
||||
private final String description;
|
||||
|
||||
/**
|
||||
* Created an instance of BaseOption using name as description
|
||||
*
|
||||
* @param clazz the value type of the option, must not be <code>null</code>
|
||||
* @param identifier the identifier of the option, must not be <code>null</code>
|
||||
* @param defaultValue the default value of the option, must not be <code>null</code>
|
||||
* @param name the name of the option, must not be <code>null</code>
|
||||
*
|
||||
* @see BaseOption#BaseOption(Class, String, Object, String, String)
|
||||
*/
|
||||
public BaseOption(Class<V> clazz, String identifier, V defaultValue, String name) {
|
||||
this(clazz, identifier, defaultValue, name, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Created an instance of BaseOption of all the the given parameters
|
||||
*
|
||||
* @param clazz the value type of the option, must not be <code>null</code>
|
||||
* @param identifier the identifier of the option, must not be <code>null</code>
|
||||
* @param defaultValue the default value of the option, must not be <code>null</code>
|
||||
* @param name the name of the option, must not be <code>null</code>
|
||||
* @param description the description of the option, must not be <code>null</code>
|
||||
*
|
||||
* @see BaseOption#BaseOption(Class, String, Object, String)
|
||||
*/
|
||||
public BaseOption(Class<V> clazz, String identifier, V defaultValue, String name, String description) {
|
||||
Objects.requireNonNull(clazz, OptionMessages.BaseOption_e_null_value_type);
|
||||
Objects.requireNonNull(identifier, OptionMessages.BaseOption_e_null_identifier);
|
||||
Objects.requireNonNull(defaultValue, OptionMessages.BaseOption_e_null_default_value);
|
||||
Objects.requireNonNull(name, OptionMessages.BaseOption_e_null_name);
|
||||
Objects.requireNonNull(description, OptionMessages.BaseOption_e_null_description);
|
||||
this.clazz = clazz;
|
||||
this.identifier = identifier;
|
||||
this.defaultValue = defaultValue;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String identifer() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V defaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<V> valueClass() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2020 ArSysOp and others.
|
||||
*
|
||||
* This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License 2.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.options;
|
||||
|
||||
/**
|
||||
* The option metadata provides the information needed to configure
|
||||
* everything about the option except the option value itself.
|
||||
*
|
||||
* @param <V> the value type for the option
|
||||
*/
|
||||
public interface OptionMetadata<V> {
|
||||
|
||||
/**
|
||||
* The option identifier to use as a key to access the option value.
|
||||
* Must not be <code>null</code>.
|
||||
*
|
||||
* @return the identifier
|
||||
*/
|
||||
String identifer();
|
||||
|
||||
/**
|
||||
* The default value for the option. Must not be <code>null</code>.
|
||||
*
|
||||
* @return the option's default value
|
||||
*/
|
||||
V defaultValue();
|
||||
|
||||
/**
|
||||
* Briefly describes the option purpose, intended to be used in UI.
|
||||
* Must not be <code>null</code> and should be localized. Should not be blank.
|
||||
*
|
||||
* @return the option's name
|
||||
*/
|
||||
String name();
|
||||
|
||||
/**
|
||||
* Widely describes the option purpose, intended to be used in UI.
|
||||
* Must not be <code>null</code> and should be localized. May be blank.
|
||||
*
|
||||
* @return the option's description
|
||||
*/
|
||||
String description();
|
||||
|
||||
/**
|
||||
* The type of option value needed to perform type checks. Must not be <code>null</code>.
|
||||
*
|
||||
* @return the value class
|
||||
*/
|
||||
Class<V> valueClass();
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2020 ArSysOp and others.
|
||||
*
|
||||
* This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License 2.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.options;
|
||||
|
||||
/**
|
||||
* Provides metadata-based access to an enclosed storage of options.
|
||||
*
|
||||
*/
|
||||
public interface OptionStorage {
|
||||
|
||||
/**
|
||||
* Checks if the value type can be consumed by an enclosed storage.
|
||||
*
|
||||
* @param <V> the value type for the option
|
||||
* @param valueType the value type to be checked
|
||||
*
|
||||
* @return true if this value type can be consumed by an enclosed storage and false otherwise
|
||||
*/
|
||||
<V> boolean consumable(Class<V> valueType);
|
||||
|
||||
/**
|
||||
* Loads the value of specified option from an enclosed storage.
|
||||
* If the value is not found returns the option default value.
|
||||
*
|
||||
* @param <V> the value type for the option
|
||||
* @param option the option metadata, must not be <code>null</code>.
|
||||
*
|
||||
* @return the option value or default value if option is unknown
|
||||
* @throws UnsupportedOperationException for unsupported option value types
|
||||
*
|
||||
* @see #consumable(Class)
|
||||
* @see OptionMetadata
|
||||
*/
|
||||
<V> V load(OptionMetadata<V> option);
|
||||
|
||||
/**
|
||||
* Saves the value of specified option to the enclosed storage.
|
||||
*
|
||||
* @param <V> the value type for the option
|
||||
* @param value to be saved, must not be <code>null</code>.
|
||||
* @param option the option metadata, must not be <code>null</code>.
|
||||
*
|
||||
* @throws UnsupportedOperationException for unsupported option value types
|
||||
*
|
||||
* @see #consumable(Class)
|
||||
* @see OptionMetadata
|
||||
*/
|
||||
<V> void save(V value, OptionMetadata<V> option);
|
||||
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2020 ArSysOp and others.
|
||||
*
|
||||
* This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License 2.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.options;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.internal.core.options.OptionMessages;
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
import org.osgi.service.prefs.Preferences;
|
||||
|
||||
/**
|
||||
* The option storage implementation that uses OSGi preference node as an enclosed storage.
|
||||
*
|
||||
* @see Preferences
|
||||
*
|
||||
*/
|
||||
public final class OsgiPreferenceStorage implements OptionStorage {
|
||||
|
||||
private final Preferences preferences;
|
||||
private final Set<Class<?>> classes;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param preferences the OSGi preference node, must not be <code>null</code>
|
||||
*/
|
||||
public OsgiPreferenceStorage(Preferences preferences) {
|
||||
Objects.requireNonNull(preferences, OptionMessages.OsgiPreferenceStorage_e_null_preference_node);
|
||||
this.preferences = preferences;
|
||||
this.classes = new HashSet<>();
|
||||
classes.add(String.class);
|
||||
classes.add(Boolean.class);
|
||||
classes.add(byte[].class);
|
||||
classes.add(Double.class);
|
||||
classes.add(Float.class);
|
||||
classes.add(Integer.class);
|
||||
classes.add(Long.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V> boolean consumable(Class<V> valueType) {
|
||||
return classes.contains(valueType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V> V load(OptionMetadata<V> option) {
|
||||
Class<V> valueClass = option.valueClass();
|
||||
String identifer = option.identifer();
|
||||
V defaultValue = option.defaultValue();
|
||||
if (String.class.equals(valueClass)) {
|
||||
return valueClass.cast(preferences.get(identifer, String.class.cast(defaultValue)));
|
||||
} else if (Boolean.class.equals(valueClass)) {
|
||||
return valueClass.cast(preferences.getBoolean(identifer, Boolean.class.cast(defaultValue)));
|
||||
} else if (byte[].class.equals(valueClass)) {
|
||||
return valueClass.cast(preferences.getByteArray(identifer, byte[].class.cast(defaultValue)));
|
||||
} else if (Double.class.equals(valueClass)) {
|
||||
return valueClass.cast(preferences.getDouble(identifer, Double.class.cast(defaultValue)));
|
||||
} else if (Float.class.equals(valueClass)) {
|
||||
return valueClass.cast(preferences.getFloat(identifer, Float.class.cast(defaultValue)));
|
||||
} else if (Integer.class.equals(valueClass)) {
|
||||
return valueClass.cast(preferences.getInt(identifer, Integer.class.cast(defaultValue)));
|
||||
} else if (Long.class.equals(valueClass)) {
|
||||
return valueClass.cast(preferences.getLong(identifer, Long.class.cast(defaultValue)));
|
||||
}
|
||||
String message = OptionMessages.PreferenceStorage_e_load_unsupported;
|
||||
throw new UnsupportedOperationException(NLS.bind(message, option, valueClass));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V> void save(V value, OptionMetadata<V> option) {
|
||||
Class<V> valueClass = option.valueClass();
|
||||
String identifer = option.identifer();
|
||||
if (String.class.equals(valueClass)) {
|
||||
preferences.put(identifer, String.class.cast(value));
|
||||
} else if (Boolean.class.equals(valueClass)) {
|
||||
preferences.putBoolean(identifer, Boolean.class.cast(value));
|
||||
} else if (byte[].class.equals(valueClass)) {
|
||||
preferences.putByteArray(identifer, byte[].class.cast(value));
|
||||
} else if (Double.class.equals(valueClass)) {
|
||||
preferences.putDouble(identifer, Double.class.cast(value));
|
||||
} else if (Float.class.equals(valueClass)) {
|
||||
preferences.putFloat(identifer, Float.class.cast(value));
|
||||
} else if (Integer.class.equals(valueClass)) {
|
||||
preferences.putInt(identifer, Integer.class.cast(value));
|
||||
} else if (Long.class.equals(valueClass)) {
|
||||
preferences.putLong(identifer, Long.class.cast(value));
|
||||
} else {
|
||||
String message = OptionMessages.PreferenceStorage_e_save_unsupported;
|
||||
throw new UnsupportedOperationException(NLS.bind(message, option, valueClass));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2020 ArSysOp and others.
|
||||
*
|
||||
* This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License 2.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.options;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
public class OptionMessages extends NLS {
|
||||
private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.core.options.OptionMessages"; //$NON-NLS-1$
|
||||
public static String BaseOption_e_null_default_value;
|
||||
public static String BaseOption_e_null_description;
|
||||
public static String BaseOption_e_null_identifier;
|
||||
public static String BaseOption_e_null_name;
|
||||
public static String BaseOption_e_null_value_type;
|
||||
public static String OsgiPreferenceStorage_e_null_preference_node;
|
||||
public static String PreferenceStorage_e_load_unsupported;
|
||||
public static String PreferenceStorage_e_save_unsupported;
|
||||
static {
|
||||
// initialize resource bundle
|
||||
NLS.initializeMessages(BUNDLE_NAME, OptionMessages.class);
|
||||
}
|
||||
|
||||
private OptionMessages() {
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
###############################################################################
|
||||
# Copyright (c) 2020 ArSysOp and others.
|
||||
#
|
||||
# This program and the accompanying materials
|
||||
# are made available under the terms of the Eclipse Public License 2.0
|
||||
# which accompanies this distribution, and is available at
|
||||
# https://www.eclipse.org/legal/epl-2.0/
|
||||
#
|
||||
# SPDX-License-Identifier: EPL-2.0
|
||||
#
|
||||
# Contributors:
|
||||
# Alexander Fedorov <alexander.fedorov@arsysop.ru> - Initial API and implementation
|
||||
###############################################################################
|
||||
|
||||
BaseOption_e_null_default_value=Option default value must not be null
|
||||
BaseOption_e_null_description=Option description must not be null
|
||||
BaseOption_e_null_identifier=Option identifier must not be null
|
||||
BaseOption_e_null_name=Option name must not be null
|
||||
BaseOption_e_null_value_type=Option value type must not be null
|
||||
OsgiPreferenceStorage_e_null_preference_node=Preference node must not be null
|
||||
PreferenceStorage_e_load_unsupported=Failed to load value for option {0}: class {1} is unsupported
|
||||
PreferenceStorage_e_save_unsupported=Failed to save value for option {0}: class {1} is unsupported
|
|
@ -42,6 +42,7 @@
|
|||
<li><a href="#cdtutilsPlatform">Remove org.eclipse.cdt.utils.Platform.</a></li>
|
||||
<li><a href="#dsf">DSF and DSF-GDB API Changes.</a></li>
|
||||
<li><a href="#oldStyleProjects">Partial removal of CDT 3.X project support.</a></li>
|
||||
<li><a href="#optionsAPI">Removal of CDT Core Options API.</a></li>
|
||||
</ol>
|
||||
<p>
|
||||
Planned Removals after June 2022
|
||||
|
@ -215,6 +216,18 @@
|
|||
See <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=564949" target="_blank">Bug 564949</a>.
|
||||
</p>
|
||||
|
||||
<h3>11. <a name="optionsAPI">Removal of CDT Core Options API</a></h3>
|
||||
<p>
|
||||
The CDT Core Options API and implementation has been removed as now it is a part of Eclipse Equinox 4.16 Preferences API, the removed packages are:
|
||||
<ul>
|
||||
<li>org.eclipse.cdt.core.options</li>
|
||||
<li>org.eclipse.cdt.internal.core.options</li>
|
||||
</ul>
|
||||
</p>
|
||||
<p>
|
||||
See <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=565154" target="_blank">Bug 565154</a>.
|
||||
</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<h2>Future Deletions</h2>
|
||||
|
|
Loading…
Add table
Reference in a new issue