Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, I'm in need of some code refactoring, because I made some bade decisions on function names. It are not functions used on one or two places but through my ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2010
    Posts
    5

    Using linux tools to refactor code


    Hi,

    I'm in need of some code refactoring, because I made some bade decisions on function names. It are not functions used on one or two places but through my entire project. Now, since I don't use an IDE like netbeans or something similar I have to refactor them manually. I was hoping that there is some tool for linux to automate this process. Using grep or some ctags based tool..

    Thanks in advance,
    Bietje

  2. #2
    Super Moderator Roxoff's Avatar
    Join Date
    Aug 2005
    Location
    Nottingham, England
    Posts
    3,848
    If all you're doing is a simple method and/or class rename, then you can use grep to find where the names are used, then use gedit or kate to do a search and replace inside each file. Just don't forget to check (using grep again) that the new method name you're going to apply isn't already in use for something else. That's how I'd do it if I weren't using an IDE.
    Linux user #126863 - see http://linuxcounter.net/

  3. #3
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    Depending on language, there are a few ways of doing this.

    One way that pops into my mind for C, at least, is to use cscope. This lets you find every place in your code that calls a function: you could manually rename all of these.

    You could also probably just hook into sed or something. If we assume that "func(" always indicates calling func, the sed is pretty straightforward to replace the function name. However, you need to be careful of things like this when in quotes.

  4. #4
    Just Joined!
    Join Date
    May 2010
    Posts
    5
    Hi,

    I wrote a small Java application which searches through my entire source tree and replaces every instance. I will publish it if you guys like it, after i fixed some bugs with hidden characters. Because it currently destroys your git/svn repository due to the fact that it also searches in hidden directories.

    Greetz

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •