}
public LazyPackage findOrCreatePackage(Module module, final String pkgName) {
synchronized(getLock()){
String quotedPkgName = Util.quoteJavaKeywords(pkgName);
LazyPackage pkg = findCachedPackage(module, quotedPkgName);
if(pkg != null)
return pkg;
// try to find it from the module, perhaps it already got created and we didn't catch it
if(module instanceof LazyModule){
pkg = (LazyPackage) ((LazyModule) module).findPackageNoLazyLoading(pkgName);
}else if(module != null){
pkg = (LazyPackage) module.getDirectPackage(pkgName);
}
boolean isNew = pkg == null;
if(pkg == null){
pkg = new LazyPackage(this);
// FIXME: some refactoring needed
pkg.setName(Arrays.asList(pkgName.split("\\.")));
}
packagesByName.put(cacheKeyByModule(module, quotedPkgName), pkg);
// only bind it if we already have a module
if(isNew && module != null){
pkg.setModule(module);
if(module instanceof LazyModule)
((LazyModule) module).addPackage(pkg);
else
module.getPackages().add(pkg);
}