Analyzing Java sources / .class files using javaparser or javap

Yes, it is a part of the standard openJDK library, here’s the source for it: openjdk/src/jdk.jdeps/share/classes/com/sun/tools/javap/Main.java at jdk/jdk · unofficial-openjdk/openjdk · GitHub

It comes with Java, so you don’t need to depend on anything extra, it’s part of the JDK.

One big difference is that javap works on compiled class files, where as javaparser seems to be a source parser lib. With javap you can lookup method and field information for classes without having to pull down the source, but if you’re in a mixed Java/Clojure project, your own Java code would need to be compiled so that javap can access the compiled classes to grab the methods and fields from.

Also, for source file and line information to be available to javap this debug information needs to be compiled into the class file. By default, javac will include the line number and source file when compiling Java, so most Java libs should have it, but it’s possible to pass an option to javac so that it exclude all debug info from the compiled class file, including the line and source info, in which case it won’t be able to find it.

Personally, I think javap is a better fit for clj-kondo. It can tell you the arity and type of arguments to methods, it can list the public fields and methods on a class, and it can also show you the source file it was compiled from and the line number from it that maps to the method or field.

What do you need the line numbers for though? Are you planning on having clj-kondo return Java source line numbers for like jump to definition behavior that would jump to the Java source location?