public static bool DoUpdateOnWorkspace <TChange>(Workspace workspace, Func <IRoot, IEnumerable <TChange> > getItems, IUpdateRefactoring <TChange> updateRefactoring) where TChange : IDom { var solution = workspace.CurrentSolution; //var changedDocuments = ChangeAll(solution); //foreach(var document in changedDocuments ) //{ // solution = solution.WithDocumentSyntaxRoot(document.Id, document); // workspace.TryApplyChanges(solution); //} var didAnythingChange = false; var newSolution = DoUpdateOnSolution(solution, ref didAnythingChange, getItems, updateRefactoring); if (didAnythingChange) { if (workspace.TryApplyChanges(solution)) { return(true); } } return(didAnythingChange); }
public static bool DoUpdateOnFiles <TChange>(IEnumerable <Tuple <string, string> > filePairs, Func <IRoot, IEnumerable <TChange> > getItems, IUpdateRefactoring <TChange> updateRefactoring) where TChange : IDom { return(DoUpdateOnFiles(filePairs, getItems, updateRefactoring.NeedsChange, updateRefactoring.MakeChange)); }
public static SyntaxTree DoUpdateOnDocument <TChange>(Document document, Func <IRoot, IEnumerable <TChange> > getItems, IUpdateRefactoring <TChange> updateRefactoring) where TChange : IDom { var didThisChange = false; SyntaxTree tree; if (document.TryGetSyntaxTree(out tree)) { var newTree = UpdateTree(tree, ref didThisChange, getItems, updateRefactoring.NeedsChange, updateRefactoring.MakeChange); if (didThisChange) { return(newTree); } } return(null); }
public static Solution DoUpdateOnProject <TChange>(Project project, Solution solution, ref bool didChange, Func <IRoot, IEnumerable <TChange> > getItems, IUpdateRefactoring <TChange> updateRefactoring) where TChange : IDom { var documents = project.Documents.Where(x => x.SupportsSyntaxTree); var newSolution = solution; foreach (var document in documents) { var id = document.Id; var newSyntaxTree = DoUpdateOnDocument(document, getItems, updateRefactoring); if (newSyntaxTree != null) { didChange = true; newSolution = newSolution.WithDocumentSyntaxRoot(id, newSyntaxTree.GetCompilationUnitRoot()); } } return(newSolution); }
//private static IEnumerable<Document> ChangeAll(Solution solution) //{ // throw new NotImplementedException(); //} public static Solution DoUpdateOnSolution <TChange>(Solution solution, ref bool didAnythingChange, Func <IRoot, IEnumerable <TChange> > getItems, IUpdateRefactoring <TChange> updateRefactoring) where TChange : IDom { var projects = solution.Projects.Where(x => x.Language == ExpectedLanguages.CSharp); var newSolution = solution; foreach (var project in projects) { var didThisChange = false; newSolution = DoUpdateOnProject(project, newSolution, ref didThisChange, getItems, updateRefactoring); if (didThisChange) { didAnythingChange = true; } } return(newSolution); }