summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormerks2011-08-04 17:03:53 -0400
committerEd Merks2011-08-04 17:03:53 -0400
commit8e64a1838b39485e9e8c8c789a290ffe7d38e6c7 (patch)
tree8840ac2e41dfe956a200f78065c87babf00ce31b
parent5a5deb30c5728b1ec3416da8d7148f139b16c4eb (diff)
downloadorg.eclipse.emf-8e64a1838b39485e9e8c8c789a290ffe7d38e6c7.zip
org.eclipse.emf-8e64a1838b39485e9e8c8c789a290ffe7d38e6c7.tar.gz
org.eclipse.emf-8e64a1838b39485e9e8c8c789a290ffe7d38e6c7.tar.xz
Fix problem with unloading not working well. Infer accessor operations
for features.
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ParsingTest.xtend18
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/xtend-gen/org/eclipse/emf/ecore/xcore/tests/ParsingTest.java28
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/XcoreRuntimeModule.java8
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/resource/XcoreResource.java20
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/XcoreJvmInferrer.java43
5 files changed, 100 insertions, 17 deletions
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ParsingTest.xtend b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ParsingTest.xtend
index 6e775eb..4998a46 100644
--- a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ParsingTest.xtend
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ParsingTest.xtend
@@ -14,6 +14,8 @@ import org.eclipse.emf.ecore.xcore.XcoreExtensions
import org.eclipse.emf.ecore.xcore.XReference
import org.eclipse.xtext.resource.XtextResource
import org.eclipse.emf.ecore.xcore.XOperation
+import org.eclipse.xtext.junit4.validation.ValidationTestHelper
+import org.eclipse.emf.ecore.util.EcoreUtil
@RunWith(typeof(XtextRunner))
@InjectWith(typeof(XcoreInjectorProvider))
@@ -25,6 +27,9 @@ class ParsingTest {
@Inject
extension XcoreExtensions exts
+ @Inject
+ extension ValidationTestHelper vth
+
@Test
def void parseSimpleFile() {
@@ -33,6 +38,19 @@ class ParsingTest {
}
@Test
+ def void testJvmTypes() {
+ val pack = parser.parse('''
+ package foo
+ class A
+ {
+ refers A a
+ }
+ ''')
+ EcoreUtil::resolveAll(pack.eResource)
+ vth.assertNoErrors(pack);
+ }
+
+ @Test
def void testSuperTypeLinking_1() {
val pack = parser.parse('''
package foo
diff --git a/org.eclipse.emf.ecore.xcore.tests/xtend-gen/org/eclipse/emf/ecore/xcore/tests/ParsingTest.java b/org.eclipse.emf.ecore.xcore.tests/xtend-gen/org/eclipse/emf/ecore/xcore/tests/ParsingTest.java
index 015537f..0d5eee7 100644
--- a/org.eclipse.emf.ecore.xcore.tests/xtend-gen/org/eclipse/emf/ecore/xcore/tests/ParsingTest.java
+++ b/org.eclipse.emf.ecore.xcore.tests/xtend-gen/org/eclipse/emf/ecore/xcore/tests/ParsingTest.java
@@ -9,6 +9,7 @@ import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.Resource.Diagnostic;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xcore.XAnnotation;
import org.eclipse.emf.ecore.xcore.XAnnotationDirective;
import org.eclipse.emf.ecore.xcore.XClass;
@@ -23,6 +24,7 @@ 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.resource.XtextResource;
import org.eclipse.xtext.xbase.lib.ComparableExtensions;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
@@ -42,6 +44,9 @@ public class ParsingTest {
@Inject
private XcoreExtensions exts;
+ @Inject
+ private ValidationTestHelper vth;
+
@Test
public void parseSimpleFile() throws Exception {
{
@@ -53,6 +58,29 @@ public class ParsingTest {
}
@Test
+ public void testJvmTypes() throws Exception {
+ {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("package foo ");
+ _builder.newLine();
+ _builder.append("class A ");
+ _builder.newLine();
+ _builder.append("{ ");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("refers A a");
+ _builder.newLine();
+ _builder.append("} ");
+ _builder.newLine();
+ XPackage _parse = this.parser.parse(_builder);
+ final XPackage pack = _parse;
+ Resource _eResource = pack.eResource();
+ EcoreUtil.resolveAll(_eResource);
+ this.vth.assertNoErrors(pack);
+ }
+ }
+
+ @Test
public void testSuperTypeLinking_1() throws Exception {
{
StringConcatenation _builder = new StringConcatenation();
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/XcoreRuntimeModule.java b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/XcoreRuntimeModule.java
index c4fc393..c675391 100644
--- a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/XcoreRuntimeModule.java
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/XcoreRuntimeModule.java
@@ -11,6 +11,7 @@ import org.eclipse.emf.ecore.xcore.scoping.XcoreResourceDescriptionManager;
import org.eclipse.emf.ecore.xcore.scoping.XcoreResourceDescriptionStrategy;
import org.eclipse.xtext.linking.ILinker;
import org.eclipse.xtext.naming.IQualifiedNameProvider;
+import org.eclipse.xtext.parser.antlr.IReferableElementsUnloader;
import org.eclipse.xtext.resource.IDefaultResourceDescriptionStrategy;
import org.eclipse.xtext.resource.IResourceDescription;
import org.eclipse.xtext.resource.XtextResource;
@@ -62,9 +63,14 @@ public class XcoreRuntimeModule extends org.eclipse.emf.ecore.xcore.AbstractXcor
binder.bind(IScopeProvider.class).annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE)).to(XcoreImportedNamespaceAwareScopeProvider.class);
}
- public Class<? extends IResourceDescription.Manager> bindIResourceDescriptionManager() {
+ public Class<? extends IResourceDescription.Manager> bindIResourceDescriptionManager()
+ {
return XcoreResourceDescriptionManager.class;
}
+ public Class<? extends IReferableElementsUnloader> bindIReferableElementsUnloader()
+ {
+ return IReferableElementsUnloader.GenericUnloader.class;
+ }
}
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 1450447..d3257cd 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
@@ -57,8 +57,6 @@ public class XcoreResource extends XbaseResource {
@Override
protected void updateInternalState(IParseResult parseResult) {
- EObject ePackage = null;
-
EList<EObject> contents = getContents();
int size = contents.size();
if (size > 1)
@@ -66,20 +64,9 @@ public class XcoreResource extends XbaseResource {
for (Iterator<EObject> i = contents.iterator(); i.hasNext(); )
{
EObject eObject = i.next();
- if (eObject instanceof EPackage)
- {
- // Defer unloading until the GenModel is unloaded.
- //
- ePackage = eObject;
- }
- else if (eObject instanceof GenModel || eObject instanceof JvmGenericType)
+ if (eObject instanceof EPackage || eObject instanceof GenModel || eObject instanceof JvmGenericType)
{
unload(eObject);
- if (ePackage != null)
- {
- unload(ePackage);
- ePackage = null;
- }
}
}
contents.clear();
@@ -88,7 +75,8 @@ public class XcoreResource extends XbaseResource {
super.updateInternalState(parseResult);
}
- protected void lateInitialize() {
+ protected void lateInitialize()
+ {
if (getParseResult() != null && getParseResult().getRootASTElement() instanceof XPackage)
{
XPackage model = (XPackage) getParseResult().getRootASTElement();
@@ -97,7 +85,7 @@ public class XcoreResource extends XbaseResource {
super.getContents().add(ePackage);
GenModel genModel = GenModelFactory.eINSTANCE.createGenModel();
genModel.initialize(Collections.singleton(ePackage));
- super.getContents().add(genModel);
+ super.getContents().add(1, genModel);
genModel.initialize();
for (Iterator<EObject> i = genModel.eAllContents(); i.hasNext(); )
{
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 2765f59..9343538 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
@@ -8,6 +8,7 @@ import org.eclipse.emf.codegen.ecore.genmodel.GenBase;
import org.eclipse.emf.codegen.ecore.genmodel.GenClass;
import org.eclipse.emf.codegen.ecore.genmodel.GenClassifier;
import org.eclipse.emf.codegen.ecore.genmodel.GenEnum;
+import org.eclipse.emf.codegen.ecore.genmodel.GenFeature;
import org.eclipse.emf.codegen.ecore.genmodel.GenOperation;
import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
import org.eclipse.emf.codegen.ecore.genmodel.GenParameter;
@@ -19,6 +20,7 @@ import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.EGenericType;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.ETypeParameter;
import org.eclipse.emf.ecore.util.EcoreValidator;
import org.eclipse.emf.ecore.xcore.XPackage;
@@ -37,6 +39,7 @@ import org.eclipse.xtext.common.types.TypesFactory;
import org.eclipse.xtext.common.types.util.TypeReferences;
import org.eclipse.xtext.naming.IQualifiedNameConverter;
import org.eclipse.xtext.naming.QualifiedName;
+import org.eclipse.xtext.util.EmfFormatter;
import com.google.inject.Inject;
@@ -75,6 +78,11 @@ public class XcoreJvmInferrer
{
result.addAll(getDeclaredTypes(genClassifier));
}
+
+ if (true)
+ {
+ System.out.println(EmfFormatter.listToStr(result));
+ }
return result;
}
@@ -136,11 +144,42 @@ public class XcoreJvmInferrer
members.add(getJvmOperation(genOperation));
}
+ for (GenFeature genFeature : genClass.getGenFeatures())
+ {
+ EStructuralFeature eStructuralFeature = genFeature.getEcoreFeature();
+ if (eStructuralFeature.getName() != null && eStructuralFeature.getEGenericType() != null)
+ {
+ members.addAll(getJvmFeatureAccessors(genFeature));
+ }
+ }
result.add(jvmGenericType);
}
return result;
}
+ List<JvmOperation> getJvmFeatureAccessors(GenFeature genFeature)
+ {
+ List<JvmOperation> result = new ArrayList<JvmOperation>();
+ if (genFeature.isGet() && !genFeature.isSuppressedGetVisibility())
+ {
+ JvmOperation jvmOperation = TypesFactory.eINSTANCE.createJvmOperation();
+ map(jvmOperation, genFeature);
+ jvmOperation.setSimpleName(genFeature.getGetAccessor());
+ jvmOperation.setReturnType(getJvmTypeReference(genFeature.getType(genFeature.getGenClass()), genFeature));
+ result.add(jvmOperation);
+ }
+ if (genFeature.isSet() && !genFeature.isSuppressedSetVisibility())
+ {
+ JvmOperation jvmOperation = TypesFactory.eINSTANCE.createJvmOperation();
+ map(jvmOperation, genFeature);
+ jvmOperation.setSimpleName("set" + genFeature.getAccessorName());
+ jvmOperation.setReturnType(getJvmTypeReference(genFeature.getType(genFeature.getGenClass()), genFeature));
+ result.add(jvmOperation);
+ }
+
+ return result;
+ }
+
JvmOperation getJvmOperation(GenOperation genOperation)
{
JvmOperation jvmOperation = TypesFactory.eINSTANCE.createJvmOperation();
@@ -216,6 +255,10 @@ public class XcoreJvmInferrer
{
List<JvmTypeReference> arguments = getJvmTypeReferences(eGenericType.getETypeArguments(), context);
String instanceTypeName = eClassifier.getInstanceTypeName();
+ if (instanceTypeName == null)
+ {
+ System.err.println("###");
+ }
QualifiedName qualifiedName = nameConverter.toQualifiedName(instanceTypeName);
JvmGenericType jvmGenericType = TypesFactory.eINSTANCE.createJvmGenericType();
proxyUriConverter.installProxyURI(context.eResource().getURI(), jvmGenericType, qualifiedName);