org.eclipse.xtext.generator.trace
Class AbstractTraceRegion

java.lang.Object
  extended by org.eclipse.xtext.generator.trace.AbstractTraceRegion
Direct Known Subclasses:
AbstractStatefulTraceRegion, AppendableBasedTraceRegion

@NonNullByDefault
public abstract class AbstractTraceRegion
extends java.lang.Object

Abstract base class for trace regions. Implements the equals(Object) and hashCode() contract and delegates some functionality to the parent.

Author:
Sebastian Zarnekow - Initial contribution and API

Constructor Summary
protected AbstractTraceRegion(AbstractTraceRegion parent)
          Creates a new trace region and adds it to the parent if a parent was given.
 
Method Summary
protected  java.util.Map<org.eclipse.emf.common.util.URI,java.util.List<Pair<ILocationData,AbstractTraceRegion>>> collectMatchingLocations(org.eclipse.emf.common.util.URI expectedAssociatedPath)
           
 LocationData createLocationData(AbstractTraceRegion region, org.eclipse.emf.common.util.URI myPath, java.lang.String myProjectName)
           
 boolean equals(java.lang.Object obj)
          Compares the specified object with this region for equality.
 java.lang.String getAnnotatedString(java.lang.String input)
           
abstract  java.util.List<ILocationData> getAssociatedLocations()
           
 org.eclipse.emf.common.util.URI getAssociatedPath()
           
 java.lang.String getAssociatedProjectName()
           
protected  java.util.List<Pair<ILocationData,AbstractTraceRegion>> getCollectingList(org.eclipse.emf.common.util.URI associatedPath, org.eclipse.emf.common.util.URI expectedAssociatedPath, java.util.Map<org.eclipse.emf.common.util.URI,java.util.List<Pair<ILocationData,AbstractTraceRegion>>> listsPerURI)
           
 ILocationData getMergedAssociatedLocation()
          Returns the merged location of all associated locations if they belong to the same resource.
abstract  int getMyEndLineNumber()
           
abstract  int getMyLength()
           
abstract  int getMyLineNumber()
           
abstract  int getMyOffset()
           
 ITextRegionWithLineInformation getMyRegion()
           
 java.util.List<AbstractTraceRegion> getNestedRegions()
          Returns the nested trace regions.
 AbstractTraceRegion getParent()
           
protected  java.util.List<AbstractTraceRegion> getWritableNestedRegions()
           
 int hashCode()
          Returns the hash code value for this region.
protected  void inplaceSortByOffset(java.util.List<Pair<ILocationData,AbstractTraceRegion>> locations)
           
 java.util.Map<org.eclipse.emf.common.util.URI,java.util.List<AbstractTraceRegion>> invertAll(org.eclipse.emf.common.util.URI myPath, java.lang.String myProjectName)
           
 java.util.List<AbstractTraceRegion> invertFor(org.eclipse.emf.common.util.URI expectedAssociatedPath, org.eclipse.emf.common.util.URI myPath, java.lang.String myProjectName)
           
protected  boolean isConsistentWithParent()
           
 boolean isUseForDebugging()
           
 java.util.Iterator<AbstractTraceRegion> leafIterator()
          Returns an iterator that will only offer leaf trace regions.
protected  void setAsChildIn(AbstractTraceRegion parent)
           
 void setParent(AbstractTraceRegion parent)
          Sets the parent (if any) and maintains the nested regions of the parent.
protected  java.util.List<AbstractTraceRegion> toInvertedTraceRegions(java.util.List<Pair<ILocationData,AbstractTraceRegion>> locations, org.eclipse.emf.common.util.URI myPath, java.lang.String myProjectName)
          Produces trees from a sorted list of locations.
 java.lang.String toString()
           
 org.eclipse.emf.common.util.TreeIterator<AbstractTraceRegion> treeIterator()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractTraceRegion

protected AbstractTraceRegion(@Nullable
                              AbstractTraceRegion parent)
Creates a new trace region and adds it to the parent if a parent was given.

Method Detail

isConsistentWithParent

protected boolean isConsistentWithParent()

setParent

public void setParent(@Nullable
                      AbstractTraceRegion parent)
Sets the parent (if any) and maintains the nested regions of the parent.

Parameters:
parent - the parent or null if none.
See Also:
setAsChildIn(AbstractTraceRegion)

setAsChildIn

protected void setAsChildIn(AbstractTraceRegion parent)

getNestedRegions

public final java.util.List<AbstractTraceRegion> getNestedRegions()
Returns the nested trace regions. The list does not necessarily contain all the regions that will be returned by the leafIterator().

Returns:
the list of directly nested regions.

getWritableNestedRegions

protected final java.util.List<AbstractTraceRegion> getWritableNestedRegions()

invertFor

