APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.tools.javac.util

public Class Position

extends Object
Class Inheritance
Imports
java.util.BitSet, com.sun.tools.javac.util.DefinedBy.Api, javax.tools.Diagnostic

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 escape translation is considered. The first character is at location (1,1).

This is NOT part of any supported API. 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 and Inner Type Summary

Modifier and TypeClass and Description
public static interface
pack-priv static class
public static class
Position.LineTabMapImpl

A LineMap that handles tab expansion correctly.

Field Summary

Modifier and TypeField and Description
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int

Constructor Summary

AccessConstructor and Description
private
Position()

This is class is not supposed to be instantiated.

Method Summary

Modifier and TypeMethod and Description
public static int

Returns:

an encoded position or Position#NOPOS if the line or column number is too big to represent in the encoded format
encodePosition
(int
number of line (first is 1)
line
,
int
number of character on line (first is 1)
col
)

Encode line and column numbers in an integer as: line-number << LINESHIFT + column-number .

public static Position.LineMap
makeLineMap(char[]
Source characters
src
,
int
Number of characters to read
max
,
boolean
If true, expand tabs when calculating columns
expandTabs
)

A two-way map between line/column numbers and positions, derived from a scan done at creation time.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

FIRSTCOLUMNback to summary
public static final int FIRSTCOLUMN
FIRSTLINEback to summary
public static final int FIRSTLINE
FIRSTPOSback to summary
public static final int FIRSTPOS
LINESHIFTback to summary
public static final int LINESHIFT
MAXCOLUMNback to summary
public static final int MAXCOLUMN
MAXLINEback to summary
public static final int MAXLINE
MAXPOSback to summary
public static final int MAXPOS
NOPOSback to summary
public static final int NOPOS

Constructor Detail

Positionback to summary
private Position()

This is class is not supposed to be instantiated.

Method Detail

encodePositionback to summary
public static int encodePosition(int line, int col)

Encode line and column numbers in an integer as: line-number << LINESHIFT + column-number . Position#NOPOS represents an undefined position.

Parameters
line:int

number of line (first is 1)

col:int

number of character on line (first is 1)

Returns:int

an encoded position or Position#NOPOS if the line or column number is too big to represent in the encoded format

Exceptions
IllegalArgumentException:
if line or col is less than 1
makeLineMapback to summary
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:char[]

Source characters

max:int

Number of characters to read

expandTabs:boolean

If true, expand tabs when calculating columns

com.sun.tools.javac.util back to summary

public Interface Position.LineMap

extends LineMap
Known Direct Implementers
com.sun.tools.javac.util.Position.LineMapImpl

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the column number at which pos occurs
getColumnNumber
(int
character offset of the position
pos
)

Find the column for a character position.

public int

Returns:

the line number on which pos occurs (first line is 1)
getLineNumber
(int
character offset of the position
pos
)

Find the line containing a position; a line termination character is on the line it terminates.

public int

Returns:

position of character
getPosition
(int
number of line (first is 1)
line
,
int
number of character on line (first is 1)
column
)

Find the position corresponding to a (line,column).

public int

Returns:

position of first character in line
getStartPosition
(int
number of line (first is 1)
line
)

Find the start position of a line.

Inherited from com.sun.source.tree.LineMap:
getColumnNumbergetLineNumbergetPositiongetStartPosition

Method Detail

getColumnNumberback to summary
public int getColumnNumber(int pos)

Find the column for a character position.

Note

this method does not handle tab expansion. If tab expansion is needed, use a LineTabMap instead.

Parameters
pos:int

character offset of the position

Returns:int

the column number at which pos occurs

getLineNumberback to summary
public int getLineNumber(int pos)

Find the line containing a position; a line termination character is on the line it terminates.

Parameters
pos:int

character offset of the position

Returns:int

the line number on which pos occurs (first line is 1)

getPositionback to summary
public int getPosition(int line, int column)

Find the position corresponding to a (line,column).

Parameters
line:int

number of line (first is 1)

column:int

number of character on line (first is 1)

Returns:int

position of character

Exceptions
ArrayIndexOutOfBoundsException:
if line < 1 if line > no. of lines
getStartPositionback to summary
public int getStartPosition(int line)

Find the start position of a line.

Parameters
line:int

number of line (first is 1)

Returns:int

position of first character in line

Exceptions
ArrayIndexOutOfBoundsException:
if lineNumber < 1 if lineNumber > no. of lines
com.sun.tools.javac.util back to summary

pack-priv Class Position.LineMapImpl

extends Object
implements LineMap
Class Inheritance
All Implemented Interfaces
com.sun.tools.javac.util.Position.LineMap, com.sun.source.tree.LineMap
Known Direct Subclasses
com.sun.tools.javac.util.Position.LineTabMapImpl

Field Summary

Modifier and TypeField and Description
private int
private int
protected int[]

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
protected void
build(char[] src, int max)

public int
getColumnNumber(int pos)

Implements com.sun.tools.javac.util.Position.LineMap.getColumnNumber.

Find the column for a character position.

public long
getColumnNumber(long pos)

Implements com.sun.source.tree.LineMap.getColumnNumber.

Finds the column for a character position.

public int
getLineNumber(int pos)

Implements com.sun.tools.javac.util.Position.LineMap.getLineNumber.

Find the line containing a position; a line termination character is on the line it terminates.

public long
getLineNumber(long pos)

Implements com.sun.source.tree.LineMap.getLineNumber.

Finds the line containing a position; a line termination character is on the line it terminates.

