3

Working on a code generation tool to help creating boiler code for our project.

The generator is written in ruby with erb templates, the project itself is in Java.

Now I am looking for a ruby gem/library for parsing java source files, given a string from a .java files, get the imports, methods, fields, class name etc etc, that would enable me to navigate to a certain method and appending code to it etc (kinda like jQuery selector).

I am wondering if there are already solutions that I can use, kinda like the javaclass-rb library, but that is for parsing bytecodes from .class files.

I know I could use ANTLR and a ruby adapter, but I hope there are existing solutions.

Thanks!

3
  • 1
    Is JRuby okay? Then you could use any Java library, like javaparser. I don't know of any pure-Ruby libraries to do this. Commented Dec 31, 2011 at 1:41
  • Thanks @Niklas, that's a great idea that opens up so many possibilities, I am using ruby mostly for the nice concise language and erb, so switching to JRuby should be fine. Still hope there is a pure ruby library for it but this should do just fine for now. Commented Dec 31, 2011 at 1:55
  • In that case, I'll post the suggestion as an answer. Commented Dec 31, 2011 at 1:58

1 Answer 1

4

JRuby is a Ruby implementation on top of the JVM that make interaction between Ruby and Java objects trivial. If you decide to use this, you can use any Java library to solve the task, like javaparser.

Sign up to request clarification or add additional context in comments.

1 Comment

Seems the logical choice for a Java-focused project.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.