PsiElement (PsiClass innerClass, final boolean chooseIfNotUnderSource) { final PsiClass outerClass = innerClass.getContainingClass(); assert outerClass != null; // Only inner classes allowed. PsiElement outerClassParent = outerClass.getParent(); while (outerClassParent != null) { if (outerClassParent instanceof PsiClass && !(outerClassParent instanceof PsiAnonymousClass)) { return outerClassParent; } else if (outerClassParent instanceof PsiFile) { final PsiDirectory directory = innerClass.getContainingFile().getContainingDirectory(); final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(directory); if (aPackage == null) { if (chooseIfNotUnderSource) { PackageChooserDialog chooser = new PackageChooserDialog(JavaBundle.message("move.inner.select.target.package.title"), innerClass.getProject()); if (!chooser.showAndGet()) { return null; } final PsiPackage chosenPackage = chooser.getSelectedPackage(); if (chosenPackage == null) return null; return chosenPackage.getDirectories()[0]; } return null; } return directory; } outerClassParent = outerClassParent.getParent(); } // should not happen LOG.assertTrue(false); return null; }