use of org.eclipse.xtext.generator.trace.TraceNotFoundException in project xtext-core by eclipse.
the class AbstractTraceForURIProvider method getTraceToTarget.
public Trace getTraceToTarget(final SomeFile sourceFile, final AbsoluteURI absoluteSourceResource, final IProjectConfig projectConfig) {
final List<PersistedTrace> traceFiles = findInverseTraceFiles(sourceFile);
if (traceFiles.isEmpty() || projectConfig == null) {
return null;
}
Trace result = newAbstractTrace(sourceFile);
result.setTraceToSource(false);
final IResourceServiceProvider serviceProvider = getServiceProvider(absoluteSourceResource);
final ITraceURIConverter traceURIConverter = serviceProvider.get(ITraceURIConverter.class);
result.setTraceRegionProvider(new ITraceRegionProvider() {
@Override
public AbstractTraceRegion getTraceRegion() {
List<AbstractTraceRegion> result = newArrayList();
SourceRelativeURI sourceUriForTrace = traceURIConverter.getURIForTrace(projectConfig, absoluteSourceResource);
for (PersistedTrace traceFile : traceFiles) {
AbsoluteURI generatedFileURI = getGeneratedLocation(traceFile);
if (generatedFileURI == null) {
throw new TraceNotFoundException();
}
AbstractTraceRegion traceRegion = cachedTraces.getTraceRegion(traceFile);
SourceRelativeURI generatedUriForTrace = getGeneratedUriForTrace(projectConfig, absoluteSourceResource, generatedFileURI, traceURIConverter);
if (sourceUriForTrace != null && generatedUriForTrace != null) {
result.addAll(traceRegion.invertFor(sourceUriForTrace, generatedUriForTrace));
}
}
if (result.isEmpty())
throw new TraceNotFoundException();
return AbstractTraceRegion.mergedFrom(result);
}
});
return result;
}
use of org.eclipse.xtext.generator.trace.TraceNotFoundException in project xtext-eclipse by eclipse.
the class EclipseResourceFileSystemAccess2 method updateTraceInformation.
/**
* @throws CoreException
* if something unexpected happens during resource access
* @throws IOException
* if serialization of the trace data fails
* @since 2.3
*/
protected void updateTraceInformation(IFile traceFile, CharSequence contents, boolean derived) throws CoreException, IOException {
if (contents instanceof ITraceRegionProvider) {
try {
AbstractTraceRegion traceRegion = ((ITraceRegionProvider) contents).getTraceRegion();
if (sourceTraces == null) {
sourceTraces = HashMultimap.create();
}
IPath tracePath = traceFile.getFullPath();
Iterator<AbstractTraceRegion> iterator = traceRegion.treeIterator();
while (iterator.hasNext()) {
AbstractTraceRegion region = iterator.next();
for (ILocationData location : region.getAssociatedLocations()) {
SourceRelativeURI path = location.getSrcRelativePath();
if (path != null) {
sourceTraces.put(path, tracePath);
}
}
}
class AccessibleOutputStream extends ByteArrayOutputStream {
byte[] internalBuffer() {
return buf;
}
int internalLength() {
return count;
}
}
AccessibleOutputStream data = new AccessibleOutputStream();
traceSerializer.writeTraceRegionTo(traceRegion, data);
// avoid copying the byte array
InputStream input = new ByteArrayInputStream(data.internalBuffer(), 0, data.internalLength());
if (traceFile.exists()) {
traceFile.setContents(input, true, false, monitor);
} else {
traceFile.create(input, true, monitor);
}
setDerived(traceFile, derived);
return;
} catch (TraceNotFoundException e) {
// ok
}
}
if (traceFile.exists()) {
traceFile.delete(IResource.FORCE, monitor);
}
}
Aggregations