public static renameIdentifier(tokenizer as Tokenizer, source as String, oldName as String, newName as String) as String
Safely renames all occurrences of an identifier in executable code without modifying comments, documentation blocks, or string/character/regex literals.
| Parameter | Description |
|---|---|
tokenizer | Language tokenizer to use. |
source | Original source code text. |
oldName | Identifier name to replace. |
newName | Replacement identifier name. |
Updated source text with matching identifier tokens replaced.
import klyn.code import klyn.code.klyn code = "value = \"value\"\nreturn value # value" updated = SourceTokenCursor.renameIdentifier(KlynTokenizer(), code, "value", "result") assert updated == "result = \"value\"\nreturn result # value"