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

public Class UnicodeReader

extends Object
Class Inheritance
Known Direct Subclasses
com.sun.tools.javac.parser.UnicodeReader.PositionTrackingReader, com.sun.tools.javac.parser.JavaTokenizer
Imports
java.util.Arrays, com.sun.tools.javac.resources.CompilerProperties.Errors, com.sun.tools.javac.util.Log

The unicode character reader used by the javac/javadoc lexer/tokenizer, returns characters one by one as contained in the input stream, handling unicode escape sequences accordingly.

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
pack-priv static class
UnicodeReader.PositionTrackingReader

This is a specialized version of UnicodeReader that keeps track of the column position within a given character stream.

private static enum

Field Summary

Modifier and TypeField and Description
private final char[]
buffer

Buffer containing characters from source file.

private char
character

Character currently being observed.

private int
codepoint

Codepoint of character currently being observed.

private final int
length

Length of meaningful content in buffer.

private final Log
log

Log for error reporting.

private final int
offset

Virtual position offset in the original buffer.

private int
position

Character buffer index of character currently being observed.

private boolean
wasBackslash

true if the last character was a backslash.

private boolean
wasUnicodeEscape

true if the last character was derived from an unicode escape sequence.

private int
width

Number of characters combined to provide character currently being observed.

Constructor Summary

AccessConstructor and Description
protected
UnicodeReader(ScannerFactory
scan factory.
sf
,
char[]
array containing contents of source.
array
,
int
length of meaningful content in buffer.
length
)

Constructor.

protected
UnicodeReader(Log
Log for error reporting.
log
,
char[]
array containing contents of source.
array
,
int
length of meaningful content in buffer.
length
)

Constructor.

