Search in sources :

Example 86 with IStorage

use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.

the class TraceBasedOpenerContributor method collectOpeners.

private void collectOpeners(IEclipseTrace trace, ITextRegion region, IAcceptor<FileOpener> acceptor) {
    Iterable<? extends ILocationInEclipseResource> locations = null;
    if (region != null)
        locations = trace.getAllAssociatedLocations(region);
    if (locations == null || Iterables.isEmpty(locations))
        locations = trace.getAllAssociatedLocations();
    Map<IStorage, ITextRegion> result = Maps.newHashMap();
    for (ILocationInEclipseResource location : locations) {
        IStorage storage = location.getPlatformResource();
        if (storage != null) {
            ITextRegion old = result.put(storage, location.getTextRegion());
            if (old != null) {
                ITextRegion merged = old.merge(location.getTextRegion());
                result.put(storage, merged);
            }
        }
    }
    for (Map.Entry<IStorage, ITextRegion> e : result.entrySet()) {
        IStorage storage = e.getKey();
        ITextRegion textRegion = e.getValue();
        acceptor.accept(createStorageBasedTextEditorOpener(storage, textRegion));
    }
}
Also used : ITextRegion(org.eclipse.xtext.util.ITextRegion) IStorage(org.eclipse.core.resources.IStorage) Map(java.util.Map)

Example 87 with IStorage

use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.

the class Storage2UriMapperJdtImplTest method testJaredBundle.

@Test
public void testJaredBundle() throws Exception {
    IJavaProject project = createJavaProject("foo");
    IFile file = project.getProject().getFile("foo.jar");
    file.create(jarInputStream(new TextFile("foo/bar.indexed", "//empty"), new TextFile("foo/bar.notIndexed", "//empty"), new TextFile("META-INF/MANIFEST.MF", "Manifest-Version: 1.0\nBundle-SymbolicName: hubba.bubba\n")), true, monitor());
    file.setLocalTimeStamp(678L);
    addJarToClasspath(project, file);
    Storage2UriMapperJavaImpl impl = getStorage2UriMapper();
    IPackageFragmentRoot root = project.getPackageFragmentRoot(file);
    Map<URI, IStorage> rootData = impl.getAllEntries(root);
    assertEquals(1, rootData.size());
    assertEquals("platform:/resource/hubba.bubba/foo/bar.indexed", rootData.keySet().iterator().next().toString());
    // let's change the bundle name
    file.setContents(jarInputStream(new TextFile("foo/bar.indexed", "//empty"), new TextFile("foo/bar.notIndexed", "//empty"), new TextFile("META-INF/MANIFEST.MF", "Manifest-Version: 1.0\nBundle-SymbolicName: other.bundle.name;singleton:=true\n")), IResource.FORCE, monitor());
    rootData = impl.getAllEntries(root);
    assertEquals(1, rootData.size());
    assertEquals("platform:/resource/other.bundle.name/foo/bar.indexed", rootData.keySet().iterator().next().toString());
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) Storage2UriMapperJavaImpl(org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl) TextFile(org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test)

Example 88 with IStorage

use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.

the class Storage2UriMapperJdtImplTest method getStorage2UriMapper.

protected Storage2UriMapperJavaImpl getStorage2UriMapper() {
    Storage2UriMapperJavaImpl impl = new Storage2UriMapperJavaImpl();
    impl.setUriValidator(new UriValidator() {

        @Override
        public boolean isPossiblyManaged(IStorage storage) {
            return "indexed".equals(storage.getFullPath().getFileExtension());
        }

        @Override
        public boolean isValid(URI uri, IStorage storage) {
            return "indexed".equals(storage.getFullPath().getFileExtension());
        }
    });
    impl.setLocator(new JarEntryLocator());
    return impl;
}
Also used : Storage2UriMapperJavaImpl(org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl) JarEntryLocator(org.eclipse.xtext.ui.resource.JarEntryLocator) UriValidator(org.eclipse.xtext.ui.resource.UriValidator) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI)

Example 89 with IStorage

use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.

the class Storage2UriMapperJavaImplTest method createFreshStorage2UriMapper.

protected Storage2UriMapperJavaImpl createFreshStorage2UriMapper() {
    Storage2UriMapperJavaImpl mapper = new Storage2UriMapperJavaImpl();
    mapper.setUriValidator(new UriValidator() {

        @Override
        public boolean isPossiblyManaged(IStorage storage) {
            return "indexed".equals(storage.getFullPath().getFileExtension());
        }

        @Override
        public boolean isValid(URI uri, IStorage storage) {
            return "indexed".equals(storage.getFullPath().getFileExtension());
        }
    });
    mapper.setLocator(new JarEntryLocator());
    mapper.setWorkspace(ResourcesPlugin.getWorkspace());
    mapper.setWorkspaceLockAccess(new WorkspaceLockAccess());
    mapper.setJavaProjectClasspathChangeAnalyzer(new JavaProjectClasspathChangeAnalyzer());
    return mapper;
}
Also used : WorkspaceLockAccess(org.eclipse.xtext.ui.workspace.WorkspaceLockAccess) Storage2UriMapperJavaImpl(org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl) JarEntryLocator(org.eclipse.xtext.ui.resource.JarEntryLocator) UriValidator(org.eclipse.xtext.ui.resource.UriValidator) IStorage(org.eclipse.core.resources.IStorage) JavaProjectClasspathChangeAnalyzer(org.eclipse.xtext.ui.util.JavaProjectClasspathChangeAnalyzer) URI(org.eclipse.emf.common.util.URI)

Example 90 with IStorage

use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.

the class Storage2UriMapperTest method testSimpleFileInProject.

@Test
public void testSimpleFileInProject() throws Exception {
    IFile file = createFile("foo/bar/baz.txt", "");
    Storage2UriMapperImpl mapper = new Storage2UriMapperImpl() {

        @Override
        public boolean isValidUri(URI uri, IStorage storage) {
            return true;
        }
    };
    mapper.setUriValidator(new UriValidator() {

        @Override
        public boolean isValid(URI uri, IStorage storage) {
            return true;
        }

        @Override
        public boolean isPossiblyManaged(IStorage storage) {
            return true;
        }
    });
    URI uri = mapper.getUri(file);
    assertEquals(URI.createPlatformResourceURI(file.getFullPath().toString(), true), uri);
    assertEquals(file, mapper.getStorages(uri).iterator().next().getFirst());
}
Also used : IFile(org.eclipse.core.resources.IFile) Storage2UriMapperImpl(org.eclipse.xtext.ui.resource.Storage2UriMapperImpl) UriValidator(org.eclipse.xtext.ui.resource.UriValidator) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) Test(org.junit.Test)

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