use of org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource in project xtext-eclipse by eclipse.
the class OriginalEditorSelector method getXtextEditor.
/**
* @param traceToSource
*/
protected IEditorDescriptor getXtextEditor(IEclipseTrace traceToSource) {
if (traceToSource != null) {
Iterator<? extends ILocationInEclipseResource> sourceInformationIterator = traceToSource.getAllAssociatedLocations().iterator();
if (sourceInformationIterator.hasNext()) {
ILocationInEclipseResource sourceInformation = sourceInformationIterator.next();
AbsoluteURI absoluteURI = sourceInformation.getAbsoluteResourceURI();
if (absoluteURI != null) {
URI uri = absoluteURI.getURI();
return getXtextEditor(uri);
}
}
}
return null;
}
use of org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource in project xtext-eclipse by eclipse.
the class JavaBreakPointProvider method getJavaLocation.
private ILocationInEclipseResource getJavaLocation(final IJavaStratumLineBreakpoint breakpoint) throws CoreException {
IEclipseTrace javaTrace = getJavaTrace(breakpoint);
if (javaTrace == null)
return null;
TextRegion textRegion = new TextRegion(breakpoint.getCharStart(), 0);
ILocationInEclipseResource javaLocation = javaTrace.getBestAssociatedLocation(textRegion);
if (javaLocation == null)
return null;
return javaLocation;
}
use of org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource in project xtext-eclipse by eclipse.
the class XbaseDocumentProvider method setDocumentContent.
@Override
protected boolean setDocumentContent(IDocument document, IEditorInput input, String encoding) throws CoreException {
if (input instanceof IClassFileEditorInput) {
IClassFile classFile = ((IClassFileEditorInput) input).getClassFile();
ILocationInEclipseResource source = getClassFileSourceStorage(classFile);
if (source == null) {
return false;
}
InputStream contents = null;
try {
contents = source.getContents();
if (contents != null)
setDocumentContent(document, contents, encoding);
} catch (WrappedCoreException e) {
throw e.getCause();
} catch (IOException e) {
throw new CoreException(new Status(IStatus.ERROR, plugin.getBundle().getSymbolicName(), e.getMessage(), e));
} finally {
try {
if (contents != null)
contents.close();
} catch (IOException e1) {
}
}
setDocumentResource((XtextDocument) document, input, encoding);
return true;
}
return super.setDocumentContent(document, input, encoding);
}
use of org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource in project xtext-eclipse by eclipse.
the class XbaseEditorInputRedirector method findOriginalSource.
public IEditorInput findOriginalSource(final IEditorInput input) {
final IFile resource = ResourceUtil.getFile(input);
if ((resource != null)) {
final IEditorInput original = this.findOriginalSourceForOuputFolderCopy(input);
if ((original != input)) {
return original;
}
final IEclipseTrace trace = this.traceInformation.getTraceToSource(resource);
if ((trace == null)) {
return input;
}
final Iterator<? extends ILocationInEclipseResource> allLocations = trace.getAllAssociatedLocations().iterator();
ILocationInEclipseResource sourceInformation = null;
while ((allLocations.hasNext() && (sourceInformation == null))) {
{
final ILocationInEclipseResource candidate = allLocations.next();
boolean _equals = this.languageInfo.equals(candidate.getLanguage());
if (_equals) {
sourceInformation = candidate;
}
}
}
if ((sourceInformation == null)) {
return input;
}
final IStorage originalStorage = sourceInformation.getPlatformResource();
if ((originalStorage != null)) {
return EditorUtils.createEditorInput(originalStorage);
}
}
return input;
}
use of org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource 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;
}
Aggregations