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;
}
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);
}
}
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));
}
}
Aggregations