summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Zarnekow2011-08-04 07:27:26 (EDT)
committer Ed Merks2011-08-04 08:15:13 (EDT)
commit4feb5f6b1c9e06647ac090707c70dd859fe0cd3b (patch)
treec2b007f438239cd112053ee6f47aca768a1553d7
parentd47bb1718f46eafcc2a9aecda28815b5cacf01f2 (diff)
downloadorg.eclipse.emf-4feb5f6b1c9e06647ac090707c70dd859fe0cd3b.zip
org.eclipse.emf-4feb5f6b1c9e06647ac090707c70dd859fe0cd3b.tar.gz
org.eclipse.emf-4feb5f6b1c9e06647ac090707c70dd859fe0cd3b.tar.bz2
[linking] Successfully resolve cross references to inferred local types from operation bodies
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/scoping/LinkingTest.xtend99
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/xtend-gen/org/eclipse/emf/ecore/xcore/tests/scoping/LinkingTest.java186
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/resource/XcoreResource.java9
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/scoping/XcoreQualifiedNameProvider.java8
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreEcoreBuilder.java3
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreJvmInferrer.java1
6 files changed, 299 insertions, 7 deletions
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/scoping/LinkingTest.xtend b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/scoping/LinkingTest.xtend
new file mode 100644
index 0000000..9d4d65e
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/scoping/LinkingTest.xtend
@@ -0,0 +1,99 @@
+package org.eclipse.emf.ecore.xcore.tests.scoping
+
+import static org.junit.Assert.*
+
+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 org.junit.Test
+import com.google.inject.Inject
+import org.eclipse.xtext.junit4.util.ParseHelper
+import org.eclipse.emf.ecore.xcore.XPackage
+import org.eclipse.emf.ecore.xcore.XClass
+import org.eclipse.emf.ecore.xcore.XOperation
+import org.eclipse.xtext.xbase.XBlockExpression
+import org.eclipse.xtext.xbase.XAssignment
+import org.eclipse.xtext.xbase.XVariableDeclaration
+import org.eclipse.xtext.xbase.XBinaryOperation
+
+@RunWith(typeof(XtextRunner))
+@InjectWith(typeof(XcoreInjectorProvider))
+class LinkingTest {
+
+ @Inject
+ ParseHelper<XPackage> parser
+
+ @Test
+ def void linkVoidReturnType() {
+ val pack = parser.parse('''
+ package foo
+ class Bar {
+ op void operation() {
+ val int i = 0
+ }
+ }
+ ''');
+ val declaration = pack.firstVariableDeclaration
+ val intType = declaration.type.type
+ assertFalse(intType.eIsProxy)
+ assertEquals('int', intType.qualifiedName)
+ }
+
+ @Test
+ def void linkQualifiedStringType() {
+ val pack = parser.parse('''
+ package foo
+ class Bar {
+ op void operation() {
+ val java.lang.String s = null
+ }
+ }
+ ''');
+ val declaration = pack.firstVariableDeclaration
+ val stringType = declaration.type.type
+ assertFalse(stringType.eIsProxy)
+ assertEquals('java.lang.String', stringType.qualifiedName)
+ }
+
+ @Test
+ def void linkInternalDefinedType() {
+ val pack = parser.parse('''
+ package foo
+ class Bar {
+ op void operation() {
+ val Bar b = null
+ }
+ }
+ ''');
+ val declaration = pack.firstVariableDeclaration
+ val stringType = declaration.type.type
+ assertFalse(stringType.eIsProxy)
+ assertEquals('foo.Bar', stringType.qualifiedName)
+ }
+
+ @Test
+ def void linkFeatureCallType() {
+ val pack = parser.parse('''
+ package foo
+ class Bar {
+ op void operation() {
+ val s = 'a' + 'b'
+ }
+ }
+ ''');
+ val declaration = pack.firstVariableDeclaration
+ val binaryOperation = declaration.right as XBinaryOperation
+ val feature = binaryOperation.feature
+ assertFalse(feature.eIsProxy)
+ assertEquals('operator_plus', feature.simpleName)
+ }
+
+ def firstVariableDeclaration(XPackage pack) {
+ val clazz = pack.classifiers.head as XClass
+ val operation = clazz.members.head as XOperation
+ val block = operation.body as XBlockExpression
+ val declaration = block.expressions.head as XVariableDeclaration
+ declaration
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.emf.ecore.xcore.tests/xtend-gen/org/eclipse/emf/ecore/xcore/tests/scoping/LinkingTest.java b/org.eclipse.emf.ecore.xcore.tests/xtend-gen/org/eclipse/emf/ecore/xcore/tests/scoping/LinkingTest.java
new file mode 100644
index 0000000..2447111
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore.tests/xtend-gen/org/eclipse/emf/ecore/xcore/tests/scoping/LinkingTest.java
@@ -0,0 +1,186 @@
+package org.eclipse.emf.ecore.xcore.tests.scoping;
+
+import com.google.inject.Inject;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.xcore.XClass;
+import org.eclipse.emf.ecore.xcore.XClassifier;
+import org.eclipse.emf.ecore.xcore.XMember;
+import org.eclipse.emf.ecore.xcore.XOperation;
+import org.eclipse.emf.ecore.xcore.XPackage;
+import org.eclipse.emf.ecore.xcore.XcoreInjectorProvider;
+import org.eclipse.xtext.common.types.JvmIdentifiableElement;
+import org.eclipse.xtext.common.types.JvmType;
+import org.eclipse.xtext.common.types.JvmTypeReference;
+import org.eclipse.xtext.junit4.InjectWith;
+import org.eclipse.xtext.junit4.XtextRunner;
+import org.eclipse.xtext.junit4.util.ParseHelper;
+import org.eclipse.xtext.xbase.XBinaryOperation;
+import org.eclipse.xtext.xbase.XBlockExpression;
+import org.eclipse.xtext.xbase.XExpression;
+import org.eclipse.xtext.xbase.XVariableDeclaration;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xtend2.lib.StringConcatenation;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SuppressWarnings("all")
+@RunWith(XtextRunner.class)
+@InjectWith(XcoreInjectorProvider.class)
+public class LinkingTest {
+
+ @Inject
+ private ParseHelper<XPackage> parser;
+
+ @Test
+ public void linkVoidReturnType() throws Exception {
+ {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("package foo");
+ _builder.newLine();
+ _builder.append("class Bar {");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("op void operation() {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("val int i = 0");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ XPackage _parse = this.parser.parse(_builder);
+ final XPackage pack = _parse;
+ XVariableDeclaration _firstVariableDeclaration = this.firstVariableDeclaration(pack);
+ final XVariableDeclaration declaration = _firstVariableDeclaration;
+ JvmTypeReference _type = declaration.getType();
+ JvmType _type_1 = _type.getType();
+ final JvmType intType = _type_1;
+ boolean _eIsProxy = intType.eIsProxy();
+ Assert.assertFalse(_eIsProxy);
+ String _qualifiedName = intType.getQualifiedName();
+ Assert.assertEquals("int", _qualifiedName);
+ }
+ }
+
+ @Test
+ public void linkQualifiedStringType() throws Exception {
+ {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("package foo");
+ _builder.newLine();
+ _builder.append("class Bar {");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("op void operation() {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("val java.lang.String s = null");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ XPackage _parse = this.parser.parse(_builder);
+ final XPackage pack = _parse;
+ XVariableDeclaration _firstVariableDeclaration = this.firstVariableDeclaration(pack);
+ final XVariableDeclaration declaration = _firstVariableDeclaration;
+ JvmTypeReference _type = declaration.getType();
+ JvmType _type_1 = _type.getType();
+ final JvmType stringType = _type_1;
+ boolean _eIsProxy = stringType.eIsProxy();
+ Assert.assertFalse(_eIsProxy);
+ String _qualifiedName = stringType.getQualifiedName();
+ Assert.assertEquals("java.lang.String", _qualifiedName);
+ }
+ }
+
+ @Test
+ public void linkInternalDefinedType() throws Exception {
+ {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("package foo");
+ _builder.newLine();
+ _builder.append("class Bar {");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("op void operation() {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("val Bar b = null");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ XPackage _parse = this.parser.parse(_builder);
+ final XPackage pack = _parse;
+ XVariableDeclaration _firstVariableDeclaration = this.firstVariableDeclaration(pack);
+ final XVariableDeclaration declaration = _firstVariableDeclaration;
+ JvmTypeReference _type = declaration.getType();
+ JvmType _type_1 = _type.getType();
+ final JvmType stringType = _type_1;
+ boolean _eIsProxy = stringType.eIsProxy();
+ Assert.assertFalse(_eIsProxy);
+ String _qualifiedName = stringType.getQualifiedName();
+ Assert.assertEquals("foo.Bar", _qualifiedName);
+ }
+ }
+
+ @Test
+ public void linkFeatureCallType() throws Exception {
+ {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("package foo");
+ _builder.newLine();
+ _builder.append("class Bar {");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("op void operation() {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("val s = \'a\' + \'b\'");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ XPackage _parse = this.parser.parse(_builder);
+ final XPackage pack = _parse;
+ XVariableDeclaration _firstVariableDeclaration = this.firstVariableDeclaration(pack);
+ final XVariableDeclaration declaration = _firstVariableDeclaration;
+ XExpression _right = declaration.getRight();
+ final XBinaryOperation binaryOperation = ((XBinaryOperation) _right);
+ JvmIdentifiableElement _feature = binaryOperation.getFeature();
+ final JvmIdentifiableElement feature = _feature;
+ boolean _eIsProxy = feature.eIsProxy();
+ Assert.assertFalse(_eIsProxy);
+ String _simpleName = feature.getSimpleName();
+ Assert.assertEquals("operator_plus", _simpleName);
+ }
+ }
+
+ public XVariableDeclaration firstVariableDeclaration(final XPackage pack) {
+ XVariableDeclaration _xblockexpression = null;
+ {
+ EList<XClassifier> _classifiers = pack.getClassifiers();
+ XClassifier _head = IterableExtensions.<XClassifier>head(_classifiers);
+ final XClass clazz = ((XClass) _head);
+ EList<XMember> _members = clazz.getMembers();
+ XMember _head_1 = IterableExtensions.<XMember>head(_members);
+ final XOperation operation = ((XOperation) _head_1);
+ XBlockExpression _body = operation.getBody();
+ final XBlockExpression block = ((XBlockExpression) _body);
+ EList<XExpression> _expressions = block.getExpressions();
+ XExpression _head_2 = IterableExtensions.<XExpression>head(_expressions);
+ final XVariableDeclaration declaration = ((XVariableDeclaration) _head_2);
+ _xblockexpression = (declaration);
+ }
+ return _xblockexpression;
+ }
+} \ 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 42f9022..81b88a4 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
@@ -21,7 +21,6 @@ import org.eclipse.xtext.common.types.JvmGenericType;
import org.eclipse.xtext.naming.IQualifiedNameProvider;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.parser.IParseResult;
-import org.eclipse.xtext.parser.antlr.IReferableElementsUnloader;
import org.eclipse.xtext.util.Pair;
import org.eclipse.xtext.xbase.resource.XbaseResource;
@@ -36,9 +35,6 @@ public class XcoreResource extends XbaseResource {
private IQualifiedNameProvider nameProvider;
@Inject
- private IReferableElementsUnloader.GenericUnloader unloader;
-
- @Inject
private XcoreJvmInferrer jvmInferrer;
protected boolean fullyInitialized = false;
@@ -78,10 +74,10 @@ public class XcoreResource extends XbaseResource {
}
else if (eObject instanceof GenModel || eObject instanceof JvmGenericType)
{
- unloader.unloadRoot(eObject);
+ unload(eObject);
if (ePackage != null)
{
- unloader.unloadRoot(ePackage);
+ unload(ePackage);
ePackage = null;
}
}
@@ -121,6 +117,7 @@ public class XcoreResource extends XbaseResource {
}
xcoreEcoreBuilder.link();
super.getContents().addAll(jvmInferrer.getDeclaredTypes(model));
+ getCache().clear(this);
}
}
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/scoping/XcoreQualifiedNameProvider.java b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/scoping/XcoreQualifiedNameProvider.java
index 8317ea1..cb5163a 100644
--- a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/scoping/XcoreQualifiedNameProvider.java
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/scoping/XcoreQualifiedNameProvider.java
@@ -2,6 +2,8 @@ package org.eclipse.emf.ecore.xcore.scoping;
import org.eclipse.emf.codegen.ecore.genmodel.GenClassifier;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.xtext.common.types.JvmDeclaredType;
+import org.eclipse.xtext.common.types.JvmType;
import org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider;
import org.eclipse.xtext.naming.IQualifiedNameConverter;
import org.eclipse.xtext.naming.QualifiedName;
@@ -22,6 +24,12 @@ public class XcoreQualifiedNameProvider extends DefaultDeclarativeQualifiedNameP
String packageName = genClassifier.getGenPackage().getQualifiedPackageName();
return nameConverter.toQualifiedName(packageName + "." + genClassifier.getName());
}
+ else if (eObject instanceof JvmType)
+ {
+ JvmType type = (JvmType) eObject;
+ String typeName = type.getQualifiedName();
+ return nameConverter.toQualifiedName(typeName);
+ }
else
{
return super.getFullyQualifiedName(eObject);
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreEcoreBuilder.java b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreEcoreBuilder.java
index d06e480..b4a1f89 100644
--- a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreEcoreBuilder.java
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreEcoreBuilder.java
@@ -50,6 +50,7 @@ import org.eclipse.emf.ecore.xcore.XStructuralFeature;
import org.eclipse.emf.ecore.xcore.XTypeParameter;
import org.eclipse.emf.ecore.xcore.XTypedElement;
import org.eclipse.emf.ecore.xcore.XcorePackage;
+import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.xbase.XBlockExpression;
public class XcoreEcoreBuilder
@@ -301,7 +302,7 @@ public class XcoreEcoreBuilder
{
EAnnotation eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
eAnnotation.setSource(EcorePackage.eNS_URI);
- eAnnotation.getContents().add(EcoreUtil.copy(body));
+ eAnnotation.getContents().add(EcoreUtil2.cloneWithProxies(body));
eOperation.getEAnnotations().add(eAnnotation);
}
return eOperation;
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 d1eca3c..8cb9c1e 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
@@ -60,6 +60,7 @@ public class XcoreJvmInferrer
public List<? extends JvmDeclaredType> getDeclaredTypes(GenClass genClass)
{
+ // TODO set java.lang.Object super type or inferred super type
ArrayList<JvmDeclaredType> result = new ArrayList<JvmDeclaredType>();
JvmGenericType jvmGenericType = TypesFactory.eINSTANCE.createJvmGenericType();
jvmGenericType.setSimpleName(genClass.getName());