简体   繁体   中英

C++ or Java Library for automated code editing?

I am writing/planning to write a program that takes in a java file (or multiple java files), and edits and adds functions/classes/variables and then outputs a new java file (or multiple files).

Is there a C++ or Java library that

  1. Can recognize and output names of classes/functions within a text file
  2. Can recognize and output the names of the input arguments for said classes/functions
  3. Can allow me to insert code at specific lines or within specific functions
  4. Can search for a given variable name/value
  5. Maintains original file formatting

I would prefer not having to manually code something to do the above, so any help would be appreciated.

Thank you in advance!

EDIT: I currently use Eclipse, and am unsure of how to proceed. So to further explain my question:

In eclipse, if I write a program that opens another .java file, How would I go about 'asking' eclipse to output, say, all the class names of the .java file I just opened?

Also I will explain the 'purpose' of this project to further clarify. I want to write a program that can take in any java file, and turn it into a class that can implemented remotely via RMI. To do this I will need to add an execute() function, have the file implement Task and Serializable and add a few variables, etc... Based on my knowledge, doing this in Eclipse would require manual editing of the program, but I would like to completely automate this process.

Thank you, again.

Much of what you need can be found in a modern IDE; and some very good IDEs are open source (eclipse and Intellij IDEA Community Edition for Java). You might look there to see if there are modules that suite your needs.

Looks like you are talking of a tool like eclipse. You might not be looking for a full fledged IDE, but the requirements that you have mentioned are fulfilled by any basic IDE.

If you wish to make one of your own, you can do that using eclipse rich client platform. All that you would need from Java is the reflection API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM