Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 304859
Collapse All | Expand All

(-)src/org/eclipse/e4/core/services/internal/context/Computation.java (-3 / +9 lines)
Lines 97-110 Link Here
97
	/**
97
	/**
98
	 * Remove this computation from all contexts that are tracking it
98
	 * Remove this computation from all contexts that are tracking it
99
	 */
99
	 */
100
	protected void removeAll() {
100
	protected void removeAll(EclipseContext originatingContext) {
101
		for (Iterator it = dependencies.keySet().iterator(); it.hasNext();) {
101
		for (Iterator it = dependencies.keySet().iterator(); it.hasNext();) {
102
			((EclipseContext) it.next()).listeners.remove(this);
102
			((EclipseContext) it.next()).listeners.remove(this);
103
		}
103
		}
104
		dependencies.clear();
104
		dependencies.clear();
105
		// Bug 304859
106
		originatingContext.listeners.remove(this);
105
	}
107
	}
106
108
107
	void startListening() {
109
	void startListening(EclipseContext originatingContext) {
108
		if (EclipseContext.DEBUG)
110
		if (EclipseContext.DEBUG)
109
			System.out.println(toString() + " now listening to: " //$NON-NLS-1$
111
			System.out.println(toString() + " now listening to: " //$NON-NLS-1$
110
					+ mapToString(dependencies));
112
					+ mapToString(dependencies));
Lines 131-136 Link Here
131
			} else
133
			} else
132
				c.listeners.add(this);
134
				c.listeners.add(this);
133
		}
135
		}
136
		// Bug 304859
137
		if (!dependencies.containsKey(originatingContext))
138
			originatingContext.listeners.remove(this);
134
	}
139
	}
135
140
136
	protected void stopListening(IEclipseContext context, String name) {
141
	protected void stopListening(IEclipseContext context, String name) {
Lines 145-151 Link Here
145
		if (properties != null) {
150
		if (properties != null) {
146
			if (EclipseContext.DEBUG)
151
			if (EclipseContext.DEBUG)
147
				System.out.println(toString() + " no longer listening to " + context + "," + name); //$NON-NLS-1$
152
				System.out.println(toString() + " no longer listening to " + context + "," + name); //$NON-NLS-1$
148
			((EclipseContext) context).listeners.remove(this); // XXX
153
			// Bug 304859 - causes reordering of listeners
154
			// ((EclipseContext) context).listeners.remove(this); // XXX
149
			// IEclipseContext
155
			// IEclipseContext
150
			properties.remove(name);
156
			properties.remove(name);
151
			// if we no longer track any values in the context, remove dependency
157
			// if we no longer track any values in the context, remove dependency
(-)src/org/eclipse/e4/core/services/internal/context/EclipseContext.java (-2 / +3 lines)
Lines 154-163 Link Here
154
			} finally {
154
			} finally {
155
				currentComputation.set(oldComputation);
155
				currentComputation.set(oldComputation);
156
			}
156
			}
157
			EclipseContext eventsContext = (EclipseContext) ((ObjectProviderContext) event.getContext()).getContext();
157
			if (result)
158
			if (result)
158
				startListening();
159
				startListening(eventsContext);
159
			else
160
			else
160
				removeAll();
161
				removeAll(eventsContext);
161
			return result;
162
			return result;
162
		}
163
		}
163
164
(-)src/org/eclipse/e4/core/services/internal/context/ValueComputation.java (-2 / +2 lines)
Lines 115-121 Link Here
115
			IObjectProvider provider = event.getContext();
115
			IObjectProvider provider = event.getContext();
116
			IEclipseContext eventsContext = ((ObjectProviderContext) provider).getContext();
116
			IEclipseContext eventsContext = ((ObjectProviderContext) provider).getContext();
117
			if (originatingContext.equals(eventsContext)) {
117
			if (originatingContext.equals(eventsContext)) {
118
				removeAll();
118
				removeAll(originatingContext);
119
				return;
119
				return;
120
			}
120
			}
121
		}
121
		}
Lines 145-151 Link Here
145
			EclipseContext.currentComputation.set(oldComputation); // XXX
145
			EclipseContext.currentComputation.set(oldComputation); // XXX
146
			// IEclipseContext
146
			// IEclipseContext
147
		}
147
		}
148
		startListening();
148
		startListening(originatingContext);
149
		return cachedValue;
149
		return cachedValue;
150
	}
150
	}
151
151
(-)src/org/eclipse/e4/core/tests/services/internal/annotations/InjectionOrderTest.java (+69 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.e4.core.tests.services.internal.annotations;
12
13
import javax.inject.Inject;
14
import javax.inject.Named;
15
16
import junit.framework.TestCase;
17
18
import org.eclipse.e4.core.services.IDisposable;
19
import org.eclipse.e4.core.services.annotations.PreDestroy;
20
import org.eclipse.e4.core.services.context.EclipseContextFactory;
21
import org.eclipse.e4.core.services.context.IEclipseContext;
22
import org.eclipse.e4.core.services.context.spi.ContextInjectionFactory;
23
24
public class InjectionOrderTest extends TestCase {
25
26
	public static class InjectTargetMethod {
27
		Object o;
28
29
		@Inject
30
		void set(@Named("inject") Object o) {
31
			this.o = o;
32
		}
33
34
		@PreDestroy
35
		void pd() {
36
			assertNotNull(o);
37
		}
38
	}
39
40
	public static class InjectTargetField {
41
		@Inject @Named("inject")
42
		Object o;
43
44
		@PreDestroy
45
		void pd() {
46
			assertNotNull(o);
47
		}
48
	}
49
50
	public void testDisposeMethod() throws Exception {
51
		IEclipseContext appContext = EclipseContextFactory.create();
52
		appContext.set("inject", "a");
53
54
		ContextInjectionFactory.make(InjectTargetMethod.class, appContext);
55
		appContext.set("inject", "b");
56
57
		((IDisposable) appContext).dispose();
58
	}
59
	
60
	public void testDisposeField() throws Exception {
61
		IEclipseContext appContext = EclipseContextFactory.create();
62
		appContext.set("inject", "a");
63
64
		ContextInjectionFactory.make(InjectTargetField.class, appContext);
65
		appContext.set("inject", "b");
66
67
		((IDisposable) appContext).dispose();
68
	}
69
}
(-)src/org/eclipse/e4/core/tests/services/internal/annotations/ServicesTestSuiteAnnotations.java (+1 lines)
Lines 26-30 Link Here
26
		addTestSuite(ProviderInjectionTest.class);
26
		addTestSuite(ProviderInjectionTest.class);
27
		addTestSuite(InjectionUpdateTest.class);
27
		addTestSuite(InjectionUpdateTest.class);
28
		addTestSuite(DisposingReferencedContextTest.class);
28
		addTestSuite(DisposingReferencedContextTest.class);
29
		addTestSuite(InjectionOrderTest.class);
29
	}
30
	}
30
}
31
}

Return to bug 304859