summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Efftinge2011-08-03 06:24:55 (EDT)
committer Ed Merks2011-08-03 06:25:09 (EDT)
commitf664622b439d99f8c9a7ba0a10c3231af6f0fba1 (patch)
tree44a8b72adb429e2c0f87192475e840aaa70a2bda
parent001171cae54b871a7e9250b55932159b823dc9b7 (diff)
downloadorg.eclipse.emf-f664622b439d99f8c9a7ba0a10c3231af6f0fba1.zip
org.eclipse.emf-f664622b439d99f8c9a7ba0a10c3231af6f0fba1.tar.gz
org.eclipse.emf-f664622b439d99f8c9a7ba0a10c3231af6f0fba1.tar.bz2
XcoreResource introduced [WIP]
-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.java79
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/scoping/LazyCreationProxyUriConverter.java6
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/scoping/XcoreResourceDescriptionStrategy.java30
4 files changed, 105 insertions, 18 deletions
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 ee9e9b6..582e795 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
@@ -4,9 +4,11 @@
package org.eclipse.emf.ecore.xcore;
import org.eclipse.emf.ecore.xcore.linking.XcoreLazyLinker;
+import org.eclipse.emf.ecore.xcore.resource.XcoreResource;
import org.eclipse.emf.ecore.xcore.scoping.XcoreResourceDescriptionStrategy;
import org.eclipse.xtext.linking.ILinker;
import org.eclipse.xtext.resource.IDefaultResourceDescriptionStrategy;
+import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.serializer.ISerializer;
import org.eclipse.xtext.serializer.impl.Serializer;
@@ -29,7 +31,11 @@ public class XcoreRuntimeModule extends org.eclipse.emf.ecore.xcore.AbstractXcor
public Class<? extends IDefaultResourceDescriptionStrategy> bindIDefaultResourceDescriptionStrategy()
{
- return XcoreResourceDescriptionStrategy.class;
+ return XcoreResourceDescriptionStrategy.class;
}
+ @Override
+ public Class<? extends XtextResource> bindXtextResource() {
+ return XcoreResource.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
new file mode 100644
index 0000000..df02b51
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/resource/XcoreResource.java
@@ -0,0 +1,79 @@
+package org.eclipse.emf.ecore.xcore.resource;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.ecore.xcore.scoping.LazyCreationProxyUriConverter;
+import org.eclipse.xtext.naming.IQualifiedNameProvider;
+import org.eclipse.xtext.naming.QualifiedName;
+import org.eclipse.xtext.parser.IParseResult;
+import org.eclipse.xtext.util.Pair;
+import org.eclipse.xtext.xbase.resource.XbaseResource;
+
+import com.google.inject.Inject;
+
+public class XcoreResource extends XbaseResource {
+
+ @Inject
+ private LazyCreationProxyUriConverter proxyConverter;
+
+ @Inject
+ private IQualifiedNameProvider nameProvider;
+
+ private boolean fullyInitialized = false;
+
+ @Override
+ public EList<EObject> getContents() {
+ if (!isLoading && !fullyInitialized) {
+ try {
+ eSetDeliver(false);
+ lateInitialize();
+ fullyInitialized = true;
+ } finally {
+ eSetDeliver(true);
+ }
+ }
+ return super.getContents();
+ }
+
+ @Override
+ protected void updateInternalState(IParseResult parseResult) {
+ fullyInitialized = false;
+ super.updateInternalState(parseResult);
+ }
+
+ protected void lateInitialize() {
+
+ }
+
+ @Override
+ public synchronized EObject getEObject(String uriFragment) {
+ Pair<EClass,QualifiedName> fragmentInfo = proxyConverter.decodeFragment(uriFragment);
+ if (fragmentInfo != null) {
+ return findEObject(fragmentInfo.getFirst(), fragmentInfo.getSecond());
+ } else {
+ return super.getEObject(uriFragment);
+ }
+ }
+
+ /**
+ * finds the EObject of the given type and the given {@link QualifiedName}.
+ *
+ * TODO optimize
+ */
+ protected EObject findEObject(EClass clazz, QualifiedName name) {
+ TreeIterator<EObject> iterator = EcoreUtil.getAllContents(this, false);
+ while (iterator.hasNext()) {
+ EObject candidate = iterator.next();
+ if (clazz.isInstance(candidate)) {
+ QualifiedName qualifiedName = nameProvider.getFullyQualifiedName(candidate);
+ if (name.equals(qualifiedName))
+ return candidate;
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/scoping/LazyCreationProxyUriConverter.java b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/scoping/LazyCreationProxyUriConverter.java
index 7d9fc6e..8dcd96c 100644
--- a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/scoping/LazyCreationProxyUriConverter.java
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/scoping/LazyCreationProxyUriConverter.java
@@ -64,13 +64,13 @@ public class LazyCreationProxyUriConverter {
throw new IllegalArgumentException("couldn't parse URI :'" + proxyUri);
}
- private final static String DELIM = "%";
+ private final static String DELIM = "-=-";
- protected String encodeFragment(EClass eclass, QualifiedName name) {
+ public String encodeFragment(EClass eclass, QualifiedName name) {
return eclass.getName() + DELIM + name.toString();
}
- protected Pair<EClass, QualifiedName> decodeFragment(String fragment) {
+ public Pair<EClass, QualifiedName> decodeFragment(String fragment) {
String[] segments = fragment.split(DELIM);
if (segments.length == 2) {
String clazzName = segments[0];
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/scoping/XcoreResourceDescriptionStrategy.java b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/scoping/XcoreResourceDescriptionStrategy.java
index be932ed..f464bb9 100644
--- a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/scoping/XcoreResourceDescriptionStrategy.java
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/scoping/XcoreResourceDescriptionStrategy.java
@@ -2,12 +2,14 @@ package org.eclipse.emf.ecore.xcore.scoping;
import org.eclipse.emf.codegen.ecore.genmodel.GenClass;
import org.eclipse.emf.codegen.ecore.genmodel.GenModelFactory;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.xcore.XClass;
import org.eclipse.xtext.common.types.JvmGenericType;
import org.eclipse.xtext.common.types.TypesFactory;
+import org.eclipse.xtext.naming.IQualifiedNameProvider;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.resource.EObjectDescription;
import org.eclipse.xtext.resource.IEObjectDescription;
@@ -30,41 +32,41 @@ public class XcoreResourceDescriptionStrategy extends DefaultResourceDescription
@Inject
private LazyCreationProxyUriConverter proxyTool;
+ @Inject
+ private IQualifiedNameProvider nameProvider;
+
@Override
public boolean createEObjectDescriptions(EObject eObject, IAcceptor<IEObjectDescription> acceptor) {
if (eObject instanceof XClass) {
- final XClass clazz = (XClass) eObject;
- String name = clazz.getName();
- String packageName = clazz.getPackage().getName();
- QualifiedName qn = QualifiedName.create(packageName,name);
- createGenModelDescription(eObject, acceptor, qn);
- createEcoreDescription(eObject, acceptor, qn);
- createJvmTypesDescription(eObject, acceptor, qn);
+ QualifiedName qn = nameProvider.getFullyQualifiedName(eObject);
+ createGenModelDescription(eObject.eResource().getURI(), acceptor, qn);
+ createEcoreDescription(eObject.eResource().getURI(), acceptor, qn);
+ createJvmTypesDescription(eObject.eResource().getURI(), acceptor, qn);
return false;
}
return true;
}
- protected void createJvmTypesDescription(EObject eObject, IAcceptor<IEObjectDescription> acceptor, QualifiedName qn) {
+ protected void createJvmTypesDescription(URI resourceURI, IAcceptor<IEObjectDescription> acceptor, QualifiedName qn) {
JvmGenericType theInterface = typesFactory.createJvmGenericType();
- proxyTool.installProxyURI(eObject.eResource().getURI(), theInterface, qn);
+ proxyTool.installProxyURI(resourceURI, theInterface, qn);
acceptor.accept(EObjectDescription.create(qn, theInterface));
QualifiedName implClassName = QualifiedName.create(qn.toString()+"Impl");
JvmGenericType theImplClass = typesFactory.createJvmGenericType();
- proxyTool.installProxyURI(eObject.eResource().getURI(), theImplClass, implClassName);
+ proxyTool.installProxyURI(resourceURI, theImplClass, implClassName);
acceptor.accept(EObjectDescription.create(implClassName, theImplClass));
}
- protected void createEcoreDescription(EObject eObject, IAcceptor<IEObjectDescription> acceptor, QualifiedName qn) {
+ protected void createEcoreDescription(URI resourceURI, IAcceptor<IEObjectDescription> acceptor, QualifiedName qn) {
EClass eclass = ecoreFactory.createEClass();
- proxyTool.installProxyURI(eObject.eResource().getURI(), eclass, qn);
+ proxyTool.installProxyURI(resourceURI, eclass, qn);
acceptor.accept(EObjectDescription.create(qn, eclass));
}
- protected void createGenModelDescription(EObject eObject, IAcceptor<IEObjectDescription> acceptor, QualifiedName qn) {
+ protected void createGenModelDescription(URI resourceURI, IAcceptor<IEObjectDescription> acceptor, QualifiedName qn) {
GenClass genClass = genFactory.createGenClass();
- proxyTool.installProxyURI(eObject.eResource().getURI(), genClass, qn);
+ proxyTool.installProxyURI(resourceURI, genClass, qn);
acceptor.accept(EObjectDescription.create(qn, genClass));
}