Search in sources :

Example 66 with IEclipseContext

use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.

the class ContextInjectionTest method testBug374421.

@Test
public void testBug374421() {
    try {
        IEclipseContext context = EclipseContextFactory.create();
        context.runAndTrack(new RunAndTrack() {

            @Override
            public boolean changed(IEclipseContext context) {
                IEclipseContext staticContext = EclipseContextFactory.create();
                ContextInjectionFactory.make(Object.class, context, staticContext);
                return true;
            }
        });
    } catch (StackOverflowError e) {
        fail("See bug 374421 for details.");
    }
}
Also used : RunAndTrack(org.eclipse.e4.core.contexts.RunAndTrack) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 67 with IEclipseContext

use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.

the class ReparentingTest method testContextFunctionParentBecomeNull.

@Test
public void testContextFunctionParentBecomeNull() {
    IEclipseContext parent = EclipseContextFactory.create();
    final IEclipseContext child = parent.createChild();
    parent.set("x", Integer.valueOf(3));
    parent.set("y", Integer.valueOf(3));
    child.set("sum", new AddContextFunction());
    assertEquals(6, ((Integer) child.get("sum")).intValue());
    child.setParent(null);
    assertEquals(0, ((Integer) child.get("sum")).intValue());
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 68 with IEclipseContext

use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.

the class ReparentingTest method testRunAndTrackSwitchParent.

@Test
public void testRunAndTrackSwitchParent() {
    final String[] value = new String[1];
    IEclipseContext parent = EclipseContextFactory.create();
    final IEclipseContext child = parent.createChild();
    parent.set("x", "oldParent");
    child.runAndTrack(new RunAndTrack() {

        @Override
        public boolean changed(IEclipseContext context) {
            value[0] = (String) child.get("x");
            return true;
        }
    });
    assertEquals("oldParent", value[0]);
    IEclipseContext newParent = EclipseContextFactory.create();
    newParent.set("x", "newParent");
    child.setParent(newParent);
    assertEquals("newParent", value[0]);
}
Also used : RunAndTrack(org.eclipse.e4.core.contexts.RunAndTrack) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 69 with IEclipseContext

use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.

the class ReparentingTest method testUpdateSameParentCalculated.

@Test
public void testUpdateSameParentCalculated() {
    final int[] testServiceCount = new int[1];
    testServiceCount[0] = 0;
    IEclipseContext parentContext = EclipseContextFactory.create("parent");
    parentContext.set(TestService.class.getName(), new ContextFunction() {

        @Override
        public Object compute(IEclipseContext context, String contextKey) {
            testServiceCount[0]++;
            return ContextInjectionFactory.make(TestService.class, context);
        }
    });
    IEclipseContext childContext = parentContext.createChild("child");
    childContext.get(TestService.class);
    assertEquals(1, testServiceCount[0]);
    childContext.setParent(childContext.getParent());
    assertEquals(1, testServiceCount[0]);
}
Also used : ContextFunction(org.eclipse.e4.core.contexts.ContextFunction) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 70 with IEclipseContext

use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.

the class ReparentingTest method testInjectSwitchParentSameGrandparent.

/**
 * Tests an object consuming services from a grandparent. A parent switch where the grandparent
 * stays unchanged should ideally not cause changes for the injected object.
 */
@Test
public void testInjectSwitchParentSameGrandparent() {
    IEclipseContext grandpa = EclipseContextFactory.create();
    grandpa.set("String", "field");
    grandpa.set(String.class.getName(), "s");
    grandpa.set(Float.class.getName(), Float.valueOf(12.3f));
    IEclipseContext oldParent = grandpa.createChild();
    IEclipseContext newParent = grandpa.createChild();
    IEclipseContext child = oldParent.createChild();
    ObjectSuperClass object = new ObjectSuperClass();
    ContextInjectionFactory.inject(object, child);
    assertEquals(1, object.setStringCalled);
    child.setParent(newParent);
    assertEquals(1, object.setStringCalled);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) ObjectSuperClass(org.eclipse.e4.core.internal.tests.contexts.inject.ObjectSuperClass) Test(org.junit.Test)

Aggregations

IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)197 Test (org.junit.Test)142 RunAndTrack (org.eclipse.e4.core.contexts.RunAndTrack)18 ContextFunction (org.eclipse.e4.core.contexts.ContextFunction)17 BundleContext (org.osgi.framework.BundleContext)15 IEntity (org.whole.lang.model.IEntity)11 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)9 Execute (org.eclipse.e4.core.di.annotations.Execute)7 MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)6 IImportAsModelDialogFactory (org.whole.lang.ui.dialogs.IImportAsModelDialogFactory)6 Hashtable (java.util.Hashtable)5 MApplication (org.eclipse.e4.ui.model.application.MApplication)5 PrimaryObjectSupplier (org.eclipse.e4.core.di.suppliers.PrimaryObjectSupplier)4 Named (javax.inject.Named)3 PerformanceTestRunner (org.eclipse.core.tests.harness.PerformanceTestRunner)3 InjectionException (org.eclipse.e4.core.di.InjectionException)3 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)3 Optional (org.eclipse.e4.core.di.annotations.Optional)3 UISynchronize (org.eclipse.e4.ui.di.UISynchronize)3 ContextMenuProvider (org.eclipse.gef.ContextMenuProvider)3