use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.
the class ResourceForIEditorInputFactory method createResource.
/**
* @throws IllegalArgumentException
* if no resource can be provided for the given input.
*/
@Override
public Resource createResource(IEditorInput editorInput) {
try {
if (editorInput instanceof IStorageEditorInput) {
IStorage storage = ((IStorageEditorInput) editorInput).getStorage();
Resource result = createResource(storage);
if (result != null)
return result;
} else if (editorInput instanceof IURIEditorInput) {
Resource result = createResource(((IURIEditorInput) editorInput).getURI());
if (result != null)
return result;
}
} catch (CoreException e) {
throw new WrappedException(e);
}
throw new IllegalArgumentException("Couldn't create EMF Resource for input " + editorInput);
}
use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.
the class XtextDocumentProvider method getEncoding.
@Override
public String getEncoding(Object element) {
String encoding = super.getEncoding(element);
if (encoding == null && element instanceof IStorageEditorInput) {
try {
IStorage storage = ((IStorageEditorInput) element).getStorage();
URI uri = storage2UriMapper.getUri(storage);
if (uri != null) {
encoding = encodingProvider.getEncoding(uri);
} else if (storage instanceof IEncodedStorage) {
encoding = ((IEncodedStorage) storage).getCharset();
}
} catch (CoreException e) {
throw new WrappedException(e);
}
}
if (encoding == null) {
if (isWorkspaceExternalEditorInput(element))
encoding = getWorkspaceExternalEncoding((IURIEditorInput) element);
else
encoding = getWorkspaceOrDefaultEncoding();
}
return encoding;
}
use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.
the class JavaBreakPointProvider method getHandleId.
private String getHandleId(final IJavaStratumLineBreakpoint breakpoint) throws CoreException {
IClassFile classFile = getClassFile(breakpoint);
if (classFile != null)
return classFile.getType().getHandleIdentifier();
ILocationInEclipseResource javaLocation = getJavaLocation(breakpoint);
if (javaLocation == null)
return null;
IStorage javaResource = javaLocation.getPlatformResource();
if (!(javaResource instanceof IFile))
return null;
ICompilationUnit compilationUnit = (ICompilationUnit) JavaCore.create((IFile) javaResource);
IJavaElement element = compilationUnit.getElementAt(javaLocation.getTextRegion().getOffset());
return element == null ? null : element.getHandleIdentifier();
}
use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.
the class StratumBreakpointAdapterFactory method getClassNamePattern.
protected String getClassNamePattern(IResource res) {
if (!(res instanceof IStorage))
return null;
URI uri = uriMapper.getUri((IStorage) res);
IResourceServiceProvider provider = providerRegistry.getResourceServiceProvider(uri);
if (provider == null)
return null;
IResourceSetProvider resourceSetProvider = provider.get(IResourceSetProvider.class);
ResourceSet set = resourceSetProvider.get(res.getProject());
Resource resource = set.getResource(uri, true);
if (resource instanceof XtextResource) {
return getClassNamePattern((XtextResource) resource);
}
return null;
}
use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.
the class TraceEditor method getLocalStorage.
protected IStorage getLocalStorage(IResourceServiceProvider serviceProvider, URI traceURI) {
TraceFileNameProvider fileNameProvider = serviceProvider.get(TraceFileNameProvider.class);
IStorage2UriMapper storage2UriMapper = serviceProvider.get(IStorage2UriMapper.class);
String generatedName = fileNameProvider.getJavaFromTrace(traceURI.lastSegment());
URI generatedURI = traceURI.trimSegments(1).appendSegment(generatedName);
for (Pair<IStorage, IProject> x : storage2UriMapper.getStorages(generatedURI)) return x.getFirst();
throw new IllegalStateException("Could not find IStorage for " + generatedURI);
}
Aggregations