spoon
spoon copied to clipboard
Can Spoon deal the .class file
Spoon is a nice job, thanks for your contribution.
I have a .java file, and I can derive the FQN with the following code: (e.g., StringBuffer in StringBuffer tabs = new StringBuffer(); will be derived into java.lang.StringBuilder.
Launcher launcher = new Launcher();
launcher.getEnvironment().setPrettyPrintingMode(Environment.PRETTY_PRINTING_MODE.FULLYQUALIFIED);
launcher.addInputResource(java_file_path);
CtModel model = launcher.buildModel();
String output = model.getAllTypes()
.stream()
.map(Object::toString)
.collect(Collectors.joining("\n\n", "", "\n"));
return output;
But, when I input the java_file_path is the .class file, the return output is the Null. How can I fix it? Thank you. :)
This does not work directly. https://spoon.gforge.inria.fr/reflection.html explains how you can analyse loaded classes at runtime and also links to spoon-decompiler. Maybe one of those solutions is what you're looking for?