public renameIdentifier(source as String, oldName as String, newName as String) as String
Renames every occurrence of code identifier oldName to newName in source while leaving comments, string/character/regex literals, and line endings untouched.
| Parameter | Description |
|---|---|
source | Full source code text. |
oldName | Identifier name to replace. |
newName | Replacement identifier name. |
Updated source text.
import klyn.code.klyn
t = KlynTokenizer()
updated = t.renameIdentifier("count = count + 1 # count in comment", "count", "total")
assert updated == "total = total + 1 # count in comment"