use of org.jetbrains.kotlin.idea.projectView.KtClassOrObjectTreeNode in project kotlin by JetBrains.
the class MoveKotlinNestedClassesDialog method initClassChooser.
private void initClassChooser(@NotNull KtClassOrObject initialTargetClass) {
//noinspection ConstantConditions
originalClassField.setText(originalClass.getFqName().asString());
//noinspection ConstantConditions
targetClassChooser = new ReferenceEditorComboWithBrowseButton(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
TreeClassChooser chooser = new TreeJavaClassChooserDialog(RefactoringBundle.message("choose.destination.class"), myProject, GlobalSearchScope.projectScope(myProject), new ClassFilter() {
@Override
public boolean isAccepted(PsiClass aClass) {
if (!(aClass instanceof KtLightClassForSourceDeclaration))
return false;
KtClassOrObject classOrObject = ((KtLightClassForSourceDeclaration) aClass).getKotlinOrigin();
if (classOrObject instanceof KtObjectDeclaration) {
return !((KtObjectDeclaration) classOrObject).isObjectLiteral();
}
if (classOrObject instanceof KtClass) {
KtClass ktClass = (KtClass) classOrObject;
return !(ktClass.isInner() || ktClass.isAnnotation());
}
return false;
}
}, null, null, true) {
@Nullable
@Override
protected PsiClass getSelectedFromTreeUserObject(DefaultMutableTreeNode node) {
PsiClass psiClass = super.getSelectedFromTreeUserObject(node);
if (psiClass != null)
return psiClass;
Object userObject = node.getUserObject();
if (!(userObject instanceof KtClassOrObjectTreeNode))
return null;
return LightClassUtilsKt.toLightClass(((KtClassOrObjectTreeNode) userObject).getValue());
}
};
chooser.selectDirectory((targetClass != null ? targetClass : originalClass).getContainingFile().getContainingDirectory());
chooser.showDialog();
PsiClass aClass = chooser.getSelected();
if (aClass instanceof KtLightClassForSourceDeclaration) {
targetClass = ((KtLightClassForSourceDeclaration) aClass).getKotlinOrigin();
targetClassChooser.setText(aClass.getQualifiedName());
}
}
}, initialTargetClass.getFqName().asString(), myProject, true, JavaCodeFragment.VisibilityChecker.PROJECT_SCOPE_VISIBLE, RECENTS_KEY);
targetClassChooser.getChildComponent().getDocument().addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
PsiClass aClass = JavaPsiFacade.getInstance(myProject).findClass(targetClassChooser.getText(), GlobalSearchScope.projectScope(myProject));
targetClass = aClass instanceof KtLightClassForSourceDeclaration ? ((KtLightClassForSourceDeclaration) aClass).getKotlinOrigin() : null;
validateButtons();
}
});
targetClassChooserPanel.add(targetClassChooser);
}
Aggregations