How programmatically remove default import in Groo

2020-07-18 10:23发布

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.

标签: groovy
2条回答
爱情/是我丢掉的垃圾
2楼-- · 2020-07-18 10:53

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.

查看更多
乱世女痞
3楼-- · 2020-07-18 11:01

It is not a pretty good solution but it works:

Arrays.fill(ResolveVisitor.DEFAULT_IMPORTS, "java.lang.");
查看更多
登录 后发表回答