Search in sources :

Example 1 with JavaCallerChooser

use of com.intellij.refactoring.changeSignature.inCallers.JavaCallerChooser in project intellij-community by JetBrains.

the class JavaChangeSignatureDialog method createAdditionalPanels.

@NotNull
protected List<Pair<String, JPanel>> createAdditionalPanels() {
    // this method is invoked before constructor body
    myExceptionsModel = new ExceptionsTableModel(myMethod.getMethod().getThrowsList());
    myExceptionsModel.setTypeInfos(myMethod.getMethod());
    final JBTable table = new JBTable(myExceptionsModel);
    table.setStriped(true);
    table.setRowHeight(20);
    table.getColumnModel().getColumn(0).setCellRenderer(new CodeFragmentTableCellRenderer(myProject));
    final JavaCodeFragmentTableCellEditor cellEditor = new JavaCodeFragmentTableCellEditor(myProject);
    cellEditor.addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            final int row = table.getSelectedRow();
            final int col = table.getSelectedColumn();
            myExceptionsModel.setValueAt(cellEditor.getCellEditorValue(), row, col);
            updateSignature();
        }
    });
    table.getColumnModel().getColumn(0).setCellEditor(cellEditor);
    table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.getSelectionModel().setSelectionInterval(0, 0);
    table.setSurrendersFocusOnKeystroke(true);
    myPropExceptionsButton = new AnActionButton(RefactoringBundle.message("changeSignature.propagate.exceptions.title"), null, AllIcons.Hierarchy.Caller) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            final Ref<JavaCallerChooser> chooser = new Ref<>();
            Consumer<Set<PsiMethod>> callback = psiMethods -> {
                myMethodsToPropagateExceptions = psiMethods;
                myExceptionPropagationTree = chooser.get().getTree();
            };
            chooser.set(new JavaCallerChooser(myMethod.getMethod(), myProject, RefactoringBundle.message("changeSignature.exception.caller.chooser"), myExceptionPropagationTree, callback));
            chooser.get().show();
        }
    };
    myPropExceptionsButton.setShortcut(CustomShortcutSet.fromString("alt X"));
    final JPanel panel = ToolbarDecorator.createDecorator(table).addExtraAction(myPropExceptionsButton).createPanel();
    panel.setBorder(IdeBorderFactory.createEmptyBorder());
    myExceptionsModel.addTableModelListener(mySignatureUpdater);
    final ArrayList<Pair<String, JPanel>> result = new ArrayList<>();
    final String message = RefactoringBundle.message("changeSignature.exceptions.panel.border.title");
    result.add(Pair.create(message, panel));
    return result;
}
Also used : JavaCallerChooser(com.intellij.refactoring.changeSignature.inCallers.JavaCallerChooser) ArrayList(java.util.ArrayList) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) JBTable(com.intellij.ui.table.JBTable) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) JavaCodeFragmentTableCellEditor(com.intellij.refactoring.ui.JavaCodeFragmentTableCellEditor) Ref(com.intellij.openapi.util.Ref) CodeFragmentTableCellRenderer(com.intellij.refactoring.ui.CodeFragmentTableCellRenderer) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with JavaCallerChooser

use of com.intellij.refactoring.changeSignature.inCallers.JavaCallerChooser in project intellij-community by JetBrains.

the class JavaSafeDeleteProcessor method preprocessUsages.

