Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How programmatically remove default import in Groovy?

Tags:

groovy

By default some packages are imported in a Groovy class. I know that you can add new one with an ImportCustomizer but is there a way to remove them programmatically?

Thanks in advance for your answers.

like image 847
Franck Anso Avatar asked Dec 19 '25 15:12

Franck Anso


2 Answers

No. If you look through the code, then you'll see that the standard imports like java.io and java.math.BigDecimal are not handled by ImportCustomizer.

Which is a pity.

The default imports are handled in ResolveVisitor.java. The code doesn't allow to modify the default imports or the method where they are added.

Kudos to andrei-krotkov for finding the code.

like image 90
Aaron Digulla Avatar answered Dec 22 '25 04:12

Aaron Digulla


It is not a pretty good solution but it works:

Arrays.fill(ResolveVisitor.DEFAULT_IMPORTS, "java.lang.");
like image 33
Dmitry Ovchinnikov Avatar answered Dec 22 '25 06:12

Dmitry Ovchinnikov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!