org.prorefactor.refactor
Class ScanLib

java.lang.Object
  extended by org.prorefactor.refactor.ScanLib

public class ScanLib
extends java.lang.Object

Library of functions for working with a scanner and its token list.


Method Summary
 void copyAndMark(int begin, int end)
          Copy and mark a section for future removal.
 java.lang.String copyToText(int begin, int end)
           
 void cutSectionHard(int begin, int end)
          "Hard" cut a scanner section, from an input beginning through to and including an input end, from a scanner token list.
static ScanLib getInstance()
          This class implements the "Singleton" design pattern.
 void insertSection(int begin, int end, int insertBefore)
           
 boolean isAllWhitespace(int scanNum)
          Is the scanner list all whitespace?
 void markToBeCut(int begin, int end)
          Mark a section for future removal.
 int seek(int h1, int h2)
          Seek to a token in a scan list.
 int seek(int theLine, int theColumn, int h2)
          Seek to a token in a scan list.
 int seekFromTop(int line, int col, int scanNum, int tokenHandle)
          Seek a scan handle to a file position.
 void sweep(int scanNum)
          Sweep out all tokens from a scanner's token list which have been marked as "cut".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static ScanLib getInstance()
This class implements the "Singleton" design pattern.


copyAndMark

public void copyAndMark(int begin,
                        int end)
Copy and mark a section for future removal. Could be thought of as a "soft cut" - the section cut out won't be removed until sweep() is called.

Parameters:
begin - Handle to first token to be cut out. On return, will point to the beginning of the "copied out" chain.
end - Handle to last token to be cut out. On return, will point to the end of the "copied out" chain.

copyToText

public java.lang.String copyToText(int begin,
                                   int end)

cutSectionHard

public void cutSectionHard(int begin,
                           int end)
"Hard" cut a scanner section, from an input beginning through to and including an input end, from a scanner token list. Normally you want to use copyAndMark() instead, which copies a segment and marks the original as scheduled to be cut.

Parameters:
begin - Handle to first token to be cut out.
end - Handle to last token to be cut out.

insertSection

public void insertSection(int begin,
                          int end,
                          int insertBefore)

isAllWhitespace

public boolean isAllWhitespace(int scanNum)
Is the scanner list all whitespace?


markToBeCut

public void markToBeCut(int begin,
                        int end)
Mark a section for future removal. Could be thought of as a "soft cut" - the section cut out won't be removed until sweep() is called.

Parameters:
begin - Handle to first token to be cut out.
end - Handle to last token to be cut out.

seek

public int seek(int h1,
                int h2)
Seek to a token in a scan list. This variant seeks the scanner handle h2 to row/column of h1. Assumes scanner file matches filename for node h1. If finding a node at row/column fails, return 0. Does not reposition h2 if fail. This will fail if the node's text comes from preprocessing.

Parameters:
The - handle with the row/column we want to reposition to
The - handle that gets moved
Returns:
Positive int on success

seek

public int seek(int theLine,
                int theColumn,
                int h2)
Seek to a token in a scan list. This variant seeks the scanner to specified line and column number. Assumes you already know which file you want to seek in. If finding a node at row/column fails, return 0. Does not reposition h2 if fail. This will fail if the node's text comes from preprocessing, or if preprocessing earlier on the node's line has caused Proparse's column number to be inaccurrate.


seekFromTop

public int seekFromTop(int line,
                       int col,
                       int scanNum,
                       int tokenHandle)
Seek a scan handle to a file position. Use's Proparse's query function for fast seek from the front of the scan list.

Parameters:
line - Line to seek to.
col - Column to seek to.
scanNum - The scanner number.
tokenHandle - Handle to reposition. Unlike other functions in this library, this does not already have to be pointing to an earlier token in the scan list.
Returns:
Integer token type if found, 0 if not found, negative int on error.

sweep

public void sweep(int scanNum)
           throws RefactorException
Sweep out all tokens from a scanner's token list which have been marked as "cut". Note that the calling routines are expected to never cut Scanner_tail because this expects to setNodeNextSibling to *something*, even at the end of a file.

Throws:
RefactorException


Copyright © 2008 Joanju Software. All Rights Reserved.