D
- the type of document identifiers@Runtime public abstract class Location<D> extends Object implements Serializable, Cloneable, Locatable<D>
A document is a textual entity. A document
identifier is an object that refers to a document.
(In this implementation, a document id ==null
is permitted.
"D" may even be the "Void" type.)
A document
contains a set of positions. Each position is characterized
uniquely by the identifier of the containing document, a line
number and a column number. Positions are related
spatially in many ways:
p
and q
lie in the same
document if and only if their document identifiers are equal.
p
and q
lie in the same line
if and only if they lie in the same document and their line
numbers are equal.
p
lies before position q
, or
equivalently q
after p
in the same line if and
only if they lie in the same line and the column number of q
is greater.
p
lies at the beginning of a line if and
only if there is no position q
that lies before p
in the same line.
p
lies at the end of a line if and only if
there is no position q
that lies after p
in the
same line.
p
lies before position q
in the
same document if and only if either p
lies before q
in the same line or they lie in the same document and the line
number of q
is greater.
p
lies immediately before position q
if and only if there is no position r
that lies after
p
and before q
in the same document.
A document contains exactly one character between each pair of adjacent positions.
A location may refer to both positions and characters in one or more documents. If a character is included, then so are the adjacent positions that enclose it. Every location refers to one or more positions.
A location is one of the following:
Particular line and column numbers are in the range MIN_PARTICULAR
(0) thru MAX_PARTICULAR
(2147483646). Whether a document
starts numbering lines and/or columns from zero or one is
application-specific.
(ATTENTION: In the metatools context the following traditions are relevant:
xemacs | starts LINES with 1(one) | starts COLUMNS with 0(zero) |
antlr | starts LINES with 1(one) | starts COLUMNS with 1(one) |
tools.d2d2.infra.MemString | starts LINES with 0(zero) | starts COLUMNS with 0(zero) |
SimpleMessage
or sim. FIXME
Two additional pseudo-numbers are valid for lines and columns:
NOT_APPLICABLE
for either lines
or columns indicates that the document's structure does not have
the respective dimension. For instance, a vertical list of atomic
strings has lines but no columns, whereas a Swing text document
model has columns but no lines. A position is called
line-deficient if and only if its line number is NOT_APPLICABLE
, and column-deficient if and only if its
column number is NOT_APPLICABLE
. An application should
never have locations referring to both deficient and
non-deficient positions, in either dimension, in the same
document. Spatial relations are simplified for deficient
locations, with the concerned dimension being treated like a
fixed number. Deficient and non-deficient locations are
incomparable.
UNKNOWN
for either lines or
columns indicates that no information is available for the
respective dimension. The referred document is assumed to have
the respective dimension, but the coordinate of the location is
unavailable to the application for some reason. Spatial relations
are restricted for such locations. Position p
can only be
inferred to lie before position q
, or vice versa, in the
same document if their line numbers are different from UNKNOWN
and each other. Otherwise, such locations are
incomparable.
Modifier and Type | Class and Description |
---|---|
static class |
Location.NumberMode
models the classification of (particular/pseudo) line and column numbers
|
Modifier and Type | Field and Description |
---|---|
static Relation<Location<?>,Location<?>> |
eq
Realizes algebraic identiy.
|
static Function<Location<?>,String> |
formatEmacs |
static Function<Location<?>,Location<?>> |
getReferencePoint |
static int |
MAX_PARTICULAR |
static int |
MIN_PARTICULAR |
static int |
NOT_APPLICABLE |
static Comparator<Location<?>> |
referencePointOrder |
static int |
UNKNOWN |
Constructor and Description |
---|
Location() |
Modifier and Type | Method and Description |
---|---|
abstract int |
abs2rel(Location<D> loc)
Only defined for Regions covering only one line:
Delivers the relative offset (in column numbers) of
the given position from the start of the interval
|
static <D> Location<D> |
cast(Location<? extends D> loc) |
Location<D> |
clone() |
static Relation<Location<?>,Location<?>> |
comparable() |
static boolean |
comparable(Location<?> x,
Location<?> y) |
abstract boolean |
contains(Location<?> loc) |
abstract int |
contiguousSize() |
boolean |
equals(Object o)
Algebraic equality, recurs to
eq |
static <D> Function<Location<? extends D>,String> |
formatEmacs(Function<D,? extends String> formatDoc) |
int |
getBeginColumn()
Returns the column number of this location's begin point.
|
int |
getBeginLine()
Returns the line number of this location's begin point.
|
abstract Location<D> |
getBeginPoint()
Returns the begin point of this location.
|
int |
getColumn()
Returns the column number of this location's reference point.
|
D |
getDocumentId()
Returns the document identifier of this location's reference point, maybe null.
|
int |
getEndColumn()
Returns the column number of this location's end point.
|
int |
getEndLine()
Returns the line number of this location's end point.
|
abstract Location<D> |
getEndPoint()
Returns the end point of this location.
|
int |
getLine()
Returns the line number of this location's reference point.
|
Location<D> |
getLocation() |
static Location.NumberMode |
getMode(int n) |
abstract Location<D> |
getReferencePoint()
Returns the reference point of this location.
|
static <D> Function<Location<D>,Location<D>> |
getReferencePoint(Class<? extends D> doc) |
abstract Collection<Location<D>> |
getRegions() |
static <D> Location<D> |
interval(D document,
int startline,
int startCol,
int endline,
int endCol) |
static <D> Location<D> |
interval(Location<D> a,
Location<D> b) |
static <D> Location<D> |
intervalRobust(Location<D> a,
Location<D> b) |
static Location |
intervalRobustUnchecked(Location a,
Location b) |
static <D> boolean |
isAdjacent(Location<D> a,
Location<D> b) |
static boolean |
isApplicable(int n) |
boolean |
isColumnDeficient() |
abstract boolean |
isContiguous() |
boolean |
isDeficient() |
boolean |
isLineDeficient() |
static boolean |
isParticular(int n) |
abstract boolean |
isPoint()
Checks whether this location is a point.
|
abstract boolean |
isRegion()
Checks whether this location is a region.
|
boolean |
isRegionInOneLine() |
static boolean |
isSpecified(int n) |
static boolean |
isValid(int n) |
static <D,E> Function<Location<D>,Location<E>> |
liftMapDocumentId(Function<D,E> f)
Delivers a function which maps Locations to Locations (never null to never null),
when a function which maps
the document IDs (maybe null to maybe null) is given.
|
static <D> Location<D> |
line_from_to(D document,
int line,
int startCol,
int endCol) |
static <D> Location<D> |
line(D document,
int line) |
static @Opt Location<String> |
live(int depth,
Predicate<? super StackTraceElement> skipCaller)
Creates a location from the current JVM thread stack trace.
|
static Location<String> |
live(StackTraceElement elem)
Creates a location from a JVM stack trace element.
|
static <D,E> BiFunction<Function<D,E>,Location<D>,Location<E>> |
mapDocumentId()
Delivers a bi-function which takes a function on document ids and a location (maybe null)
to a location.
|
abstract <E> Location<E> |
mapDocumentId(Function<? super D,? extends E> f) |
static <D> Location<D> |
max(Location<D> x,
Location<D> y) |
static <D> Location<D> |
min(Location<D> x,
Location<D> y) |
Location<D> |
nextLine() |
static <D> Location<D> |
offset(D document,
int offset) |
static <D> Location<D> |
point(D document,
int line,
int column) |
static <D> Comparator<Location<D>> |
pointOrder() |
static <D> Comparator<Location<D>> |
referencePointOrder() |
abstract Location<D> |
rel2abs(int off)
Only defined for Regions covering only one line:
Delivers a point in the region which
has the given offset from the start of the region.
|
static <D> Location<D> |
setOf(Collection<? extends Location<D>> members) |
Location<D> |
singleColumn() |
String |
toString() |
public static final int MIN_PARTICULAR
public static final int MAX_PARTICULAR
public static final int NOT_APPLICABLE
public static final int UNKNOWN
public static final Relation<Location<?>,Location<?>> eq
public static final Comparator<Location<?>> referencePointOrder
public final Location<D> getLocation()
getLocation
in interface Locatable<D>
@Opt public D getDocumentId()
public abstract <E> Location<E> mapDocumentId(Function<? super D,? extends E> f)
public int getLine()
public int getColumn()
public int getBeginLine()
public int getBeginColumn()
public int getEndLine()
public int getEndColumn()
public abstract boolean isPoint()
true
, then the reference point, begin point and end point
of this location are all equal to this location.true
if this location is a point, false
if this location is a region or set.public abstract Location<D> getReferencePoint()
public abstract Location<D> getBeginPoint()
public abstract Location<D> getEndPoint()
public abstract boolean isRegion()
true
, then the region partition (as returned by getRegions()
)
of this location contains
a single location equal to this location.true
if this location is a region, false
if this location is a point or set.public boolean isRegionInOneLine()
public abstract Collection<Location<D>> getRegions()
public abstract boolean contains(Location<?> loc)
public abstract boolean isContiguous()
public abstract int contiguousSize()
public abstract int abs2rel(Location<D> loc)
public abstract Location<D> rel2abs(int off)
public static <D,E> Function<Location<D>,Location<E>> liftMapDocumentId(Function<D,E> f)
public static <D,E> BiFunction<Function<D,E>,Location<D>,Location<E>> mapDocumentId()
public static <D> Function<Location<D>,Location<D>> getReferencePoint(Class<? extends D> doc)
public static Location.NumberMode getMode(int n)
Location.NumberMode
and defined by the constants NOT_APPLICABLE
and UNKNOWN
.IllegalArgumentException
- in case of negative arguments not matching these
constants.public static boolean isSpecified(int n)
public static boolean isValid(int n)
public static boolean isParticular(int n)
public static boolean isApplicable(int n)
public final boolean isLineDeficient()
public final boolean isColumnDeficient()
public final boolean isDeficient()
public static <D> Comparator<Location<D>> pointOrder()
public static <D> Comparator<Location<D>> referencePointOrder()
public static <D> Function<Location<? extends D>,String> formatEmacs(Function<D,? extends String> formatDoc)
public static <D> Location<D> interval(@Opt D document, int startline, int startCol, int endline, int endCol)
public static <D> Location<D> line_from_to(@Opt D document, int line, int startCol, int endCol)
public static <D> Location<D> setOf(Collection<? extends Location<D>> members)
public static Location<String> live(StackTraceElement elem)
elem
- the stack trace element@Opt public static @Opt Location<String> live(int depth, Predicate<? super StackTraceElement> skipCaller)
This operation can be used to support automatic collection of location information in dynamic code generators. By extracting the element corresponding to the immediate caller of the code generator API from the current thread stack trace, the source position of the requester of the current code generation action can be captured transparently.
This operation may not be suitable for high-performance applications. It is recommended to be used only during testing and debugging of dynamic code generators.
depth
- the expected nesting depth of the requester: 0 indicates
the immediate caller of this method, 1 its own immediate caller, etc.skipCaller
- indicates whether stack frames should be
skipped. Starting at the given depth, consecutive stack frames
matched by the given predicate are not considered for determining
the requester.null
if the current stack trace is too short.IllegalArgumentException
- if depth < 0
Thread.getStackTrace()
see also the complete user documentation .