Command-line tools like grep
, sed
, awk
, and perl
allow one to carry out textual search-and-replace operations.
However, is there any tool that would allow me to carry out semantic search-and-replace operations in a Java codebase, from command-line?
The Eclipse IDE allows me, e.g., to easily rename a variable, a field, a method, or a class. But I would like to be able to do the same from command-line.
The rename operation above is just one example. I would further like to be able to select the replacee text with additional semantic constraints such as:
- only the scopes of methods M1, M2 of classes C, D, and E;
- only all variables or fields of class C;
- all expressions in which a variable of some class occurs;
- only the scope of the class definition of a variable;
- only the scopes of all overridden versions of method M of class C;
- etc.
Having selected the code using such arbitrary semantic constraints, I would like to be able to then carry out arbitrary transformations on it.
So, basically, I would need access to the symbol-table of the code.
Question:
- Is there an existing tool for this type of work, or would I have to build one myself?
- Even if I have to build one myself, do any tools or libraries exist that would at least provide me the symbol-table of Java code, on top of which I could add my own search-and-replace and other refactoring operations?