summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Efftinge2011-08-05 05:47:55 (EDT)
committerEd Merks2011-08-05 05:47:55 (EDT)
commit16954f514a3765ce31b3fc7375fdedee9237634d (patch)
treec128bd93091e7d958c2088f70e0923725f4ac765
parentab568a880d440f6ecd6cae1e0609a0e773ba6b03 (diff)
downloadorg.eclipse.emf-16954f514a3765ce31b3fc7375fdedee9237634d.zip
org.eclipse.emf-16954f514a3765ce31b3fc7375fdedee9237634d.tar.gz
org.eclipse.emf-16954f514a3765ce31b3fc7375fdedee9237634d.tar.bz2
some xbase scoping and typing
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/scoping/XbaseScopingTest.xtend36
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/xtend-gen/org/eclipse/emf/ecore/xcore/tests/scoping/XbaseScopingTest.java50
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/resource/XcoreResource.java14
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/scoping/XcoreScopeProvider.java4
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/typing/XcoreTypeProvider.java28
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreJvmInferrer.java13
6 files changed, 139 insertions, 6 deletions
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/scoping/XbaseScopingTest.xtend b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/scoping/XbaseScopingTest.xtend
new file mode 100644
index 0000000..dc79513
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/scoping/XbaseScopingTest.xtend
@@ -0,0 +1,36 @@
+package org.eclipse.emf.ecore.xcore.tests.scoping
+
+import org.junit.runner.RunWith
+import org.eclipse.xtext.junit4.XtextRunner
+import org.eclipse.xtext.junit4.InjectWith
+import org.eclipse.emf.ecore.xcore.XcoreInjectorProvider
+import com.google.inject.Inject
+import org.eclipse.xtext.junit4.util.ParseHelper
+import org.eclipse.emf.ecore.xcore.XPackage
+import org.eclipse.xtext.junit4.validation.ValidationTestHelper
+import org.junit.Test
+
+@RunWith(typeof(XtextRunner))
+@InjectWith(typeof(XcoreInjectorProvider))
+class XbaseScopingTest {
+
+ @Inject
+ ParseHelper<XPackage> parser
+
+ @Inject
+ ValidationTestHelper validator
+
+ @Test
+ def testLinkToThis() {
+ val pack = parser.parse('''
+ package foo.bar
+
+ class X {
+ op X foo(X x) {
+ return this.foo(x)
+ }
+ }
+ ''')
+ validator.assertNoErrors(pack)
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.emf.ecore.xcore.tests/xtend-gen/org/eclipse/emf/ecore/xcore/tests/scoping/XbaseScopingTest.java b/org.eclipse.emf.ecore.xcore.tests/xtend-gen/org/eclipse/emf/ecore/xcore/tests/scoping/XbaseScopingTest.java
new file mode 100644
index 0000000..28f6829
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore.tests/xtend-gen/org/eclipse/emf/ecore/xcore/tests/scoping/XbaseScopingTest.java
@@ -0,0 +1,50 @@
+package org.eclipse.emf.ecore.xcore.tests.scoping;
+
+import com.google.inject.Inject;
+import org.eclipse.emf.ecore.xcore.XPackage;
+import org.eclipse.emf.ecore.xcore.XcoreInjectorProvider;
+import org.eclipse.xtext.junit4.InjectWith;
+import org.eclipse.xtext.junit4.XtextRunner;
+import org.eclipse.xtext.junit4.util.ParseHelper;
+import org.eclipse.xtext.junit4.validation.ValidationTestHelper;
+import org.eclipse.xtext.xtend2.lib.StringConcatenation;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SuppressWarnings("all")
+@RunWith(XtextRunner.class)
+@InjectWith(XcoreInjectorProvider.class)
+public class XbaseScopingTest {
+
+ @Inject
+ private ParseHelper<XPackage> parser;
+
+ @Inject
+ private ValidationTestHelper validator;
+
+ @Test
+ public void testLinkToThis() throws Exception {
+ {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("package foo.bar");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("class X {");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("op X foo(X x) {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("return this.foo(x)");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ XPackage _parse = this.parser.parse(_builder);
+ final XPackage pack = _parse;
+ this.validator.assertNoErrors(pack);
+ }
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/resource/XcoreResource.java b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/resource/XcoreResource.java
index 3a23500..a02228c 100644
--- a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/resource/XcoreResource.java
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/resource/XcoreResource.java
@@ -15,12 +15,18 @@ import org.eclipse.emf.ecore.xcore.util.XcoreEcoreBuilder;
import org.eclipse.emf.ecore.xcore.util.XcoreGenmodelBuilder;
import org.eclipse.emf.ecore.xcore.util.XcoreJvmInferrer;
import org.eclipse.xtext.common.types.JvmGenericType;
+import org.eclipse.xtext.common.types.TypesPackage;
import org.eclipse.xtext.naming.IQualifiedNameProvider;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.parser.IParseResult;
+import org.eclipse.xtext.resource.IEObjectDescription;
+import org.eclipse.xtext.scoping.IScope;
+import org.eclipse.xtext.scoping.IScopeProvider;
import org.eclipse.xtext.util.Pair;
import org.eclipse.xtext.xbase.resource.XbaseResource;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Iterators;
import com.google.inject.Inject;
import com.google.inject.Provider;
@@ -40,6 +46,9 @@ public class XcoreResource extends XbaseResource {
@Inject
private Provider<XcoreEcoreBuilder> xcoreEcoreBuilderProvider;
+
+ @Inject
+ private IScopeProvider scopeProvider;
protected boolean fullyInitialized = false;
@@ -110,6 +119,11 @@ public class XcoreResource extends XbaseResource {
* TODO optimize
*/
protected EObject findEObject(EClass clazz, QualifiedName name) {
+ if (clazz == TypesPackage.Literals.JVM_GENERIC_TYPE) {
+ IScope scope = scopeProvider.getScope(getContents().get(0), TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
+ final IEObjectDescription desc = scope.getSingleElement(name);
+ return desc == null ? null : desc.getEObjectOrProxy();
+ }
TreeIterator<EObject> iterator = EcoreUtil.getAllContents(this, false);
while (iterator.hasNext()) {
EObject candidate = iterator.next();
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/scoping/XcoreScopeProvider.java b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/scoping/XcoreScopeProvider.java
index 25a7b25..0cf87ee 100644
--- a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/scoping/XcoreScopeProvider.java
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/scoping/XcoreScopeProvider.java
@@ -70,9 +70,9 @@ public class XcoreScopeProvider extends XbaseScopeProvider
{
list.add(EObjectDescription.create(QualifiedName.create(param.getName()), param, null));
}
- return new SimpleScope(parent, list);
+ return super.createLocalVarScope(new SimpleScope(parent, list), scopeContext);
}
- }
+ }
return super.createLocalVarScope(parent, scopeContext);
}
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/typing/XcoreTypeProvider.java b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/typing/XcoreTypeProvider.java
new file mode 100644
index 0000000..61a53f8
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/typing/XcoreTypeProvider.java
@@ -0,0 +1,28 @@
+package org.eclipse.emf.ecore.xcore.typing;
+
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.xcore.XOperation;
+import org.eclipse.emf.ecore.xcore.XcorePackage;
+import org.eclipse.emf.ecore.xcore.mappings.XcoreMapper;
+import org.eclipse.xtext.common.types.JvmOperation;
+import org.eclipse.xtext.common.types.JvmTypeReference;
+import org.eclipse.xtext.xbase.typing.XbaseTypeProvider;
+
+import com.google.inject.Inject;
+
+public class XcoreTypeProvider extends XbaseTypeProvider
+{
+
+ @Inject
+ private XcoreMapper mapper;
+
+ protected JvmTypeReference _expectedType(XOperation expr, EReference reference, int index, boolean rawType)
+ {
+ if (reference == XcorePackage.Literals.XOPERATION__BODY) {
+ JvmOperation operation = mapper.getMapping(expr).getJvmOperation();
+ return operation.getReturnType();
+ }
+ return null;
+ }
+
+}
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreJvmInferrer.java b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreJvmInferrer.java
index edda8f5..59c6904 100644
--- a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreJvmInferrer.java
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreJvmInferrer.java
@@ -134,10 +134,15 @@ public class XcoreJvmInferrer
// TODO should deal with EClass.getEGenericSuperTypes().
EList<JvmTypeReference> superTypes = jvmGenericType.getSuperTypes();
- List<String> qualifiedInterfaceExtendsList = genClass.getQualifiedInterfaceExtendsList();
- for (String instanceTypeName : qualifiedInterfaceExtendsList)
- {
- superTypes.add(getJvmTypeReference(instanceTypeName, genClass));
+ try {
+ List<String> qualifiedInterfaceExtendsList = genClass.getQualifiedInterfaceExtendsList();
+ for (String instanceTypeName : qualifiedInterfaceExtendsList)
+ {
+ superTypes.add(getJvmTypeReference(instanceTypeName, genClass));
+ }
+ } catch (NullPointerException e) {
+ //TODO get rid of me
+ e.printStackTrace();
}
EList<JvmMember> members = jvmGenericType.getMembers();