Search in sources :

Example 1 with WrappedRuntimeException

use of org.eclipse.core.internal.utils.WrappedRuntimeException in project xtext-xtend by eclipse.

the class DerivedSourceView method computeInput.

@Override
protected String computeInput(IWorkbenchPartSelection workbenchPartSelection) {
    openEditorAction.setInputFile(null);
    openEditorAction.setSelectedRegion(null);
    IEclipseTrace trace = traceInformation.getTraceToTarget(getEditorResource(workbenchPartSelection));
    if (trace != null) {
        if (workbenchPartSelection instanceof DerivedSourceSelection) {
            DerivedSourceSelection derivedSourceSelection = (DerivedSourceSelection) workbenchPartSelection;
            selectedSource = derivedSourceSelection.getStorage();
        } else {
            derivedSources = Sets.newHashSet();
            TextRegion localRegion = mapTextRegion(workbenchPartSelection);
            Iterable<IStorage> transform = Iterables.filter(transform(trace.getAllAssociatedLocations(localRegion), new Function<ILocationInEclipseResource, IStorage>() {

                @Override
                public IStorage apply(ILocationInEclipseResource input) {
                    return input.getPlatformResource();
                }
            }), Predicates.notNull());
            addAll(derivedSources, transform);
            ILocationInEclipseResource bestAssociatedLocation = trace.getBestAssociatedLocation(localRegion);
            if (bestAssociatedLocation != null) {
                selectedSource = bestAssociatedLocation.getPlatformResource();
            } else if (!derivedSources.isEmpty()) {
                selectedSource = derivedSources.iterator().next();
            }
        }
    }
    IFile file = getSelectedFile();
    if (file != null) {
        try {
            file.refreshLocal(1, new NullProgressMonitor());
            if (file.exists()) {
                openEditorAction.setInputFile(file);
                try (InputStream contents = file.getContents()) {
                    return Files.readStreamIntoString(contents);
                }
            }
        } catch (CoreException | IOException e) {
            throw new WrappedRuntimeException(e);
        }
    }
    return null;
}
Also used : ILocationInEclipseResource(org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) InputStream(java.io.InputStream) IOException(java.io.IOException) IStorage(org.eclipse.core.resources.IStorage) Function(com.google.common.base.Function) CoreException(org.eclipse.core.runtime.CoreException) IEclipseTrace(org.eclipse.xtext.ui.generator.trace.IEclipseTrace) WrappedRuntimeException(org.eclipse.core.internal.utils.WrappedRuntimeException)

Example 2 with WrappedRuntimeException

use of org.eclipse.core.internal.utils.WrappedRuntimeException in project xtext-xtend by eclipse.

the class OpenEditorAction method run.

@Override
public void run() {
    if (inputFile == null) {
        return;
    }
    IWorkbenchPartSite workbenchPartSite = derivedSourceView.getSite();
    IWorkbenchPage workbenchPage = workbenchPartSite.getPage();
    try {
        IEditorPart editorPart = workbenchPage.openEditor(new FileEditorInput(inputFile), COMPILATION_UNIT_EDITOR_ID, true, IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT);
        if (selectedRegion != null) {
            ((ITextEditor) editorPart).selectAndReveal(selectedRegion.getOffset(), selectedRegion.getLength());
        }
    } catch (PartInitException partInitException) {
        throw new WrappedRuntimeException(partInitException);
    }
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) WrappedRuntimeException(org.eclipse.core.internal.utils.WrappedRuntimeException)

Example 3 with WrappedRuntimeException

use of org.eclipse.core.internal.utils.WrappedRuntimeException in project che by eclipse.

the class Resource method accept.

@Override
public void accept(final IResourceProxyVisitor visitor, final int depth, final int memberFlags) throws CoreException {
    java.io.File file = workspace.getFile(getFullPath());
    int maxDepth = depth == IResource.DEPTH_INFINITE ? Integer.MAX_VALUE : depth;
    try {
        final ResourceProxy resourceProxy = new ResourceProxy();
        final int workspacePath = workspace.getAbsoluteWorkspacePath().length();
        Files.walkFileTree(file.toPath(), Collections.<FileVisitOption>emptySet(), maxDepth, new FileVisitor<java.nio.file.Path>() {

            @Override
            public FileVisitResult preVisitDirectory(java.nio.file.Path dir, BasicFileAttributes attrs) throws IOException {
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult visitFile(java.nio.file.Path file, BasicFileAttributes attrs) throws IOException {
                FileVisitResult result = FileVisitResult.CONTINUE;
                try {
                    String string = file.toString();
                    IPath path = new Path(string.substring(workspacePath));
                    resourceProxy.info = workspace.getResourceInfo(path);
                    resourceProxy.fullPath = path;
                    boolean shouldContinue = true;
                    switch(depth) {
                        case DEPTH_ZERO:
                            shouldContinue = false;
                            break;
                        case DEPTH_ONE:
                            shouldContinue = !Resource.this.path.equals(path.removeLastSegments(1));
                            break;
                        case DEPTH_INFINITE:
                            shouldContinue = true;
                            break;
                    }
                    boolean visit = visitor.visit(resourceProxy) && shouldContinue;
                    result = visit ? FileVisitResult.CONTINUE : FileVisitResult.SKIP_SUBTREE;
                } catch (CoreException e) {
                    throw new WrappedRuntimeException(e);
                } finally {
                    resourceProxy.reset();
                }
                return result;
            }

            @Override
            public FileVisitResult visitFileFailed(java.nio.file.Path file, IOException exc) throws IOException {
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult postVisitDirectory(java.nio.file.Path dir, IOException exc) throws IOException {
                return FileVisitResult.CONTINUE;
            }
        });
    } catch (IOException e) {
        throw new CoreException(new Status(IStatus.ERROR, ResourcesPlugin.getPluginId(), e.getMessage(), e));
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IResourceStatus(org.eclipse.core.resources.IResourceStatus) IPath(org.eclipse.core.runtime.IPath) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) IResourceProxy(org.eclipse.core.resources.IResourceProxy) CoreException(org.eclipse.core.runtime.CoreException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) WrappedRuntimeException(org.eclipse.core.internal.utils.WrappedRuntimeException)

Aggregations

WrappedRuntimeException (org.eclipse.core.internal.utils.WrappedRuntimeException)3 IOException (java.io.IOException)2 CoreException (org.eclipse.core.runtime.CoreException)2 Function (com.google.common.base.Function)1 InputStream (java.io.InputStream)1 FileVisitResult (java.nio.file.FileVisitResult)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 IFile (org.eclipse.core.resources.IFile)1 IResourceProxy (org.eclipse.core.resources.IResourceProxy)1 IResourceStatus (org.eclipse.core.resources.IResourceStatus)1 IStorage (org.eclipse.core.resources.IStorage)1 IPath (org.eclipse.core.runtime.IPath)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Path (org.eclipse.core.runtime.Path)1 Status (org.eclipse.core.runtime.Status)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IWorkbenchPartSite (org.eclipse.ui.IWorkbenchPartSite)1 PartInitException (org.eclipse.ui.PartInitException)1