RefPackage (String packageName) { RefPackage refPackage; synchronized (this) { if (myPackages == null) { myPackages = new HashMap<>(); } refPackage = myPackages.get(packageName); } if (refPackage == null) { refPackage = new RefPackageImpl(packageName, myRefManager); boolean saved; synchronized (this) { RefPackage oldPackage = myPackages.get(packageName); if (oldPackage == null) { myPackages.put(packageName, refPackage); saved = true; } else { refPackage = oldPackage; saved = false; } } if (saved) { int dotIndex = packageName.lastIndexOf('.'); if (dotIndex >= 0) { ((RefPackageImpl)getPackage(packageName.substring(0, dotIndex))).add(refPackage); } else { ((RefProjectImpl)myRefManager.getRefProject()).add(refPackage); } } } return refPackage; }