Package com.github.javaparser
Class AbstractCharStream
- java.lang.Object
-
- com.github.javaparser.AbstractCharStream
-
- All Implemented Interfaces:
CharStream
- Direct Known Subclasses:
SimpleCharStream
public abstract class AbstractCharStream extends Object implements CharStream
An implementation of interface CharStream, where the stream is assumed to contain only ASCII characters (without unicode processing).
-
-
Field Summary
Fields Modifier and Type Field Description protected int
available
The number of unoccupied buffer array positionsprotected char[]
buffer
Internal circular bufferprotected int
bufpos
Current read position in buffer.protected int
bufsize
Overall buffer size - same as buffer.lengthstatic int
DEFAULT_BUF_SIZE
Default buffer size if nothing is specifiedprotected int
inBuf
Characters in the backup/pushBack bufferprotected int
maxNextCharInd
protected int
tokenBegin
The first array index (of `buffer`) that the current token starts
-
Constructor Summary
Constructors Constructor Description AbstractCharStream(int nStartLine, int nStartColumn, int nBufferSize)
Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
adjustBeginLineColumn(int nNewLine, int newCol)
Method to adjust line and column numbers for the start of a token.void
backup(int nAmount)
Backs up the input stream by amount steps.char
beginToken()
void
done()
The lexer calls this function to indicate that it is done with the stream and hence implementations can free any resources held by this class.protected void
expandBuff(boolean bWrapAround)
protected void
fillBuff()
int
getBeginColumn()
int
getBeginLine()
protected int
getBufSizeAfterExpansion()
protected int
getColumn()
int
getEndColumn()
int
getEndLine()
String
getImage()
protected int
getLine()
char[]
getSuffix(int len)
int
getTabSize()
protected void
internalAdjustBuffSize()
protected void
internalSetBufLineColumn(int nLine, int nColumn)
protected void
internalUpdateLineColumn(char c)
boolean
isTrackLineColumn()
char
readChar()
Get the next character from the selected input.void
reInit(int nStartLine, int nStartColumn, int nBufferSize)
Reinitialise.void
setTabSize(int nTabSize)
Set the tab size to use.void
setTrackLineColumn(boolean bTrackLineColumn)
Enable or disable line number and column number tracking.protected abstract void
streamClose()
Close the underlying stream.protected abstract int
streamRead(char[] aBuf, int nOfs, int nLen)
Read from the underlying stream.
-
-
-
Field Detail
-
DEFAULT_BUF_SIZE
public static final int DEFAULT_BUF_SIZE
Default buffer size if nothing is specified- See Also:
- Constant Field Values
-
buffer
protected char[] buffer
Internal circular buffer
-
bufsize
protected int bufsize
Overall buffer size - same as buffer.length
-
bufpos
protected int bufpos
Current read position in buffer.
-
available
protected int available
The number of unoccupied buffer array positions
-
tokenBegin
protected int tokenBegin
The first array index (of `buffer`) that the current token starts
-
inBuf
protected int inBuf
Characters in the backup/pushBack buffer
-
maxNextCharInd
protected int maxNextCharInd
-
-
Method Detail
-
reInit
public final void reInit(int nStartLine, int nStartColumn, int nBufferSize)
Reinitialise.
-
streamRead
protected abstract int streamRead(char[] aBuf, int nOfs, int nLen) throws IOException
Read from the underlying stream.- Parameters:
aBuf
- the buffer to be fillednOfs
- The offset into the buffer. 0-basednLen
- Number of chars to read.- Returns:
- Number of effective chars read, or -1 on error.
- Throws:
IOException
-
streamClose
protected abstract void streamClose() throws IOException
Close the underlying stream.- Throws:
IOException
- If closing fails.
-
getBufSizeAfterExpansion
protected int getBufSizeAfterExpansion()
-
expandBuff
protected void expandBuff(boolean bWrapAround)
-
internalAdjustBuffSize
protected final void internalAdjustBuffSize()
-
fillBuff
protected void fillBuff() throws IOException
- Throws:
IOException
-
internalSetBufLineColumn
protected final void internalSetBufLineColumn(int nLine, int nColumn)
-
internalUpdateLineColumn
protected final void internalUpdateLineColumn(char c)
-
readChar
public char readChar() throws IOException
Description copied from interface:CharStream
Get the next character from the selected input. The method of selecting the input is the responsibility of the class implementing this interface.- Specified by:
readChar
in interfaceCharStream
- Returns:
- the next character from the selected input
- Throws:
IOException
- on IO error
-
beginToken
public char beginToken() throws IOException
- Specified by:
beginToken
in interfaceCharStream
- Returns:
- the next character that marks the beginning of the next token. All characters must remain in the buffer between two successive calls to this method to implement backup correctly.
- Throws:
IOException
-
getBeginColumn
public int getBeginColumn()
- Specified by:
getBeginColumn
in interfaceCharStream
- Returns:
- the column number of the first character for current token (being matched after the last call to beginToken).
-
getBeginLine
public int getBeginLine()
- Specified by:
getBeginLine
in interfaceCharStream
- Returns:
- the line number of the first character for current token (being matched after the last call to BeginToken).
-
getEndColumn
public int getEndColumn()
- Specified by:
getEndColumn
in interfaceCharStream
- Returns:
- the column number of the last character for current token (being matched after the last call to BeginToken).
-
getEndLine
public int getEndLine()
- Specified by:
getEndLine
in interfaceCharStream
- Returns:
- the line number of the last character for current token (being matched after the last call to BeginToken).
-
backup
public void backup(int nAmount)
Description copied from interface:CharStream
Backs up the input stream by amount steps. Lexer calls this method if it had already read some characters, but could not use them to match a (longer) token. So, they will be used again as the prefix of the next token and it is the implemetation's responsibility to do this right.- Specified by:
backup
in interfaceCharStream
- Parameters:
nAmount
- Number of chars to back up.
-
getImage
public String getImage()
- Specified by:
getImage
in interfaceCharStream
- Returns:
- a string made up of characters from the marked token beginning to the current buffer position. Implementations have the choice of returning anything that they want to. For example, for efficiency, one might decide to just return null, which is a valid implementation.
-
getSuffix
public char[] getSuffix(int len)
- Specified by:
getSuffix
in interfaceCharStream
- Returns:
- an array of characters that make up the suffix of length 'len' for
the currently matched token. This is used to build up the matched string
for use in actions in the case of MORE. A simple and inefficient
implementation of this is as follows:
{ String t = getImage(); return t.substring(t.length() - len, t.length()).toCharArray(); }
-
done
public void done()
Description copied from interface:CharStream
The lexer calls this function to indicate that it is done with the stream and hence implementations can free any resources held by this class. Again, the body of this function can be just empty and it will not affect the lexer's operation.- Specified by:
done
in interfaceCharStream
-
getTabSize
public final int getTabSize()
- Specified by:
getTabSize
in interfaceCharStream
- Returns:
- Current tab size.
-
setTabSize
public final void setTabSize(int nTabSize)
Description copied from interface:CharStream
Set the tab size to use.- Specified by:
setTabSize
in interfaceCharStream
- Parameters:
nTabSize
- spaces per tab
-
adjustBeginLineColumn
public final void adjustBeginLineColumn(int nNewLine, int newCol)
Method to adjust line and column numbers for the start of a token. This is used internally to
-
getLine
protected final int getLine()
- Returns:
- the current line number. 0-based.
-
getColumn
protected final int getColumn()
- Returns:
- the current column number. 0-based.
-
isTrackLineColumn
public final boolean isTrackLineColumn()
- Specified by:
isTrackLineColumn
in interfaceCharStream
- Returns:
true
if line number and column numbers should be tracked.
-
setTrackLineColumn
public final void setTrackLineColumn(boolean bTrackLineColumn)
Description copied from interface:CharStream
Enable or disable line number and column number tracking.- Specified by:
setTrackLineColumn
in interfaceCharStream
- Parameters:
bTrackLineColumn
-true
to track it,false
to not do it.
-
-