I want my plugin (an automated termination analysis tool) to run on code the user selects inside Eclipse. Naturally, the user selects source code (a .java file, a method in the outline, …). However, my program needs the compiled .class file(s) as input.
How can I get the .class files for selected source items? Related to this, how can I get a bytecode descriptor to the selected source method? In case of generics and varargs transforming a (Eclipse) source descriptor to the corresponding bytecode descriptor seems nontrivial to me.
I do not want to run javac on my own and I do not want to guess how the .class file is named (this is nasty for inner classes) and then try to find it on the disk (if it exists? maybe I can force Eclipse to compile?).
The Bytecode Outline plugin uses the following solution (see
JdtUtils.getByteCodePath):/home/user/workspace/project/build/)build/, e.g./home/user/workspace/project/build/some/package/.classfile, e.g./home/user/workspace/project/build/some/package/Foo.classJdtUtils.getClassName) and modify the name of the resulting class file accordingly (maybe resulting inFoo$1.class)So the problem of this question is solved, where the translation of inner classes to the corresponding file names could be improved. According to the author, though, the current approach (using “magic”) works for “95% of the cases” and he does not know about any related bugs in the past few years.