/** @since 2.5 */ @Override public URI getUri(/* @NonNull */ IStorage storage) { if (storage instanceof IJarEntryResource) { final IJarEntryResource casted = (IJarEntryResource) storage; IPackageFragmentRoot packageFragmentRoot = casted.getPackageFragmentRoot(); Map<URI, IStorage> data = getAllEntries(packageFragmentRoot); for (Map.Entry<URI, IStorage> entry : data.entrySet()) { if (entry.getValue().equals(casted)) return entry.getKey(); } if (packageFragmentRoot.exists() && packageFragmentRoot.isArchive()) { IPath jarPath = packageFragmentRoot.getPath(); URI jarURI; if (packageFragmentRoot.isExternal()) { jarURI = URI.createFileURI(jarPath.toOSString()); } else { jarURI = URI.createPlatformResourceURI(jarPath.toString(), true); } URI result = URI.createURI("archive:" + jarURI + "!" + storage.getFullPath()); return result; } } return null; }
private static IEditorInput convertStorageEditorInput(IStorageEditorInput input) { if (input instanceof JarEntryEditorInput) { IProject project = null; JarEntryEditorInput j = (JarEntryEditorInput) input; if (j.getStorage() instanceof IJarEntryResource) { IJarEntryResource file = (IJarEntryResource) j.getStorage(); String jarFile = file.getPackageFragmentRoot().getPath().toString(); if (file.getPackageFragmentRoot().getResource() != null) { jarFile = file.getPackageFragmentRoot().getResource().getLocation().toString(); } String entry = file.getName(); IJarEntryResource r = file; while (r != null && r.getParent() instanceof IJarEntryResource) { r = (IJarEntryResource) r.getParent(); entry = r.getName() + "/" + entry; } if (r != null && r.getParent() instanceof IPackageFragment) { IPackageFragment pf = (IPackageFragment) r.getParent(); IJavaProject jp = pf.getJavaProject(); if (jp != null) project = jp.getProject(); while (pf != null) { String p = pf.getElementName(); entry = p + "/" + entry; if (pf.getParent() instanceof IPackageFragment) { pf = (IPackageFragment) pf.getParent(); } else { pf = null; } } } else if (r != null && r.getPackageFragmentRoot() != null) { IPackageFragmentRoot root = r.getPackageFragmentRoot(); if (root.getJavaProject() != null) { project = root.getJavaProject().getProject(); } } IEditorInput result = createJarEntryEditorInput(project, jarFile, entry); if (result != null) return result; } } String[] entryInfo = parseJarEntryFileInput(input); if (entryInfo == null) return input; String jarFile = entryInfo[0]; String entry = entryInfo[1]; IEditorInput result = createJarEntryEditorInput(null, jarFile, entry); return (result == null || result instanceof NullEditorInput) ? input : result; }