Bug 463520 - Useing @Adapt in Handlers makes the system call the method
whenever the value changes
diff --git a/bundles/runtime/org.eclipse.fx.core.di.context.tests/src/org/eclipse/fx/core/di/context/tests/AdaptSupplierTestCase.java b/bundles/runtime/org.eclipse.fx.core.di.context.tests/src/org/eclipse/fx/core/di/context/tests/AdaptSupplierTestCase.java
index ff49dee..c2a26aa 100644
--- a/bundles/runtime/org.eclipse.fx.core.di.context.tests/src/org/eclipse/fx/core/di/context/tests/AdaptSupplierTestCase.java
+++ b/bundles/runtime/org.eclipse.fx.core.di.context.tests/src/org/eclipse/fx/core/di/context/tests/AdaptSupplierTestCase.java
@@ -18,6 +18,7 @@
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.EclipseContextFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.fx.core.adapter.Adapt;
import org.eclipse.fx.core.adapter.AdapterProvider;
import org.eclipse.fx.core.adapter.AdapterService.ValueAccess;
@@ -41,6 +42,13 @@
@Adapt
@Named("test")
Double doubleValue;
+
+ int executeCalled;
+
+ @Execute
+ public void callMe(@Adapt @Named("test") Double doubleValue) {
+ this.executeCalled++;
+ }
}
/**
@@ -69,6 +77,12 @@
Assert.assertEquals(15,bean.integerValue.intValue());
Assert.assertEquals(15.0,bean.doubleValue.doubleValue(),0.0);
+ ContextInjectionFactory.invoke(bean, Execute.class, serviceContext);
+ Assert.assertEquals(1,bean.executeCalled);
+
+ serviceContext.set("test", "16");
+ Assert.assertEquals(1,bean.executeCalled);
+
r1.unregister();
r2.unregister();
}
diff --git a/bundles/runtime/org.eclipse.fx.core.di.context/src/org/eclipse/fx/core/di/context/internal/AdaptValueSupplier.java b/bundles/runtime/org.eclipse.fx.core.di.context/src/org/eclipse/fx/core/di/context/internal/AdaptValueSupplier.java
index df86923..5cacde3 100644
--- a/bundles/runtime/org.eclipse.fx.core.di.context/src/org/eclipse/fx/core/di/context/internal/AdaptValueSupplier.java
+++ b/bundles/runtime/org.eclipse.fx.core.di.context/src/org/eclipse/fx/core/di/context/internal/AdaptValueSupplier.java
@@ -36,7 +36,6 @@
@SuppressWarnings("restriction")
public class AdaptValueSupplier extends ExtendedObjectSupplier {
- @SuppressWarnings("null")
@Override
public Object get(IObjectDescriptor descriptor, IRequestor requestor, boolean track, boolean group) {
Requestor<?> r = (Requestor<?>) requestor;
@@ -55,19 +54,23 @@
AtomicInteger i = new AtomicInteger();
AtomicReference<Object> ref = new AtomicReference<>();
Dummy dummy = r.getInjector().make(Dummy.class, r.getPrimarySupplier());
- dummy.context.runAndTrack(new RunAndTrack() {
+ if( track ) {
+ dummy.context.runAndTrack(new RunAndTrack() {
- @Override
- public boolean changed(IEclipseContext context) {
- if( i.getAndIncrement() == 1 ) {
- requestor.resolveArguments(false);
- requestor.execute();
- return false;
+ @Override
+ public boolean changed(IEclipseContext context) {
+ if( i.getAndIncrement() == 1 ) {
+ requestor.resolveArguments(false);
+ requestor.execute();
+ return false;
+ }
+ ref.set(dummy.context.get(key));
+ return true;
}
- ref.set(dummy.context.get(key));
- return true;
- }
- });
+ });
+ } else {
+ ref.set(dummy.context.get(key));
+ }
if( ref.get() != null ) {
if( dummy.adapterService.canAdapt(ref.get(), desiredClass) ) {
return dummy.adapterService.adapt(ref.get(), desiredClass, new ValueAccessImpl(dummy.context));