Search in sources :

Example 1 with StorageAwareTrace

use of org.eclipse.xtext.ui.generator.trace.StorageAwareTrace 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);
}
Also used : StorageAwareTrace(org.eclipse.xtext.ui.generator.trace.StorageAwareTrace) Registry(org.eclipse.xtext.resource.IResourceServiceProvider.Registry) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) TraceNotFoundException(org.eclipse.xtext.generator.trace.TraceNotFoundException) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) ITraceRegionProvider(org.eclipse.xtext.generator.trace.ITraceRegionProvider)

Aggregations

IStorage (org.eclipse.core.resources.IStorage)1 URI (org.eclipse.emf.common.util.URI)1 AbstractTraceRegion (org.eclipse.xtext.generator.trace.AbstractTraceRegion)1 ITraceRegionProvider (org.eclipse.xtext.generator.trace.ITraceRegionProvider)1 SourceRelativeURI (org.eclipse.xtext.generator.trace.SourceRelativeURI)1 TraceNotFoundException (org.eclipse.xtext.generator.trace.TraceNotFoundException)1 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)1 Registry (org.eclipse.xtext.resource.IResourceServiceProvider.Registry)1 StorageAwareTrace (org.eclipse.xtext.ui.generator.trace.StorageAwareTrace)1