Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java source code parser in Ruby

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!

like image 938
Desmond Zhou Avatar asked Nov 23 '25 14:11

Desmond Zhou


1 Answers

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.

like image 122
Niklas B. Avatar answered Nov 26 '25 05:11

Niklas B.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!