/// <summary> /// A new Rename refactoring command. /// </summary> /// <param name="target">The target declaration to find references to.</param> /// <param name="outputResults">If true, will send the found results to the trace log and results panel</param> /// <param name="newName">If provided, will not query the user for a new name.</param> /// <param name="ignoreDeclarationSource">If true, will not rename the original declaration source. Useful for Encapsulation refactoring.</param> public Rename(ASResult target, Boolean outputResults, String newName, Boolean ignoreDeclarationSource) { if (target == null) { TraceManager.Add("refactor target is null"); return; } this.outputResults = outputResults; if (target.IsPackage) { string package = target.Path.Replace('.', Path.DirectorySeparatorChar); foreach (PathModel aPath in ASContext.Context.Classpath) { if (aPath.IsValid && !aPath.Updating) { string path = Path.Combine(aPath.Path, package); if (aPath.IsValid && Directory.Exists(path)) { this.newName = string.IsNullOrEmpty(newName) ? GetNewName(Path.GetFileName(path)) : newName; if (string.IsNullOrEmpty(this.newName)) { return; } renamePackage = new Move(new Dictionary <string, string> { { path, this.newName } }, true, true); return; } } } return; } this.newName = !string.IsNullOrEmpty(newName) ? newName : GetNewName(RefactoringHelper.GetRefactorTargetName(target)); if (string.IsNullOrEmpty(this.newName)) { return; } // create a FindAllReferences refactor to get all the changes we need to make // we'll also let it output the results, at least until we implement a way of outputting the renamed results later this.findAllReferencesCommand = new FindAllReferences(target, false, ignoreDeclarationSource) { OnlySourceFiles = true }; // register a completion listener to the FindAllReferences so we can rename the entries this.findAllReferencesCommand.OnRefactorComplete += OnFindAllReferencesCompleted; }
/// <summary> /// Initializes a new instance of <see cref="Rename"/> class. /// </summary> /// <param name="target">The target declaration to find references to.</param> /// <param name="outputResults">If true, will send the found results to the trace log and results panel</param> /// <param name="newName">If provided, will not query the user for a new name.</param> /// <param name="ignoreDeclarationSource">If true, will not rename the original declaration source. Useful for Encapsulation refactoring.</param> /// <param name="inline">Whether to use inline renaming.</param> public Rename(ASResult target, bool outputResults, string newName, bool ignoreDeclarationSource, bool inline = false) { if (target == null) { TraceManager.Add("Refactor target is null."); return; } Target = target; OutputResults = outputResults; if (target.IsPackage) { isRenamePackage = true; string package = target.Path.Replace('.', Path.DirectorySeparatorChar); foreach (var aPath in ASContext.Context.Classpath) { if (aPath.IsValid && !aPath.Updating) { string path = Path.Combine(aPath.Path, package); if (aPath.IsValid && Directory.Exists(path)) { TargetName = Path.GetFileName(path); renamePackagePath = path; StartRename(inline, TargetName, newName); return; } } } return; } isRenamePackage = false; TargetName = RefactoringHelper.GetRefactorTargetName(target); // create a FindAllReferences refactor to get all the changes we need to make // we'll also let it output the results, at least until we implement a way of outputting the renamed results later findAllReferencesCommand = new FindAllReferences(target, false, ignoreDeclarationSource) { OnlySourceFiles = true }; // register a completion listener to the FindAllReferences so we can rename the entries findAllReferencesCommand.OnRefactorComplete += OnFindAllReferencesCompleted; StartRename(inline, TargetName, newName); }