Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.e4.core.di.extensions/src/org/eclipse/e4/core/di/internal/extensions/PreferencesObjectSupplier.java12
-rw-r--r--tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionPreferencesTest.java32
2 files changed, 37 insertions, 7 deletions
diff --git a/bundles/org.eclipse.e4.core.di.extensions/src/org/eclipse/e4/core/di/internal/extensions/PreferencesObjectSupplier.java b/bundles/org.eclipse.e4.core.di.extensions/src/org/eclipse/e4/core/di/internal/extensions/PreferencesObjectSupplier.java
index fc05a940f..2ddb30f89 100644
--- a/bundles/org.eclipse.e4.core.di.extensions/src/org/eclipse/e4/core/di/internal/extensions/PreferencesObjectSupplier.java
+++ b/bundles/org.eclipse.e4.core.di.extensions/src/org/eclipse/e4/core/di/internal/extensions/PreferencesObjectSupplier.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2010, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -72,9 +72,9 @@ public class PreferencesObjectSupplier extends ExtendedObjectSupplier {
if (descriptor == null)
return null;
Class<?> descriptorsClass = getDesiredClass(descriptor.getDesiredType());
- String nodePath = getNodePath(descriptor, requestor.getRequestingObject());
+ String nodePath = getNodePath(descriptor, requestor.getRequestingObjectClass());
if (IEclipsePreferences.class.equals(descriptorsClass)) {
- return (new InstanceScope()).getNode(nodePath);
+ return InstanceScope.INSTANCE.getNode(nodePath);
}
String key = getKey(descriptor);
@@ -132,7 +132,7 @@ public class PreferencesObjectSupplier extends ExtendedObjectSupplier {
return qualifier.value();
}
- private String getNodePath(IObjectDescriptor descriptor, Object requestingObject) {
+ private String getNodePath(IObjectDescriptor descriptor, Class<?> requestingObject) {
if (descriptor == null)
return null;
Preference qualifier = descriptor.getQualifier(Preference.class);
@@ -141,7 +141,7 @@ public class PreferencesObjectSupplier extends ExtendedObjectSupplier {
if (nodePath == null || nodePath.length() == 0) {
if (requestingObject == null)
return null;
- nodePath = FrameworkUtil.getBundle(requestingObject.getClass()).getSymbolicName();
+ nodePath = FrameworkUtil.getBundle(requestingObject).getSymbolicName();
}
return nodePath;
}
@@ -162,7 +162,7 @@ public class PreferencesObjectSupplier extends ExtendedObjectSupplier {
}
}
}
- final IEclipsePreferences node = new InstanceScope().getNode(nodePath);
+ final IEclipsePreferences node = InstanceScope.INSTANCE.getNode(nodePath);
PrefInjectionListener listener = new PrefInjectionListener(node, requestor);
node.addPreferenceChangeListener(listener);
diff --git a/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionPreferencesTest.java b/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionPreferencesTest.java
index 18eee0504..ead97649c 100644
--- a/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionPreferencesTest.java
+++ b/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionPreferencesTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2010, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -132,6 +132,18 @@ public class InjectionPreferencesTest extends TestCase {
}
}
+ static class InjectTargetConstructor {
+ public String pref;
+ public String prefNode;
+
+ @Inject
+ public InjectTargetConstructor(@Preference(TEST_PREFS_KEY) String string, @Preference(value=TEST_PREFS_KEY, nodePath=TEST_PREFS_NODE) String stringNode) {
+ pref = string;
+ prefNode = stringNode;
+
+ }
+ }
+
public void testPreferencesQualifier() throws BackingStoreException {
setPreference(TEST_PREFS_KEY, "abc");
setPreference(TEST_PREFS_KEY, TEST_PREFS_NODE, "123");
@@ -255,4 +267,22 @@ public class InjectionPreferencesTest extends TestCase {
node.flush();
}
+ public void testPreferencesConstructor() throws BackingStoreException {
+ setPreference(TEST_PREFS_KEY, "abc");
+ setPreference(TEST_PREFS_KEY, TEST_PREFS_NODE, "123");
+ IEclipseContext context = EclipseContextFactory.create();
+ InjectTargetConstructor target = ContextInjectionFactory.make(InjectTargetConstructor.class, context);
+ // default node
+ assertEquals("abc", target.pref);
+ // specific node
+ assertEquals("123", target.prefNode);
+
+ // change
+ setPreference(TEST_PREFS_KEY, "xyz");
+ setPreference(TEST_PREFS_KEY, TEST_PREFS_NODE, "456");
+
+ // values should stay the same - no tracking for constructor injection
+ assertEquals("abc", target.pref);
+ assertEquals("123", target.prefNode);
+ }
}

Back to the top