Esempio n. 1
0
        /// <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;
            }
            Boolean isEnum  = target.Type.IsEnum();
            Boolean isVoid  = target.Type.IsVoid();
            Boolean isClass = !isVoid && target.IsStatic && target.Member == null;

            if (!string.IsNullOrEmpty(newName))
            {
                this.newName = newName;
            }
            else if (isEnum || isClass)
            {
                this.newName = GetNewName(target.Type.Name);
            }
            else
            {
                this.newName = GetNewName(target.Member.Name);
            }

            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);
            // register a completion listener to the FindAllReferences so we can rename the entries
            this.findAllReferencesCommand.OnRefactorComplete += OnFindAllReferencesCompleted;
        }
Esempio n. 2
0
 /// <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)
 {
     this.outputResults           = outputResults;
     this.ignoreDeclarationSource = ignoreDeclarationSource;
     this.newName = (newName == null || newName.Trim() == String.Empty) ? GetNewName(target.Member.Name) : newName;  // gets the new name to refactor to
     if (this.newName != null)
     {
         // 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);
         // register a completion listener to the FindAllReferences so we can rename the entries
         this.findAllReferencesCommand.OnRefactorComplete += new EventHandler <RefactorCompleteEventArgs <IDictionary <string, List <SearchMatch> > > >(this.OnFindAllReferencesCompleted);
     }
 }
Esempio n. 3
0
        /// <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);
        }
Esempio n. 4
0
        /// <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;

            Boolean isEnum  = target.Type.IsEnum();
            Boolean isVoid  = target.Type.IsVoid();
            Boolean isClass = !isVoid && target.IsStatic && target.Member == null;

            if (!string.IsNullOrEmpty(newName))
            {
                this.newName = newName;
            }
            else if (isEnum || isClass)
            {
                this.newName = GetNewName(target.Type.Name);
            }
            else
            {
                this.newName = GetNewName(target.Member.Name);
            }

            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);
            // register a completion listener to the FindAllReferences so we can rename the entries
            this.findAllReferencesCommand.OnRefactorComplete += new EventHandler <RefactorCompleteEventArgs <IDictionary <string, List <SearchMatch> > > >(this.OnFindAllReferencesCompleted);
        }