Пример #1
0
        private List <FilePreviewItem> CreatePreviewItems()
        {
            Dictionary <string, FilePreviewItem> files = new Dictionary <string, FilePreviewItem>();
            Dictionary <FilePreviewItem, HashSet <LocationInfo> > allItems = new Dictionary <FilePreviewItem, HashSet <LocationInfo> >();

            foreach (var variable in _variables)
            {
                if (string.IsNullOrEmpty(variable.Location?.FilePath))
                {
                    continue;
                }

                switch (variable.Type)
                {
                case VariableType.Definition:
                case VariableType.Reference:
                    string                 file = variable.Location.FilePath;
                    FilePreviewItem        fileItem;
                    HashSet <LocationInfo> curLocations;
                    if (!files.TryGetValue(file, out fileItem))
                    {
                        files[file]        = fileItem = new FilePreviewItem(this, file);
                        allItems[fileItem] = curLocations = new HashSet <LocationInfo>(LocationInfo.FullComparer);
                    }
                    else
                    {
                        curLocations = allItems[fileItem];
                    }

                    if (!curLocations.Contains(variable.Location))
                    {
                        try {
                            var item = LocationPreviewItem.Create(_analyzer, fileItem, variable.Location, variable.Type);
                            if (item != null && item.Length > 0)
                            {
                                fileItem.Items.Add(item);
                                curLocations.Add(variable.Location);
                            }
                        } catch (Exception ex) when(!ex.IsCriticalException())
                        {
                            ex.ReportUnhandledException(_serviceProvider, GetType());
                        }
                    }
                    break;
                }
            }

            List <FilePreviewItem> fileItems = new List <FilePreviewItem>(files.Values);

            foreach (var fileItem in fileItems)
            {
                fileItem.Items.Sort(LocationComparer);
            }

            fileItems.Sort(FileComparer);
            return(fileItems);
        }
Пример #2
0
        private void UpdateFile(IFileUpdater updater)
        {
            for (int i = Items.Count - 1; i >= 0; i--)
            {
                LocationPreviewItem item = (LocationPreviewItem)Items[i];
                if (item.CheckState == __PREVIEWCHANGESITEMCHECKSTATE.PCCS_Checked)
                {
                    // change is applied
                    updater.Replace(item.Line - 1, item.Column - 1, item.Length, Engine.Request.Name);

                    updater.Log(Strings.RefactorPreviewUpdatedLogEntry.FormatUI(Filename, item.Line, item.Column, item.Type == Analysis.VariableType.Definition ? Strings.RefactorPreviewUpdatedLogEntryDefinition : Strings.RefactorPreviewUpdatedLogEntryReference));
                }
            }

            updater.Save();
        }
Пример #3
0
        private void UpdateFile(IFileUpdater updater)
        {
            for (int i = Items.Count - 1; i >= 0; i--)
            {
                LocationPreviewItem item = (LocationPreviewItem)Items[i];
                if (item.CheckState == __PREVIEWCHANGESITEMCHECKSTATE.PCCS_Checked)
                {
                    // change is applied
                    updater.Replace(item.Line - 1, item.Column - 1, item.Length, Engine.Request.Name);

                    updater.Log(String.Format("{0}({1},{2}): updated {3}", Filename, item.Line, item.Column, item.Type == Analysis.VariableType.Definition ? "definition" : "reference"));
                }
            }

            updater.Save();
        }