summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/scoping/LazyGenmodelInferenceTest.java')
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/scoping/LazyGenmodelInferenceTest.java131
1 files changed, 131 insertions, 0 deletions
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/scoping/LazyGenmodelInferenceTest.java b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/scoping/LazyGenmodelInferenceTest.java
new file mode 100644
index 0000000..3f593ee
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/scoping/LazyGenmodelInferenceTest.java
@@ -0,0 +1,131 @@
+package org.eclipse.emf.ecore.xcore.tests.scoping;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.xcore.XcoreInjectorProvider;
+import org.eclipse.emf.ecore.xcore.XcoreStandaloneSetup;
+import org.eclipse.emf.ecore.xcore.resource.XcoreResource;
+import org.eclipse.xtext.common.types.TypesPackage;
+import org.eclipse.xtext.junit4.InjectWith;
+import org.eclipse.xtext.junit4.XtextRunner;
+import org.eclipse.xtext.resource.IEObjectDescription;
+import org.eclipse.xtext.resource.IResourceDescription;
+import org.eclipse.xtext.resource.IResourceDescription.Manager;
+import org.eclipse.xtext.resource.XtextResource;
+import org.eclipse.xtext.resource.XtextResourceSet;
+import org.eclipse.xtext.util.StringInputStream;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.google.inject.Guice;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import com.google.inject.Provider;
+
+@RunWith(XtextRunner.class)
+@InjectWith(LazyGenmodelInferenceTest.MyXcoreInjectorProvider.class)
+public class LazyGenmodelInferenceTest {
+
+ @Inject
+ private Provider<XtextResourceSet> resourceSetProvider;
+
+ public static class MyXcoreInjectorProvider extends XcoreInjectorProvider {
+
+ private Injector injector;
+
+ @Override
+ public Injector getInjector() {
+ if (injector == null) {
+ this.injector = new XcoreStandaloneSetup() {
+ @Override
+ public Injector createInjector() {
+ return Guice.createInjector(new org.eclipse.emf.ecore.xcore.XcoreRuntimeModule() {
+ public Class<? extends XtextResource> bindXtextResource() {
+ return InspectableXcoreResource.class;
+ }
+ });
+ }
+ }.createInjectorAndDoEMFRegistration();
+ }
+ return injector;
+ }
+
+ @Override
+ public void setupRegistry() {
+ super.setupRegistry();
+ if (injector != null) {
+ new XcoreStandaloneSetup().register(injector);
+ }
+ }
+ }
+
+ public static class InspectableXcoreResource extends XcoreResource {
+
+ public EList<EObject> getContentsUnsafe() {
+ return contents;
+ }
+
+ }
+
+ @Test
+ public void testSetup() {
+ XtextResourceSet resourceSet = resourceSetProvider.get();
+ Resource resource = resourceSet.createResource(URI.createURI("foo.xcore"));
+ assertTrue(resource.toString(), resource instanceof InspectableXcoreResource);
+ assertNull(((InspectableXcoreResource)resource).getContentsUnsafe());
+ }
+
+ @Test
+ public void testContentsWithoutDerived() throws IOException {
+ XtextResourceSet resourceSet = resourceSetProvider.get();
+ Resource resource = resourceSet.createResource(URI.createURI("foo.xcore"));
+ resource.load(new StringInputStream("package foo.bar class Baz {}"), null);
+ assertEquals(1, ((InspectableXcoreResource)resource).getContentsUnsafe().size());
+ }
+
+ @Test
+ public void testContentsWithDerived() throws IOException {
+ XtextResourceSet resourceSet = resourceSetProvider.get();
+ Resource resource = resourceSet.createResource(URI.createURI("foo.xcore"));
+ resource.load(new StringInputStream("package foo.bar class Baz {}"), null);
+ assertTrue(1 < resource.getContents().size());
+ }
+
+ public void testResourceDescriptionManagerDoesNotResolve() throws IOException {
+ XtextResourceSet resourceSet = resourceSetProvider.get();
+ InspectableXcoreResource resource = (InspectableXcoreResource) resourceSet.createResource(URI.createURI("foo.xcore"));
+ resource.load(new StringInputStream("package foo.bar class Baz {}"), null);
+ Manager manager = resource.getResourceServiceProvider().getResourceDescriptionManager();
+ IResourceDescription resourceDescription = manager.getResourceDescription(resource);
+
+ Iterator<IEObjectDescription> eclass = resourceDescription.getExportedObjectsByType(EcorePackage.Literals.ECLASS)
+ .iterator();
+ Iterator<IEObjectDescription> genclass = resourceDescription.getExportedObjectsByType(
+ GenModelPackage.Literals.GEN_CLASS).iterator();
+ Iterator<IEObjectDescription> jvmTypes = resourceDescription.getExportedObjectsByType(
+ TypesPackage.Literals.JVM_GENERIC_TYPE).iterator();
+ final String expected = "foo.bar.Baz";
+ assertEquals(expected, eclass.next().getName().toString());
+ assertFalse(eclass.hasNext());
+ assertEquals(expected, genclass.next().getName().toString());
+ assertFalse(genclass.hasNext());
+ assertEquals(expected, jvmTypes.next().getName().toString());
+ assertEquals(expected + "Impl", jvmTypes.next().getName().toString());
+ assertFalse(genclass.hasNext());
+
+ assertEquals(1, resource.getContentsUnsafe().size());
+ }
+
+}