org.eclipse.xtext.builder.trace
Class AbstractTrace

java.lang.Object
  extended by org.eclipse.xtext.builder.trace.AbstractTrace
All Implemented Interfaces:
ITrace, ITrace.Internal
Direct Known Subclasses:
StorageAwareTrace

@NonNullByDefault
public abstract class AbstractTrace
extends java.lang.Object
implements ITrace, ITrace.Internal

Author:
Sebastian Zarnekow - Initial contribution and API

Nested Class Summary
protected  class AbstractTrace.TraceRegionsByURI
           
 
Nested classes/interfaces inherited from interface org.eclipse.xtext.generator.trace.ITrace
ITrace.Internal
 
Constructor Summary
AbstractTrace()
           
 
Method Summary
protected  ILocationInResource createLocationInResourceFor(ILocationData location, AbstractTraceRegion traceRegion)
          Creates a new location for a target resource that matches the given location.
protected abstract  AbstractTraceRegion doGetRootTraceRegion()
           
 boolean encloses(AbstractTraceRegion region, int offset, boolean includeRegionEnd)
          Calculate whether the given region encloses the offset.
 boolean encloses(int regionOffset, int regionLength, int offset, boolean includeRegionEnd)
          Calculate whether the given region encloses the offset.
protected  LanguageInfo findLanguage(org.eclipse.emf.common.util.URI uri)
           
protected  AbstractTraceRegion findParentByURI(AbstractTraceRegion region, org.eclipse.emf.common.util.URI uri)
           
protected  org.eclipse.core.resources.IProject findProject(java.lang.String projectName)
           
protected  org.eclipse.core.resources.IStorage findStorage(org.eclipse.emf.common.util.URI uri, org.eclipse.core.resources.IProject project)
           
protected  AbstractTraceRegion findTraceRegionAt(int offset, boolean includeRegionEnd)
           
 AbstractTraceRegion findTraceRegionAtLeftOffset(int offset)
           
 AbstractTraceRegion findTraceRegionAtRightOffset(int offset)
           
 java.lang.Iterable<ILocationInResource> getAllAssociatedLocations()
          Returns all known associated locations.
 java.lang.Iterable<ILocationInResource> getAllAssociatedLocations(org.eclipse.core.resources.IStorage storage)
          Returns all known locations that were produced from the associated resource in the given targetResource.
 java.lang.Iterable<ILocationInResource> getAllAssociatedLocations(ITextRegion localRegion)
          Returns all associated locations that match the given region.
 java.lang.Iterable<ILocationInResource> getAllAssociatedLocations(ITextRegion region, org.eclipse.core.resources.IStorage storage)
          Returns all individual locations that match the given sourceRegion for the expected targetResource.
protected  java.lang.Iterable<AbstractTraceRegion> getAllTraceRegions()
           
protected  java.lang.Iterable<AbstractTraceRegion> getAllTraceRegions(ITextRegion localRegion)
           
 ILocationInResource getBestAssociatedLocation(ITextRegion region)
          Returns the best associated location that matches the given region.
 ILocationInResource getBestAssociatedLocation(ITextRegion region, org.eclipse.core.resources.IStorage storage)
          Returns the best location that matches the given sourceRegion in the targetResource.
 LanguageInfo getLanguage()
          Returns the language that is associated with the source resource.
abstract  org.eclipse.core.resources.IProject getLocalProject()
          Returns the source project.
abstract  org.eclipse.core.resources.IStorage getLocalStorage()
          Returns the storage that is associated with this trace.
 org.eclipse.emf.common.util.URI getLocalURI()
          Returns the URI of the source resource.
protected  ILocationInResource getMergedLocationInResource(AbstractTraceRegion region)
           
protected  org.eclipse.emf.ecore.resource.Resource getResource(org.eclipse.emf.common.util.URI uri, org.eclipse.core.resources.IProject project)
           
 AbstractTraceRegion getRootTraceRegion()
          Returns the root trace region where AbstractStatefulTraceRegion.getMyOffset() and AbstractStatefulTraceRegion.getMyLength() return the information for the resource that this ITrace is associated with.
protected
<T> T
getService(org.eclipse.emf.common.util.URI uri, java.lang.Class<T> type)
           
