com.sun.tools.javac.util
Class Position

java.lang.Object
  extended by com.sun.tools.javac.util.Position

public class Position
extends java.lang.Object

A class that defines source code positions as simple character offsets from the beginning of the file. The first character is at position 0. Support is also provided for (line,column) coordinates, but tab expansion is optional and no Unicode excape translation is considered. The first character is at location (1,1).

This is NOT part of any API supported by Sun Microsystems. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.


Nested Class Summary
static interface Position.LineMap
           
(package private) static class Position.LineMapImpl
           
static class Position.LineTabMapImpl
          A LineMap that handles tab expansion correctly.
 
Field Summary
static int FIRSTCOLUMN
           
static int FIRSTLINE
           
static int FIRSTPOS
           
static int LINESHIFT
           
static int MAXCOLUMN
           
static int MAXLINE
           
static int MAXPOS
           
static int NOPOS
           
 
Constructor Summary
private Position()
          This is class is not supposed to be instantiated.
 
Method Summary
static int encodePosition(int line, int col)
          Encode line and column numbers in an integer as: line-number << LINESHIFT + column-number {@link Position.NOPOS represents an undefined position.
static Position.LineMap makeLineMap(char[] src, int max, boolean expandTabs)
          A two-way map between line/column numbers and positions, derived from a scan done at creation time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NOPOS

public static final int NOPOS
See Also:
Constant Field Values

FIRSTPOS

public static final int FIRSTPOS
See Also:
Constant Field Values

FIRSTLINE

public static final int FIRSTLINE
See Also:
Constant Field Values

FIRSTCOLUMN

public static final int FIRSTCOLUMN
See Also:
Constant Field Values

LINESHIFT

public static final int LINESHIFT
See Also:
Constant Field Values

MAXCOLUMN

public static final int MAXCOLUMN
See Also:
Constant Field Values

MAXLINE

public static final int MAXLINE
See Also:
Constant Field Values

MAXPOS

public static final int MAXPOS
See Also:
Constant Field Values
Constructor Detail

Position

private Position()
This is class is not supposed to be instantiated.

Method Detail

makeLineMap

public static Position.LineMap makeLineMap(char[] src,
                                           int max,
                                           boolean expandTabs)
A two-way map between line/column numbers and positions, derived from a scan done at creation time. Tab expansion is optionally supported via a character map. Text content is not retained.

Notes: The first character position FIRSTPOS is at (FIRSTLINE,FIRSTCOLUMN). No account is taken of Unicode escapes.

Parameters:
src - Source characters
max - Number of characters to read
expandTabs - If true, expand tabs when calculating columns

encodePosition

public static int encodePosition(int line,
                                 int col)
Encode line and column numbers in an integer as: line-number << LINESHIFT + column-number {@link Position.NOPOS represents an undefined position.

Parameters:
line - number of line (first is 1)
col - number of character on line (first is 1)
Returns:
an encoded position or {@link Position.NOPOS if the line or column number is too big to represent in the encoded format
Throws:
java.lang.IllegalArgumentException - if line or col is less than 1