spoon icon indicating copy to clipboard operation
spoon copied to clipboard

How to set the launcher or something that can remain original used import statements?

Open Man-On-Earth opened this issue 6 years ago • 4 comments

It's happy to see the redundant imports in Java files are removed after processing, but I'm confused that all the useful imports are inserted into the class body like below. How can I remain the classical imports format? import spoon.reflect.code.CtComment;.......CtComment comment = new CtJavaDocImpl()(); ------> spoon.reflect.code.CtComment comment = new code.demo.CtJavaDocImpl(); Here the comment is a FieldType belongs to a class. Thanks a lot!

Man-On-Earth avatar Mar 08 '20 02:03 Man-On-Earth

auto imports should do want you want. launcher.getEnvironment() for getting the evironment object

MartinWitt avatar Mar 08 '20 02:03 MartinWitt

Oh thanks! I initiate the launcher by doing this: init(ConstantUtil.PROCESSOR_ROOT_PATH); launcher.setArgs(args); init()is a method with static and public modifiers,I set some environment properties in it, including setAutoImports(), it just doesn't work at all. I reversed the order of these two statements just now and it worked, I guess the setArgs() method may reset some options of launcher. Thank you MartinWitt!

Man-On-Earth avatar Mar 08 '20 02:03 Man-On-Earth

You could have a look at the FluentLauncher with easy methods for often used settings.

MartinWitt avatar Mar 08 '20 02:03 MartinWitt

Yeah I saw it just a few days ago, it seems like a new feature and it's quite convenient to use. Anyway, thanks for your help again, wish you have a good day.

Man-On-Earth avatar Mar 08 '20 02:03 Man-On-Earth