Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2010 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 /
 package org.eclipse.xtext.ui.resource;
import  org.eclipse.core.resources.IResource;
import  org.eclipse.core.runtime.IPath;
import  org.eclipse.core.runtime.Path;
import  org.eclipse.jdt.core.IJarEntryResource;
import  org.eclipse.jdt.core.IPackageFragment;
import  org.eclipse.jdt.core.IPackageFragmentRoot;
import  org.eclipse.jdt.internal.core.ExternalPackageFragmentRoot;

Sven Efftinge - Initial contribution and API
Sebastian Zarnekow - Initial contribution and API
public class JarEntryLocator {
	private static final Logger log = Logger.getLogger(JarEntryLocator.class);

a URI for the given jarEntry, can be null.
	public URI getURI(IPackageFragmentRoot root, IJarEntryResource jarEntryTraversalState state) {
		if (root.isArchive()) {
			URI jarURI = JarEntryURIHelper.getUriForPackageFragmentRoot(root);
			URI storageURI = URI.createURI(jarEntry.getFullPath().toString());
			return createJarURI(root.isArchive(), jarURIstorageURI);
else if (root instanceof ExternalPackageFragmentRoot) {
			IResource resource = ((ExternalPackageFragmentRoot) root).resource();
			IPath result = resource.getFullPath();
			for(int i = 1; i < state.getParents().size(); i++) {
				Object obj = state.getParents().get(i);
				if (obj instanceof IPackageFragment) {
					result = result.append(new Path(((IPackageFragment) obj).getElementName().replace('.''/')));
else if (obj instanceof IJarEntryResource) {
					result = result.append(((IJarEntryResource) obj).getName());
			result = result.append(jarEntry.getName());
			return URI.createPlatformResourceURI(result.toString(), true);			
else {
			throw new IllegalStateException("Unexpeced root type: " + root.getClass().getName());
	protected URI createJarURI(boolean isArchiveURI uriToRootURI pathToResourceInRoot) {
		if (isArchive) {
			String fullURI = "archive:" + uriToRoot.toString() + "!" + pathToResourceInRoot.toString();
			return URI.createURI(fullURI);
else {
			return null;
New to GrepCode? Check out our FAQ X