Search in sources :

Example 71 with IStorage

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) IJarEntryResource(org.eclipse.jdt.core.IJarEntryResource) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ForwardingMap(com.google.common.collect.ForwardingMap) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 72 with IStorage

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;
}
Also used : IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) IStorage(org.eclipse.core.resources.IStorage) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 73 with IStorage

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;
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) IStorage(org.eclipse.core.resources.IStorage) IProject(org.eclipse.core.resources.IProject) Pair(org.eclipse.xtext.util.Pair)

Example 74 with IStorage

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;
}
Also used : WrappedException(org.eclipse.emf.common.util.WrappedException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) IStorage(org.eclipse.core.resources.IStorage) IEditorInput(org.eclipse.ui.IEditorInput) Pair(org.eclipse.xtext.util.Pair)

Example 75 with IStorage

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();
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IJavaProject(org.eclipse.jdt.core.IJavaProject) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Aggregations

IStorage (org.eclipse.core.resources.IStorage)96 URI (org.eclipse.emf.common.util.URI)32 IFile (org.eclipse.core.resources.IFile)31 IProject (org.eclipse.core.resources.IProject)27 CoreException (org.eclipse.core.runtime.CoreException)25 IResource (org.eclipse.core.resources.IResource)20 Pair (org.eclipse.xtext.util.Pair)16 Test (org.junit.Test)15 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)13 IStorageEditorInput (org.eclipse.ui.IStorageEditorInput)12 IPath (org.eclipse.core.runtime.IPath)11 IJavaProject (org.eclipse.jdt.core.IJavaProject)10 IOException (java.io.IOException)7 WrappedException (org.eclipse.emf.common.util.WrappedException)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 GitSynchronizeData (org.eclipse.egit.core.synchronize.dto.GitSynchronizeData)6 GitSynchronizeDataSet (org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)6 Storage2UriMapperJavaImpl (org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl)6