Search code examples
javaprogram-transformation

How to automatically remove methods in java code


I need to remove some methods in a large java project and I was wondering if there are tools that would help me do so. I would basically specify a signature and a source folder in which all the matching method would be removed.

It no such thing exists then I will write a script.


Solution

  • I looked for quick solutions and did not find any, I used different tools to get there:

    1. grep to find all the files containing the main methods I wanted to remove
    2. find/replace in these files to make those methods private
    3. Eclipse clean-up with just one rule: remove unused private methods

    It did the job with the minor side effect of removing other unused private methods. It is not a big deal in the context of that project since pretty much all the files were previously saved with a save action removing unused private methods.

    Thanks all for the input, it may be applicable later on.