|
Class: ParseTreeSourceRewriter
Object
|
+--RBProgramNodeVisitor
|
+--ParseTreeSearcher
|
+--ParseTreeRewriter
|
+--ParseTreeSourceRewriter
- Package:
- stx:goodies/refactoryBrowser/parser
- Category:
- Refactory-ParseTree Matching
- Version:
- rev:
1.25
date: 2023/09/07 21:04:17
- user: stefan
- file: ParseTreeSourceRewriter.st directory: goodies/refactoryBrowser/parser
- module: stx stc-classLibrary: parser
- Author:
- Claus Gittinger
This is a parse tree rewriter which does NOT generate new code from scratch
(i.e. it does not generate its source by recursively walking along the formattedCode methods),
but instead inserts the new nodes code right into the original source code.
This has two advantages:
it does not destroy the user's formatting, indentation etc.
it does not forget comments.
I added this, because I constantly got mad at the rewriter reformatting my code for every tiny
little variable rewrite operation.
Caveats:
needs more intelligence when rewriting non-trivial code, such as keyword message sends.
For now, it seems to only behave reasonable for very simple stuff, such as replacing a variable
by another or by a simple unary send.
ParseTreeRewriter
accessing
-
addReplacement: aReplacement
-
-
alwaysPerformAllSearches
-
please read the comment in the inherited alwaysPerformAllSearches
-
alwaysPerformAllSearches: aBoolean
-
please read the comment in the inherited alwaysPerformAllSearches
-
executeTree: aParseTree in: optionalClassBeingProcessed
-
Performs rewrites on given tree;
but instead of creating new source code by pretty printing the rewritten tree,
this one applies the replacements to the original source;
thus preserving indentation, comments and line breaks (empty lines).
This does not work all the time; then a pretty printed version is returned - as before.
(which is bad, because the original RB code had severe trouble in handling comments,
at times even forgetting one)
-
forgetReplacements
-
-
replacements
-
queries
-
isRewritingOriginalSource
-
replacing
-
executeReplacementsInSource: aSourceString
-
execute all replacements in a sourceString.
Invoked after we have collected all replacements.
-
replaceLiteral: oldLiteral with: newLiteral
-
-
replaceLiteral: oldLiteral with: newLiteral when: condition
-
-
replaceVariable: variable with: newVariable
-
Transcript showCR:'replacing variable ',variable,' by ',newVariable.
NodesOverlapError
|