@Nullable
public UsageInfo[] preprocessUsages(final Project project, final UsageInfo[] usages) {
    final ArrayList<UsageInfo> result = new ArrayList<>();
    final ArrayList<UsageInfo> overridingMethods = new ArrayList<>();
    final ArrayList<SafeDeleteParameterCallHierarchyUsageInfo> delegatingParams = new ArrayList<>();
    final ArrayList<SafeDeleteMethodCalleeUsageInfo> calleesSafeToDelete = new ArrayList<>();
    for (UsageInfo usage : usages) {
        if (usage.isNonCodeUsage) {
            result.add(usage);
        } else if (usage instanceof SafeDeleteMethodCalleeUsageInfo) {
            calleesSafeToDelete.add((SafeDeleteMethodCalleeUsageInfo) usage);
        } else if (usage instanceof SafeDeleteOverridingMethodUsageInfo) {
            overridingMethods.add(usage);
        } else if (usage instanceof SafeDeleteParameterCallHierarchyUsageInfo) {
            delegatingParams.add((SafeDeleteParameterCallHierarchyUsageInfo) usage);
        } else if (usage instanceof SafeDeleteAnnotation) {
            result.add(new SafeDeleteAnnotation((PsiAnnotation) usage.getElement(), ((SafeDeleteAnnotation) usage).getReferencedElement(), true));
        } else {
            result.add(usage);
        }
    }
    if (!overridingMethods.isEmpty()) {
        if (ApplicationManager.getApplication().isUnitTestMode()) {
            result.addAll(overridingMethods);
        } else {
            OverridingMethodsDialog dialog = new OverridingMethodsDialog(project, overridingMethods);
            if (!dialog.showAndGet()) {
                return null;
            }
            final ArrayList<UsageInfo> selected = dialog.getSelected();
            final Set<UsageInfo> unselected = new HashSet<>(overridingMethods);
            unselected.removeAll(selected);
            if (!unselected.isEmpty()) {
                final List<PsiMethod> unselectedMethods = ContainerUtil.map(unselected, info -> ((SafeDeleteOverridingMethodUsageInfo) info).getOverridingMethod());
                for (Iterator<UsageInfo> iterator = result.iterator(); iterator.hasNext(); ) {
                    final UsageInfo info = iterator.next();
                    if (info instanceof SafeDeleteOverrideAnnotation && !allSuperMethodsSelectedToDelete(unselectedMethods, ((SafeDeleteOverrideAnnotation) info).getMethod())) {
                        iterator.remove();
                    }
                }
            }
            result.addAll(selected);
        }
    }
    if (!delegatingParams.isEmpty()) {
        final SafeDeleteParameterCallHierarchyUsageInfo parameterHierarchyUsageInfo = delegatingParams.get(0);
        if (ApplicationManager.getApplication().isUnitTestMode()) {
            result.addAll(delegatingParams);
        } else {
            final PsiMethod method = parameterHierarchyUsageInfo.getCalledMethod();
            final PsiParameter parameter = parameterHierarchyUsageInfo.getReferencedElement();
            final int parameterIndex = method.getParameterList().getParameterIndex(parameter);
            final JavaCallerChooser chooser = new SafeDeleteJavaCallerChooser(method, project, result) {

                @Override
                protected ArrayList<SafeDeleteParameterCallHierarchyUsageInfo> getTopLevelItems() {
                    return delegatingParams;
                }

                @Override
                protected int getParameterIdx() {
                    return parameterIndex;
                }
            };
            TreeUtil.expand(chooser.getTree(), 2);
            if (!chooser.showAndGet()) {
                return null;
            }
        }
    }
    if (!calleesSafeToDelete.isEmpty()) {
        if (ApplicationManager.getApplication().isUnitTestMode()) {
            result.addAll(calleesSafeToDelete);
        } else {
            final PsiMethod method = calleesSafeToDelete.get(0).getCallerMethod();
            final ArrayList<UsageInfo> list = new ArrayList<>();
            JavaCallerChooser chooser = new SafeDeleteJavaCalleeChooser(method, project, list) {

                @Override
                protected ArrayList<SafeDeleteMethodCalleeUsageInfo> getTopLevelItems() {
                    return calleesSafeToDelete;
                }
            };
            TreeUtil.expand(chooser.getTree(), 2);
            if (!chooser.showAndGet()) {
                return null;
            }
            result.addAll(list);
            final List<PsiElement> methodsToDelete = new ArrayList<>();
            for (UsageInfo info : list) {
                methodsToDelete.add(info.getElement());
            }
            methodsToDelete.add(method);
            final Condition<PsiElement> insideDeletedCondition = getUsageInsideDeletedFilter(methodsToDelete.toArray(new PsiElement[methodsToDelete.size()]));
            for (UsageInfo info : list) {
                SafeDeleteProcessor.addNonCodeUsages(info.getElement(), result, insideDeletedCondition, JavaRefactoringSettings.getInstance().RENAME_SEARCH_FOR_TEXT_FOR_METHOD, JavaRefactoringSettings.getInstance().RENAME_SEARCH_IN_COMMENTS_FOR_METHOD);
            }
        }
    }
    return result.toArray(new UsageInfo[result.size()]);
}
Also used : UsageInfo(com.intellij.usageView.UsageInfo) JavaCallerChooser(com.intellij.refactoring.changeSignature.inCallers.JavaCallerChooser) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with JavaCallerChooser

use of com.intellij.refactoring.changeSignature.inCallers.JavaCallerChooser in project intellij-community by JetBrains.

the class MakeMethodStaticProcessor method findAdditionalMembers.

@Override
protected boolean findAdditionalMembers(final Set<UsageInfo> toMakeStatic) {
    if (!toMakeStatic.isEmpty()) {
        myAdditionalMethods = new ArrayList<>();
        if (ApplicationManager.getApplication().isUnitTestMode()) {
            for (UsageInfo usageInfo : toMakeStatic) {
                myAdditionalMethods.add((PsiMethod) usageInfo.getElement());
            }
        } else {
            final JavaCallerChooser chooser = new MakeStaticJavaCallerChooser(myMember, myProject, methods -> myAdditionalMethods.addAll(methods)) {

                @Override
                protected ArrayList<UsageInfo> getTopLevelItems() {
                    return new ArrayList<>(toMakeStatic);
                }
            };
            TreeUtil.expand(chooser.getTree(), 2);
            if (!chooser.showAndGet()) {
                return false;
            }
        }
    }
    return true;
}
Also used : JavaCallerChooser(com.intellij.refactoring.changeSignature.inCallers.JavaCallerChooser) ArrayList(java.util.ArrayList) UsageInfo(com.intellij.usageView.UsageInfo)

Aggregations

JavaCallerChooser (com.intellij.refactoring.changeSignature.inCallers.JavaCallerChooser)3 UsageInfo (com.intellij.usageView.UsageInfo)2 ArrayList (java.util.ArrayList)2 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)1 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)1 Pair (com.intellij.openapi.util.Pair)1 Ref (com.intellij.openapi.util.Ref)1 CodeFragmentTableCellRenderer (com.intellij.refactoring.ui.CodeFragmentTableCellRenderer)1 JavaCodeFragmentTableCellEditor (com.intellij.refactoring.ui.JavaCodeFragmentTableCellEditor)1 JBTable (com.intellij.ui.table.JBTable)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1