void (@NotNull AnActionEvent e) { final Ref<String> visitorNameRef = Ref.create("MyVisitor"); final Ref<PsiClass> parentClassRef = Ref.create(null); final Project project = e.getData(CommonDataKeys.PROJECT); assert project != null; final PsiNameHelper helper = PsiNameHelper.getInstance(project); final PackageChooserDialog dialog = new PackageChooserDialog("Choose Target Package and Hierarchy Root Class", project) { @Override protected ValidationInfo doValidate() { PsiDocumentManager.getInstance(project).commitAllDocuments(); if (!helper.isQualifiedName(visitorNameRef.get())) { return new ValidationInfo("Visitor class name is not valid"); } else if (parentClassRef.isNull()) { return new ValidationInfo("Hierarchy root class should be specified"); } else if (parentClassRef.get().isAnnotationType() || parentClassRef.get().isEnum()) { return new ValidationInfo("Hierarchy root class should be an interface or a class"); } return super.doValidate(); } @Override protected JComponent createCenterPanel() { final JPanel panel = new JPanel(new BorderLayout()); panel.add(super.createCenterPanel(), BorderLayout.CENTER); panel.add(createNamePanel(), BorderLayout.NORTH); panel.add(createBaseClassPanel(), BorderLayout.SOUTH); return panel; } private JComponent createNamePanel() { LabeledComponent<JTextField> labeledComponent = new LabeledComponent<>(); labeledComponent.setText("Visitor class"); final JTextField nameField = new JTextField(visitorNameRef.get()); labeledComponent.setComponent(nameField); nameField.getDocument().addDocumentListener(new DocumentAdapter() { @Override protected void textChanged(@NotNull final DocumentEvent e) { visitorNameRef.set(nameField.getText()); } }); return labeledComponent; } private JComponent createBaseClassPanel() { LabeledComponent<EditorTextField> labeledComponent = new LabeledComponent<>(); labeledComponent.setText("Hierarchy root class"); final JavaCodeFragmentFactory factory = JavaCodeFragmentFactory.getInstance(project); final PsiTypeCodeFragment codeFragment = factory.createTypeCodeFragment("", null, true, JavaCodeFragmentFactory.ALLOW_VOID); final Document document = PsiDocumentManager.getInstance(project).getDocument(codeFragment); final EditorTextField editorTextField = new EditorTextField(document, project, JavaFileType.INSTANCE); labeledComponent.setComponent(editorTextField); editorTextField.addDocumentListener(new DocumentListener() { @Override public void documentChanged(@NotNull final com.intellij.openapi.editor.event.DocumentEvent e) { parentClassRef.set(null); try { final PsiType psiType = codeFragment.getType(); final PsiClass psiClass = psiType instanceof PsiClassType ? ((PsiClassType)psiType).resolve() : null; parentClassRef.set(psiClass); } catch (PsiTypeCodeFragment.IncorrectTypeException e1) { // ok } } }); return labeledComponent; } }; final PsiElement element = e.getData(CommonDataKeys.PSI_ELEMENT); if (element instanceof PsiPackage) { dialog.selectPackage(((PsiPackage)element).getQualifiedName()); } else if (element instanceof PsiDirectory) { final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory)element); if (aPackage != null) { dialog.selectPackage(aPackage.getQualifiedName()); } } dialog.show(); if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE || dialog.getSelectedPackage() == null || dialog.getSelectedPackage().getQualifiedName().length() == 0 || parentClassRef.isNull()) { return; } final String visitorQName = generateEverything(dialog.getSelectedPackage(), parentClassRef.get(), visitorNameRef.get()); final IdeView ideView = e.getData(LangDataKeys.IDE_VIEW); final PsiClass visitorClass = JavaPsiFacade.getInstance(project).findClass(visitorQName, GlobalSearchScope.projectScope(project)); if (ideView != null && visitorClass != null) { ideView.selectElement(visitorClass); } }