public abstract class Location extends java.lang.Object implements java.lang.Comparable<Location>, Located
Location
s and constructs in the source model for the model. A location adjusts the offset and length it exposes to clients to account for edits in the containing model that happen after its creation.
The model is defined by a ModelAdapter
, which encapsulates a workspace, project, and file and serves as a factory and service provider for locations.
Analyzer
implementations typically work directly with constructs rather than with Locations
. However, the Audit framework relies on locations to avoid holding references to constructs and thereby locking entire source models into memory; and to allow it to use source models which are completely recreated whenever the underlying model changes.
Location implements Comparable in such a way that a location which includes another always sorts first.
Notes
When a whole model location is created, the length should be the length of the model. To avoid opening files that don't otherwise need to be opened, the length is set internally to Integer.MAX_VALUE. When used, lengths of Integer.MAX_VALUE are always replaced by model.getStartLength(), which will also be Integer.MAX_VALUE until the model is actually opened. Because getEnd propagates the length to the offset, the same replacement is also done for the internal offset value.
ModelAdapter
Constructor and Description |
---|
Location(ModelAdapter model)
Creates a location within a model.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Location that)
A Location which encloses another will always sort first.
|
boolean |
contains(Location that)
Gets whether this location contains a location.
|
boolean |
equals(java.lang.Object object) |
Location |
getBeginning()
Gets a zero length location at the beginning of this location.
|
Location |
getEnd()
Gets a zero length location at the end of this location.
|
int |
getEndOffset()
Gets the number of characters in the model text buffer before the first character following this location, adjusted for edits to the containing model.
|
int |
getLength()
Gets the number of characters in the model text buffer contained by this location, adjusted for edits to the containing model.
|
Location |
getLocation()
Gets this location in fulfillment of the
Located interface. |
ModelAdapter |
getModel()
Gets the model containing this location.
|
int |
getOffset()
Gets the number of characters in the model text buffer before this location, adjusted for edits to the containing model.
|
Project |
getProject()
Gets the project containing this location.
|
Workspace |
getWorkspace()
Gets the workspace containing this location.
|
int |
hashCode() |
Location |
intersection(Location that)
Gets the intersection of this location with a location, or null if they do not intersect.
|
boolean |
intersects(Location that)
Gets whether this location intersects with a location.
|
boolean |
isRoot()
Gets whether this location corresponds to the root construct in the object model for its model.
|
java.lang.String |
toString() |
public Location(ModelAdapter model)
model
- The ModelAdapter
containing this location.public final Location getLocation()
Located
interface.getLocation
in interface Located
public boolean isRoot()
public Workspace getWorkspace()
public Project getProject()
public ModelAdapter getModel()
public int getOffset()
public int getLength()
public int getEndOffset()
public Location getBeginning()
public Location getEnd()
public Location intersection(Location that)
public boolean contains(Location that)
that
- The location to test.public int compareTo(Location that)
compareTo
in interface java.lang.Comparable<Location>
public boolean intersects(Location that)
public boolean equals(java.lang.Object object)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object