protected  org.eclipse.emf.common.util.URI getURIForStorage(org.eclipse.core.resources.IStorage storage)
           
protected  boolean isAssociatedWith(AbstractTraceRegion region, org.eclipse.emf.common.util.URI uri)
           
protected  ILocationInResource mergeRegions(AbstractTraceRegion left, AbstractTraceRegion right)
           
protected  java.lang.Iterable<ILocationInResource> toLocations(java.lang.Iterable<AbstractTraceRegion> allTraceRegions)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractTrace

public AbstractTrace()
Method Detail

getRootTraceRegion

@Nullable
public final AbstractTraceRegion getRootTraceRegion()
Returns the root trace region where AbstractStatefulTraceRegion.getMyOffset() and AbstractStatefulTraceRegion.getMyLength() return the information for the resource that this ITrace is associated with.

Specified by:
getRootTraceRegion in interface ITrace.Internal
Returns:
the root trace region. May be null if no trace data is available.

doGetRootTraceRegion

@Nullable
protected abstract AbstractTraceRegion doGetRootTraceRegion()

getBestAssociatedLocation

@Nullable
public ILocationInResource getBestAssociatedLocation(ITextRegion region)
Description copied from interface: ITrace
Returns the best associated location that matches the given region. If the region does not match a single location, the following strategy applies: If no location data is available, returns null.

Specified by:
getBestAssociatedLocation in interface ITrace
Parameters:
region - the region in the current resource. May not be null.
Returns:
the best associated location or null if none.

mergeRegions

@Nullable
protected ILocationInResource mergeRegions(@Nullable
                                                    AbstractTraceRegion left,
                                                    @Nullable
                                                    AbstractTraceRegion right)

getMergedLocationInResource

@Nullable
protected ILocationInResource getMergedLocationInResource(AbstractTraceRegion region)

createLocationInResourceFor

@Nullable
protected ILocationInResource createLocationInResourceFor(ILocationData location,
                                                                   AbstractTraceRegion traceRegion)
Creates a new location for a target resource that matches the given location.

Parameters:
location - the location
Returns:
the location in resource, null detecting a path or a projectName fails.

findTraceRegionAtRightOffset

@Nullable
public AbstractTraceRegion findTraceRegionAtRightOffset(int offset)

findTraceRegionAt

@Nullable
protected AbstractTraceRegion findTraceRegionAt(int offset,
                                                         boolean includeRegionEnd)

findTraceRegionAtLeftOffset

@Nullable
public AbstractTraceRegion findTraceRegionAtLeftOffset(int offset)

encloses

public boolean encloses(AbstractTraceRegion region,
                        int offset,
                        boolean includeRegionEnd)
Calculate whether the given region encloses the offset.

Parameters:
region - the region to be checked. May not be null.
offset - the offset that should be enclosed by the region.
includeRegionEnd - whether a region is enclosing the offset if it ends at that location.
Returns:
true if the given region encloses the offset.

encloses

public boolean encloses(int regionOffset,
                        int regionLength,
                        int offset,
                        boolean includeRegionEnd)
Calculate whether the given region encloses the offset.

Parameters:
regionOffset - the start of the region that should be checked.
regionLength - the length of the region that should be checked.
offset - the offset that should be enclosed by the region.
includeRegionEnd - whether a region is enclosing the offset if it ends at that location.
Returns:
true if the given region encloses the offset.
This method is not intended to be referenced by clients.
This method is not intended to be referenced by clients.
This method is not intended to be extended (re-implement with a call to the overridden parent) or re-implemented (with no call to the overridden parent) by clients.
This method is not intended to be re-implemented or extended by clients.

getAllAssociatedLocations

public java.lang.Iterable<ILocationInResource> getAllAssociatedLocations(ITextRegion localRegion)
Description copied from interface: ITrace
Returns all associated locations that match the given region.

Specified by:
getAllAssociatedLocations in interface ITrace
Parameters:
localRegion - the region in the current resource. May not be null.
Returns:
all associated locations. Never null.

getBestAssociatedLocation

@Nullable
public ILocationInResource getBestAssociatedLocation(ITextRegion region,
                                                              org.eclipse.core.resources.IStorage storage)
