summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoritz Eysholdt2012-05-23 10:31:51 (EDT)
committer Sebastian Zarnekow2012-05-24 03:21:45 (EDT)
commite093c7e026e43e0ce30f5aa003e9bd4573a895cb (patch)
treed1312e722d56e463756b8d3dab8409096a7410c5
parente8693b487a4ee66a297f28a5249a61881038b252 (diff)
downloadorg.eclipse.mwe-e093c7e026e43e0ce30f5aa003e9bd4573a895cb.zip
org.eclipse.mwe-e093c7e026e43e0ce30f5aa003e9bd4573a895cb.tar.gz
org.eclipse.mwe-e093c7e026e43e0ce30f5aa003e9bd4573a895cb.tar.bz2
fixed 378958: cannot resolve workflow references
Signed-off-by: Sebastian Zarnekow <Sebastian.Zarnekow@itemis.de>
-rw-r--r--plugins/org.eclipse.emf.mwe2.language.ui/src/org/eclipse/emf/mwe2/language/ui/Mwe2UiModule.java6
-rw-r--r--plugins/org.eclipse.emf.mwe2.language/src/org/eclipse/emf/mwe2/language/Mwe2RuntimeModule.java7
-rw-r--r--plugins/org.eclipse.emf.mwe2.language/src/org/eclipse/emf/mwe2/language/scoping/Mwe2StateBasedContainerManager.java50
-rw-r--r--tests/org.eclipse.emf.mwe2.language.tests/src/org/eclipse/emf/mwe2/language/tests/container/Mwe2ContainerTest.java67
4 files changed, 130 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.mwe2.language.ui/src/org/eclipse/emf/mwe2/language/ui/Mwe2UiModule.java b/plugins/org.eclipse.emf.mwe2.language.ui/src/org/eclipse/emf/mwe2/language/ui/Mwe2UiModule.java
index 374cdfa..37ff18d 100644
--- a/plugins/org.eclipse.emf.mwe2.language.ui/src/org/eclipse/emf/mwe2/language/ui/Mwe2UiModule.java
+++ b/plugins/org.eclipse.emf.mwe2.language.ui/src/org/eclipse/emf/mwe2/language/ui/Mwe2UiModule.java
@@ -15,7 +15,9 @@ import org.eclipse.emf.mwe2.language.ui.highlighting.TokenToAttributeMapper;
import org.eclipse.emf.mwe2.language.ui.hover.Mwe2EObjectHoverProvider;
import org.eclipse.emf.mwe2.language.ui.outline.Mwe2OutlineComparator;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.eclipse.xtext.resource.IContainer;
import org.eclipse.xtext.resource.XtextResourceSet;
+import org.eclipse.xtext.resource.containers.StateBasedContainerManager;
import org.eclipse.xtext.ui.editor.hover.IEObjectHoverProvider;
import org.eclipse.xtext.ui.editor.outline.impl.OutlineFilterAndSorter;
import org.eclipse.xtext.ui.editor.syntaxcoloring.AbstractAntlrTokenToAttributeIdMapper;
@@ -61,4 +63,8 @@ public class Mwe2UiModule extends org.eclipse.emf.mwe2.language.ui.AbstractMwe2U
return Mwe2EObjectHoverProvider.class;
}
+ public Class<? extends IContainer.Manager> bindIContainer$Manager() {
+ return StateBasedContainerManager.class;
+ }
+
}
diff --git a/plugins/org.eclipse.emf.mwe2.language/src/org/eclipse/emf/mwe2/language/Mwe2RuntimeModule.java b/plugins/org.eclipse.emf.mwe2.language/src/org/eclipse/emf/mwe2/language/Mwe2RuntimeModule.java
index 10b758e..01562f7 100644
--- a/plugins/org.eclipse.emf.mwe2.language/src/org/eclipse/emf/mwe2/language/Mwe2RuntimeModule.java
+++ b/plugins/org.eclipse.emf.mwe2.language/src/org/eclipse/emf/mwe2/language/Mwe2RuntimeModule.java
@@ -11,6 +11,7 @@ package org.eclipse.emf.mwe2.language;
import org.eclipse.emf.mwe2.language.resource.MweLocationInFileProvider;
import org.eclipse.emf.mwe2.language.resource.MweResourceDescriptionStrategy;
import org.eclipse.emf.mwe2.language.resource.MweResourceSetProvider;
+import org.eclipse.emf.mwe2.language.scoping.Mwe2StateBasedContainerManager;
import org.eclipse.emf.mwe2.language.scoping.NamespaceAwareScopeProvider;
import org.eclipse.emf.mwe2.language.scoping.QualifiedNameProvider;
import org.eclipse.xtext.conversion.IValueConverterService;
@@ -18,6 +19,7 @@ import org.eclipse.xtext.naming.IQualifiedNameProvider;
import org.eclipse.xtext.resource.IDefaultResourceDescriptionStrategy;
import org.eclipse.xtext.resource.ILocationInFileProvider;
import org.eclipse.xtext.resource.XtextResourceSet;
+import org.eclipse.xtext.resource.IContainer.Manager;
import com.google.inject.Provider;
@@ -59,4 +61,9 @@ public class Mwe2RuntimeModule extends org.eclipse.emf.mwe2.language.AbstractMwe
return MweResourceDescriptionStrategy.class;
}
+ @Override
+ public Class<? extends Manager> bindIContainer$Manager() {
+ return Mwe2StateBasedContainerManager.class;
+ }
+
}
diff --git a/plugins/org.eclipse.emf.mwe2.language/src/org/eclipse/emf/mwe2/language/scoping/Mwe2StateBasedContainerManager.java b/plugins/org.eclipse.emf.mwe2.language/src/org/eclipse/emf/mwe2/language/scoping/Mwe2StateBasedContainerManager.java
new file mode 100644
index 0000000..3927e47
--- /dev/null
+++ b/plugins/org.eclipse.emf.mwe2.language/src/org/eclipse/emf/mwe2/language/scoping/Mwe2StateBasedContainerManager.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2012 itemis AG (http://www.itemis.eu) 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
+ *******************************************************************************/
+package org.eclipse.emf.mwe2.language.scoping;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.xtext.resource.IContainer;
+import org.eclipse.xtext.resource.IResourceDescription;
+import org.eclipse.xtext.resource.IResourceDescriptions;
+import org.eclipse.xtext.resource.containers.DescriptionAddingContainer;
+import org.eclipse.xtext.resource.containers.StateBasedContainerManager;
+import org.eclipse.xtext.resource.impl.DefaultContainer;
+
+/**
+ * @author Moritz Eysholdt - Initial contribution and API
+ */
+public class Mwe2StateBasedContainerManager extends StateBasedContainerManager {
+
+ /**
+ * In contrast to super.{@link #getVisibleContainers(IResourceDescription, IResourceDescriptions)}, this
+ * implementation will never return an empty list of containers.
+ *
+ * If the current resource (desc) is not in any container, a new container will be created.
+ *
+ * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=378958
+ */
+ @Override
+ public List<IContainer> getVisibleContainers(IResourceDescription desc, IResourceDescriptions resourceDescriptions) {
+ String root = internalGetContainerHandle(desc, resourceDescriptions);
+ List<String> handles = getState(resourceDescriptions).getVisibleContainerHandles(root);
+ List<IContainer> result = getVisibleContainers(handles, resourceDescriptions);
+ if (result.isEmpty())
+ result.add(new DefaultContainer(Collections.singleton(desc)));
+ else {
+ IContainer first = result.get(0);
+ if (!first.hasResourceDescription(desc.getURI())) {
+ first = new DescriptionAddingContainer(desc, first);
+ result.set(0, first);
+ }
+ }
+ return result;
+ }
+
+}
diff --git a/tests/org.eclipse.emf.mwe2.language.tests/src/org/eclipse/emf/mwe2/language/tests/container/Mwe2ContainerTest.java b/tests/org.eclipse.emf.mwe2.language.tests/src/org/eclipse/emf/mwe2/language/tests/container/Mwe2ContainerTest.java
new file mode 100644
index 0000000..0662a53
--- /dev/null
+++ b/tests/org.eclipse.emf.mwe2.language.tests/src/org/eclipse/emf/mwe2/language/tests/container/Mwe2ContainerTest.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2012 itemis AG (http://www.itemis.eu) 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
+ *******************************************************************************/
+package org.eclipse.emf.mwe2.language.tests.container;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.mwe2.language.Mwe2InjectorProvider;
+import org.eclipse.emf.mwe2.language.mwe2.Module;
+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.mwe.ContainersStateFactory;
+import org.eclipse.xtext.resource.XtextResourceSet;
+import org.eclipse.xtext.resource.containers.DelegatingIAllContainerAdapter;
+import org.eclipse.xtext.resource.containers.IAllContainersState;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.google.common.collect.Multimaps;
+import com.google.common.collect.SetMultimap;
+import com.google.inject.Inject;
+
+/**
+ * @author Moritz Eysholdt - Initial contribution and API
+ */
+@RunWith(XtextRunner.class)
+@InjectWith(Mwe2InjectorProvider.class)
+public class Mwe2ContainerTest {
+
+ @Inject
+ private ParseHelper<Module> parseHelper;
+
+ @Inject
+ private ContainersStateFactory stateFactory;
+
+ @Inject
+ private ValidationTestHelper validator;
+
+ @Test
+ public void testFileNotOnClasspath() throws Exception {
+ ResourceSet rs = new XtextResourceSet();
+
+ // create first file
+ URI target = URI.createURI("platform:/resource/project/target.mwe2");
+ parseHelper.parse("module target", target, rs);
+
+ // configure container for this file
+ final String CONTAINER = "mycontainer";
+ SetMultimap<String, URI> mapped = Multimaps.forMap(Collections.singletonMap(CONTAINER, target));
+ List<String> containers = Collections.singletonList(CONTAINER);
+ IAllContainersState containersState = stateFactory.getContainersState(containers, mapped);
+ rs.eAdapters().add(new DelegatingIAllContainerAdapter(containersState));
+
+ // assume we can link to the first file even though the new file is not contained in any container
+ Module module = parseHelper.parse("module source Workflow { component = @target {} }", rs);
+ validator.assertNoErrors(module);
+ }
+}