Java Code Examples for org.eclipse.jdt.core.IPackageFragmentRoot#getUnderlyingResource()

The following examples show how to use org.eclipse.jdt.core.IPackageFragmentRoot#getUnderlyingResource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Storage2UriMapperJavaImpl.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.4
 */
@Override
public Map<URI, IStorage> getAllEntries(IPackageFragmentRoot root) {
	try {
		IResource underlyingResource = root.getUnderlyingResource();
		if (underlyingResource instanceof IFolder) {
			return host.getAllEntries((IFolder) underlyingResource);
		}
	} catch (JavaModelException e) {
		if (!e.isDoesNotExist())
			log.error(e.getMessage(), e);
		return emptyMap();
	}
	PackageFragmentRootData data = getData(root);
	return data.uri2Storage;
}
 
Example 2
Source File: Storage2UriMapperJavaImpl.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private Object computeModificationStamp(IPackageFragmentRoot root) {
	try {
		if (root.exists()) {
			IResource resource = root.getUnderlyingResource();
			if (resource != null) {
				Object result = getLastModified(resource);
				if (result != null) {
					return result;
				}
			}
			return root.getPath().toFile().lastModified();
		}
	} catch (CoreException e) {
		log.error(e.getMessage(), e);
	}
	return new Object();
}
 
Example 3
Source File: JavaProjectsStateHelper.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected IPackageFragmentRoot getJavaElement(final IFile file) {
	IJavaProject jp = JavaCore.create(file.getProject());
	if (!jp.exists())
		return null;
	IPackageFragmentRoot[] roots;
	try {
		roots = jp.getPackageFragmentRoots();
		for (IPackageFragmentRoot root : roots) {
			if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
				IResource resource2 = root.getUnderlyingResource();
				if (resource2.contains(file))
					return root;
			}
		}
	} catch (JavaModelException e) {
		if (!e.isDoesNotExist())
			log.error(e.getMessage(), e);
	}
	return null;
}
 
Example 4
Source File: JdtTypeProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.9
 */
protected boolean canLink(IType type) throws JavaModelException {
	IndexedJvmTypeAccess indexedJvmTypeAccess = this.getIndexedJvmTypeAccess();
	if (indexedJvmTypeAccess != null && indexedJvmTypeAccess.isIndexingPhase(getResourceSet())) {
		IResource underlyingResource = type.getUnderlyingResource();
		if (underlyingResource == null) {
			return true;
		}
		for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) {
			if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
				IResource srcUnderlyingResource = root.getUnderlyingResource();
				if (srcUnderlyingResource != null && srcUnderlyingResource.contains(underlyingResource)) {
					return false;
				}
			}
		}
		return true;
	}
	return true;
}
 
Example 5
Source File: SourceAttachmentCommand.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public static SourceAttachmentResult resolveSourceAttachment(IPackageFragmentRoot root, IProgressMonitor monitor) {
	ClasspathEntryWrapper entryWrapper = null;
	try {
		entryWrapper = getClasspathEntry(root);
	} catch (CoreException e) {
		return new SourceAttachmentResult(e.getMessage(), null);
	}

	IResource jarResource = null;
	try {
		jarResource = root.getUnderlyingResource();
	} catch (JavaModelException e1) {
		// do nothing.
	}

	String jarPath = jarResource != null ? jarResource.getLocation().toOSString() : entryWrapper.original.getPath().toOSString();
	String sourceAttachmentPath = entryWrapper.original.getSourceAttachmentPath() != null ? entryWrapper.original.getSourceAttachmentPath().toOSString() : null;
	String sourceAttachmentEncoding = getSourceAttachmentEncoding(entryWrapper.original);
	return new SourceAttachmentResult(null, new SourceAttachmentAttribute(jarPath, sourceAttachmentPath, sourceAttachmentEncoding, entryWrapper.canEditEncoding));
}