use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.
the class Storage2UriMapperJavaImpl method clearCache.
protected void clearCache(IJavaProject project, Set<PackageFragmentRootData> toBeKept) {
Collection<PackageFragmentRootData> values;
synchronized (cachedPackageFragmentRootData) {
values = newArrayList(cachedPackageFragmentRootData.values());
}
List<PackageFragmentRootData> toBeRemoved = newArrayList();
for (PackageFragmentRootData data : values) {
if (toBeKept.contains(data)) {
continue;
}
Map<String, IPackageFragmentRoot> associatedRoots = data.associatedRoots;
synchronized (associatedRoots) {
Iterator<IPackageFragmentRoot> i = associatedRoots.values().iterator();
IPackageFragmentRoot someRoot = null;
boolean didChange = false;
while (i.hasNext()) {
IPackageFragmentRoot root = i.next();
if (project.equals(root.getJavaProject())) {
i.remove();
didChange = true;
} else if (someRoot == null) {
someRoot = root;
}
}
if (associatedRoots.size() == 0) {
toBeRemoved.add(data);
} else if (didChange) {
// get rid of cached storages that still point to roots / projects that are no longer available
// and recompute them lazily on demand
final IPackageFragmentRoot rootToProcess = someRoot;
data.uri2Storage = new ForwardingMap<URI, IStorage>() {
Map<URI, IStorage> delegate;
@Override
protected Map<URI, IStorage> delegate() {
if (delegate == null) {
return delegate = initializeData(rootToProcess).uri2Storage;
}
return delegate;
}
};
}
}
}
if (!toBeRemoved.isEmpty()) {
synchronized (cachedPackageFragmentRootData) {
cachedPackageFragmentRootData.values().removeAll(toBeRemoved);
}
}
}
use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.
the class Storage2UriMapperJavaImpl method initializeData.
/**
* @since 2.4
*/
protected PackageFragmentRootData initializeData(final IPackageFragmentRoot root) {
final PackageFragmentRootData data = new PackageFragmentRootData(computeModificationStamp(root));
data.addRoot(root);
if (shouldHandle(root)) {
try {
final SourceAttachmentPackageFragmentRootWalker<Void> walker = new SourceAttachmentPackageFragmentRootWalker<Void>() {
@Override
protected URI getURI(IFile file, org.eclipse.xtext.ui.resource.PackageFragmentRootWalker.TraversalState state) {
if (!uriValidator.isPossiblyManaged(file))
return null;
return super.getURI(file, state);
}
@Override
protected URI getURI(IJarEntryResource jarEntry, org.eclipse.xtext.ui.resource.PackageFragmentRootWalker.TraversalState state) {
if (!uriValidator.isPossiblyManaged(jarEntry))
return null;
final URI uri = locator.getURI(root, jarEntry, state);
if (!uriValidator.isValid(uri, jarEntry))
return null;
return uri;
}
@Override
protected Void handle(URI uri, IStorage storage, org.eclipse.xtext.ui.resource.PackageFragmentRootWalker.TraversalState state) {
data.uri2Storage.put(uri, storage);
return null;
}
};
walker.traverse(root, false);
if (walker.getBundleSymbolicName() != null)
data.uriPrefix = URI.createPlatformResourceURI(walker.getBundleSymbolicName() + "/", true);
} catch (RuntimeException e) {
log.error(e.getMessage(), e);
} catch (JavaModelException e) {
log.debug(e.getMessage(), e);
}
}
return data;
}
use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.
the class XbaseBreakpointUtil method getBreakpointURI.
// this URI is only used for breakpoints on JARed files
public SourceRelativeURI getBreakpointURI(IEditorInput input) {
IResource resource = Adapters.adapt(input, IResource.class);
if (resource != null)
return null;
if (input instanceof IStorageEditorInput) {
IStorage storage;
try {
storage = ((IStorageEditorInput) input).getStorage();
if (storage instanceof IResource)
return null;
if (storage instanceof IJarEntryResource) {
IJarEntryResource jarEntryResource = (IJarEntryResource) storage;
if (!jarEntryResource.getPackageFragmentRoot().isArchive())
return null;
Object parent = jarEntryResource.getParent();
if (parent instanceof IPackageFragment) {
String path = ((IPackageFragment) parent).getElementName().replace('.', '/');
return new SourceRelativeURI(path + "/" + storage.getName());
} else if (parent instanceof IPackageFragmentRoot) {
return new SourceRelativeURI(storage.getName());
}
}
} catch (CoreException e) {
logger.error("Error finding breakpoint URI", e);
return null;
}
} else {
IClassFile classFile = Adapters.adapt(input, IClassFile.class);
if (classFile != null) {
ITrace traceToSource = traceForTypeRootProvider.getTraceToSource(classFile);
if (traceToSource == null)
return null;
for (ILocationInResource loc : traceToSource.getAllAssociatedLocations()) return loc.getSrcRelativeResourceURI();
return null;
}
}
return null;
}
use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.
the class TraceEditor method updateText.
protected void updateText(EObject obj) {
DebugTraceRegion region = EcoreUtil2.getContainerOfType(obj, DebugTraceRegion.class);
if (region == null) {
text.setText("No " + DebugTraceRegion.class.getSimpleName() + " found for " + obj.eClass().getName());
return;
}
final DebugTraceBasedRegion trace = new DebugTraceBasedRegion(null, region);
SourceRelativeURI sourceURI = trace.getAssociatedSrcRelativePath();
if (sourceURI == null) {
text.setText("Could not find associated URI");
return;
}
Registry registry = IResourceServiceProvider.Registry.INSTANCE;
IResourceServiceProvider serviceProvider = registry.getResourceServiceProvider(sourceURI.getURI());
URI traceURI = obj.eResource().getURI();
IStorage localStorage = getLocalStorage(serviceProvider, traceURI);
StorageAwareTrace traceProvider = serviceProvider.get(StorageAwareTrace.class);
traceProvider.setLocalStorage(localStorage);
traceProvider.setTraceToSource(true);
traceProvider.setTraceRegionProvider(new ITraceRegionProvider() {
@Override
public AbstractTraceRegion getTraceRegion() throws TraceNotFoundException {
return trace;
}
});
String newText = traceProvider.toString();
text.setText(newText);
}
use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.
the class QueuedBuildData method queueURI.
public void queueURI(URI uri) {
Iterable<Pair<IStorage, IProject>> iterable = mapper.getStorages(uri);
boolean associatedWithProject = false;
for (Pair<IStorage, IProject> pair : iterable) {
IProject project = pair.getSecond();
if (XtextProjectHelper.hasNature(project) && XtextProjectHelper.hasBuilder(project)) {
String projectName = project.getName();
LinkedHashSetQueue<URI> list = projectNameToChangedResource.get(projectName);
if (list == null) {
list = new LinkedHashSetQueue<>();
projectNameToChangedResource.put(projectName, list);
}
list.add(uri);
associatedWithProject = true;
}
}
if (!associatedWithProject) {
this.uris.add(uri);
}
}
Aggregations