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