Search in sources :

Example 6 with IEncodedStorage

use of org.eclipse.core.resources.IEncodedStorage 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;
}
Also used : IStorageEditorInput(org.eclipse.ui.IStorageEditorInput) WrappedException(org.eclipse.emf.common.util.WrappedException) CoreException(org.eclipse.core.runtime.CoreException) IEncodedStorage(org.eclipse.core.resources.IEncodedStorage) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI)

Aggregations

IEncodedStorage (org.eclipse.core.resources.IEncodedStorage)6 CoreException (org.eclipse.core.runtime.CoreException)5 IStorage (org.eclipse.core.resources.IStorage)4 IStorageEditorInput (org.eclipse.ui.IStorageEditorInput)3 InputStream (java.io.InputStream)2 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Charset (java.nio.charset.Charset)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 Path (org.eclipse.core.runtime.Path)1 QualifiedName (org.eclipse.core.runtime.QualifiedName)1 IContentDescription (org.eclipse.core.runtime.content.IContentDescription)1 IJobManager (org.eclipse.core.runtime.jobs.IJobManager)1 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)1 URI (org.eclipse.emf.common.util.URI)1 WrappedException (org.eclipse.emf.common.util.WrappedException)1 Document (org.eclipse.jface.text.Document)1 IDocument (org.eclipse.jface.text.IDocument)1 IEditorInput (org.eclipse.ui.IEditorInput)1