String () { Ref<JComponent> componentWithFocus = Ref.create(); String message = ActionUtil.underModalProgress(myProject, JavaRefactoringBundle.message("changeSignature.validating.title"), () -> { PsiManager manager = PsiManager.getInstance(myProject); PsiElementFactory factory = JavaPsiFacade.getElementFactory(manager.getProject()); String name = getMethodName(); if (!PsiNameHelper.getInstance(manager.getProject()).isIdentifier(name)) { return RefactoringMessageUtil.getIncorrectIdentifierMessage(name); } if (myMethod.canChangeReturnType() == MethodDescriptor.ReadWriteOption.ReadWrite) { try { ((PsiTypeCodeFragment)myReturnTypeCodeFragment).getType(); } catch (PsiTypeCodeFragment.TypeSyntaxException e) { componentWithFocus.set(myReturnTypeField); return JavaRefactoringBundle.message("changeSignature.wrong.return.type", myReturnTypeCodeFragment.getText()); } catch (PsiTypeCodeFragment.NoTypeException e) { componentWithFocus.set(myReturnTypeField); return JavaRefactoringBundle.message("changeSignature.no.return.type"); } } List<ParameterTableModelItemBase<ParameterInfoImpl>> parameterInfos = myParametersTableModel.getItems(); final int newParametersNumber = parameterInfos.size(); for (int i = 0; i < newParametersNumber; i++) { final ParameterTableModelItemBase<ParameterInfoImpl> item = parameterInfos.get(i); if (!PsiNameHelper.getInstance(manager.getProject()).isIdentifier(item.parameter.getName())) { return RefactoringMessageUtil.getIncorrectIdentifierMessage(item.parameter.getName()); } final PsiType type; try { type = ((PsiTypeCodeFragment)parameterInfos.get(i).typeCodeFragment).getType(); } catch (PsiTypeCodeFragment.TypeSyntaxException e) { return JavaRefactoringBundle.message("changeSignature.wrong.type.for.parameter", item.typeCodeFragment.getText(), item.parameter.getName()); } catch (PsiTypeCodeFragment.NoTypeException e) { return JavaRefactoringBundle.message("changeSignature.no.type.for.parameter", "return", item.parameter.getName()); } item.parameter.setType(type); if (type instanceof PsiEllipsisType && i != newParametersNumber - 1) { return JavaRefactoringBundle.message("changeSignature.vararg.not.last"); } if (item.parameter.oldParameterIndex < 0) { String def = JavaCodeStyleManager.getInstance(myProject) .qualifyClassReferences(item.defaultValueCodeFragment.copy()).getText().trim(); item.parameter.defaultValue = def; if (!(type instanceof PsiEllipsisType)) { try { if (!StringUtil.isEmpty(def)) { factory.createExpressionFromText(def, null); } } catch (IncorrectOperationException e) { return e.getMessage(); } } } } ThrownExceptionInfo[] exceptionInfos; PsiTypeCodeFragment[] typeCodeFragments; if (myExceptionsModel != null) { exceptionInfos = myExceptionsModel.getThrownExceptions(); typeCodeFragments = myExceptionsModel.getTypeCodeFragments(); } else { exceptionInfos = new ThrownExceptionInfo[0]; typeCodeFragments = new PsiTypeCodeFragment[0]; } for (int i = 0; i < exceptionInfos.length; i++) { ThrownExceptionInfo exceptionInfo = exceptionInfos[i]; PsiTypeCodeFragment typeCodeFragment = typeCodeFragments[i]; try { PsiType type = typeCodeFragment.getType(); if (!(type instanceof PsiClassType)) { return JavaRefactoringBundle.message("changeSignature.wrong.type.for.exception", typeCodeFragment.getText()); } PsiClassType throwable = JavaPsiFacade.getElementFactory(myProject) .createTypeByFQClassName(CommonClassNames.JAVA_LANG_THROWABLE, type.getResolveScope()); if (!throwable.isAssignableFrom(type)) { return JavaRefactoringBundle.message("changeSignature.not.throwable.type", typeCodeFragment.getText()); } exceptionInfo.setType((PsiClassType)type); } catch (PsiTypeCodeFragment.TypeSyntaxException e) { return JavaRefactoringBundle.message("changeSignature.wrong.type.for.exception", typeCodeFragment.getText()); } catch (PsiTypeCodeFragment.NoTypeException e) { return JavaRefactoringBundle.message("changeSignature.no.type.for.exception"); } } return null; }); if (!componentWithFocus.isNull()) { IdeFocusManager.getGlobalInstance() .doWhenFocusSettlesDown(() -> IdeFocusManager.getGlobalInstance().requestFocus(componentWithFocus.get(), true)); } else if (message == null) { // warnings try { if (myMethod.canChangeReturnType() == MethodDescriptor.ReadWriteOption.ReadWrite) { if (PsiTypesUtil.hasUnresolvedComponents(((PsiTypeCodeFragment)myReturnTypeCodeFragment).getType())) { if (Messages.showOkCancelDialog(myProject, JavaRefactoringBundle .message("changeSignature.cannot.resolve.return.type", myReturnTypeCodeFragment.getText()), RefactoringBundle.message("changeSignature.refactoring.name"), Messages.getWarningIcon()) != Messages.OK) { return EXIT_SILENTLY; } } } for (ParameterTableModelItemBase<ParameterInfoImpl> item : myParametersTableModel.getItems()) { if (PsiTypesUtil.hasUnresolvedComponents(((PsiTypeCodeFragment)item.typeCodeFragment).getType())) { if (Messages.showOkCancelDialog(myProject, RefactoringBundle .message("changeSignature.cannot.resolve.parameter.type", item.typeCodeFragment.getText(), item.parameter.getName()), RefactoringBundle.message("changeSignature.refactoring.name"), Messages.getWarningIcon()) != Messages.OK) { return EXIT_SILENTLY; } } } } catch (PsiTypeCodeFragment.IncorrectTypeException ignored) { } } return message; }