2

Are there any free and open text-manipulation-tools for the command-line specialized in source code? I especially would love a feature where I could just add a new method stub automatically or remove methods by name altogether.

Automatic generation of getters/setters would be nice, too.

If there is any website with good SED/Perl examples to do this, it may be the solution, too.

It would be nice if the solution would work for several languages or is easily adapted for other languages.

Thank you very much in advance.

Doctor Who
  • 97
  • 1
  • 6

2 Answers2

0

To modify source code reliably, you pretty much need to be able to parse it the same way a compiler does, point at language entities using the standard scoping rules for that language, and state your changes to the code. Tools that do this are called program transformation engines. To provide all this compiler machinery integrated with production quality language front ends is considerable work so there aren't a lot of these tools around.

See our DMS Software Reengineering Toolkit. This is a program transformation engine that handles multiple languages (C, C++, C#, Java, PHP, JavaScript, ...) and enables this kind of work. A nice property of a source-to-source style transformation engine like DMS is the ability to write transformations using the (surface) syntax of the langauge(s) you want to manipulate, rather than more traditional pure-compiler like tools that insist you simply hack at an abstract syntax tree with lots of procedural code.

It isn't as easy is "oh, just change this". But is it reliable.

EDIT 6/23/2011: OP said it had to work with Java and PHP. DMS does.

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
  • Not much on the term "program transformation" on the internet. Also I am looking for a concrete tool, which should be gpl at best and run in the GNU/Linux cli. – Doctor Who Jun 23 '11 at 09:12
  • @Doctor Who: R&D on program transformation has been going on since the late 1970s. Google in Scholar for tons of technical papers. The wikipedia link I provided list virtually all the "real" (you call this "concrete") tools that really exist in other than demo form. Some of them are "open source". Most of them have the concepts right, but what matters is having production-quality language front ends. DMS is, IMHO (caused by 15 years of sweat), the leader here but isn't "open source". YMMV. [DMS does run under Wine]. – Ira Baxter Jun 23 '11 at 09:18
  • I checked with the wiki-article again and found the part where the tools are mentioned. Thank you very much. – Doctor Who Jun 23 '11 at 09:26
  • The bibliography referenced at the Wikipedia site is (grin) my personal index into the transformation literature. Its a bit dated, but what has happened since it was built is mostly dark corner detail; it covers the really fundamental stuff. – Ira Baxter Jun 23 '11 at 09:32
0

There is also the tool named Comby (https://comby.dev/), which bills itself as "a tool for searching and changing code structure".

From this blog post explaining the gist of Comby, here is a screenshot of an example usage in the comby.live playground:

enter image description here

Robert K. Bell
  • 9,350
  • 2
  • 35
  • 50