summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorszarnekow2009-03-05 11:35:53 (EST)
committer sefftinge2009-03-05 11:35:53 (EST)
commit6686f44aa671906f3354705f150a9dc0405a93b1 (patch)
tree153f67517dd5b0d51355ba1be608a009801a2673
parent5021ec4eac832a3d41f16bed98fc08231e42c160 (diff)
downloadorg.eclipse.xtext-6686f44aa671906f3354705f150a9dc0405a93b1.zip
org.eclipse.xtext-6686f44aa671906f3354705f150a9dc0405a93b1.tar.gz
org.eclipse.xtext-6686f44aa671906f3354705f150a9dc0405a93b1.tar.bz2
Fix: Some ClasspathURIResolver-Implementation omitted the fragment of the uri
Fix: Navigation works for cross links, that were defined via datatype rules
-rw-r--r--plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/hyperlinking/DefaultHyperlinkDetector.java45
-rw-r--r--plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/util/BundleClasspathUriResolver.java5
-rw-r--r--plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/util/JdtClasspathUriResolver.java5
-rw-r--r--plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/util/WorkspaceClasspathUriResolver.java7
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/resource/ClassloaderClasspathUriResolverTests.java17
-rw-r--r--tests/org.eclipse.xtext.ui.integration.tests/src/org/eclipse/xtext/ui/core/util/BundleClasspathUriResolverTest.java14
-rw-r--r--tests/org.eclipse.xtext.ui.integration.tests/src/org/eclipse/xtext/ui/core/util/JdtClasspathUriResolverTest.java23
-rw-r--r--tests/org.eclipse.xtext.ui.integration.tests/src/org/eclipse/xtext/ui/core/util/WorkspaceClasspathUriResolverTest.java23
8 files changed, 115 insertions, 24 deletions
diff --git a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/hyperlinking/DefaultHyperlinkDetector.java b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/hyperlinking/DefaultHyperlinkDetector.java
index 94e2773..cda351d 100644
--- a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/hyperlinking/DefaultHyperlinkDetector.java
+++ b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/hyperlinking/DefaultHyperlinkDetector.java
@@ -29,13 +29,13 @@ import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.xtext.Assignment;
import org.eclipse.xtext.CrossReference;
import org.eclipse.xtext.GrammarUtil;
import org.eclipse.xtext.crossref.ILinkingService;
import org.eclipse.xtext.crossref.impl.IllegalNodeException;
import org.eclipse.xtext.parser.IParseResult;
import org.eclipse.xtext.parsetree.AbstractNode;
-import org.eclipse.xtext.parsetree.LeafNode;
import org.eclipse.xtext.parsetree.NodeUtil;
import org.eclipse.xtext.parsetree.ParseTreeUtil;
import org.eclipse.xtext.resource.XtextResource;
@@ -50,18 +50,18 @@ import com.google.inject.Inject;
* Represents an implementation of interface {@link IHyperlinkDetector} to find
* and convert {@link CrossReference elements}, at a given location, to
* <code>IHyperlink</code>.
- *
+ *
* @author Michael Clay - Initial contribution and API
* @see org.eclipse.jface.text.hyperlink.IHyperlinkDetector
* @see org.eclipse.jface.text.hyperlink.IHyperlink
*/
public class DefaultHyperlinkDetector extends org.eclipse.core.commands.AbstractHandler implements IHyperlinkDetector {
- private ILinkingService linkingService;
- private ILocationInFileProvider locationProvider;
- private ILabelProvider labelProvider;
-
-
+ private final ILinkingService linkingService;
+ private final ILocationInFileProvider locationProvider;
+ private final ILabelProvider labelProvider;
+
+
@Inject
public DefaultHyperlinkDetector(ILinkingService linkingService, ILocationInFileProvider locationProvider, ILabelProvider labelProvider) {
super();
@@ -72,7 +72,7 @@ public class DefaultHyperlinkDetector extends org.eclipse.core.commands.Abstract
// logger available to subclasses
protected final Logger logger = Logger.getLogger(getClass());
-
+
/*
* (non-Javadoc)
* @see org.eclipse.jface.text.hyperlink.IHyperlinkDetector#detectHyperlinks(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion, boolean)
@@ -92,8 +92,9 @@ public class DefaultHyperlinkDetector extends org.eclipse.core.commands.Abstract
for (EObject crossReffed : crossLinkedEObjects) {
final String label = labelProvider.getText(crossReffed);
final URI uri = EcoreUtil.getURI(crossReffed);
+ final URI normalized = crossReffed.eResource().getResourceSet().getURIConverter().normalize(uri);
links.add(new IHyperlink() {
-
+
public IRegion getHyperlinkRegion() {
return location;
}
@@ -104,9 +105,9 @@ public class DefaultHyperlinkDetector extends org.eclipse.core.commands.Abstract
return null;
}
public void open() {
- new OpenDeclarationAction(uri, locationProvider).run();
+ new OpenDeclarationAction(normalized, locationProvider).run();
}
-
+
});
}
return links.toArray(new IHyperlink[links.size()]);
@@ -132,17 +133,21 @@ public class DefaultHyperlinkDetector extends org.eclipse.core.commands.Abstract
});
return this;
}
-
+
protected List<EObject> findCrossLinkedEObject(AbstractNode node) {
- if (node instanceof LeafNode && node.getGrammarElement() instanceof CrossReference) {
- EObject semanticModel = NodeUtil.getNearestSemanticObject(node);
- EReference eReference = GrammarUtil.getReference((CrossReference) node.getGrammarElement(),
- semanticModel.eClass());
- try {
- return linkingService.getLinkedObjects(semanticModel, eReference, node);
- } catch (IllegalNodeException ex) {
- return Collections.emptyList();
+ AbstractNode nodeToCheck = node;
+ while(nodeToCheck != null && !(nodeToCheck.getGrammarElement() instanceof Assignment)) {
+ if (nodeToCheck.getGrammarElement() instanceof CrossReference) {
+ EObject semanticModel = NodeUtil.getNearestSemanticObject(nodeToCheck);
+ EReference eReference = GrammarUtil.getReference((CrossReference) nodeToCheck.getGrammarElement(),
+ semanticModel.eClass());
+ try {
+ return linkingService.getLinkedObjects(semanticModel, eReference, nodeToCheck);
+ } catch (IllegalNodeException ex) {
+ return Collections.emptyList();
+ }
}
+ nodeToCheck = nodeToCheck.getParent();
}
return Collections.emptyList();
}
diff --git a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/util/BundleClasspathUriResolver.java b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/util/BundleClasspathUriResolver.java
index db8bcd1..bb35416 100644
--- a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/util/BundleClasspathUriResolver.java
+++ b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/util/BundleClasspathUriResolver.java
@@ -32,7 +32,10 @@ public class BundleClasspathUriResolver implements IClasspathUriResolver {
Bundle bundle = (Bundle) context;
try {
if (ClasspathUriUtil.isClasspathUri(classpathUri)) {
- return findResourceInBundle(bundle, classpathUri);
+ URI result = findResourceInBundle(bundle, classpathUri);
+ if (classpathUri.fragment() != null)
+ result = result.appendFragment(classpathUri.fragment());
+ return result;
}
} catch (Exception exc) {
throw new ClasspathUriResolutionException(exc);
diff --git a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/util/JdtClasspathUriResolver.java b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/util/JdtClasspathUriResolver.java
index 9ab0140..2014df0 100644
--- a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/util/JdtClasspathUriResolver.java
+++ b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/util/JdtClasspathUriResolver.java
@@ -42,7 +42,10 @@ public class JdtClasspathUriResolver implements IClasspathUriResolver {
try {
if (ClasspathUriUtil.isClasspathUri(classpathUri)) {
IJavaProject javaProject = javaElement.getJavaProject();
- return findResourceInWorkspace(javaProject, classpathUri);
+ URI result = findResourceInWorkspace(javaProject, classpathUri);
+ if (classpathUri.fragment() != null)
+ result = result.appendFragment(classpathUri.fragment());
+ return result;
}
}
catch (Exception exc) {
diff --git a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/util/WorkspaceClasspathUriResolver.java b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/util/WorkspaceClasspathUriResolver.java
index ab8044c..266ea34 100644
--- a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/util/WorkspaceClasspathUriResolver.java
+++ b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/util/WorkspaceClasspathUriResolver.java
@@ -18,7 +18,7 @@ import org.eclipse.xtext.resource.ClasspathUriUtil;
/**
* TODO: implement JDT independent strategy, maybe ignoring JARs
- *
+ *
* @author Jan Köhnlein
*/
public class WorkspaceClasspathUriResolver extends JdtClasspathUriResolver {
@@ -33,7 +33,10 @@ public class WorkspaceClasspathUriResolver extends JdtClasspathUriResolver {
if (ClasspathUriUtil.isClasspathUri(classpathUri)) {
IProject project = resource.getProject();
IJavaProject javaProject = JavaCore.create(project);
- return findResourceInWorkspace(javaProject, classpathUri);
+ URI result = findResourceInWorkspace(javaProject, classpathUri);
+ if (classpathUri.fragment() != null)
+ result = result.appendFragment(classpathUri.fragment());
+ return result;
}
} catch (Exception exc) {
throw new ClasspathUriResolutionException(exc);
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/resource/ClassloaderClasspathUriResolverTests.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/resource/ClassloaderClasspathUriResolverTests.java
index 8cb2f9d..bed8cc1 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/resource/ClassloaderClasspathUriResolverTests.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/resource/ClassloaderClasspathUriResolverTests.java
@@ -42,6 +42,15 @@ public class ClassloaderClasspathUriResolverTests extends TestCase {
normalizeUriAndLoadResource(classpathUri, expectedUri);
}
+ public void testClasspathUriForFileWithFragment() {
+ URI classpathUri = URI
+ .createURI("classpath:/org/eclipse/xtext/resource/mydsl.ecore#/");
+ URL rootURL = getClass().getClassLoader().getResource(
+ "org/eclipse/xtext/resource/mydsl.ecore");
+ String expectedUri = rootURL.toString() + "#/";
+ normalizeUriAndLoadResource(classpathUri, expectedUri);
+ }
+
public void testClasspathUriForFileInJar() {
URI classpathUri = URI.createURI("classpath:/model/simple.ecore");
URL rootURL = getClass().getClassLoader().getResource(
@@ -50,6 +59,14 @@ public class ClassloaderClasspathUriResolverTests extends TestCase {
normalizeUriAndLoadResource(classpathUri, expectedUri);
}
+ public void testClasspathUriForFileInJarWithFragment() {
+ URI classpathUri = URI.createURI("classpath:/model/simple.ecore#/");
+ URL rootURL = getClass().getClassLoader().getResource(
+ "model/simple.ecore");
+ String expectedUri = rootURL.toString() + "#/";
+ normalizeUriAndLoadResource(classpathUri, expectedUri);
+ }
+
private void normalizeUriAndLoadResource(URI classpathUri,
String expectedUri) {
URI normalizedUri = _resolver.resolve(_classLoader, classpathUri);
diff --git a/tests/org.eclipse.xtext.ui.integration.tests/src/org/eclipse/xtext/ui/core/util/BundleClasspathUriResolverTest.java b/tests/org.eclipse.xtext.ui.integration.tests/src/org/eclipse/xtext/ui/core/util/BundleClasspathUriResolverTest.java
index 9d976d4..39332bf 100644
--- a/tests/org.eclipse.xtext.ui.integration.tests/src/org/eclipse/xtext/ui/core/util/BundleClasspathUriResolverTest.java
+++ b/tests/org.eclipse.xtext.ui.integration.tests/src/org/eclipse/xtext/ui/core/util/BundleClasspathUriResolverTest.java
@@ -20,6 +20,13 @@ public class BundleClasspathUriResolverTest extends AbstractClasspathUriResolver
assertResourceLoadable(classpathUri, normalizedUri, null);
}
+ public void testClasspathUriForFileInPluginWithFragment() {
+ URI classpathUri = URI.createURI("classpath:/org/eclipse/xtext/ui/core/util/simple.ecore#/");
+ URI normalizedUri = _resolver.resolve(Platform.getBundle(XtextUIIntegrationTestsPlugin.PLUGIN_ID), classpathUri);
+ assertEquals("/", normalizedUri.fragment());
+ assertResourceLoadable(classpathUri, normalizedUri, null);
+ }
+
public void testPluginClasspathUriForJarredFile() {
// doesn't work
}
@@ -30,4 +37,11 @@ public class BundleClasspathUriResolverTest extends AbstractClasspathUriResolver
assertResourceLoadable(classpathUri, normalizedUri, null);
}
+ public void testClasspathUriForEcoreWithFragment() {
+ URI classpathUri = URI.createURI("classpath:/model/Ecore.ecore#/");
+ URI normalizedUri = _resolver.resolve(Platform.getBundle("org.eclipse.emf.ecore"), classpathUri);
+ assertEquals("/", normalizedUri.fragment());
+ assertResourceLoadable(classpathUri, normalizedUri, null);
+ }
+
}
diff --git a/tests/org.eclipse.xtext.ui.integration.tests/src/org/eclipse/xtext/ui/core/util/JdtClasspathUriResolverTest.java b/tests/org.eclipse.xtext.ui.integration.tests/src/org/eclipse/xtext/ui/core/util/JdtClasspathUriResolverTest.java
index 3046e48..017f8f1 100644
--- a/tests/org.eclipse.xtext.ui.integration.tests/src/org/eclipse/xtext/ui/core/util/JdtClasspathUriResolverTest.java
+++ b/tests/org.eclipse.xtext.ui.integration.tests/src/org/eclipse/xtext/ui/core/util/JdtClasspathUriResolverTest.java
@@ -35,6 +35,17 @@ public class JdtClasspathUriResolverTest extends AbstractClasspathUriResolverTes
assertResourceLoadable(classpathUri, normalizedUri, expectedUri);
}
+ public void testClasspathUriForFileInWorkspaceWithFragment() throws Exception {
+ _javaProject = JavaProjectSetupUtil.createJavaProject(TEST_PROJECT_NAME);
+ _project = _javaProject.getProject();
+ PluginUtil.copyFileToWorkspace(XtextUIIntegrationTestsPlugin.getDefault(), "/testfiles/" + MODEL_FILE, _project, "src/"
+ + MODEL_FILE);
+ URI classpathUri = URI.createURI("classpath:/" + MODEL_FILE + "#/");
+ String expectedUri = "platform:/resource/" + TEST_PROJECT_NAME + "/src/" + MODEL_FILE + "#/";
+ URI normalizedUri = _resolver.resolve(_javaProject, classpathUri);
+ assertResourceLoadable(classpathUri, normalizedUri, expectedUri);
+ }
+
public void testClasspathUriForFileInJarInWorkspace() throws Exception {
_javaProject = JavaProjectSetupUtil.createJavaProject(TEST_PROJECT_NAME);
_project = _javaProject.getProject();
@@ -47,4 +58,16 @@ public class JdtClasspathUriResolverTest extends AbstractClasspathUriResolverTes
assertResourceLoadable(classpathUri, normalizedUri, expectedUri);
}
+ public void testClasspathUriForFileInJarInWorkspaceWithFragment() throws Exception {
+ _javaProject = JavaProjectSetupUtil.createJavaProject(TEST_PROJECT_NAME);
+ _project = _javaProject.getProject();
+ IFile jarFile = PluginUtil.copyFileToWorkspace(XtextUIIntegrationTestsPlugin.getDefault(), "/testfiles/" + JAR_FILE, _project, "/"
+ + JAR_FILE);
+ JavaProjectSetupUtil.addJarToClasspath(_javaProject, jarFile);
+ URI classpathUri = URI.createURI("classpath:/model/" + MODEL_FILE + "#/");
+ String expectedUri = "jar:platform:/resource/" + TEST_PROJECT_NAME + "/" + JAR_FILE + "!/model/" + MODEL_FILE + "#/";
+ URI normalizedUri = _resolver.resolve(_javaProject, classpathUri);
+ assertResourceLoadable(classpathUri, normalizedUri, expectedUri);
+ }
+
}
diff --git a/tests/org.eclipse.xtext.ui.integration.tests/src/org/eclipse/xtext/ui/core/util/WorkspaceClasspathUriResolverTest.java b/tests/org.eclipse.xtext.ui.integration.tests/src/org/eclipse/xtext/ui/core/util/WorkspaceClasspathUriResolverTest.java
index 45e6984..70f3387 100644
--- a/tests/org.eclipse.xtext.ui.integration.tests/src/org/eclipse/xtext/ui/core/util/WorkspaceClasspathUriResolverTest.java
+++ b/tests/org.eclipse.xtext.ui.integration.tests/src/org/eclipse/xtext/ui/core/util/WorkspaceClasspathUriResolverTest.java
@@ -27,6 +27,17 @@ public class WorkspaceClasspathUriResolverTest extends AbstractClasspathUriResol
assertResourceLoadable(classpathUri, normalizedUri, expectedUri);
}
+ public void testClasspathUriForFileInWorkspaceWithFragment() throws Exception {
+ _javaProject = JavaProjectSetupUtil.createJavaProject(TEST_PROJECT_NAME);
+ _project = _javaProject.getProject();
+ PluginUtil.copyFileToWorkspace(XtextUIIntegrationTestsPlugin.getDefault(), "/testfiles/" + MODEL_FILE, _project, "src/"
+ + MODEL_FILE);
+ URI classpathUri = URI.createURI("classpath:/" + MODEL_FILE + "#/");
+ String expectedUri = "platform:/resource/" + TEST_PROJECT_NAME + "/src/" + MODEL_FILE + "#/";
+ URI normalizedUri = _resolver.resolve(_project, classpathUri);
+ assertResourceLoadable(classpathUri, normalizedUri, expectedUri);
+ }
+
public void testClasspathUriForFileInJarInWorkspace() throws Exception {
_javaProject = JavaProjectSetupUtil.createJavaProject(TEST_PROJECT_NAME);
_project = _javaProject.getProject();
@@ -39,4 +50,16 @@ public class WorkspaceClasspathUriResolverTest extends AbstractClasspathUriResol
assertResourceLoadable(classpathUri, normalizedUri, expectedUri);
}
+ public void testClasspathUriForFileInJarInWorkspaceWithFragment() throws Exception {
+ _javaProject = JavaProjectSetupUtil.createJavaProject(TEST_PROJECT_NAME);
+ _project = _javaProject.getProject();
+ IFile jarFile = PluginUtil.copyFileToWorkspace(XtextUIIntegrationTestsPlugin.getDefault(), "/testfiles/" + JAR_FILE, _project, "/"
+ + JAR_FILE);
+ JavaProjectSetupUtil.addJarToClasspath(_javaProject, jarFile);
+ URI classpathUri = URI.createURI("classpath:/model/" + MODEL_FILE + "#/");
+ String expectedUri = "jar:platform:/resource/" + TEST_PROJECT_NAME + "/" + JAR_FILE + "!/model/" + MODEL_FILE + "#/";
+ URI normalizedUri = _resolver.resolve(_project, classpathUri);
+ assertResourceLoadable(classpathUri, normalizedUri, expectedUri);
+ }
+
}