Search in sources :

Example 1 with InplaceChangeSignature

use of com.intellij.refactoring.changeSignature.inplace.InplaceChangeSignature in project intellij-community by JetBrains.

the class JavaChangeSignatureHandler method invoke.

private static void invoke(final PsiMethod method, final Project project, @Nullable final Editor editor) {
    PsiMethod newMethod = SuperMethodWarningUtil.checkSuperMethod(method, RefactoringBundle.message("to.refactor"));
    if (newMethod == null)
        return;
    if (!newMethod.equals(method)) {
        ChangeSignatureUtil.invokeChangeSignatureOn(newMethod, project);
        return;
    }
    if (!CommonRefactoringUtil.checkReadOnlyStatus(project, method))
        return;
    final PsiClass containingClass = method.getContainingClass();
    final PsiReferenceExpression refExpr = editor != null ? JavaTargetElementEvaluator.findReferenceExpression(editor) : null;
    final boolean allowDelegation = containingClass != null && (!containingClass.isInterface() || PsiUtil.isLanguageLevel8OrHigher(containingClass));
    InplaceChangeSignature inplaceChangeSignature = editor != null ? InplaceChangeSignature.getCurrentRefactoring(editor) : null;
    ChangeInfo initialChange = inplaceChangeSignature != null ? inplaceChangeSignature.getStableChange() : null;
    boolean isInplace = Registry.is("inplace.change.signature") && editor != null && editor.getSettings().isVariableInplaceRenameEnabled() && (initialChange == null || initialChange.getMethod() != method) && refExpr == null;
    PsiIdentifier nameIdentifier = method.getNameIdentifier();
    LOG.assertTrue(nameIdentifier != null);
    if (isInplace) {
        CommandProcessor.getInstance().executeCommand(project, () -> new InplaceChangeSignature(project, editor, nameIdentifier), REFACTORING_NAME, null);
    } else {
        JavaMethodDescriptor methodDescriptor = new JavaMethodDescriptor(method);
        if (initialChange != null) {
            JavaChangeInfo currentInfo = (JavaChangeInfo) inplaceChangeSignature.getCurrentInfo();
            if (currentInfo != null) {
                methodDescriptor = new JavaMethodDescriptor(method) {

                    @Override
                    public String getName() {
                        return currentInfo.getNewName();
                    }

                    @Override
                    public List<ParameterInfoImpl> getParameters() {
                        return Arrays.asList((ParameterInfoImpl[]) currentInfo.getNewParameters());
                    }

                    @Override
                    public String getVisibility() {
                        return currentInfo.getNewVisibility();
                    }

                    @Override
                    public int getParametersCount() {
                        return currentInfo.getNewParameters().length;
                    }

                    @Nullable
                    @Override
                    public String getReturnTypeText() {
                        return currentInfo.getNewReturnType().getTypeText();
                    }
                };
            }
            inplaceChangeSignature.cancel();
        }
        final DialogWrapper dialog = new JavaChangeSignatureDialog(project, methodDescriptor, allowDelegation, refExpr == null ? method : refExpr);
        dialog.show();
    }
}
Also used : DialogWrapper(com.intellij.openapi.ui.DialogWrapper) List(java.util.List) InplaceChangeSignature(com.intellij.refactoring.changeSignature.inplace.InplaceChangeSignature) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with InplaceChangeSignature

use of com.intellij.refactoring.changeSignature.inplace.InplaceChangeSignature in project intellij-community by JetBrains.

the class ChangeSignatureGestureTest method doTest.

private void doTest(final Runnable run) {
    myFixture.configureByFile("/refactoring/changeSignatureGesture/" + getTestName(false) + ".java");
    myFixture.enableInspections(new UnusedDeclarationInspection());
    CommandProcessor.getInstance().executeCommand(myFixture.getProject(), () -> new InplaceChangeSignature(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile().findElementAt(myFixture.getCaretOffset())), ChangeSignatureHandler.REFACTORING_NAME, null);
    run.run();
    myFixture.launchAction(ContainerUtil.findInstance(myFixture.getAvailableIntentions(), ApplyChangeSignatureAction.class));
    myFixture.checkResultByFile("/refactoring/changeSignatureGesture/" + getTestName(false) + "_after.java");
}
Also used : ApplyChangeSignatureAction(com.intellij.refactoring.changeSignature.inplace.ApplyChangeSignatureAction) InplaceChangeSignature(com.intellij.refactoring.changeSignature.inplace.InplaceChangeSignature) UnusedDeclarationInspection(com.intellij.codeInspection.deadCode.UnusedDeclarationInspection)

Aggregations

InplaceChangeSignature (com.intellij.refactoring.changeSignature.inplace.InplaceChangeSignature)2 UnusedDeclarationInspection (com.intellij.codeInspection.deadCode.UnusedDeclarationInspection)1 DialogWrapper (com.intellij.openapi.ui.DialogWrapper)1 ApplyChangeSignatureAction (com.intellij.refactoring.changeSignature.inplace.ApplyChangeSignatureAction)1 List (java.util.List)1 Nullable (org.jetbrains.annotations.Nullable)1