protected
UnicodeReader(Log
Log for error reporting.
log
,
char[]
array containing contents of source.
array
,
int offset, int
start of meaningful content in buffer.
pos
,
int
end of meaningful content in buffer.
endPos
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
protected boolean

Returns:

true if a match.
accept
(char
character to match.
ch
)

Compare character and advance if a match.

protected boolean

Returns:

true if a match.
accept
(String
string to match character for character.
string
)

Compare string and advance if a match.

protected boolean
acceptOneOf(char ch1, char ch2)

Match one of the arguments and advance if a match.

protected boolean
acceptOneOf(char ch1, char ch2, char ch3)

Match one of the arguments and advance if a match.

protected char[]

Returns:

character buffer.
buffer
()

Returns the character buffer.

protected int

Returns:

value of digit.
digit
(int
starting position.
pos
,
int
base of number being converted.
digitRadix
)

Convert an ASCII digit from its base (8, 10, or 16) to its value.

protected char

Returns:

current character in at the current position.
get
()

Return the current character in at the current position.

protected int

Returns:

current codepoint in at the current position.
getCodepoint
()

Return the current codepoint in at the current position.

public char[]

Returns:

the input buffer.
getRawCharacters
()

Returns the input buffer.

public char[]
getRawCharacters(int
the beginning index, inclusive.
beginIndex
,
int
the ending index, exclusive.
endIndex
)

Returns a copy of a character array subset of the input buffer.

public String
getRawString(int
the beginning index, inclusive.
beginIndex
,
int
the ending index, exclusive.
endIndex
)

Returns a string subset of the input buffer.

public String
getRawString()

Returns a string subset of the input buffer.

protected boolean

Returns:

true if the current character is in range.
inRange
(char
lowest character in range.
lo
,
char
highest character in range.
hi
)

Tests to see if current character is in the range of lo to hi characters (inclusive).

protected boolean

Returns:

true if a match.
is
(char
character to match.
ch
)

Compare character.

protected boolean

Returns:

true if the current character is ASCII.
isASCII
()

Returns true if the current character is ASCII.

protected boolean

Returns:

true if current position is within the meaningful part of the buffer.
isAvailable
()

Return true if current position is within the meaningful part of the buffer.

protected boolean

Returns:

true if is ASCII line terminator.
isEOLN
()

Is ASCII line terminator.

protected boolean
isOneOf(char ch1, char ch2)

Match one of the arguments.

protected boolean
isOneOf(char ch1, char ch2, char ch3)

protected boolean
isOneOf(char ch1, char ch2, char ch3, char ch4)

protected boolean
isOneOf(char ch1, char ch2, char ch3, char ch4, char ch5, char ch6)

protected boolean

Returns:

true if the current codepoint is a surrogate.
isSurrogate
()

Returns true if the current codepoint is a surrogate.

protected boolean

Returns:

true if is ASCII white space character
isWhitespace
()

Is ASCII white space character.

protected int

Returns:

length of the buffer.
length
()

Returns the length of the buffer.

protected UnicodeReader

Returns:

a new reader
lineReader
()

Return a reader which is bracketed by the currect position and the next line terminator.

protected UnicodeReader

Returns:

a new reader
lineReader
(int
initial position
pos
,
int
end position
endPos
)

Return a reader which is bracketed by the pos and endPos.

protected char

Returns:

next character.
next
()

Advances the current character to the next character.

private void
nextCodePoint()

Fetches the nextcode point from the buffer.

private void
nextCodeUnit()

Fetches the next 16-bit character from the buffer and places it in this.character.

private void
nextUnicodeInputCharacter()

Fetches the next 16-bit character from the buffer.

protected int

Returns:

virtual position in the character buffer.
position
()

Return the virtual position in the character buffer.

protected void
reset(int pos)

Reset the reader to the specified virtual position.

protected int

Returns:

number of characters skipped
skip
(char
character to accept.
ch
)

Skip over all occurrences of character.

protected void
skipToEOLN()

Skip to end of line.

protected void
skipWhitespace()

Skip over ASCII white space characters.

private UnicodeReader.UnicodeEscapeResult

Returns:

true if was an unicode escape.
unicodeEscape
()

Converts an unicode escape into a character.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferback to summary
private final char[] buffer

Buffer containing characters from source file. May contain extraneous characters beyond this.length.

characterback to summary
private char character

Character currently being observed. If a surrogate pair is read then will be the high member of the pair.

codepointback to summary
private int codepoint

Codepoint of character currently being observed. Typically equivalent to the character but will have a value greater that 0xFFFF when a surrogate pair.

lengthback to summary
private final int length

Length of meaningful content in buffer.

logback to summary
private final Log log

Log for error reporting.

offsetback to summary
private final int offset

Virtual position offset in the original buffer.

positionback to summary
private int position

Character buffer index of character currently being observed.

wasBackslashback to summary
private boolean wasBackslash

true if the last character was a backslash. This is used to handle the special case when a backslash precedes an unicode escape. In that case, the second backslash is treated as a backslash and not part of an unicode escape.

wasUnicodeEscapeback to summary
private boolean wasUnicodeEscape

true if the last character was derived from an unicode escape sequence.

widthback to summary
private int width

Number of characters combined to provide character currently being observed. Typically one, but may be more when combinations of surrogate pairs and unicode escape sequences are read.

Constructor Detail

UnicodeReaderback to summary
protected UnicodeReader(ScannerFactory sf, char[] array, int length)

Constructor.

Parameters
sf:ScannerFactory

scan factory.

array:char[]

array containing contents of source.

length:int

length of meaningful content in buffer.

UnicodeReaderback to summary
protected UnicodeReader(Log log, char[] array, int length)

Constructor.

Parameters
log:Log

Log for error reporting.

array:char[]

array containing contents of source.

length:int

length of meaningful content in buffer.

UnicodeReaderback to summary
protected UnicodeReader(Log log, char[] array, int offset, int pos, int endPos)

Constructor.

Parameters
log:Log

Log for error reporting.

array:char[]

array containing contents of source.

pos:int

start of meaningful content in buffer.

endPos:int

end of meaningful content in buffer.

Annotations
@SuppressWarnings:this-escape

Method Detail

acceptback to summary
protected boolean accept(char ch)

Compare character and advance if a match. Returns true if a match.

Parameters
ch:char

character to match.

Returns:boolean

true if a match.

acceptback to summary
protected boolean accept(String string)

Compare string and advance if a match. Returns true if a match.

Warning

Do not use when previous character was a backslash (confuses state of wasBackslash.)

Parameters
string:String

string to match character for character.

Returns:boolean

true if a match.

acceptOneOfback to summary
protected boolean acceptOneOf(char ch1, char ch2)

Match one of the arguments and advance if a match. Returns true if a match.

acceptOneOfback to summary
protected boolean acceptOneOf(char ch1, char ch2, char ch3)

Match one of the arguments and advance if a match. Returns true if a match.

bufferback to summary
protected char[] buffer()

Returns the character buffer.

Returns:char[]

character buffer.

digitback to summary
protected int digit(int pos, int digitRadix)

Convert an ASCII digit from its base (8, 10, or 16) to its value. Does not advance character.

Parameters
pos:int

starting position.

digitRadix:int

base of number being converted.

Returns:int

value of digit.

getback to summary
protected char get()

Return the current character in at the current position.

Returns:char

current character in at the current position.

getCodepointback to summary
protected int getCodepoint()

Return the current codepoint in at the current position.

Returns:int

current codepoint in at the current position.

getRawCharactersback to summary
public char[] getRawCharacters()

Returns the input buffer. Unicode escape sequences are not translated.

Returns:char[]

the input buffer.

getRawCharactersback to summary
public char[] getRawCharacters(int beginIndex, int endIndex)

Returns a copy of a character array subset of the input buffer. The returned array begins at the beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex. This behavior is like String.substring(beginIndex, endIndex). Unicode escape sequences are not translated.

Parameters
beginIndex:int

the beginning index, inclusive.

endIndex:int

the ending index, exclusive.

Exceptions
ArrayIndexOutOfBoundsException:
if either offset is outside of the array bounds
getRawStringback to summary
public String getRawString(int beginIndex, int endIndex)

Returns a string subset of the input buffer. The returned string begins at the beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex. This behavior is like String.substring(beginIndex, endIndex). Unicode escape sequences are not translated.

Parameters
beginIndex:int

the beginning index, inclusive.

endIndex:int

the ending index, exclusive.

Exceptions
ArrayIndexOutOfBoundsException:
if either offset is outside of the array bounds
getRawStringback to summary
public String getRawString()

Returns a string subset of the input buffer. The returned string begins at the position and extends to the character at index length - 1. Thus the length of the substring is length-position. This behavior is like String.substring(position, length). Unicode escape sequences are not translated.

Exceptions
ArrayIndexOutOfBoundsException:
if either offset is outside of the array bounds
inRangeback to summary
protected boolean inRange(char lo, char hi)

Tests to see if current character is in the range of lo to hi characters (inclusive).

Parameters
lo:char

lowest character in range.

hi:char

highest character in range.

Returns:boolean

true if the current character is in range.

isback to summary
protected boolean is(char ch)

Compare character. Returns true if a match.

Parameters
ch:char

character to match.

Returns:boolean

true if a match.

isASCIIback to summary
protected boolean isASCII()

Returns true if the current character is ASCII.

Returns:boolean

true if the current character is ASCII.

isAvailableback to summary
protected boolean isAvailable()

Return true if current position is within the meaningful part of the buffer.

Returns:boolean

true if current position is within the meaningful part of the buffer.

isEOLNback to summary
protected boolean isEOLN()

Is ASCII line terminator.

Returns:boolean

true if is ASCII line terminator.

isOneOfback to summary
protected boolean isOneOf(char ch1, char ch2)

Match one of the arguments. Returns true if a match.

isOneOfback to summary
protected boolean isOneOf(char ch1, char ch2, char ch3)
isOneOfback to summary
protected boolean isOneOf(char ch1, char ch2, char ch3, char ch4)
isOneOfback to summary
protected boolean isOneOf(char ch1, char ch2, char ch3, char ch4, char ch5, char ch6)
isSurrogateback to summary
protected boolean isSurrogate()

Returns true if the current codepoint is a surrogate.

Returns:boolean

true if the current codepoint is a surrogate.

isWhitespaceback to summary
protected boolean isWhitespace()

Is ASCII white space character.

Returns:boolean

true if is ASCII white space character

lengthback to summary
protected int length()

Returns the length of the buffer. This is length of meaningful content in buffer and not the length of the buffer array.

Returns:int

length of the buffer.

lineReaderback to summary
protected UnicodeReader lineReader()

Return a reader which is bracketed by the currect position and the next line terminator.

Returns:UnicodeReader

a new reader

lineReaderback to summary
protected UnicodeReader lineReader(int pos, int endPos)

Return a reader which is bracketed by the pos and endPos.

Parameters
pos:int

initial position

endPos:int

end position

Returns:UnicodeReader

a new reader

nextback to summary
protected char next()

Advances the current character to the next character.

Returns:char

next character.

nextCodePointback to summary
private void nextCodePoint()

Fetches the nextcode point from the buffer. If an unicode escape is recognized then converts unicode escape to a character. If two characters are a surrogate pair then converts to a codepoint.

nextCodeUnitback to summary
private void nextCodeUnit()

Fetches the next 16-bit character from the buffer and places it in this.character.

nextUnicodeInputCharacterback to summary
private void nextUnicodeInputCharacter()

Fetches the next 16-bit character from the buffer. If an unicode escape is detected then converts the unicode escape to a character.

positionback to summary
protected int position()

Return the virtual position in the character buffer.

Returns:int

virtual position in the character buffer.

resetback to summary
protected void reset(int pos)

Reset the reader to the specified virtual position.

Warning

Do not use when previous character was an ASCII or unicode backslash.

skipback to summary
protected int skip(char ch)

Skip over all occurrences of character.

Parameters
ch:char

character to accept.

Returns:int

number of characters skipped

skipToEOLNback to summary
protected void skipToEOLN()

Skip to end of line.

skipWhitespaceback to summary
protected void skipWhitespace()

Skip over ASCII white space characters.

unicodeEscapeback to summary
private UnicodeReader.UnicodeEscapeResult unicodeEscape()

Converts an unicode escape into a character.

Returns:UnicodeReader.UnicodeEscapeResult

true if was an unicode escape.

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

pack-priv Class UnicodeReader.PositionTrackingReader

extends UnicodeReader
Class Inheritance
Known Direct Subclasses
com.sun.tools.javac.parser.JavaTokenizer.BasicComment

This is a specialized version of UnicodeReader that keeps track of the column position within a given character stream. Used for Javadoc processing to build a table for mapping positions in the comment string to positions in the source file.

Field Summary

Modifier and TypeField and Description
private int
column

Current column in the comment.

Constructor Summary

AccessConstructor and Description
protected
PositionTrackingReader(UnicodeReader
existing reader
reader
,
int
start of meaningful content in buffer.
pos
,
int
end of meaningful content in buffer.
endPos
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
protected int

Returns:

the current column.
column
()

Returns the current column.

protected char

Returns:

next character.
next
()

Overrides com.sun.tools.javac.parser.UnicodeReader.next.

Advances the current character to the next character.

Inherited from com.sun.tools.javac.parser.UnicodeReader:
acceptacceptacceptOneOfacceptOneOfbufferdigitgetgetCodepointgetRawCharactersgetRawCharactersgetRawStringgetRawStringinRangeisisASCIIisAvailableisEOLNisOneOfisOneOfisOneOfisOneOfisSurrogateisWhitespacelengthlineReaderlineReaderpositionresetskipskipToEOLNskipWhitespace

Field Detail

columnback to summary
private int column

Current column in the comment.

Constructor Detail

PositionTrackingReaderback to summary
protected PositionTrackingReader(UnicodeReader reader, int pos, int endPos)

Constructor.

Parameters
reader:UnicodeReader

existing reader

pos:int

start of meaningful content in buffer.

endPos:int

end of meaningful content in buffer.

Method Detail

columnback to summary
protected int column()

Returns the current column.

Returns:int

the current column.

nextback to summary
protected char next()

Overrides com.sun.tools.javac.parser.UnicodeReader.next.

Advances the current character to the next character. Tracks column.

Returns:char

next character.

Annotations
@Override
com.sun.tools.javac.parser back to summary

private final Enum UnicodeReader.UnicodeEscapeResult

extends Enum<UnicodeReader.UnicodeEscapeResult>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final UnicodeReader.UnicodeEscapeResult
public static final UnicodeReader.UnicodeEscapeResult
public static final UnicodeReader.UnicodeEscapeResult

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static UnicodeReader.UnicodeEscapeResult
public static UnicodeReader.UnicodeEscapeResult[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

BACKSLASHback to summary
public static final UnicodeReader.UnicodeEscapeResult BACKSLASH
BROKEN_ESCAPEback to summary
public static final UnicodeReader.UnicodeEscapeResult BROKEN_ESCAPE
VALID_ESCAPEback to summary
public static final UnicodeReader.UnicodeEscapeResult VALID_ESCAPE

Constructor Detail

UnicodeEscapeResultback to summary
private UnicodeEscapeResult()

Method Detail

valueOfback to summary
public static UnicodeReader.UnicodeEscapeResult valueOf(String name)
valuesback to summary
public static UnicodeReader.UnicodeEscapeResult[] values()