|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.prorefactor.refactor.Refactor
public class Refactor
A collection of functions to help with refactoring. Mostly these are for working together with both an AST as well as a scanner's token list. See also ScanLib for functions that operate only on scanner token lists.
Method Summary | |
---|---|
int |
consecComments()
Test if we have consecutive comments. |
void |
cutToChain(int node,
int scanNum,
LooseChain theChain)
Uses getSectionWithComments to find a token list segment from an AST node, copyAndMark the segment so it can be removed later with sweep(), put the copy of the segment onto a LooseChain. |
boolean |
findLeadingWhitespace(int astHandle,
int tokenHandle)
Find comments before the node which are not separated from the node by any blank lines. |
boolean |
findTrailingWhitespace(int astHandle,
int tokenHandle)
Find comments on the same line as the end of the AST branch, as well as one newline. |
boolean |
getInsertPointInFile(int astHandle,
java.lang.String filename,
int scanNum,
int tokenHandle,
ListingParser listingParser)
Find an "insert point" in a specific source file, to come in front of a given AST node. |
static Refactor |
getInstance()
This class implements the "Singleton" design pattern. |
int |
getSectionWithComments(int ast,
int begin,
int end)
Get a scanner section, based on an AST node/branch, with leading comments and whitespace, and any trailing comments before the line break. |
int |
hiddenBeforeSync(int h1,
int h2)
Attempt to change scan nodes so they match AST hidden tokens. |
void |
markToBeCut(int node,
int scanNum)
Uses getSectionWithComments to find a token list segment from an AST node, markToBeCut the segment so it can be removed later with sweep(). |
int |
msyncBranch(int inParseHandle,
int inScanHandle1,
int inScanHandle2)
Multinode Sync (Branch) - synchronize an entire AST branch with a scanner list. |
int |
nsync(int h1,
int h2)
Node Sync - Synchronize a scanner node to a parser node. |
void |
replaceScannerSection(int scanHandle1,
int scanHandle2,
int parseHandle)
Replace Scanner Section Input scan number, scanner start handle, scanner end handle, and a handle to an AST branch to replace it with. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static Refactor getInstance()
public int consecComments()
public void cutToChain(int node, int scanNum, LooseChain theChain) throws RefactorException
node
- The AST node.scanNum
- The scanner reference number.theChain
- The chain that we append the copied segment onto the end of.
RefactorException
public boolean findLeadingWhitespace(int astHandle, int tokenHandle)
astHandle
- Must be a handle to a natural node.tokenHandle
- Must be a valid handle to an early token in the scanner.
On success, this handle is repositioned to the desired token.
On fail, there is no guarantee as to where the handle points.
public boolean findTrailingWhitespace(int astHandle, int tokenHandle)
astHandle
- A handle to the top of the AST branch.
This function deals with finding the end of the branch.tokenHandle
- Must be a valid handle to an early token in the scan list.
On success, this handle is repositioned to the desired token.
On fail, there is no guarantee as to where the handle points.
public boolean getInsertPointInFile(int astHandle, java.lang.String filename, int scanNum, int tokenHandle, ListingParser listingParser)
astHandle
- The handle to find the insert point in front of.filename
- The file name that we want an insertion point for.
(Currently no support for file index numbers with hidden tokens)scanNum
- A number for an existing scan for the file we want.tokenHandle
- The token handle to be repositioned.
Does not have to be pre-positioned.
public int getSectionWithComments(int ast, int begin, int end)
ast
- The node handle from the syntax treebegin
- A scanner handle, on success will point at beginning of sectionend
- A scanner handle, on success will point at end of section
public int hiddenBeforeSync(int h1, int h2)
public void markToBeCut(int node, int scanNum) throws RefactorException
node
- The AST nodescanNum
- The scanner for the branch's code.
RefactorException
public int msyncBranch(int inParseHandle, int inScanHandle1, int inScanHandle2)
inParseHandle
- is positioned at the first node we want in the parse treeinScanHandle1
- is positioned in the scanner list *before* the expected node,
probably just at the head of the scanner list.inScanHandle2
- is positioned anywhere.
On success, inScanHandle1 is sync'd with the first natural node, and inScanHandle2 is at the end of the section of synchronized scan nodes. Does NOT attempt to synchronize whitespace until after the first natural node, because those may have nothing to do with this branch. Note that this will synchronize as far as it can before failing - so it may actually get some, but not all, of the relevent scan nodes changed so that they directly reflect the parse nodes. The two input scanHandles DO get moved around - don't count on their position for anything if the synchronization failed.
nsync(int, int)
public int nsync(int h1, int h2)
int
- h1 handle positioned at the node in the parse tree which we are interested in.int
- h2 handle positioned in the scanner list, somewhere *before* the expected node.
Causes one or more tokens in the scanner list to be changed in order for them to be synchronised with a token in the AST.
public void replaceScannerSection(int scanHandle1, int scanHandle2, int parseHandle)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |