public static Package getPackage(Tree.ImportPath path) {
if (path!=null && !path.getIdentifiers().isEmpty()) {
String nameToImport = formatPath(path.getIdentifiers());
Module module = path.getUnit().getPackage().getModule();
Package pkg = module.getPackage(nameToImport);
if (pkg != null) {
if (pkg.getModule().equals(module)) {
return pkg;
}
if (!pkg.isShared()) {
path.addError("imported package is not shared: '" +
nameToImport + "'");
}
// if (module.isDefault() &&
// !pkg.getModule().isDefault() &&
// !pkg.getModule().getNameAsString()
// .equals(Module.LANGUAGE_MODULE_NAME)) {
// path.addError("package belongs to a module and may not be imported by default module: " +
// nameToImport);
// }
//check that the package really does belong to
//an imported module, to work around bug where
//default package thinks it can see stuff in
//all modules in the same source dir
Set<Module> visited = new HashSet<Module>();
for (ModuleImport mi: module.getImports()) {
if (findModuleInTransitiveImports(mi.getModule(),
pkg.getModule(), visited)) {
return pkg;
}
}
}
String help;