Search in sources :

Example 1 with GrMemberInfo

use of org.jetbrains.plugins.groovy.refactoring.classMembers.GrMemberInfo in project intellij-community by JetBrains.

the class GrPullUpDialog method doAction.

@Override
protected void doAction() {
    if (!myCallback.checkConflicts(this))
        return;
    JavaRefactoringSettings.getInstance().PULL_UP_MEMBERS_JAVADOC = myJavaDocPanel.getPolicy();
    final PsiClass superClass = getSuperClass();
    String name = superClass.getQualifiedName();
    if (name != null) {
        StatisticsManager.getInstance().incUseCount(new StatisticsInfo(PULL_UP_STATISTICS_KEY + myClass.getQualifiedName(), name));
    }
    List<GrMemberInfo> infos = getSelectedMemberInfos();
    //GrPullUpProcessor processor = new GrPullUpProcessor(myClass, superClass, infos.toArray(new GrMemberInfo[infos.size()]), new DocCommentPolicy(getJavaDocPolicy()));
    //invokeRefactoring(processor);
    close(OK_EXIT_CODE);
}
Also used : StatisticsInfo(com.intellij.psi.statistics.StatisticsInfo) GrMemberInfo(org.jetbrains.plugins.groovy.refactoring.classMembers.GrMemberInfo)

Example 2 with GrMemberInfo

use of org.jetbrains.plugins.groovy.refactoring.classMembers.GrMemberInfo in project intellij-community by JetBrains.

the class GrPullUpHandler method checkConflicts.

@Override
public boolean checkConflicts(final GrPullUpDialog dialog) {
    /*                         todo */
    List<GrMemberInfo> _infos = dialog.getSelectedMemberInfos();
    final GrMemberInfo[] infos = _infos.toArray(new GrMemberInfo[_infos.size()]);
    final PsiClass superClass = dialog.getSuperClass();
    if (!checkWritable(superClass, infos))
        return false;
    final MultiMap<PsiElement, String> conflicts = new MultiMap<>();
    if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> ApplicationManager.getApplication().runReadAction(() -> {
        final PsiDirectory targetDirectory = superClass.getContainingFile().getContainingDirectory();
        final PsiPackage targetPackage = targetDirectory != null ? JavaDirectoryService.getInstance().getPackage(targetDirectory) : null;
        conflicts.putAllValues(GrPullUpConflictsUtil.checkConflicts(infos, mySubclass, superClass, targetPackage, targetDirectory, dialog.getContainmentVerifier()));
    }), RefactoringBundle.message("detecting.possible.conflicts"), true, myProject)) {
        return false;
    }
    if (!conflicts.isEmpty()) {
        ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
        conflictsDialog.show();
        final boolean ok = conflictsDialog.isOK();
        if (!ok && conflictsDialog.isShowConflicts())
            dialog.close(DialogWrapper.CANCEL_EXIT_CODE);
        return ok;
    }
    return true;
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog) GrMemberInfo(org.jetbrains.plugins.groovy.refactoring.classMembers.GrMemberInfo)

Example 3 with GrMemberInfo

use of org.jetbrains.plugins.groovy.refactoring.classMembers.GrMemberInfo in project intellij-community by JetBrains.

the class GrPullUpDialog method addCustomElementsToCentralPanel.

@Override
protected void addCustomElementsToCentralPanel(JPanel panel) {
    myJavaDocPanel = new DocCommentPanel(RefactoringBundle.message("javadoc.for.abstracts"));
    myJavaDocPanel.setPolicy(JavaRefactoringSettings.getInstance().PULL_UP_MEMBERS_JAVADOC);
    boolean hasJavadoc = false;
    for (GrMemberInfo info : myMemberInfos) {
        final PsiMember member = info.getMember();
        if (myMemberInfoModel.isAbstractEnabled(info) && member instanceof PsiDocCommentOwner && ((PsiDocCommentOwner) member).getDocComment() != null) {
            hasJavadoc = true;
            break;
        }
    }
    UIUtil.setEnabled(myJavaDocPanel, hasJavadoc, true);
    panel.add(myJavaDocPanel, BorderLayout.EAST);
}
Also used : DocCommentPanel(com.intellij.refactoring.ui.DocCommentPanel) GrMemberInfo(org.jetbrains.plugins.groovy.refactoring.classMembers.GrMemberInfo)

Example 4 with GrMemberInfo

use of org.jetbrains.plugins.groovy.refactoring.classMembers.GrMemberInfo in project intellij-community by JetBrains.

the class GrPullUpHandler method invokeImpl.

private void invokeImpl(Project project, DataContext dataContext, GrTypeDefinition aClass, PsiElement aMember) {
    final Editor editor = dataContext != null ? CommonDataKeys.EDITOR.getData(dataContext) : null;
    if (aClass == null) {
        String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("is.not.supported.in.the.current.context", REFACTORING_NAME));
        CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.MEMBERS_PULL_UP);
        return;
    }
    ArrayList<PsiClass> bases = RefactoringHierarchyUtil.createBasesList(aClass, false, true);
    if (bases.isEmpty()) {
        final GrTypeDefinition containingClass = DefaultGroovyMethods.asType(aClass.getContainingClass(), GrTypeDefinition.class);
        if (containingClass != null) {
            invokeImpl(project, dataContext, containingClass, aClass);
            return;
        }
        String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("class.does.not.have.base.classes.interfaces.in.current.project", aClass.getQualifiedName()));
        CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.MEMBERS_PULL_UP);
        return;
    }
    mySubclass = aClass;
    GrMemberInfoStorage memberInfoStorage = new GrMemberInfoStorage((GrTypeDefinition) mySubclass, new MemberInfoBase.Filter<GrMember>() {

        @Override
        public boolean includeMember(GrMember element) {
            return true;
        }
    });
    List<GrMemberInfo> members = memberInfoStorage.getClassMemberInfos(mySubclass);
    PsiManager manager = mySubclass.getManager();
    for (GrMemberInfo member : members) {
        if (manager.areElementsEquivalent(member.getMember(), aMember)) {
            member.setChecked(true);
            break;
        }
    }
    final GrPullUpDialog dialog = new GrPullUpDialog(project, aClass, bases, memberInfoStorage, this);
    dialog.show();
}
Also used : GrMember(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember) GrMemberInfo(org.jetbrains.plugins.groovy.refactoring.classMembers.GrMemberInfo) MemberInfoBase(com.intellij.refactoring.classMembers.MemberInfoBase) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) GrMemberInfoStorage(org.jetbrains.plugins.groovy.refactoring.classMembers.GrMemberInfoStorage) Editor(com.intellij.openapi.editor.Editor)

Aggregations

GrMemberInfo (org.jetbrains.plugins.groovy.refactoring.classMembers.GrMemberInfo)4 Editor (com.intellij.openapi.editor.Editor)1 StatisticsInfo (com.intellij.psi.statistics.StatisticsInfo)1 MemberInfoBase (com.intellij.refactoring.classMembers.MemberInfoBase)1 ConflictsDialog (com.intellij.refactoring.ui.ConflictsDialog)1 DocCommentPanel (com.intellij.refactoring.ui.DocCommentPanel)1 MultiMap (com.intellij.util.containers.MultiMap)1 GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)1 GrMember (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember)1 GrMemberInfoStorage (org.jetbrains.plugins.groovy.refactoring.classMembers.GrMemberInfoStorage)1