use of org.eclipse.xtext.generator.trace.TraceNotFoundException 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.xtext.generator.trace.TraceNotFoundException in project xtext-eclipse by eclipse.
the class TraceForTypeRootProvider method getTraceToSource.
public IEclipseTrace getTraceToSource(final IClassFile classFile) {
IPath sourcePath = getSourcePath(classFile);
if (sourcePath == null)
return null;
IProject project = classFile.getJavaProject().getProject();
final String javaSimpleFileName = getJavaSimpleFileName(classFile);
SourceRelativeURI localURI = getPathInFragmentRoot(classFile, javaSimpleFileName);
class TraceRegionProvider implements ITraceRegionProvider {
private AbstractTraceWithoutStorage trace;
TraceRegionProvider(AbstractTraceWithoutStorage trace) {
this.trace = trace;
}
@Override
public AbstractTraceRegion getTraceRegion() {
if (javaSimpleFileName == null)
throw new TraceNotFoundException();
String traceSimpleFileName = traceFileNameProvider.getTraceFromJava(javaSimpleFileName);
SourceRelativeURI traceURI = getPathInFragmentRoot(classFile, traceSimpleFileName);
try {
InputStream contents = trace.getContents(traceURI, trace.getLocalProject());
if (contents != null)
try {
return traceRegionSerializer.readTraceRegionFrom(contents);
} finally {
contents.close();
}
} catch (IOException e) {
log.error("Error finding trace region", e);
}
throw new TraceNotFoundException();
}
}
if (isZipFile(sourcePath)) {
ZipFileAwareTrace zipFileAwareTrace = zipFileAwareTraceProvider.get();
zipFileAwareTrace.setProject(project);
zipFileAwareTrace.setZipFilePath(sourcePath);
zipFileAwareTrace.setLocalURI(localURI);
zipFileAwareTrace.setEncoding(getSourceEncoding(classFile));
zipFileAwareTrace.setTraceRegionProvider(new TraceRegionProvider(zipFileAwareTrace));
return zipFileAwareTrace;
} else {
FolderAwareTrace folderAwareTrace = folderAwareTraceProvider.get();
folderAwareTrace.setProject(project);
folderAwareTrace.setRootFolder(sourcePath.toString());
folderAwareTrace.setLocalURI(localURI);
folderAwareTrace.setEncoding(getSourceEncoding(classFile));
folderAwareTrace.setTraceRegionProvider(new TraceRegionProvider(folderAwareTrace));
return folderAwareTrace;
}
}
use of org.eclipse.xtext.generator.trace.TraceNotFoundException in project xtext-core by eclipse.
the class JavaIoFileSystemAccess method generateTrace.
protected void generateTrace(String generatedFile, String outputConfigName, CharSequence contents) {
try {
if (contents instanceof ITraceRegionProvider) {
OutputStream out = null;
try {
AbstractTraceRegion traceRegion = ((ITraceRegionProvider) contents).getTraceRegion();
String traceFileName = traceFileNameProvider.getTraceFromJava(generatedFile);
File traceFile = getFile(traceFileName, outputConfigName);
out = new BufferedOutputStream(new FileOutputStream(traceFile));
traceSerializer.writeTraceRegionTo(traceRegion, out);
if (callBack != null)
callBack.fileAdded(traceFile);
} catch (TraceNotFoundException e) {
// ok
} finally {
if (out != null) {
out.close();
}
}
}
} catch (FileNotFoundException e) {
throw new RuntimeIOException(e);
} catch (IOException e) {
throw new RuntimeIOException(e);
}
}
use of org.eclipse.xtext.generator.trace.TraceNotFoundException in project xtext-core by eclipse.
the class AbstractTraceForURIProvider method getTraceToSource.
public Trace getTraceToSource(final SomeFile generatedFile) {
final PersistedTrace persistedTrace = findPersistedTrace(generatedFile);
if (persistedTrace == null || !persistedTrace.exists()) {
return null;
}
Trace result = newAbstractTrace(generatedFile);
result.setTraceToSource(true);
result.setTraceRegionProvider(new ITraceRegionProvider() {
@Override
public AbstractTraceRegion getTraceRegion() {
AbstractTraceRegion traceRegion = cachedTraces.getTraceRegion(persistedTrace);
if (traceRegion == null) {
throw new TraceNotFoundException();
}
return traceRegion;
}
});
return result;
}
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;
}
Aggregations