use of org.eclipse.core.resources.IStorage 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.core.resources.IStorage in project xtext-eclipse by eclipse.
the class ToBeBuiltComputer method updateProject.
/**
* Full build was triggered. Update all information that is available for the given project.
* All contained resources are processed by {@link #updateStorage(IProgressMonitor, ToBeBuilt, IStorage)}.
*
* @see #updateStorage(IProgressMonitor, ToBeBuilt, IStorage)
* @see #isHandled(IFolder)
* @see IToBeBuiltComputerContribution#updateProject(ToBeBuilt, IProject, IProgressMonitor)
*/
public ToBeBuilt updateProject(IProject project, IProgressMonitor monitor) throws CoreException, OperationCanceledException {
final SubMonitor progress = SubMonitor.convert(monitor, Messages.ToBeBuiltComputer_CollectingResources, 10);
progress.subTask(Messages.ToBeBuiltComputer_CollectingResources);
final ToBeBuilt toBeBuilt = doRemoveProject(project, progress.split(8));
if (!project.isAccessible())
return toBeBuilt;
if (progress.isCanceled())
throw new OperationCanceledException();
final SubMonitor childMonitor = progress.split(1);
project.accept(new IResourceVisitor() {
@Override
public boolean visit(IResource resource) throws CoreException {
if (progress.isCanceled())
throw new OperationCanceledException();
if (resource instanceof IStorage) {
return updateStorage(childMonitor, toBeBuilt, (IStorage) resource);
}
if (resource instanceof IFolder) {
return isHandled((IFolder) resource);
}
return true;
}
});
if (progress.isCanceled())
throw new OperationCanceledException();
contribution.updateProject(toBeBuilt, project, progress.split(1));
return toBeBuilt;
}
use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.
the class ToBeBuiltComputer method doRemoveProject.
protected ToBeBuilt doRemoveProject(IProject project, IProgressMonitor monitor) {
queuedBuildData.reset(project);
SubMonitor progress = SubMonitor.convert(monitor, Iterables.size(builderState.getAllResourceDescriptions()) / MONITOR_CHUNK_SIZE + 1);
ToBeBuilt result = new ToBeBuilt();
Iterable<IResourceDescription> allResourceDescriptions = builderState.getAllResourceDescriptions();
int i = 0;
for (IResourceDescription description : allResourceDescriptions) {
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
Iterable<Pair<IStorage, IProject>> storages = mapper.getStorages(description.getURI());
boolean onlyOnThisProject = true;
Iterator<Pair<IStorage, IProject>> iterator = storages.iterator();
while (iterator.hasNext() && onlyOnThisProject) {
Pair<IStorage, IProject> storage2Project = iterator.next();
final IProject second = storage2Project.getSecond();
final boolean isSameProject = project.equals(second);
onlyOnThisProject = isSameProject || second == null || !second.isAccessible();
}
if (onlyOnThisProject)
result.getToBeDeleted().add(description.getURI());
i++;
if (i % MONITOR_CHUNK_SIZE == 0)
progress.worked(1);
}
return result;
}
use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.
the class LanguageSpecificURIEditorOpener method open.
@Override
public IEditorPart open(final URI uri, final EReference crossReference, final int indexInList, final boolean select) {
Iterator<Pair<IStorage, IProject>> storages = mapper.getStorages(uri.trimFragment()).iterator();
if (storages != null && storages.hasNext()) {
try {
IStorage storage = storages.next().getFirst();
IEditorInput editorInput = EditorUtils.createEditorInput(storage);
IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
final IEditorPart editor = IDE.openEditor(activePage, editorInput, getEditorId());
selectAndReveal(editor, uri, crossReference, indexInList, select);
return EditorUtils.getXtextEditor(editor);
} catch (WrappedException e) {
logger.error("Error while opening editor part for EMF URI '" + uri + "'", e.getCause());
} catch (PartInitException partInitException) {
logger.error("Error while opening editor part for EMF URI '" + uri + "'", partInitException);
}
}
return null;
}
use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.
the class JavaProjectsStateHelper method initContainedURIs.
public Collection<URI> initContainedURIs(String containerHandle) {
IJavaElement javaElement = JavaCore.create(containerHandle);
if (javaElement instanceof IPackageFragmentRoot) {
IPackageFragmentRoot root = (IPackageFragmentRoot) javaElement;
IJavaProject javaProject = root.getJavaProject();
if (!isAccessibleXtextProject(javaProject.getProject())) {
return Collections.emptyList();
}
Map<URI, IStorage> entries = uriMapperExtensions.getAllEntries(root);
return entries.keySet();
}
return Collections.emptyList();
}
Aggregations