use of org.eclipse.jdt.core.IJarEntryResource in project xtext-eclipse by eclipse.
the class SourceAttachmentPackageFragmentRootWalker method getLogicalURI.
/**
* Converts the physical URI to a logic URI based on the bundle symbolic name.
*/
protected URI getLogicalURI(URI uri, IStorage storage, TraversalState state) {
if (bundleSymbolicName != null) {
URI logicalURI = URI.createPlatformResourceURI(bundleSymbolicName, false);
List<?> parents = state.getParents();
for (int i = 1; i < parents.size(); i++) {
Object obj = parents.get(i);
if (obj instanceof IPackageFragment) {
logicalURI = logicalURI.appendSegments(((IPackageFragment) obj).getElementName().split("\\."));
} else if (obj instanceof IJarEntryResource) {
logicalURI = logicalURI.appendSegment(((IJarEntryResource) obj).getName());
} else if (obj instanceof IFolder) {
logicalURI = logicalURI.appendSegment(((IFolder) obj).getName());
}
}
return logicalURI.appendSegment(uri.lastSegment());
}
return uri;
}
use of org.eclipse.jdt.core.IJarEntryResource in project xtext-eclipse by eclipse.
the class JarEntryLocator method getURI.
/**
* @return a URI for the given jarEntry, can be <code>null</code>.
*/
public URI getURI(IPackageFragmentRoot root, IJarEntryResource jarEntry, TraversalState state) {
if (root.isArchive()) {
URI jarURI = JarEntryURIHelper.getUriForPackageFragmentRoot(root);
URI storageURI = URI.createURI(jarEntry.getFullPath().toString());
return createJarURI(root.isArchive(), jarURI, storageURI);
} 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());
}
}
use of org.eclipse.jdt.core.IJarEntryResource in project xtext-eclipse by eclipse.
the class Storage2UriMapperJavaImpl method getUri.
/**
* @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;
}
use of org.eclipse.jdt.core.IJarEntryResource in project xtext-eclipse by eclipse.
the class JdtClasspathUriResolver method findResourceInWorkspace.
protected URI findResourceInWorkspace(IJavaProject javaProject, URI classpathUri) throws CoreException {
if (javaProject.exists()) {
String packagePath = classpathUri.trimSegments(1).path();
String fullPath = classpathUri.path();
String fileName = classpathUri.lastSegment();
IPath filePath = new Path(fileName);
String packageName = isEmpty(packagePath) ? "" : packagePath.substring(1).replace('/', '.');
for (IPackageFragmentRoot packageFragmentRoot : javaProject.getAllPackageFragmentRoots()) {
IPackageFragment packageFragment = packageFragmentRoot.getPackageFragment(packageName);
if (packageFragment.exists()) {
IResource packageFragmentResource = packageFragment.getResource();
if (packageFragmentResource instanceof IContainer) {
IFile file = ((IContainer) packageFragmentResource).getFile(filePath);
if (file.exists())
return createPlatformResourceURI(file);
} else {
// jar file or external class folder
if (packageFragmentRoot.isArchive()) {
// jar file
Object[] nonJavaResources = getNonJavaResources(packageFragmentRoot, packageFragment);
for (Object nonJavaResource : nonJavaResources) {
IJarEntryResource jarEntryResource = (IJarEntryResource) nonJavaResource;
if (fullPath.equals(jarEntryResource.getFullPath().toString())) {
IResource packageFragmentRootResource = packageFragmentRoot.getResource();
if (packageFragmentRootResource != null) {
// we have a resource - use nested platform/resource
URI packageFragmentRootURI = createPlatformResourceURI(packageFragmentRootResource);
URI result = createArchiveURI(packageFragmentRootURI, fullPath);
return result;
} else {
// no resource - use file uri
IPath packageFragmentRootPath = packageFragmentRoot.getPath();
URI packageFragmentRootURI = URI.createFileURI(packageFragmentRootPath.toString());
URI result = createArchiveURI(packageFragmentRootURI, fullPath);
return result;
}
}
}
} else if (packageFragmentRoot.isExternal()) {
// external class folder
Object[] nonJavaResources = getNonJavaResources(packageFragmentRoot, packageFragment);
for (Object nonJavaResource : nonJavaResources) {
IJarEntryResource jarEntryResource = (IJarEntryResource) nonJavaResource;
if (fileName.equals(jarEntryResource.getName())) {
IResource packageFragmentRootResource = ((ExternalPackageFragmentRoot) packageFragmentRoot).resource();
IPath absolutePath = packageFragmentRootResource.getFullPath();
absolutePath = absolutePath.append(fullPath);
return createPlatformResourceURI(absolutePath);
}
}
}
}
}
}
// not found in a source folder - look for a resource relative to project root
// of this project or one of its dependencies
URI result = findResourceInProjectRoot(javaProject, classpathUri.path(), Sets.<String>newHashSet());
if (result != null) {
return result;
}
}
return classpathUri;
}
Aggregations