Search in sources :

Example 1 with ITraceURIConverter

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

the class AbstractTrace method isAssociatedWith.

protected boolean isAssociatedWith(AbstractTraceRegion region, AbsoluteURI uri, IProjectConfig project) {
    ITraceURIConverter traceURIConverter = getService(uri, ITraceURIConverter.class);
    if (traceURIConverter == null) {
        traceURIConverter = getService(getLocalURI(), ITraceURIConverter.class);
    }
    SourceRelativeURI convertedUri = traceURIConverter.getURIForTrace(project, uri);
    return convertedUri.equals(region.getAssociatedSrcRelativePath());
}
Also used : ITraceURIConverter(org.eclipse.xtext.generator.trace.ITraceURIConverter) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI)

Example 2 with ITraceURIConverter

use of org.eclipse.xtext.generator.trace.ITraceURIConverter 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

ITraceURIConverter (org.eclipse.xtext.generator.trace.ITraceURIConverter)2 SourceRelativeURI (org.eclipse.xtext.generator.trace.SourceRelativeURI)2 List (java.util.List)1 AbsoluteURI (org.eclipse.xtext.generator.trace.AbsoluteURI)1 AbstractTraceRegion (org.eclipse.xtext.generator.trace.AbstractTraceRegion)1 ITraceRegionProvider (org.eclipse.xtext.generator.trace.ITraceRegionProvider)1 TraceNotFoundException (org.eclipse.xtext.generator.trace.TraceNotFoundException)1 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)1