PsiMethod (@NotNull PsiCall call, @NotNull PsiExpression target, @NotNull PsiExpression replacement) { final PsiExpressionList argumentList = call.getArgumentList(); if (argumentList == null) { return null; } final PsiExpression[] expressions = argumentList.getExpressions(); int index = ArrayUtil.indexOf(expressions, target); if (index < 0) { return null; } final PsiCall copy = (PsiCall)call.copy(); final PsiExpressionList copyArgumentList = copy.getArgumentList(); assert copyArgumentList != null; final PsiExpression[] arguments = copyArgumentList.getExpressions(); arguments[index].replace(replacement); if (call instanceof PsiEnumConstant) { final PsiClass containingClass = ((PsiEnumConstant)call).getContainingClass(); assert containingClass != null; final JavaPsiFacade facade = JavaPsiFacade.getInstance(call.getProject()); final PsiClassType type = facade.getElementFactory().createType(containingClass); final JavaResolveResult resolveResult = facade.getResolveHelper().resolveConstructor(type, copy.getArgumentList(), call); return (PsiMethod)resolveResult.getElement(); } return copy.resolveMethod(); }