spoon icon indicating copy to clipboard operation
spoon copied to clipboard

Can Spoon deal the .class file

Open yz-qiang opened this issue 3 years ago • 1 comments

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. :)

yz-qiang avatar Jan 15 '22 01:01 yz-qiang

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?

SirYwell avatar Jan 15 '22 09:01 SirYwell