PsiClass () { if (myTargetClass != null) return myTargetClass; final String packageName = StringUtil.getPackageName(myQualifiedName); final String shortName = StringUtil.getShortName(myQualifiedName); if (Comparing.strEqual(myParentClass.getQualifiedName(), packageName)) { myTargetClass = (PsiClass)myParentClass.add(JavaPsiFacade.getElementFactory(myProject).createClass(shortName)); return myTargetClass; } PsiPackage psiPackage = JavaPsiFacade.getInstance(myProject).findPackage(packageName); final PsiDirectory psiDirectory; if (psiPackage != null) { final PsiDirectory[] directories = psiPackage.getDirectories(GlobalSearchScope.allScope(myProject)); psiDirectory = directories.length > 1 ? DirectoryChooserUtil.chooseDirectory(directories, null, myProject, new HashMap<>()) : directories[0]; } else { psiDirectory = PackageUtil.findOrCreateDirectoryForPackage(myProject, packageName, myParentClass.getContainingFile().getContainingDirectory(), false); } myTargetClass = psiDirectory != null ? JavaDirectoryService.getInstance().createClass(psiDirectory, shortName) : null; return myTargetClass; }