private bool UpdateExistingMethod([CanBeNull] IMethodDeclaration methodDeclaration, IPsiServices psiServices) { if (methodDeclaration?.Body == null) { return(false); } var classLikeDeclaration = methodDeclaration.GetContainingTypeDeclaration() as IClassLikeDeclaration; if (classLikeDeclaration == null) { return(false); } using (var cookie = new PsiTransactionCookie(psiServices, DefaultAction.Rollback, "UpdateExistingMethod")) using (WriteLockCookie.Create()) { methodDeclaration.SetName(myEventFunction.Name); // TODO: We should also update return type and parameters // This doesn't work - it doesn't shorten the references and we end up "global::System.Void". Don't know // why and don't have time to look into right now. // At least the method signature inspections will help fix up if necessary // When this comes back, remember to try to match the existing parameters - they might be correct but // renamed. We don't want to set the names back and break code // methodDeclaration.SetTypeUsage(newDeclaration.TypeUsage); // methodDeclaration.SetParams(newDeclaration.Params); cookie.Commit(); } return(true); }
private static void SetSignature([NotNull] IMethodDeclaration methodDeclaration, [NotNull] IType newReturnValue, [NotNull] string newName) { methodDeclaration.SetType(newReturnValue); if(!methodDeclaration.IsAbstract) methodDeclaration.SetAsync(true); methodDeclaration.SetName(newName); }