Package org.sonar.sslr.channel
Class CodeBuffer
java.lang.Object
org.sonar.sslr.channel.CodeBuffer
- All Implemented Interfaces:
CharSequence
- Direct Known Subclasses:
CodeReader
The CodeBuffer class provides all the basic features required to manipulate a source code character stream. Those features are :
- Read and consume next source code character : pop()
- Retrieve last consumed character : lastChar()
- Read without consuming next source code character : peek()
- Read without consuming character at the specified index after the cursor
- Position of the pending cursor : line and column
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCodeBuffer(Reader initialCodeReader, CodeReaderConfiguration configuration) Note that this constructor will read everything from reader and will close it.protectedCodeBuffer(String code, CodeReaderConfiguration configuration) -
Method Summary
Modifier and TypeMethodDescriptionfinal charcharAt(int index) Returns the character at the specified index after the cursor without consuming itfinal intfinal CodeBuffer.Cursorfinal intprotected final intintAt(int index) final intlastChar()Looks at the last consumed characterfinal intlength()Returns the relative length of the string (i.e. excluding the popped chars)final intpeek()Looks at the next character without consuming itfinal intpop()Read and consume the next characterfinal CodeBuffersetColumnPosition(int cp) Overrides the current column positionfinal voidsetLinePosition(int lp) Overrides the current line positionfinal voidfinal CharSequencefinal CharSequencesubSequence(int start, int end) final StringtoString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.CharSequence
chars, codePoints
-
Constructor Details
-
CodeBuffer
-
CodeBuffer
Note that this constructor will read everything from reader and will close it.
-
-
Method Details
-
pop
public final int pop()Read and consume the next character- Returns:
- the next character or -1 if the end of the stream is reached
-
lastChar
public final int lastChar()Looks at the last consumed character- Returns:
- the last character or -1 if the no character has been yet consumed
-
peek
public final int peek()Looks at the next character without consuming it- Returns:
- the next character or -1 if the end of the stream has been reached
-
getLinePosition
public final int getLinePosition()- Returns:
- the current line of the cursor
-
getCursor
-
getColumnPosition
public final int getColumnPosition()- Returns:
- the current column of the cursor
-
setColumnPosition
Overrides the current column position -
setLinePosition
public final void setLinePosition(int lp) Overrides the current line position -
startRecording
public final void startRecording() -
stopRecording
-
charAt
public final char charAt(int index) Returns the character at the specified index after the cursor without consuming it- Specified by:
charAtin interfaceCharSequence- Parameters:
index- the relative index of the character to be returned- Returns:
- the desired character
- See Also:
-
intAt
protected final int intAt(int index) -
length
public final int length()Returns the relative length of the string (i.e. excluding the popped chars)- Specified by:
lengthin interfaceCharSequence
-
subSequence
- Specified by:
subSequencein interfaceCharSequence
-
toString
- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-