org.sonar.channel
Class CodeBuffer

java.lang.Object
  extended by org.sonar.channel.CodeBuffer
All Implemented Interfaces:
CharSequence
Direct Known Subclasses:
CodeReader

public class CodeBuffer
extends Object
implements CharSequence

The CodeBuffer class provides all the basic features required to manipulate a source code character stream. Those features are :


Nested Class Summary
 class CodeBuffer.Cursor
           
 
Constructor Summary
protected CodeBuffer(Reader initialCodeReader, CodeReaderConfiguration configuration)
          Note that this constructor will read everything from reader and will close it.
protected CodeBuffer(String code, CodeReaderConfiguration configuration)
           
 
Method Summary
 char charAt(int index)
          Returns the character at the specified index after the cursor without consuming it
 void close()
          Deprecated. in 2.12, do not use anymore.
 int getColumnPosition()
           
 CodeBuffer.Cursor getCursor()
           
 int getLinePosition()
           
protected  int intAt(int index)
           
 int lastChar()
          Looks at the last consumed character
 int length()
          Returns the relative length of the string (i.e.
 int peek()
          Looks at the next character without consuming it
 int pop()
          Read and consume the next character
 CodeBuffer setColumnPosition(int cp)
          Overrides the current column position
 void setLinePosition(int lp)
          Overrides the current line position
 void startRecording()
           
 CharSequence stopRecording()
           
 CharSequence subSequence(int start, int end)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CodeBuffer

protected CodeBuffer(String code,
                     CodeReaderConfiguration configuration)

CodeBuffer

protected CodeBuffer(Reader initialCodeReader,
                     CodeReaderConfiguration configuration)
Note that this constructor will read everything from reader and will close it.

Method Detail

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

close

@Deprecated
public final void close()
Deprecated. in 2.12, do not use anymore.


getLinePosition

public final int getLinePosition()
Returns:
the current line of the cursor

getCursor

public final CodeBuffer.Cursor getCursor()

getColumnPosition

public final int getColumnPosition()
Returns:
the current column of the cursor

setColumnPosition

public final CodeBuffer setColumnPosition(int cp)
Overrides the current column position


setLinePosition

public final void setLinePosition(int lp)
Overrides the current line position


startRecording

public final void startRecording()

stopRecording

public final CharSequence stopRecording()

charAt

public final char charAt(int index)
Returns the character at the specified index after the cursor without consuming it

Specified by:
charAt in interface CharSequence
Parameters:
index - the relative index of the character to be returned
Returns:
the desired character
See Also:
CharSequence.charAt(int)

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:
length in interface CharSequence

subSequence

public final CharSequence subSequence(int start,
                                      int end)
Specified by:
subSequence in interface CharSequence

toString

public final String toString()
Specified by:
toString in interface CharSequence
Overrides:
toString in class Object


Copyright © 2009-2012 SonarSource. All Rights Reserved.