Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How get by code list of default Groovy imports

Tags:

groovy

I want to get programmatically in any form a list of default packages imported by Groovy. Like the documentation says:

All these packages and classes are imported by default, i.e. you do not have to use an explicit import statement to use them: java.io.*

java.lang.*

java.math.BigDecimal

java.math.BigInteger

java.net.*

java.util.*

groovy.lang.*

groovy.util.*

In others words, check whether import is required (for any classes out of this list) or not. The List should be valid for current version and potentially for future versions.

like image 834
Jacek Cz Avatar asked Feb 09 '23 03:02

Jacek Cz


1 Answers

The static variable org.codehaus.groovy.control.ResolveVisitor.DEFAULT_IMPORTS is an array of String​ that contains all default imported package names.

Currently it's (printed) value is:

[java.lang., java.io., java.net., java.util., groovy.lang., groovy.util.]

Check the ResolveVisitor doc for more info. If you want to know how to add custom packages to the defaults check this Jira issue.

like image 167
lifeisfoo Avatar answered Mar 28 '23 10:03

lifeisfoo