Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoracuccuru2013-08-28 13:04:05 +0000
committerArnaud Cuccuru2013-09-02 09:40:48 +0000
commit710cde428dee51f208d36ff0deacef954c6fdb5c (patch)
tree0e94b84481880dcb06b7728f845a6141f43816db /plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core
parent0ddf2331d864f3d0d6f9ea15a19a73c38320f43a (diff)
downloadorg.eclipse.papyrus-710cde428dee51f208d36ff0deacef954c6fdb5c.tar.gz
org.eclipse.papyrus-710cde428dee51f208d36ff0deacef954c6fdb5c.tar.xz
org.eclipse.papyrus-710cde428dee51f208d36ff0deacef954c6fdb5c.zip
Bug 315231 - Improvement of xtext integration.
Applies patch produced by ITEMIS.
Diffstat (limited to 'plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core')
-rw-r--r--plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/.classpath7
-rw-r--r--plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/.project28
-rw-r--r--plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/META-INF/MANIFEST.MF8
-rw-r--r--plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/build.properties4
-rw-r--r--plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/src/org/eclipse/papyrus/uml/xtext/integration/core/CloningBasedFakeContextResourcesProvider.java46
-rw-r--r--plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/src/org/eclipse/papyrus/uml/xtext/integration/core/ContextElementAdapter.java45
-rw-r--r--plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/src/org/eclipse/papyrus/uml/xtext/integration/core/ContextElementUtil.java31
-rw-r--r--plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/src/org/eclipse/papyrus/uml/xtext/integration/core/IXtextFakeContextResourcesProvider.java34
9 files changed, 210 insertions, 0 deletions
diff --git a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/.classpath b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/.classpath
new file mode 100644
index 00000000000..8a8f1668cdc
--- /dev/null
+++ b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/.project b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/.project
new file mode 100644
index 00000000000..9560df3c7f9
--- /dev/null
+++ b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.uml.xtext.integration.core</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/.settings/org.eclipse.jdt.core.prefs b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..f287d53cf45
--- /dev/null
+++ b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/META-INF/MANIFEST.MF b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..fcc5fe3625b
--- /dev/null
+++ b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/META-INF/MANIFEST.MF
@@ -0,0 +1,8 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Core
+Bundle-SymbolicName: org.eclipse.papyrus.uml.xtext.integration.core
+Bundle-Version: 1.0.0.qualifier
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Require-Bundle: org.eclipse.xtext;bundle-version="2.4.2"
+Export-Package: org.eclipse.papyrus.uml.xtext.integration.core
diff --git a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/build.properties b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/build.properties
new file mode 100644
index 00000000000..41eb6ade2b4
--- /dev/null
+++ b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/src/org/eclipse/papyrus/uml/xtext/integration/core/CloningBasedFakeContextResourcesProvider.java b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/src/org/eclipse/papyrus/uml/xtext/integration/core/CloningBasedFakeContextResourcesProvider.java
new file mode 100644
index 00000000000..2fb3b492aa8
--- /dev/null
+++ b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/src/org/eclipse/papyrus/uml/xtext/integration/core/CloningBasedFakeContextResourcesProvider.java
@@ -0,0 +1,46 @@
+package org.eclipse.papyrus.uml.xtext.integration.core;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.xtext.resource.XtextResource;
+
+/**
+ * An {@link IXtextFakeContextResourcesProvider} that populates the fake
+ * {@link ResourceSet} with 'clones' of the passed in context resources.
+ *
+ * @author alexander.nyssen@itemis.de
+ *
+ */
+public class CloningBasedFakeContextResourcesProvider implements
+ IXtextFakeContextResourcesProvider {
+
+ private final List<Resource> contextResources = new ArrayList<Resource>();
+
+ public CloningBasedFakeContextResourcesProvider(
+ List<Resource> contextResources) {
+ this.contextResources.addAll(contextResources);
+ }
+
+ public void populateFakeResourceSet(
+ ResourceSet fakeResourceSet, XtextResource fakeResource) {
+ for (Resource r : contextResources) {
+ createContextResourceCopyInResourceSet(fakeResourceSet, r);
+ }
+ }
+
+ protected void createContextResourceCopyInResourceSet(
+ ResourceSet resourceSet, Resource contextResource) {
+ // we may not add the context resource to the fake resource set, because
+ // it would be removed from its original resource set then. We can also
+ // not simply load the resource by its uri, because this would not be
+ // "dirty-aware". Therefore we perform a deep copy here.
+ Resource contextResourceCopy = resourceSet
+ .createResource(contextResource.getURI());
+ contextResourceCopy.getContents().addAll(
+ EcoreUtil.copyAll(contextResource.getContents()));
+ }
+}
diff --git a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/src/org/eclipse/papyrus/uml/xtext/integration/core/ContextElementAdapter.java b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/src/org/eclipse/papyrus/uml/xtext/integration/core/ContextElementAdapter.java
new file mode 100644
index 00000000000..20c25b9b74a
--- /dev/null
+++ b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/src/org/eclipse/papyrus/uml/xtext/integration/core/ContextElementAdapter.java
@@ -0,0 +1,45 @@
+/**
+ * Copyright (c) 2012 itemis AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * itemis AG - initial API and implementation
+ *
+ */
+package org.eclipse.papyrus.uml.xtext.integration.core;
+
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ * The {@link ContextElementAdapter} is added to the FakeResource to get access
+ * to the context element for scoping/validation.
+ *
+ * @author andreas muelder - Initial contribution and API
+ *
+ */
+
+public class ContextElementAdapter extends AdapterImpl {
+
+ public interface IContextElementProvider {
+ public EObject getContextObject();
+ }
+
+ private final IContextElementProvider provider;
+
+ public ContextElementAdapter(IContextElementProvider provider) {
+ this.provider = provider;
+ }
+
+ @Override
+ public boolean isAdapterForType(Object type) {
+ return type == ContextElementAdapter.class;
+ }
+
+ public EObject getElement() {
+ return provider.getContextObject();
+ }
+}
diff --git a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/src/org/eclipse/papyrus/uml/xtext/integration/core/ContextElementUtil.java b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/src/org/eclipse/papyrus/uml/xtext/integration/core/ContextElementUtil.java
new file mode 100644
index 00000000000..e95f6d51632
--- /dev/null
+++ b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/src/org/eclipse/papyrus/uml/xtext/integration/core/ContextElementUtil.java
@@ -0,0 +1,31 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.xtext.integration.core;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+
+public class ContextElementUtil {
+
+ public static EObject getContextElement(Resource resource) {
+ ContextElementAdapter existingAdapter = (ContextElementAdapter) EcoreUtil.getExistingAdapter(resource,
+ ContextElementAdapter.class);
+ if (existingAdapter != null) {
+ return existingAdapter.getElement();
+ }
+ return null;
+ }
+}
diff --git a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/src/org/eclipse/papyrus/uml/xtext/integration/core/IXtextFakeContextResourcesProvider.java b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/src/org/eclipse/papyrus/uml/xtext/integration/core/IXtextFakeContextResourcesProvider.java
new file mode 100644
index 00000000000..7ee13090d39
--- /dev/null
+++ b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.core/src/org/eclipse/papyrus/uml/xtext/integration/core/IXtextFakeContextResourcesProvider.java
@@ -0,0 +1,34 @@
+package org.eclipse.papyrus.uml.xtext.integration.core;
+
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.xtext.resource.XtextResource;
+
+/**
+ *
+ * @author alexander.nyssen@itemis.de
+ *
+ */
+public interface IXtextFakeContextResourcesProvider {
+
+ public static final IXtextFakeContextResourcesProvider NULL_CONTEXT_PROVIDER = new IXtextFakeContextResourcesProvider() {
+ public void populateFakeResourceSet(
+ ResourceSet fakeResourceSet, XtextResource fakeResource) {
+ };
+ };
+
+ /**
+ * Populate the fake resource set with additional resources that may be
+ * needed for scoping/linking. The fake resource used will be passe in as
+ * context information. Note that at the time this callback is invoked, the
+ * fake resource will not be contained in the fake resource set, because
+ * that may cause problems when working with the resource set (as the fake
+ * resource does actually not exist in the file system).
+ *
+ * @param fakeResourceSet
+ * the {@link ResourceSet} to populate
+ * @param fakeResource
+ * the fake {@link XtextResource} as context information.
+ */
+ void populateFakeResourceSet(ResourceSet fakeResourceSet,
+ XtextResource fakeResource);
+}

Back to the top