Search in sources :

Example 21 with SourceRelativeURI

use of org.eclipse.xtext.generator.trace.SourceRelativeURI in project xtext-core by eclipse.

the class TracingSugar method location.

/**
 * @return ILocationData covering the <code>fullTextRegion</code> of the given EObject.
 */
public ILocationData location(EObject obj) {
    ITextRegion region = locationProvider.getFullTextRegion(obj);
    SourceRelativeURI uri = traceURIConverter.getURIForTrace(obj.eResource());
    return new LocationData((ITextRegionWithLineInformation) region, uri);
}
Also used : LocationData(org.eclipse.xtext.generator.trace.LocationData) ILocationData(org.eclipse.xtext.generator.trace.ILocationData) ITextRegion(org.eclipse.xtext.util.ITextRegion) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI)

Example 22 with SourceRelativeURI

use of org.eclipse.xtext.generator.trace.SourceRelativeURI 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;
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) TraceNotFoundException(org.eclipse.xtext.generator.trace.TraceNotFoundException) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) List(java.util.List) ITraceURIConverter(org.eclipse.xtext.generator.trace.ITraceURIConverter) ITraceRegionProvider(org.eclipse.xtext.generator.trace.ITraceRegionProvider) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) AbsoluteURI(org.eclipse.xtext.generator.trace.AbsoluteURI)

Aggregations

SourceRelativeURI (org.eclipse.xtext.generator.trace.SourceRelativeURI)22 AbstractTraceRegion (org.eclipse.xtext.generator.trace.AbstractTraceRegion)7 ITraceRegionProvider (org.eclipse.xtext.generator.trace.ITraceRegionProvider)5 IFile (org.eclipse.core.resources.IFile)4 IPath (org.eclipse.core.runtime.IPath)4 URI (org.eclipse.emf.common.util.URI)4 AbsoluteURI (org.eclipse.xtext.generator.trace.AbsoluteURI)4 ILocationData (org.eclipse.xtext.generator.trace.ILocationData)4 TraceNotFoundException (org.eclipse.xtext.generator.trace.TraceNotFoundException)4 InputStream (java.io.InputStream)3 IResource (org.eclipse.core.resources.IResource)3 CoreException (org.eclipse.core.runtime.CoreException)3 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IContainer (org.eclipse.core.resources.IContainer)2 IProject (org.eclipse.core.resources.IProject)2 IStorage (org.eclipse.core.resources.IStorage)2 Path (org.eclipse.core.runtime.Path)2 IClassFile (org.eclipse.jdt.core.IClassFile)2 IEditorInput (org.eclipse.ui.IEditorInput)2