public java.util.List<AbstractTraceRegion> invertFor(org.eclipse.emf.common.util.URI expectedAssociatedPath,
                                                     org.eclipse.emf.common.util.URI myPath,
                                                     java.lang.String myProjectName)

invertAll

public java.util.Map<org.eclipse.emf.common.util.URI,java.util.List<AbstractTraceRegion>> invertAll(org.eclipse.emf.common.util.URI myPath,
                                                                                                    java.lang.String myProjectName)

collectMatchingLocations

protected java.util.Map<org.eclipse.emf.common.util.URI,java.util.List<Pair<ILocationData,AbstractTraceRegion>>> collectMatchingLocations(@Nullable
                                                                                                                                          org.eclipse.emf.common.util.URI expectedAssociatedPath)

getCollectingList

@Nullable
protected java.util.List<Pair<ILocationData,AbstractTraceRegion>> getCollectingList(@Nullable
                                                                                             org.eclipse.emf.common.util.URI associatedPath,
                                                                                             @Nullable
                                                                                             org.eclipse.emf.common.util.URI expectedAssociatedPath,
                                                                                             java.util.Map<org.eclipse.emf.common.util.URI,java.util.List<Pair<ILocationData,AbstractTraceRegion>>> listsPerURI)

treeIterator

public org.eclipse.emf.common.util.TreeIterator<AbstractTraceRegion> treeIterator()

inplaceSortByOffset

protected void inplaceSortByOffset(java.util.List<Pair<ILocationData,AbstractTraceRegion>> locations)

toInvertedTraceRegions

protected java.util.List<AbstractTraceRegion> toInvertedTraceRegions(java.util.List<Pair<ILocationData,AbstractTraceRegion>> locations,
                                                                     org.eclipse.emf.common.util.URI myPath,
                                                                     java.lang.String myProjectName)
Produces trees from a sorted list of locations. If the locations overlap, they'll be splitted automatically to fulfill the contract of invariant of trace regions.


createLocationData

public LocationData createLocationData(AbstractTraceRegion region,
                                       org.eclipse.emf.common.util.URI myPath,
                                       java.lang.String myProjectName)

leafIterator

public final java.util.Iterator<AbstractTraceRegion> leafIterator()
Returns an iterator that will only offer leaf trace regions. If the nested regions have gaps, these will be filled with parent data. If this region is a leaf, a singleton iterator will be returned.

Returns:
an unmodifiable iterator for all leafs. Never null.

getMyLength

public abstract int getMyLength()

getMyOffset

public abstract int getMyOffset()

getMyLineNumber

public abstract int getMyLineNumber()

getMyEndLineNumber

public abstract int getMyEndLineNumber()

getMyRegion

public ITextRegionWithLineInformation getMyRegion()

getAssociatedLocations

public abstract java.util.List<ILocationData> getAssociatedLocations()

getMergedAssociatedLocation

@Nullable
public ILocationData getMergedAssociatedLocation()
Returns the merged location of all associated locations if they belong to the same resource. Otherwise null is returned.


getAssociatedPath

@Nullable
public org.eclipse.emf.common.util.URI getAssociatedPath()

getAssociatedProjectName

@Nullable
public java.lang.String getAssociatedProjectName()

getParent

@Nullable
public AbstractTraceRegion getParent()

getAnnotatedString

public java.lang.String getAnnotatedString(java.lang.String input)

isUseForDebugging

public boolean isUseForDebugging()

hashCode

public int hashCode()
Returns the hash code value for this region. The hash code of a trace region r is defined to be:
       r.getMyOffset() 
     ^ r.getMyLength()
     ^ r.getAssociatedOffset()
     ^ r.getAssociatedLength()
     ^ (r.getParent() == null ? 0 : r.getParent().hashCode())
 
This ensures that r1.equals(r2) implies that r1.hashCode()==r2.hashCode() for any two AbstractTraceRegion r1 and r2, as required by the general contract of Object.hashCode.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code value for this trace region
See Also:
Object.hashCode(), Object.equals(Object), equals(Object)

equals

public boolean equals(@Nullable
                      java.lang.Object obj)
Compares the specified object with this region for equality. Returns true if the given object is also an AbstractTraceRegion and the two regions represent the same data. More formally, two regions r1 and r2 are considered to be equal if
     (r1.getMyOffset() == r2.getMyOffset())
  && (r1.getMyLength() == r2.getMyLength())
  && (r1.getAssociatedOffset() == r2.getAssociatedOffset())
  && (r1.getAssociatedLength() == r2.getAssociatedLength())
  && (r1.getParent()==null ?
      r2.getParent()==null : r1.getParent().equals(r2.getParent()))
 
This ensures that the equals(Object) method works properly across different implementations of the AbstractTraceRegion interface.

Overrides:
equals in class java.lang.Object
Parameters:
obj - object to be compared for equality with this trace region
Returns:
true if the specified object is equal to this trace region

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object