Intelligent search and generation of Java code, preferrably using Python?

Posted by Ipsquiggle on Stack Overflow See other posts from Stack Overflow or by Ipsquiggle
Published on 2010-04-23T22:22:41Z Indexed on 2010/04/23 22:23 UTC
Read the original article Hit count: 192

Filed under:
|
|
|
|

Basically, I do lots of one-off code generation, large-scale refactorings, etc. etc. in Java.

My tool language of choice is Python, but I'll take whatever solutions you can offer.


Here is a simplified illustration of what I would like, in a pseudocode

Generating an implementation for an interface

search within my project:
  for each Interface as iName:
    write class(name=iName+"Impl", implements=iName)
    search within the body of iName:
      for each Method as mName:
        write method(name=mName, body="// TODO implement this...")

Basically, the tool I'm searching for would allow me to:

  • parse files according to their Java structure ("search for interfaces")
  • search for words contextualized by language elements and types ("variables of type SomeClass", "doStuff() method calls on SomeClass instances")
  • to run searches with structural context ("within the body of the current result")
  • easily replace or generate code (with helpers to generate, as above, or functions for replacing, "rename the interface to Foo", "insert the line Blah.Blah()", etc.)

The point is, I don't want to spend a lot of time writing these things, as they are usually throwaway. But sometimes I need something just a little smarter than what grep offers. It wouldn't be too hard to write up a simplistic version of this, but if I'm going to use something like this at all, I'd expect it to be robust.

Any suggestions of a tool/library that will help me accomplish this?

© Stack Overflow or respective owner

Related posts about java

Related posts about code-generation