diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2011-12-01 11:23:02 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2011-12-01 11:23:02 +0400 |
commit | c1c3e6cd7921e158bf5826b6cf7a08e1967e19e1 (patch) | |
tree | 5b271e1130c0ae00e6467617a82ad274a08495ce /main/src/addins/MonoDevelop.Refactoring | |
parent | e397f88ca1002c52701ab2b95db44106a8df8f9f (diff) |
[Refactoring] Track API changes.
Diffstat (limited to 'main/src/addins/MonoDevelop.Refactoring')
16 files changed, 74 insertions, 115 deletions
diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.AnalysisCore/Fixes/RenameMemberFix.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.AnalysisCore/Fixes/RenameMemberFix.cs index 2791274414..14e45b7007 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.AnalysisCore/Fixes/RenameMemberFix.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.AnalysisCore/Fixes/RenameMemberFix.cs @@ -63,14 +63,13 @@ namespace MonoDevelop.AnalysisCore.Fixes var refactoring = new RenameRefactoring (); var options = new RefactoringOptions () { Document = doc, - Dom = doc.TypeResolveContext, SelectedItem = renameFix.Item, }; if (renameFix.Item == null) { ResolveResult resolveResult; - options.SelectedItem = CurrentRefactoryOperationsHandler.GetItem (options.Dom, options.Document, out resolveResult); + options.SelectedItem = CurrentRefactoryOperationsHandler.GetItem (options.Document, out resolveResult); } if (!refactoring.IsValid (options)) @@ -125,10 +124,10 @@ namespace MonoDevelop.AnalysisCore.Fixes //FIXME: performchanges should probably use a monitor too, as it can be slow var changes = Refactoring.PerformChanges (Options, Properties); if (Preview) { - MessageService.ShowCustomDialog (new RefactoringPreviewDialog (Options.Dom, changes)); + MessageService.ShowCustomDialog (new RefactoringPreviewDialog (changes)); } else { var monitor = IdeApp.Workbench.ProgressMonitors.GetBackgroundProgressMonitor ("Rename", null); - RefactoringService.AcceptChanges (monitor, Options.Dom, changes); + RefactoringService.AcceptChanges (monitor, changes); } } } diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeGeneration/AbstractGenerateAction.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeGeneration/AbstractGenerateAction.cs index 0d5b67d4e6..96fb4608fc 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeGeneration/AbstractGenerateAction.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeGeneration/AbstractGenerateAction.cs @@ -78,7 +78,7 @@ namespace MonoDevelop.CodeGeneration treeView.AppendColumn (column); Ambience ambience = AmbienceService.GetAmbienceForFile (options.Document.FileName); foreach (var member in GetValidMembers ()) { - Store.AppendValues (false, ImageService.GetPixbuf (member.GetStockIcon (), IconSize.Menu), ambience.GetString (options.Document.TypeResolveContext, member,/* member.EntityType == EntityType. ? OutputFlags.IncludeParameterName :*/ OutputFlags.ClassBrowserEntries), member); + Store.AppendValues (false, ImageService.GetPixbuf (member.GetStockIcon (), IconSize.Menu), ambience.GetString (member,/* member.EntityType == EntityType. ? OutputFlags.IncludeParameterName :*/ OutputFlags.ClassBrowserEntries), member); } treeView.Model = store; diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.ImplementInterface/ImplementExplicit.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.ImplementInterface/ImplementExplicit.cs index 50fe1a943d..0877a91600 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.ImplementInterface/ImplementExplicit.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.ImplementInterface/ImplementExplicit.cs @@ -55,7 +55,7 @@ namespace MonoDevelop.Refactoring.ImplementInterface return false; if (!declaration.BaseTypes.Any (bt => bt.Contains (loc.Line, loc.Column))) return false; - interfaceType = options.ResolveResult.Type.Resolve (options.Dom); + interfaceType = options.ResolveResult.Type; var def = interfaceType.GetDefinition (); if (def == null) return false; @@ -98,7 +98,7 @@ namespace MonoDevelop.Refactoring.ImplementInterface var generator = options.CreateCodeGenerator (); if (generator == null) return; - args.InsertionPoint.Insert (options.GetTextEditorData (), generator.CreateInterfaceImplementation (options.Dom, declaringType, interfaceType, implementExplicit)); + args.InsertionPoint.Insert (options.GetTextEditorData (), generator.CreateInterfaceImplementation (declaringType, interfaceType, implementExplicit)); } }; } diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.IntegrateTemporaryVariable/IntegrateTemporaryVariableRefactoring.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.IntegrateTemporaryVariable/IntegrateTemporaryVariableRefactoring.cs index 18efd6b76a..24218affae 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.IntegrateTemporaryVariable/IntegrateTemporaryVariableRefactoring.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.IntegrateTemporaryVariable/IntegrateTemporaryVariableRefactoring.cs @@ -103,7 +103,7 @@ namespace MonoDevelop.Refactoring.IntegrateTemporaryVariable { List<Change> changes = PerformChanges (options, null); IProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetBackgroundProgressMonitor (this.Name, null); - RefactoringService.AcceptChanges (monitor, options.Dom, changes); + RefactoringService.AcceptChanges (monitor, changes); // Console.WriteLine ("Changes accepted"); } diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Rename/RenameItemDialog.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Rename/RenameItemDialog.cs index 180ba81c1b..7f4868e0bd 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Rename/RenameItemDialog.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Rename/RenameItemDialog.cs @@ -156,7 +156,7 @@ namespace MonoDevelop.Refactoring.Rename ((Widget)this).Destroy (); List<Change> changes = rename.PerformChanges (options, properties); IProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetBackgroundProgressMonitor (this.Title, null); - RefactoringService.AcceptChanges (monitor, options.Dom, changes); + RefactoringService.AcceptChanges (monitor, changes); } void OnPreviewClicked (object sender, EventArgs e) @@ -164,7 +164,7 @@ namespace MonoDevelop.Refactoring.Rename var properties = Properties; ((Widget)this).Destroy (); List<Change> changes = rename.PerformChanges (options, properties); - MessageService.ShowCustomDialog (new RefactoringPreviewDialog (options.Dom, changes)); + MessageService.ShowCustomDialog (new RefactoringPreviewDialog (changes)); } } diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Rename/RenameRefactoring.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Rename/RenameRefactoring.cs index 01a7b2696b..c05c97b4e0 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Rename/RenameRefactoring.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Rename/RenameRefactoring.cs @@ -60,13 +60,13 @@ namespace MonoDevelop.Refactoring.Rename { if (options.SelectedItem is IVariable || options.SelectedItem is IParameter) return true; - - if (options.SelectedItem is ITypeDefinition) - return ((ITypeDefinition)options.SelectedItem).ProjectContent is SimpleProjectContent; +// TODO: Type system conversion. +// if (options.SelectedItem is ITypeDefinition) +// return ((ITypeDefinition)options.SelectedItem).ProjectContent is SimpleProjectContent; if (options.SelectedItem is IMember) { var cls = ((IMember)options.SelectedItem).DeclaringTypeDefinition; - return cls != null && cls.ProjectContent is SimpleProjectContent; + return cls != null; } return false; } @@ -87,7 +87,7 @@ namespace MonoDevelop.Refactoring.Rename result.Add (change); } if (result.Count > 0) { - RefactoringService.AcceptChanges (monitor, ctx, result); + RefactoringService.AcceptChanges (monitor, result); } } } @@ -179,14 +179,14 @@ namespace MonoDevelop.Refactoring.Rename var cls = (ITypeDefinition)options.SelectedItem; int currentPart = 1; HashSet<string> alreadyRenamed = new HashSet<string> (); - foreach (var part in cls.GetParts ()) { - if (part.GetDefinition ().Region.FileName != options.Document.FileName && System.IO.Path.GetFileNameWithoutExtension (part.GetDefinition ().Region.FileName) != System.IO.Path.GetFileNameWithoutExtension (options.Document.FileName)) + foreach (var part in cls.Parts) { + if (part.Region.FileName != options.Document.FileName && System.IO.Path.GetFileNameWithoutExtension (part.Region.FileName) != System.IO.Path.GetFileNameWithoutExtension (options.Document.FileName)) continue; - if (alreadyRenamed.Contains (part.GetDefinition ().Region.FileName)) + if (alreadyRenamed.Contains (part.Region.FileName)) continue; - alreadyRenamed.Add (part.GetDefinition ().Region.FileName); + alreadyRenamed.Add (part.Region.FileName); - string oldFileName = System.IO.Path.GetFileNameWithoutExtension (part.GetDefinition ().Region.FileName); + string oldFileName = System.IO.Path.GetFileNameWithoutExtension (part.Region.FileName); string newFileName; if (oldFileName.ToUpper () == properties.NewName.ToUpper () || oldFileName.ToUpper ().EndsWith ("." + properties.NewName.ToUpper ())) continue; @@ -199,10 +199,10 @@ namespace MonoDevelop.Refactoring.Rename } int t = 0; - while (System.IO.File.Exists (GetFullFileName (newFileName, part.GetDefinition ().Region.FileName, t))) { + while (System.IO.File.Exists (GetFullFileName (newFileName, part.Region.FileName, t))) { t++; } - result.Add (new RenameFileChange (part.GetDefinition ().Region.FileName, GetFullFileName (newFileName, part.GetDefinition ().Region.FileName, t))); + result.Add (new RenameFileChange (part.Region.FileName, GetFullFileName (newFileName, part.Region.FileName, t))); } } diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/AbstractRefactoringCommandHandler.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/AbstractRefactoringCommandHandler.cs index 833e8a7b15..82b6f8b640 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/AbstractRefactoringCommandHandler.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/AbstractRefactoringCommandHandler.cs @@ -52,14 +52,11 @@ namespace MonoDevelop.Refactoring if (editor == null) return; - var dom = doc.TypeResolveContext; - ResolveResult result; - var item = CurrentRefactoryOperationsHandler.GetItem (dom, doc, out result); + var item = CurrentRefactoryOperationsHandler.GetItem (doc, out result); RefactoringOptions options = new RefactoringOptions () { Document = doc, - Dom = dom, ResolveResult = result, SelectedItem = item }; diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/FindDerivedClassesHandler.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/FindDerivedClassesHandler.cs index 33a563c992..87c405c0e6 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/FindDerivedClassesHandler.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/FindDerivedClassesHandler.cs @@ -52,8 +52,7 @@ namespace MonoDevelop.Refactoring var solution = IdeApp.ProjectOperations.CurrentSelectedSolution; if (solution == null) return; - var sourceCtx = cls.GetProjectContent (); - var sourceProject = sourceCtx.Annotation<Project> (); + var sourceProject = TypeSystemService.GetProject (cls); var projects = ReferenceFinder.GetAllReferencingProjects (solution, sourceProject); ThreadPool.QueueUserWorkItem (delegate { using (var monitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor (true, true)) { @@ -61,9 +60,8 @@ namespace MonoDevelop.Refactoring foreach (var p in projects) { if (p.Item2 == null) // may happen for cecil contexts continue; - ITypeResolveContext combinedContent = sourceProject != p.Item2 ? (ITypeResolveContext)new CompositeTypeResolveContext (new ITypeResolveContext[] { sourceCtx, p.Item2 }) : sourceCtx; - foreach (var type in p.Item2.GetAllTypes ()) { - if (!type.IsDerivedFrom (cls, combinedContent)) + foreach (var type in TypeSystemService.GetCompilation (p.Item1).GetAllTypeDefinitions ()) { + if (!type.IsDerivedFrom (cls)) continue; TextEditorData textFile; if (!cache.TryGetValue (type.Region.FileName, out textFile)) { @@ -86,9 +84,8 @@ namespace MonoDevelop.Refactoring var doc = IdeApp.Workbench.ActiveDocument; if (doc == null || doc.FileName == FilePath.Null) return; - var ctx = doc.TypeResolveContext; ResolveResult resolveResult; - var item = CurrentRefactoryOperationsHandler.GetItem (ctx, doc, out resolveResult); + var item = CurrentRefactoryOperationsHandler.GetItem (doc, out resolveResult); /* IMember eitem = resolveResult != null ? (resolveResult.CallingMember ?? resolveResult.CallingType) : null; string itemName = null; diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/FindReferencesHandler.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/FindReferencesHandler.cs index 5adcaa13b2..65f44cbef5 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/FindReferencesHandler.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/FindReferencesHandler.cs @@ -65,7 +65,7 @@ namespace MonoDevelop.Refactoring if (doc == null || doc.FileName == FilePath.Null) return; ResolveResult resolveResoult; - object item = CurrentRefactoryOperationsHandler.GetItem (doc.TypeResolveContext, doc, out resolveResoult); + object item = CurrentRefactoryOperationsHandler.GetItem (doc, out resolveResoult); var entity = item as IEntity; if (entity == null) return; diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/GotoDeclarationHandler.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/GotoDeclarationHandler.cs index 2333d8d4fb..36c1afb185 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/GotoDeclarationHandler.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/GotoDeclarationHandler.cs @@ -45,7 +45,7 @@ namespace MonoDevelop.Refactoring return; ResolveResult resolveResoult; - object item = CurrentRefactoryOperationsHandler.GetItem (doc.TypeResolveContext, doc, out resolveResoult); + object item = CurrentRefactoryOperationsHandler.GetItem (doc, out resolveResoult); var entity = item as INamedElement; if (entity != null) IdeApp.ProjectOperations.JumpToDeclaration (entity); diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/ImportSymbolHandler.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/ImportSymbolHandler.cs index 257cec8cd5..58b2347853 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/ImportSymbolHandler.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/ImportSymbolHandler.cs @@ -58,7 +58,7 @@ namespace MonoDevelop.Refactoring { Dictionary<string, GenerateNamespaceImport> cache = new Dictionary<string, GenerateNamespaceImport> (); - public GenerateNamespaceImport GetResult (ITypeResolveContext dom, IParsedFile unit, IType type, MonoDevelop.Ide.Gui.Document doc) + public GenerateNamespaceImport GetResult (IParsedFile unit, IType type, MonoDevelop.Ide.Gui.Document doc) { GenerateNamespaceImport result; if (cache.TryGetValue (type.Namespace, out result)) @@ -80,7 +80,7 @@ namespace MonoDevelop.Refactoring string name = type.Name; foreach (string ns in RefactoringOptions.GetUsedNamespaces (doc, loc)) { - if (dom.GetTypeDefinition (ns, name, type.TypeParameterCount, StringComparer.Ordinal) != null) { + if (doc.Compilation.MainAssembly.GetTypeDefinition (ns, name, type.TypeParameterCount) != null) { result.GenerateUsing = false; result.InsertNamespace = true; return result; @@ -96,7 +96,6 @@ namespace MonoDevelop.Refactoring IType type; Ambience ambience; ParsedDocument unit; - ITypeResolveContext dom; MonoDevelop.Ide.Gui.Document doc; ImportSymbolCache cache; @@ -104,11 +103,10 @@ namespace MonoDevelop.Refactoring get { return this.type; } } - public ImportSymbolCompletionData (MonoDevelop.Ide.Gui.Document doc, ImportSymbolCache cache, ITypeResolveContext dom, IType type) + public ImportSymbolCompletionData (MonoDevelop.Ide.Gui.Document doc, ImportSymbolCache cache, IType type) { this.doc = doc; this.cache = cache; - this.dom = dom; this.data = doc.Editor; this.ambience = AmbienceService.GetAmbience (doc.Editor.MimeType); this.type = type; @@ -125,7 +123,7 @@ namespace MonoDevelop.Refactoring initialized = true; if (string.IsNullOrEmpty (type.Namespace)) return; - var result = cache.GetResult (dom, unit, type, doc); + var result = cache.GetResult (unit, type, doc); generateUsing = result.GenerateUsing; insertNamespace = result.InsertNamespace; } @@ -162,7 +160,7 @@ namespace MonoDevelop.Refactoring public override string DisplayText { get { if (displayText == null) - displayText = ambience.GetString (dom, type, OutputFlags.IncludeGenerics); + displayText = ambience.GetString (type, OutputFlags.IncludeGenerics); return displayText; } } @@ -212,12 +210,12 @@ namespace MonoDevelop.Refactoring if (ext == null) return; - ITypeResolveContext dom = doc.TypeResolveContext; + var dom = doc.Compilation; ImportSymbolCache cache = new ImportSymbolCache (); List<ImportSymbolCompletionData> typeList = new List<ImportSymbolCompletionData> (); - foreach (var type in dom.GetTypes ()) { - typeList.Add (new ImportSymbolCompletionData (doc, cache, dom, type)); + foreach (var type in dom.GetAllTypeDefinitions ()) { + typeList.Add (new ImportSymbolCompletionData (doc, cache, type)); } typeList.Sort (delegate (ImportSymbolCompletionData left, ImportSymbolCompletionData right) { diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringOperation.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringOperation.cs index f23c3a2189..444970df71 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringOperation.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringOperation.cs @@ -68,7 +68,7 @@ namespace MonoDevelop.Refactoring { var changes = PerformChanges (options, null); var monitor = IdeApp.Workbench.ProgressMonitors.GetBackgroundProgressMonitor (Name, null); - RefactoringService.AcceptChanges (monitor, options.Dom, changes); + RefactoringService.AcceptChanges (monitor, changes); } } } diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringOptions.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringOptions.cs index c6abdd994f..6d75897251 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringOptions.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringOptions.cs @@ -38,16 +38,12 @@ using System.Collections.Generic; using System.Linq; using ICSharpCode.NRefactory.Semantics; using ICSharpCode.NRefactory; +using ICSharpCode.NRefactory.CSharp.TypeSystem; namespace MonoDevelop.Refactoring { public class RefactoringOptions { - public ITypeResolveContext Dom { - get; - set; - } - public Document Document { get; set; @@ -154,44 +150,37 @@ namespace MonoDevelop.Refactoring public static List<string> GetUsedNamespaces (Document doc, TextLocation loc) { var result = new List<string> (); - var pf = doc.ParsedDocument.Annotation<CSharpParsedFile> (); + var pf = doc.ParsedDocument.ParsedFile as CSharpParsedFile; if (pf == null) return result; var scope = pf.GetUsingScope (loc); if (scope == null) return result; var ctx = doc.TypeResolveContext; - + var resolver = pf.GetResolver (doc.Compilation, loc); for (var n = scope; n != null; n = n.Parent) { result.Add (n.NamespaceName); - result.AddRange (n.Usings.Select (u => u.ResolveNamespace (ctx)) + result.AddRange (n.Usings.Select (u => u.ResolveNamespace (resolver)) .Where (nr => nr != null) - .Select (nr => nr.NamespaceName)); + .Select (nr => nr.FullName)); } return result; } public ResolveResult Resolve (AstNode node) { - var pf = Document.ParsedDocument.Annotation<CSharpParsedFile> (); - var unit = Document.ParsedDocument.Annotation<CompilationUnit> (); - var csResolver = new CSharpResolver (Document.TypeResolveContext, System.Threading.CancellationToken.None); - var navigator = new NodeListResolveVisitorNavigator (new[] { node }); + var parsedFile = Document.ParsedDocument.ParsedFile as CSharpParsedFile; + var cu = Document.ParsedDocument.Annotation<CompilationUnit> (); - var visitor = new ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor (csResolver, pf, navigator); - visitor.Scan (unit); - return visitor.GetResolveResult (node); + var resolver = new CSharpAstResolver (Document.Compilation, cu, parsedFile); + return resolver.Resolve (node); } public AstType CreateShortType (IType fullType) { - var csResolver = new CSharpResolver (Document.TypeResolveContext, System.Threading.CancellationToken.None); - - var pf = Document.ParsedDocument.Annotation<CSharpParsedFile> (); + var parsedFile = Document.ParsedDocument.ParsedFile as CSharpParsedFile; - csResolver.CurrentMember = pf.GetMember (Location); - csResolver.CurrentTypeDefinition = pf.GetInnermostTypeDefinition (Location); - csResolver.CurrentUsingScope = pf.GetUsingScope (Location); + var csResolver = parsedFile.GetResolver (Document.Compilation, Document.Editor.Caret.Location); var builder = new ICSharpCode.NRefactory.CSharp.Refactoring.TypeSystemAstBuilder (csResolver); return builder.ConvertType (fullType); diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringPreviewDialog.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringPreviewDialog.cs index 53b220afde..dcc37a565e 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringPreviewDialog.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringPreviewDialog.cs @@ -48,7 +48,7 @@ namespace MonoDevelop.Refactoring List<Change> changes; - public RefactoringPreviewDialog (ITypeResolveContext ctx, List<Change> changes) + public RefactoringPreviewDialog (List<Change> changes) { this.Build (); this.changes = changes; @@ -86,7 +86,7 @@ namespace MonoDevelop.Refactoring buttonOk.Clicked += delegate { IProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetBackgroundProgressMonitor (this.Title, null); - RefactoringService.AcceptChanges (monitor, ctx, changes); + RefactoringService.AcceptChanges (monitor, changes); Destroy (); }; diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringService.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringService.cs index 63bfe39469..a9b541710a 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringService.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringService.cs @@ -134,12 +134,12 @@ namespace MonoDevelop.Refactoring } } - public static void AcceptChanges (IProgressMonitor monitor, ITypeResolveContext dom, List<Change> changes) + public static void AcceptChanges (IProgressMonitor monitor, List<Change> changes) { - AcceptChanges (monitor, dom, changes, MonoDevelop.Ide.TextFileProvider.Instance); + AcceptChanges (monitor, changes, MonoDevelop.Ide.TextFileProvider.Instance); } - public static void AcceptChanges (IProgressMonitor monitor, ITypeResolveContext dom, List<Change> changes, MonoDevelop.Projects.Text.ITextFileProvider fileProvider) + public static void AcceptChanges (IProgressMonitor monitor, List<Change> changes, MonoDevelop.Projects.Text.ITextFileProvider fileProvider) { var rctx = new RefactoringOptions (); var handler = new RenameHandler (changes); diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoryCommands.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoryCommands.cs index 535dc699ae..bdeef02157 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoryCommands.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoryCommands.cs @@ -86,7 +86,7 @@ namespace MonoDevelop.Refactoring return null; } - public static object GetItem (ITypeResolveContext ctx, MonoDevelop.Ide.Gui.Document doc, out ResolveResult resolveResult) + public static object GetItem (MonoDevelop.Ide.Gui.Document doc, out ResolveResult resolveResult) { resolveResult = GetResolveResult (doc); if (resolveResult is LocalResolveResult) @@ -122,24 +122,19 @@ namespace MonoDevelop.Refactoring class GotoBase { - ITypeResolveContext ctx; IEntity item; - public GotoBase (ITypeResolveContext ctx, IEntity item) + public GotoBase (IEntity item) { - this.ctx = ctx; this.item = item; } public void Run () { var cls = item as ITypeDefinition; - if (cls != null && cls.BaseTypes != null) { - foreach (var bc in cls.BaseTypes) { - var bcls = bc.Resolve (ctx); - if (bcls == null) - continue; - var def = bcls.GetDefinition (); + if (cls != null && cls.DirectBaseTypes != null) { + foreach (var bt in cls.DirectBaseTypes) { + var def = bt.GetDefinition (); if (def != null && def.Kind != TypeKind.Interface && !def.Region.IsEmpty) { IdeApp.Workbench.OpenDocument (def.Region.FileName, def.Region.BeginLine, def.Region.BeginColumn); return; @@ -149,15 +144,10 @@ namespace MonoDevelop.Refactoring var method = item as IMethod; if (method != null) { - foreach (var bc in method.DeclaringTypeDefinition.BaseTypes) { - var bcls = bc.Resolve (ctx); - if (bcls == null) - continue; - var def = bcls.GetDefinition (); - - if (def != null && def.Kind != TypeKind.Interface && !def.Region.IsEmpty) { + foreach (var def in method.DeclaringTypeDefinition.DirectBaseTypes) { + if (def != null && def.Kind != TypeKind.Interface && !def.GetDefinition ().Region.IsEmpty) { IMethod baseMethod = null; - foreach (var m in def.Methods) { + foreach (var m in def.GetMethods ()) { if (m.Name == method.Name && m.Parameters.Count == m.Parameters.Count) { baseMethod = m; break; @@ -245,17 +235,15 @@ namespace MonoDevelop.Refactoring return; var parsedDocument = doc.ParsedDocument; - var ctx = doc.TypeResolveContext; - if (parsedDocument == null || ctx == null) + if (parsedDocument == null) return; ResolveResult resolveResult; - object item = GetItem (ctx, doc, out resolveResult); + object item = GetItem (doc, out resolveResult); bool added = false; var options = new RefactoringOptions () { Document = doc, - Dom = ctx, ResolveResult = resolveResult, SelectedItem = item }; @@ -277,11 +265,11 @@ namespace MonoDevelop.Refactoring if (IdeApp.ProjectOperations.CanJumpToDeclaration (item as INamedElement)) { var type = item as ICSharpCode.NRefactory.TypeSystem.IType; - if (type != null && type.GetDefinition ().GetParts ().Count > 1) { + if (type != null && type.GetDefinition ().Parts.Count > 1) { var declSet = new CommandInfoSet (); declSet.Text = GettextCatalog.GetString ("_Go to declaration"); var ct = type.GetDefinition (); - foreach (var part in ct.GetParts ()) + foreach (var part in ct.Parts) declSet.CommandInfos.Add (string.Format (GettextCatalog.GetString ("{0}, Line {1}"), FormatFileName (part.Region.FileName), part.Region.BeginLine), new System.Action (new JumpTo (part).Run)); ainfo.Add (declSet); } else { @@ -298,15 +286,14 @@ namespace MonoDevelop.Refactoring if (item is IMethod) { IMethod method = item as IMethod; if (method.IsOverride) { - ainfo.Add (GettextCatalog.GetString ("Go to _base"), new System.Action (new GotoBase (ctx, (IMethod)item).Run)); + ainfo.Add (GettextCatalog.GetString ("Go to _base"), new System.Action (new GotoBase ((IMethod)item).Run)); added = true; } } else if (item is ITypeDefinition) { ITypeDefinition cls = (ITypeDefinition) item; - foreach (var rt in cls.BaseTypes) { - var bc = rt.Resolve (ctx); + foreach (var bc in cls.DirectBaseTypes) { if (bc != null && bc.GetDefinition () != null && bc.GetDefinition ().Kind != TypeKind.Interface/* TODO: && IdeApp.ProjectOperations.CanJumpToDeclaration (bc)*/) { - ainfo.Add (GettextCatalog.GetString ("Go to _base"), new System.Action (new GotoBase (ctx, (ITypeDefinition)item).Run)); + ainfo.Add (GettextCatalog.GetString ("Go to _base"), new System.Action (new GotoBase ((ITypeDefinition)item).Run)); break; } } @@ -330,28 +317,20 @@ namespace MonoDevelop.Refactoring if (resolveResult is UnknownIdentifierResolveResult) { usedNamespaces = options.GetUsedNamespaces (); var uiResult = resolveResult as UnknownIdentifierResolveResult; - foreach (var typeDefinition in ctx.GetTypes ()) { + foreach (var typeDefinition in doc.Compilation.GetAllTypeDefinitions ()) { if (typeDefinition.Name == uiResult.Identifier) { possibleNamespaces.Add (typeDefinition.Namespace); } } - } else if (resolveResult is UnknownTypeResolveResult) { - usedNamespaces = options.GetUsedNamespaces (); - var uiResult = resolveResult as UnknownTypeResolveResult; - foreach (var typeDefinition in ctx.GetTypes ()) { - if (typeDefinition.Name == uiResult.Identifier && typeDefinition.TypeParameterCount == uiResult.TypeParameterCount) { - possibleNamespaces.Add (typeDefinition.Namespace); - } - } } else if (resolveResult is UnknownMemberResolveResult) { usedNamespaces = options.GetUsedNamespaces (); var umResult = (UnknownMemberResolveResult)resolveResult; - var conv = new Conversions (ctx); - var baseTypes = new List<IType> (umResult.TargetType.GetAllBaseTypes (ctx)); + var conv = new Conversions (options.Document.Compilation); + var baseTypes = new List<IType> (umResult.TargetType.GetAllBaseTypes ()); - foreach (var typeDefinition in ctx.GetTypes ().Where (t => t.HasExtensionMethods && !usedNamespaces.Contains (t.Namespace))) { + foreach (var typeDefinition in doc.Compilation.GetAllTypeDefinitions ().Where (t => t.HasExtensionMethods && !usedNamespaces.Contains (t.Namespace))) { foreach (var m in typeDefinition.Methods.Where (m => m.IsExtensionMethod && m.Name == umResult.MemberName)) { - var pType = m.Parameters.First ().Type.Resolve (ctx); + var pType = m.Parameters.First ().Type; foreach (var baseType in baseTypes) { if (conv.ImplicitConversion (pType, baseType)) { possibleNamespaces.Add (typeDefinition.Namespace); @@ -952,7 +931,7 @@ namespace MonoDevelop.Refactoring { if (cls == null) return false; - return cls.GetMembers (ctx).Any (m => m.IsAbstract); + return cls.GetMembers ().Any (m => m.IsAbstract); } /* void AddRefactoryMenuForClass (ITypeResolveContext ctx, IParsedFile pinfo, CommandInfoSet ciset, string className) |