PsiMethod (final @NotNull PsiMethod methodToReplaceIn, final @NotNull String parameterInitializer, final @NotNull IntList parametersToRemove) { final PsiMethod delegate = (PsiMethod)methodToReplaceIn.copy(); final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(methodToReplaceIn.getProject()); ChangeSignatureProcessor.makeEmptyBody(elementFactory, delegate); final PsiCallExpression callExpression = ChangeSignatureProcessor.addDelegatingCallTemplate(delegate, delegate.getName()); final PsiExpression initializer = elementFactory.createExpressionFromText(parameterInitializer, callExpression); final PsiExpressionList argumentList = callExpression.getArgumentList(); assert argumentList != null; final PsiParameter[] psiParameters = methodToReplaceIn.getParameterList().getParameters(); if (psiParameters.length == 0) { argumentList.add(initializer); } else { final PsiParameter anchorParameter = getAnchorParameter(methodToReplaceIn); if (anchorParameter == null) { argumentList.add(initializer); } for (int i = 0; i < psiParameters.length; i++) { PsiParameter psiParameter = psiParameters[i]; if (!parametersToRemove.contains(i)) { final PsiExpression expression = elementFactory.createExpressionFromText(psiParameter.getName(), delegate); argumentList.add(expression); } if (psiParameter == anchorParameter) { argumentList.add(initializer); } } } return delegate; }