Search in sources :

Example 81 with IStorage

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);
}
Also used : IStorageEditorInput(org.eclipse.ui.IStorageEditorInput) IURIEditorInput(org.eclipse.ui.IURIEditorInput) WrappedException(org.eclipse.emf.common.util.WrappedException) CoreException(org.eclipse.core.runtime.CoreException) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) IStorage(org.eclipse.core.resources.IStorage)

Example 82 with IStorage

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

Example 83 with IStorage

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();
}
Also used : ILocationInEclipseResource(org.eclipse.xtext.ui.generator.trace.ILocationInEclipseResource) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IJavaElement(org.eclipse.jdt.core.IJavaElement) IClassFile(org.eclipse.jdt.core.IClassFile) IFile(org.eclipse.core.resources.IFile) IStorage(org.eclipse.core.resources.IStorage)

Example 84 with IStorage

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;
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) XtextResource(org.eclipse.xtext.resource.XtextResource) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) IResourceSetProvider(org.eclipse.xtext.ui.resource.IResourceSetProvider)

Example 85 with IStorage

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);
}
Also used : TraceFileNameProvider(org.eclipse.xtext.generator.trace.TraceFileNameProvider) IStorage2UriMapper(org.eclipse.xtext.ui.resource.IStorage2UriMapper) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) IProject(org.eclipse.core.resources.IProject)

Aggregations

IStorage (org.eclipse.core.resources.IStorage)96 URI (org.eclipse.emf.common.util.URI)32 IFile (org.eclipse.core.resources.IFile)31 IProject (org.eclipse.core.resources.IProject)27 CoreException (org.eclipse.core.runtime.CoreException)25 IResource (org.eclipse.core.resources.IResource)20 Pair (org.eclipse.xtext.util.Pair)16 Test (org.junit.Test)15 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)13 IStorageEditorInput (org.eclipse.ui.IStorageEditorInput)12 IPath (org.eclipse.core.runtime.IPath)11 IJavaProject (org.eclipse.jdt.core.IJavaProject)10 IOException (java.io.IOException)7 WrappedException (org.eclipse.emf.common.util.WrappedException)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 GitSynchronizeData (org.eclipse.egit.core.synchronize.dto.GitSynchronizeData)6 GitSynchronizeDataSet (org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)6 Storage2UriMapperJavaImpl (org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl)6