public int
getPosition(int line, int column)

Implements com.sun.tools.javac.util.Position.LineMap.getPosition.

Find the position corresponding to a (line,column).

public long
getPosition(long line, long column)

Implements com.sun.source.tree.LineMap.getPosition.

Finds the position corresponding to a (line,column).

public int
getStartPosition(int line)

Implements com.sun.tools.javac.util.Position.LineMap.getStartPosition.

Find the start position of a line.

public long
getStartPosition(long line)

Implements com.sun.source.tree.LineMap.getStartPosition.

Finds the start position of a line.

private static int
longToInt(long longValue)

protected void
setTabPosition(int offset)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

lastLineback to summary
private int lastLine
lastPositionback to summary
private int lastPosition
startPositionback to summary
protected int[] startPosition

Constructor Detail

LineMapImplback to summary
protected LineMapImpl()

Method Detail

buildback to summary
protected void build(char[] src, int max)
getColumnNumberback to summary
public int getColumnNumber(int pos)

Implements com.sun.tools.javac.util.Position.LineMap.getColumnNumber.

Doc from com.sun.tools.javac.util.Position.LineMap.getColumnNumber.

Find the column for a character position.

Note

this method does not handle tab expansion. If tab expansion is needed, use a LineTabMap instead.

getColumnNumberback to summary
public long getColumnNumber(long pos)

Implements com.sun.source.tree.LineMap.getColumnNumber.

Doc from com.sun.source.tree.LineMap.getColumnNumber.

Finds the column for a character position. Tab characters preceding the position on the same line will be expanded when calculating the column number.

Annotations
@DefinedBy:COMPILER_TREE
getLineNumberback to summary
public int getLineNumber(int pos)

Implements com.sun.tools.javac.util.Position.LineMap.getLineNumber.

Doc from com.sun.tools.javac.util.Position.LineMap.getLineNumber.

Find the line containing a position; a line termination character is on the line it terminates.

getLineNumberback to summary
public long getLineNumber(long pos)

Implements com.sun.source.tree.LineMap.getLineNumber.

Doc from com.sun.source.tree.LineMap.getLineNumber.

Finds the line containing a position; a line termination character is on the line it terminates.

Annotations
@DefinedBy:COMPILER_TREE
getPositionback to summary
public int getPosition(int line, int column)

Implements com.sun.tools.javac.util.Position.LineMap.getPosition.

Doc from com.sun.tools.javac.util.Position.LineMap.getPosition.

Find the position corresponding to a (line,column).

getPositionback to summary
public long getPosition(long line, long column)

Implements com.sun.source.tree.LineMap.getPosition.

Doc from com.sun.source.tree.LineMap.getPosition.

Finds the position corresponding to a (line,column).

Annotations
@DefinedBy:COMPILER_TREE
getStartPositionback to summary
public int getStartPosition(int line)

Implements com.sun.tools.javac.util.Position.LineMap.getStartPosition.

Doc from com.sun.tools.javac.util.Position.LineMap.getStartPosition.

Find the start position of a line.

getStartPositionback to summary
public long getStartPosition(long line)

Implements com.sun.source.tree.LineMap.getStartPosition.

Doc from com.sun.source.tree.LineMap.getStartPosition.

Finds the start position of a line.

Annotations
@DefinedBy:COMPILER_TREE
longToIntback to summary
private static int longToInt(long longValue)
setTabPositionback to summary
protected void setTabPosition(int offset)
com.sun.tools.javac.util back to summary

public Class Position.LineTabMapImpl

extends LineMapImpl
Class Inheritance

A LineMap that handles tab expansion correctly. The cost is an additional bit per character in the source array.

Field Summary

Modifier and TypeField and Description
private BitSet
Inherited from com.sun.tools.javac.util.Position.LineMapImpl:
startPosition

Constructor Summary

AccessConstructor and Description
public
LineTabMapImpl(int max)

Method Summary

Modifier and TypeMethod and Description
public int
public int
getPosition(int line, int column)

Overrides com.sun.tools.javac.util.Position.LineMapImpl.getPosition.

Implements com.sun.tools.javac.util.Position.LineMap.getPosition.

Find the position corresponding to a (line,column).

protected void
Inherited from com.sun.tools.javac.util.Position.LineMapImpl:
buildgetColumnNumbergetLineNumbergetLineNumbergetPositiongetStartPositiongetStartPosition

Field Detail

tabMapback to summary
private BitSet tabMap

Constructor Detail

LineTabMapImplback to summary
public LineTabMapImpl(int max)

Method Detail

getColumnNumberback to summary
public int getColumnNumber(int pos)

Overrides com.sun.tools.javac.util.Position.LineMapImpl.getColumnNumber.

Implements com.sun.tools.javac.util.Position.LineMap.getColumnNumber.

Doc from com.sun.tools.javac.util.Position.LineMap.getColumnNumber.

Find the column for a character position.

Note

this method does not handle tab expansion. If tab expansion is needed, use a LineTabMap instead.

getPositionback to summary
public int getPosition(int line, int column)

Overrides com.sun.tools.javac.util.Position.LineMapImpl.getPosition.

Implements com.sun.tools.javac.util.Position.LineMap.getPosition.

Doc from com.sun.tools.javac.util.Position.LineMap.getPosition.

Find the position corresponding to a (line,column).

setTabPositionback to summary
protected void setTabPosition(int offset)

Overrides com.sun.tools.javac.util.Position.LineMapImpl.setTabPosition.