Organize Java Imports programmatically

2019-09-19 05:45发布

问题:

I have written a custom build script for my android app. I included some "easy" preprocessing, so I can define comments like

//#ifdef something
... CODE
//#endif

and get rid of the Code part if configured so. The Problem is, that after preprocessing I don't need some modules anymore, so I leave them out. What remains is the import statement for that module which bites me, if I want to build the app finally. I'm searching for a way within my preprocessing, to organize the java Imports inside my script after preprocessing happens. Any Solution without the need for additional "clicks" is very welcome.

回答1:

Sometimes you're really need preprocessor (quite rare). But you could actually achieve same goal with right build process.

Anyway back to the question you could use next technique:

//#ifdef something
... IMPORTS
//#endif


回答2:

take a look at http://code.google.com/p/java-comment-preprocessor/ p.s. example of usage for one of my cases http://code.google.com/p/java-comment-preprocessor/wiki/ExampleOfUsageForJ2ME