Search in sources :

Example 1 with CollectingNameValidator

use of org.jetbrains.kotlin.idea.core.CollectingNameValidator in project kotlin by JetBrains.

the class MoveKotlinNestedClassesToUpperLevelDialog method init.

@Override
protected void init() {
    classNameField.setText(innerClass.getName());
    classNameField.selectAll();
    if (innerClass instanceof KtClass && ((KtClass) innerClass).isInner()) {
        passOuterClassCheckBox.setSelected(true);
        passOuterClassCheckBox.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent e) {
                parameterField.setEnabled(passOuterClassCheckBox.isSelected());
            }
        });
    } else {
        passOuterClassCheckBox.setSelected(false);
        passOuterClassCheckBox.setEnabled(false);
        parameterField.setEnabled(false);
    }
    if (passOuterClassCheckBox.isEnabled()) {
        boolean thisNeeded = isThisNeeded();
        passOuterClassCheckBox.setSelected(thisNeeded);
        parameterField.setEnabled(thisNeeded);
    }
    passOuterClassCheckBox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            boolean selected = passOuterClassCheckBox.isSelected();
            parameterField.getComponent().setEnabled(selected);
        }
    });
    if (!(targetContainer instanceof PsiDirectory)) {
        packageNameField.setVisible(false);
        packageNameLabel.setVisible(false);
    }
    if (innerClass instanceof KtClass && ((KtClass) innerClass).isInner()) {
        KtClassBody innerClassBody = innerClass.getBody();
        Function1<String, Boolean> validator = innerClassBody != null ? new NewDeclarationNameValidator(innerClassBody, (PsiElement) null, NewDeclarationNameValidator.Target.VARIABLES, Collections.<KtDeclaration>emptyList()) : new CollectingNameValidator();
        List<String> suggestions = KotlinNameSuggester.INSTANCE.suggestNamesByType(getOuterInstanceType(), validator, "outer");
        parameterField.setSuggestions(ArrayUtil.toStringArray(suggestions));
    } else {
        parameterField.getComponent().setEnabled(false);
    }
    FqName packageFqName = getTargetPackageFqName();
    if (packageFqName != null) {
        packageNameField.prependItem(packageFqName.asString());
    }
    KotlinRefactoringSettings settings = KotlinRefactoringSettings.getInstance();
    searchForTextOccurrencesCheckBox.setSelected(settings.MOVE_TO_UPPER_LEVEL_SEARCH_FOR_TEXT);
    searchInCommentsCheckBox.setSelected(settings.MOVE_TO_UPPER_LEVEL_SEARCH_IN_COMMENTS);
    super.init();
}
Also used : ItemEvent(java.awt.event.ItemEvent) FqName(org.jetbrains.kotlin.name.FqName) CollectingNameValidator(org.jetbrains.kotlin.idea.core.CollectingNameValidator) NewDeclarationNameValidator(org.jetbrains.kotlin.idea.core.NewDeclarationNameValidator) KotlinRefactoringSettings(org.jetbrains.kotlin.idea.refactoring.KotlinRefactoringSettings) ItemListener(java.awt.event.ItemListener)

Aggregations

ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 CollectingNameValidator (org.jetbrains.kotlin.idea.core.CollectingNameValidator)1 NewDeclarationNameValidator (org.jetbrains.kotlin.idea.core.NewDeclarationNameValidator)1 KotlinRefactoringSettings (org.jetbrains.kotlin.idea.refactoring.KotlinRefactoringSettings)1 FqName (org.jetbrains.kotlin.name.FqName)1