Description copied from interface: ITrace
Returns the best location that matches the given sourceRegion in the targetResource. If the region does not match a single location in the target, the following strategy applies:
  • The merged region of all matching locations in the targetResource is returned.
If no location data is available or the sourceRegion does not yield a location in targetResource, returns null.

Specified by:
getBestAssociatedLocation in interface ITrace
Parameters:
region - the region in the current resource. May not be null.
storage - the expected target resource. May not be null.
Returns:
the best associated location or null if none.

isAssociatedWith

protected boolean isAssociatedWith(AbstractTraceRegion region,
                                   org.eclipse.emf.common.util.URI uri)

findParentByURI

@Nullable
protected AbstractTraceRegion findParentByURI(@Nullable
                                                       AbstractTraceRegion region,
                                                       org.eclipse.emf.common.util.URI uri)

getAllAssociatedLocations

public java.lang.Iterable<ILocationInResource> getAllAssociatedLocations(ITextRegion region,
                                                                         org.eclipse.core.resources.IStorage storage)
Description copied from interface: ITrace
Returns all individual locations that match the given sourceRegion for the expected targetResource.

Specified by:
getAllAssociatedLocations in interface ITrace
Parameters:
region - the region in the current resource. May not be null.
storage - the expected target resource. May not be null.
Returns:
all associated locations. Never null.

getAllAssociatedLocations

public java.lang.Iterable<ILocationInResource> getAllAssociatedLocations(org.eclipse.core.resources.IStorage storage)
Description copied from interface: ITrace
Returns all known locations that were produced from the associated resource in the given targetResource.

Specified by:
getAllAssociatedLocations in interface ITrace
Parameters:
storage - the expected target resource. May not be null.
Returns:
all locations. Never null.

getLanguage

@Nullable
public LanguageInfo getLanguage()
Description copied from interface: ITrace
Returns the language that is associated with the source resource. Never null.

Specified by:
getLanguage in interface ITrace
Returns:
the language that is associated with the source resource. Never null.

getLocalURI

public org.eclipse.emf.common.util.URI getLocalURI()
Description copied from interface: ITrace
Returns the URI of the source resource. Never null.

Specified by:
getLocalURI in interface ITrace
Returns:
the URI of the source resource. Never null.

getURIForStorage

protected org.eclipse.emf.common.util.URI getURIForStorage(org.eclipse.core.resources.IStorage storage)

getLocalProject

public abstract org.eclipse.core.resources.IProject getLocalProject()
Description copied from interface: ITrace
Returns the source project. Never null.

Specified by:
getLocalProject in interface ITrace
Returns:
the source project. Never null.

getLocalStorage

public abstract org.eclipse.core.resources.IStorage getLocalStorage()
Description copied from interface: ITrace
Returns the storage that is associated with this trace.

Specified by:
getLocalStorage in interface ITrace
Returns:
the associated storage. Never null.

toLocations

protected java.lang.Iterable<ILocationInResource> toLocations(java.lang.Iterable<AbstractTraceRegion> allTraceRegions)

getAllTraceRegions

protected java.lang.Iterable<AbstractTraceRegion> getAllTraceRegions(ITextRegion localRegion)

getAllAssociatedLocations

public java.lang.Iterable<ILocationInResource> getAllAssociatedLocations()
Description copied from interface: ITrace
Returns all known associated locations.

Specified by:
getAllAssociatedLocations in interface ITrace
Returns:
all associated locations. Never null.

getAllTraceRegions

protected java.lang.Iterable<AbstractTraceRegion> getAllTraceRegions()

getResource

@Nullable
protected org.eclipse.emf.ecore.resource.Resource getResource(org.eclipse.emf.common.util.URI uri,
                                                                       org.eclipse.core.resources.IProject project)

findStorage

protected org.eclipse.core.resources.IStorage findStorage(org.eclipse.emf.common.util.URI uri,
                                                          org.eclipse.core.resources.IProject project)

findProject

protected org.eclipse.core.resources.IProject findProject(java.lang.String projectName)

findLanguage

@Nullable
protected LanguageInfo findLanguage(@Nullable
                                             org.eclipse.emf.common.util.URI uri)

getService

@Nullable
protected <T> T getService(@Nullable
                                    org.eclipse.emf.common.util.URI uri,
                                    java.lang.Class<T> type)