Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 750331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:32:19+00:00 2026-05-14T14:32:19+00:00

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

  • 0

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?


Edit to add some clarification

  1. Python is definitely not necessary; I’ll take whatever is that. I merely suggest it incase there are choices.
  2. This is to be used in combination with IDE refactoring; sometimes it just doesn’t do everything I want.
  3. In instances where I’m using for code generation (as above), it’s for augmenting the output of other code generators. e.g. a library we use outputs a tonne of interfaces, and we need to make standard implementations of each one to mesh it to our codebase.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:32:20+00:00Added an answer on May 14, 2026 at 2:32 pm

    First, I am not aware of any tool or libraries implemented in Python that specifically designed for refactoring Java code, and a Google search did not give me any leads.

    Second, I would posit that writing such a decent tool or library for refactoring Java in Python would be a large task. You would have to implement a Java compiler front-end (lexer/parser, AST builder and type analyser) in Python, then figure out how to integrate this with a program editor. I’m not surprised that nobody has done this … given that mature alternatives already exist.

    Thirdly, doing refactoring without a full analysis of the source code (but uses pattern matching for example) will be incapable of doing complex refactoring, and will is likely to make mistakes in edge cases that the implementor did not think of. I expect that is the level at which the OP is currently operating …

    Given that bleak outlook, what are the alternatives:

    One alternative is to use one of the existing Java IDEs (e.g. NetBeans, Eclipse, IDEA. etc) as a refactoring tool. The OP won’t be able to extend the capabilities of such a tool in Python code, but the chances are that he won’t really need to. I expect that at least one of these IDEs does 95% of what he needs, and (if he is realistic) that should be good enough. Especially when you consider that IDEs have lots of incidental features that help make refactoring easier; e.g. structured editing, undo/redo, incremental compilation, intelligent code completion, intelligent searching, type and call hierarchy views, and so on.

    (Aside … if existing IDEs are not good enough (@WizardOfOdds – only the OP can make that call!!), it would make more sense to try to extend the refactoring capability of an existing IDE than start again in a different implementation language.)

    Depending on what he is actually doing, model-driven code generation may be another alternative. For instance, if the refactoring is happening because he is frequently creating and recreating his object model(s), then an alternative is to code the models in some modeling language and generate his code from those models. My tool of choice when doing this kind of thing is Eclipse EMF and related technologies. The EMF technologies include generation of editors, XML serialization, persistence, queries, model to model transformation and so on. I have used EMF to implement and roll out projects with object models consisting of 50 to 100 distinct classes with complex relationships and validation requirements. EMF’s support for merging source code edits when you regenerate from an updated model is a key feature.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 377k
  • Answers 377k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It appears that there is no "easy" way to do… May 14, 2026 at 9:01 pm
  • Editorial Team
    Editorial Team added an answer Ultimately, this is a scoping of variables problem. Global variables… May 14, 2026 at 9:01 pm
  • Editorial Team
    Editorial Team added an answer I would use the validates_uniqueness_of validation so: class Product <… May 14, 2026 at 9:01 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.