d - Tools to refactor names of types, functions and variables? -


struct foo{     bar get(){     } }  auto f = foo(); f.get(); 

for example decide get poor choice name have used in many different files , manually changing ever occurrence annoying.

you can't make global substitution because other types may have method called get.

is there d refactor names types, functions, variables etc?

here's how it:

  1. change name in definition
  2. recompile
  3. go first error line reported , replace old new
  4. goto 2

that's semi-manual, find pretty easy , goes because compiler error message bring right need be, , editors can read error messages enough dump on correct line, simple matter of telling repeat last replacement again. (in vim setup hotkeys, hit f4 next error message, dot repeat last change until done. function hundred uses can changed reliably* in couple minutes.)

you write script handles 90% of cases automatically looking ": error: " in compiler's output, extracting file/line number, , running plain text replace there. if word shows once , outside string literal, can automatically replace it, , if not, ask user handle remaining 10% of cases manually.

but think easy enough editor hotkeys i've never bothered trying script it.

  • the 1 case doesn't catch if there's function same name might still compile. should never happen if change in isolation, because ambiguous name wouldn't compile without it.

in case, three-step compiler-assisted change:

  1. make sure code compiles before. add @disable thing want rename.
  2. compile. every place complains being unusable being disabled, find/replace.
  3. remove @disable , rename definition. recompile again make sure there's nothing missed child classes (the compiler complain "method foo not override function" stand right out too.

so yeah, isn't automated, changing , having compiler errors find what's left enough me.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -