Beispiel #1
0
        private void AddGetterSetterPreview(List <ReferenceInfo> refInfos, ASResult target, string prefix, string name, bool supportInsideComment, bool supportInsideString)
        {
            target = RenamingHelper.FindGetterSetter(target, prefix + name);
            if (target == null)
            {
                return;
            }

            var results = new FRRunner().SearchSync(GetConfig(prefix + name))[currentDoc.FileName];
            int offset  = prefix.Length;

            foreach (var match in results)
            {
                int    index         = match.Index + offset;
                int    length        = match.Length - offset;
                string value         = match.Value.Substring(offset);
                int    style         = sci.BaseStyleAt(index);
                bool   insideComment = supportInsideComment && RefactoringHelper.IsCommentStyle(style);
                bool   insideString  = supportInsideString && RefactoringHelper.IsStringStyle(style);

                if (RefactoringHelper.DoesMatchPointToTarget(sci, match, target, null) || insideComment || insideString)
                {
                    var @ref = new ReferenceInfo()
                    {
                        Index = index, Length = length, Value = value
                    };
                    refInfos.Add(@ref);

                    if (previewChanges && (!insideComment || includeComments) && (!insideString || includeStrings))
                    {
                        Highlight(index, value.Length);
                    }
                }
            }
        }
        /// <summary>
        /// Filters the initial result set by determining which entries actually resolve back to our declaration target.
        /// </summary>
        private IDictionary <String, List <SearchMatch> > ResolveActualMatches(FRResults results, ASResult target)
        {
            // this will hold actual references back to the source member (some result hits could point to different members with the same name)
            IDictionary <String, List <SearchMatch> > actualMatches = new Dictionary <String, List <SearchMatch> >();
            IDictionary <String, List <SearchMatch> > initialResultsList = RefactoringHelper.GetInitialResultsList(results);
            int matchesChecked = 0; int totalMatches = 0;

            foreach (KeyValuePair <String, List <SearchMatch> > entry in initialResultsList)
            {
                totalMatches += entry.Value.Count;
            }
            Boolean foundDeclarationSource = false;
            bool    optionsEnabled = IncludeComments || IncludeStrings;

            foreach (KeyValuePair <String, List <SearchMatch> > entry in initialResultsList)
            {
                String currentFileName = entry.Key;
                UserInterfaceManager.ProgressDialog.UpdateStatusMessage(TextHelper.GetString("Info.ResolvingReferencesIn") + " \"" + currentFileName + "\"");
                foreach (SearchMatch match in entry.Value)
                {
                    // we have to open/reopen the entry's file
                    // there are issues with evaluating the declaration targets with non-open, non-current files
                    // we have to do it each time as the process of checking the declaration source can change the currently open file!
                    ScintillaControl sci = this.AssociatedDocumentHelper.LoadDocument(currentFileName).SciControl;
                    // if the search result does point to the member source, store it
                    bool add = false;
                    if (RefactoringHelper.DoesMatchPointToTarget(sci, match, target, this.AssociatedDocumentHelper))
                    {
                        if (ignoreDeclarationSource && !foundDeclarationSource && RefactoringHelper.IsMatchTheTarget(sci, match, target))
                        {
                            //ignore the declaration source
                            foundDeclarationSource = true;
                        }
                        else
                        {
                            add = true;
                        }
                    }
                    else if (optionsEnabled)
                    {
                        add = RefactoringHelper.IsInsideCommentOrString(match, sci, IncludeComments, IncludeStrings);
                    }

                    if (add)
                    {
                        if (!actualMatches.ContainsKey(currentFileName))
                        {
                            actualMatches.Add(currentFileName, new List <SearchMatch>());
                        }

                        actualMatches[currentFileName].Add(match);
                    }

                    matchesChecked++;
                    UserInterfaceManager.ProgressDialog.UpdateProgress((100 * matchesChecked) / totalMatches);
                }
            }
            this.AssociatedDocumentHelper.CloseTemporarilyOpenedDocuments();
            return(actualMatches);
        }
Beispiel #3
0
        /// <summary>
        /// Set up required variables for live preview features.
        /// </summary>
        /// <param name="supportInsideComment">Whether searching inside comments are enabled.</param>
        /// <param name="supportInsideString">Whether searching inside strings are enabled.</param>
        /// <param name="supportPreviewChanges">Whether live preview is enabled.</param>
        /// <param name="target">Current target to rename.</param>
        private void SetupLivePreview(bool supportInsideComment, bool supportInsideString, bool supportPreviewChanges, ASResult target)
        {
            if (!supportPreviewChanges)
            {
                return;
            }

            var results  = new FRRunner().SearchSync(GetConfig(oldName))[currentDoc.FileName];
            var tempRefs = new List <ReferenceInfo>();

            foreach (var match in results)
            {
                int    index         = match.Index;
                int    length        = match.Length;
                string value         = match.Value;
                int    style         = sci.BaseStyleAt(index);
                bool   insideComment = supportInsideComment && RefactoringHelper.IsCommentStyle(style);
                bool   insideString  = supportInsideString && RefactoringHelper.IsStringStyle(style);

                if (RefactoringHelper.DoesMatchPointToTarget(sci, match, target, null) || insideComment || insideString)
                {
                    var @ref = new ReferenceInfo()
                    {
                        Index = index, Length = length, Value = value
                    };
                    tempRefs.Add(@ref);

                    if (currentRef == null && match.Index == start)
                    {
                        currentRef = @ref;
                    }
                    else if (previewChanges && (!insideComment || includeComments) && (!insideString || includeStrings))
                    {
                        Highlight(index, length);
                    }
                }
            }

            if (RenamingHelper.HasGetterSetter(target))
            {
                var list = target.Member.Parameters;
                if (list[0].Name == RenamingHelper.ParamGetter)
                {
                    AddGetterSetterPreview(tempRefs, target, RenamingHelper.PrefixGetter, oldName, supportInsideComment, supportInsideString);
                }
                if (list[1].Name == RenamingHelper.ParamSetter)
                {
                    AddGetterSetterPreview(tempRefs, target, RenamingHelper.PrefixSetter, oldName, supportInsideComment, supportInsideString);
                }
                tempRefs.Sort();
            }

            refs = tempRefs.ToArray();
        }
Beispiel #4
0
        private void FindFinished(FRResults results)
        {
            UserInterfaceManager.ProgressDialog.Show();
            UserInterfaceManager.ProgressDialog.SetTitle(TextHelper.GetString("Info.UpdatingReferences"));
            MessageBar.Locked = true;
            var    currentTarget = targets[currentTargetIndex];
            string targetName    = Path.GetFileNameWithoutExtension(currentTarget.OldFilePath);
            string oldType       = (currentTarget.OldFileModel.Package + "." + targetName).Trim('.');
            string newType       = (currentTarget.NewPackage + "." + targetName).Trim('.');

            foreach (KeyValuePair <string, List <SearchMatch> > entry in results)
            {
                List <SearchMatch> matches = entry.Value;
                if (matches.Count == 0 || entry.Key == currentTarget.OldFilePath ||
                    entry.Key == currentTarget.NewFilePath)
                {
                    continue;
                }
                string file = entry.Key;
                UserInterfaceManager.ProgressDialog.UpdateStatusMessage(TextHelper.GetString("Info.Updating") + " \"" + file + "\"");
                ITabbedDocument  doc;
                ScintillaControl sci;
                var actualMatches = new List <SearchMatch>();
                foreach (SearchMatch match in entry.Value)
                {
                    // we have to open/reopen the entry's file
                    // there are issues with evaluating the declaration targets with non-open, non-current files
                    // we have to do it each time as the process of checking the declaration source can change the currently open file!
                    sci = AssociatedDocumentHelper.LoadDocument(file).SciControl;
                    // if the search result does point to the member source, store it
                    if (RefactoringHelper.DoesMatchPointToTarget(sci, match, currentTargetResult, this.AssociatedDocumentHelper))
                    {
                        actualMatches.Add(match);
                    }
                }
                if (actualMatches.Count == 0)
                {
                    continue;
                }
                int currLine = -1;
                doc = AssociatedDocumentHelper.LoadDocument(file);
                sci = doc.SciControl;
                string directory = Path.GetDirectoryName(file);
                // Let's check if we need to add the import. Check the considerations at the start of the file
                // directory != currentTarget.OwnerPath -> renamed owner directory, so both files in the same place
                bool needsImport = directory != Path.GetDirectoryName(currentTarget.NewFilePath) &&
                                   directory != currentTarget.OwnerPath &&
                                   ASContext.Context.CurrentModel.Imports.Search(targetName,
                                                                                 FlagType.Class & FlagType.Function &
                                                                                 FlagType.Namespace, 0) == null;

                // Replace matches
                int typeDiff        = sci.MBSafeTextLength(oldType) - sci.MBSafeTextLength(targetName);
                int newTypeDiff     = sci.MBSafeTextLength(newType) - sci.MBSafeTextLength(oldType);
                int accumulatedDiff = 0;
                int j = 0;
                for (int i = 0, count = actualMatches.Count; i < count; i++)
                {
                    var sm = actualMatches[j];
                    if (currLine == -1)
                    {
                        currLine = sm.Line - 1;
                    }
                    if (sm.LineText.Contains(oldType))
                    {
                        sm.Index -= typeDiff - accumulatedDiff;
                        sm.Value  = oldType;
                        RefactoringHelper.SelectMatch(sci, sm);
                        sm.Column -= typeDiff;
                        sci.ReplaceSel(newType);
                        sm.LineEnd  = sci.SelectionEnd;
                        sm.LineText = sm.LineText.Replace(oldType, newType);
                        sm.Length   = oldType.Length;
                        sm.Value    = newType;
                        if (needsImport)
                        {
                            sm.Line++;
                        }
                        accumulatedDiff += newTypeDiff;
                        j++;
                    }
                    else
                    {
                        actualMatches.RemoveAt(j);
                    }
                }
                if (needsImport)
                {
                    sci.GotoLine(currLine);
                    ASGenerator.InsertImport(new MemberModel(targetName, newType, FlagType.Import, 0), false);
                    int newLine = sci.LineFromPosition(sci.Text.IndexOfOrdinal(newType));
                    var sm      = new SearchMatch();
                    sm.Line     = newLine + 1;
                    sm.LineText = sci.GetLine(newLine);
                    sm.Column   = 0;
                    sm.Length   = sci.MBSafeTextLength(sm.LineText);
                    sm.Value    = sm.LineText;

                    actualMatches.Insert(0, sm);
                }
                if (actualMatches.Count == 0)
                {
                    continue;
                }
                if (!Results.ContainsKey(file))
                {
                    Results[file] = new List <SearchMatch>();
                }
                Results[file].AddRange(actualMatches);
                //Do we want to open modified files?
                //if (sci.IsModify) AssociatedDocumentHelper.MarkDocumentToKeep(file);
                doc.Save();
            }

            currentTargetIndex++;

            UserInterfaceManager.ProgressDialog.Hide();
            MessageBar.Locked = false;
            UpdateReferencesNextTarget();
        }