Reputation: 1906
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.
Upvotes: 4
Views: 2011
Reputation: 16294
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.
Upvotes: 8