Community
Participate
Working Groups
The org.eclipse.sphinx.xtendxpand.ui.groups.TemplateGroup#loadTemplate(IFile) method should allow loading files that are not in a project.
(In reply to comment #0) > The org.eclipse.sphinx.xtendxpand.ui.groups.TemplateGroup#loadTemplate(IFile) > method should allow loading files that are not in a project. We have the same problem when loading external extension files with org.eclipse.sphinx.xtendxpand.ui.groups.ExtensionGroup#loadExtensionFile(IFile). The root cause is we search only in workspace location in the org.eclipse.sphinx.xtendxpand.util.XtendXpandUtil#getUnderlyingFile(String, ResourceLoader) method.
(In reply to comment #1) > (In reply to comment #0) > > The org.eclipse.sphinx.xtendxpand.ui.groups.TemplateGroup#loadTemplate(IFile) > > method should allow loading files that are not in a project. > > We have the same problem when loading external extension files with > org.eclipse.sphinx.xtendxpand.ui.groups.ExtensionGroup#loadExtensionFile(IFile). > > The root cause is we search only in workspace location in the > org.eclipse.sphinx.xtendxpand.util.XtendXpandUtil#getUnderlyingFile(String, > ResourceLoader) method. I propose to modify the org.eclipse.sphinx.xtendxpand.util.XtendXpandUtil#getUnderlyingFile(String, ResourceLoader) method like this: public static IFile getUnderlyingFile(String qualifiedName, ResourceLoader resourceLoader) { Assert.isNotNull(resourceLoader); URL resourceURL = resourceLoader.getResource(qualifiedName); if (resourceURL != null) { try { Path location = new Path(resourceURL.toURI().getPath()); if (ResourcesPlugin.getWorkspace().getRoot().getLocation().isPrefixOf(location)) { return ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(location); } return getWorkspaceFileFromFileSystem(EFS.getStore(resourceURL.toURI())); } catch (URISyntaxException ex) { // Ignore exception } catch (CoreException ex) { // Ignore exception } } return null; }
(In reply to comment #2) > (In reply to comment #1) > > (In reply to comment #0) > > > The org.eclipse.sphinx.xtendxpand.ui.groups.TemplateGroup#loadTemplate(IFile) > > > method should allow loading files that are not in a project. > > > > We have the same problem when loading external extension files with > > org.eclipse.sphinx.xtendxpand.ui.groups.ExtensionGroup#loadExtensionFile(IFile). > > > > The root cause is we search only in workspace location in the > > org.eclipse.sphinx.xtendxpand.util.XtendXpandUtil#getUnderlyingFile(String, > > ResourceLoader) method. > > I propose to modify the > org.eclipse.sphinx.xtendxpand.util.XtendXpandUtil#getUnderlyingFile(String, > ResourceLoader) method like this: > > public static IFile getUnderlyingFile(String qualifiedName, ResourceLoader > resourceLoader) { > Assert.isNotNull(resourceLoader); > > URL resourceURL = resourceLoader.getResource(qualifiedName); > if (resourceURL != null) { > try { > Path location = new Path(resourceURL.toURI().getPath()); > if > (ResourcesPlugin.getWorkspace().getRoot().getLocation().isPrefixOf(location)) { > return > ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(location); > } > return > getWorkspaceFileFromFileSystem(EFS.getStore(resourceURL.toURI())); > } catch (URISyntaxException ex) { > // Ignore exception > } catch (CoreException ex) { > // Ignore exception > } > } > return null; > } public static IFile getWorkspaceFileFromFileSystem(IFileStore fileStore) { Assert.isNotNull(fileStore); IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IFile[] files = workspaceRoot.findFilesForLocationURI(fileStore.toURI()); if (files != null && files.length == 1) { return files[0]; } return null; }
(In reply to comment #3) > public static IFile getWorkspaceFileFromFileSystem(IFileStore fileStore) { > Assert.isNotNull(fileStore); > > IWorkspaceRoot workspaceRoot = > ResourcesPlugin.getWorkspace().getRoot(); > IFile[] files = > workspaceRoot.findFilesForLocationURI(fileStore.toURI()); > if (files != null && files.length == 1) { > return files[0]; > } > return null; > } Looks like an interesting approach. Let's try to use it! I'd just say that we don't need an extra getWorkspaceFileFromFileSystem() method for that purpose but should place the code directly into getUnderlyingFile(). And, in getUnderlyingFile(), instead of catch URISyntaxException, catch CoreException we should just code catch Exception.
Fixed as in the bug description.
Mass-closing Resolved tickets