public static List <PossibleNamespace> GetPossibleNamespaces(Document doc, AstNode node, ref ResolveResult resolveResult) { if (doc == null) { throw new ArgumentNullException("doc"); } if (node == null) { throw new ArgumentNullException("node"); } var location = RefactoringService.GetCorrectResolveLocation(doc, doc.Editor.Caret.Location); if (resolveResult == null || resolveResult.Type.FullName == "System.Void") { resolveResult = GetHeuristicResult(doc, location, ref node) ?? resolveResult; } var foundNamespaces = GetPossibleNamespaces(doc, node, resolveResult, location); if (!(resolveResult is AmbiguousTypeResolveResult)) { var usedNamespaces = RefactoringOptions.GetUsedNamespaces(doc, location); foundNamespaces = foundNamespaces.Where(n => !usedNamespaces.Contains(n.Namespace)); } var result = new List <PossibleNamespace> (); foreach (var ns in foundNamespaces) { if (result.Any(n => n.Namespace == ns.Namespace)) { continue; } result.Add(ns); } return(result); }
public static HashSet <PossibleNamespace> GetPossibleNamespaces(Document doc, AstNode node, ref ResolveResult resolveResult) { var location = RefactoringService.GetCorrectResolveLocation(doc, doc.Editor.Caret.Location); if (resolveResult == null || resolveResult.Type.FullName == "System.Void") { resolveResult = GetHeuristicResult(doc, location, ref node) ?? resolveResult; } var foundNamespaces = GetPossibleNamespaces(doc, node, resolveResult, location); if (!(resolveResult is AmbiguousTypeResolveResult)) { var usedNamespaces = RefactoringOptions.GetUsedNamespaces(doc, location); foundNamespaces = foundNamespaces.Where(n => !usedNamespaces.Contains(n.Namespace)); } return(new HashSet <PossibleNamespace> (foundNamespaces)); }
public GenerateNamespaceImport GetResult(IUnresolvedFile unit, IType type, MonoDevelop.Ide.Gui.Document doc) { GenerateNamespaceImport result; if (cache.TryGetValue(type.Namespace, out result)) { return(result); } result = new GenerateNamespaceImport(); cache[type.Namespace] = result; TextEditorData data = doc.Editor; result.InsertNamespace = false; var loc = new TextLocation(data.Caret.Line, data.Caret.Column); foreach (var ns in RefactoringOptions.GetUsedNamespaces(doc, loc)) { if (type.Namespace == ns) { result.GenerateUsing = false; return(result); } } result.GenerateUsing = true; string name = type.Name; foreach (string ns in RefactoringOptions.GetUsedNamespaces(doc, loc)) { if (doc.Compilation.MainAssembly.GetTypeDefinition(ns, name, type.TypeParameterCount) != null) { result.GenerateUsing = false; result.InsertNamespace = true; return(result); } } return(result); }