public void Test1() { var pcl = ResolutionTests.CreateCache(@"module modA; class A(T = int) { static int prop; static A statA; // 6 } A a = new A(); // 9 void main() { A.prop = 3; // 13 int b = A.prop + 4; // 14 A.statA.statA = new A!float(); // 15 } "); var ctxt = ResolutionContext.Create(pcl, null, pcl[0]["modA"]); var refs = ReferencesFinder.Scan(pcl[0]["modA"]["A"].First(), ctxt) as List <ISyntaxRegion>; Assert.IsNotNull(refs); Assert.AreEqual(8, refs.Count); }
private static void GetReferencesInModule(DModule ast, StringBuilder refs, DNode n, ResolutionContext ctxt) { var res = ReferencesFinder.Scan(ast, n, ctxt); int cnt = res.Count(); foreach (var r in res) { var rfilename = ast.FileName; var rloc = r.Location; var ln = String.Format("{0},{1},{2},{3}:{4}\n", rloc.Line, rloc.Column - 1, rloc.Line, rloc.Column, rfilename); refs.Append(ln); } }
static IEnumerable <SearchResult> FindReferences( AbstractDProject project, INode member, ISearchProgressMonitor monitor = null) { var searchResults = new List <SearchResult>(); var parseCache = project != null ? project.ParseCache : DCompilerService.Instance.GetDefaultCompiler().GenParseCacheView(); var modules = new List <DModule>(); if (project != null) { foreach (var p in project.GetSourcePaths(IdeApp.Workspace.ActiveConfiguration)) { modules.AddRange(GlobalParseCache.EnumModulesRecursively(p, null)); } } else { modules.Add((IdeApp.Workbench.ActiveDocument.ParsedDocument as MonoDevelop.D.Parser.ParsedDModule).DDom); } if (monitor != null) { monitor.BeginStepTask("Scan for references", modules.Count, 1); } List <ISyntaxRegion> references = null; var ctxt = ResolutionContext.Create(parseCache, null); foreach (var mod in modules) { if (mod == null) { continue; } try { references = ReferencesFinder.Scan(mod, member, ctxt).ToList(); if (references.Count < 1) { if (monitor != null) { monitor.Step(1); } continue; } // Sort the references by code location references.Sort(new IdLocationComparer()); // Get actual document code var targetDoc = TextFileProvider.Instance.GetTextEditorData(new FilePath(mod.FileName)); foreach (var reference in references) { CodeLocation loc; if (reference is AbstractTypeDeclaration) { loc = ((AbstractTypeDeclaration)reference).NonInnerTypeDependendLocation; } else if (reference is IExpression) { loc = reference.Location; } else { continue; } searchResults.Add(new SearchResult(new FileProvider(mod.FileName, project), targetDoc.LocationToOffset(loc.Line, loc.Column), member.Name.Length)); } } catch (Exception ex) { LoggingService.LogWarning("Error during reference search", ex); } if (monitor != null) { monitor.Step(1); } } if (monitor != null) { monitor.EndTask(); } return(searchResults); }
static IEnumerable <SearchResult> FindReferences( DProject project, INode member, ISearchProgressMonitor monitor = null) { var searchResults = new List <SearchResult>(); var parseCache = project != null ? project.ParseCache : ParseCacheList.Create(DCompilerService.Instance.GetDefaultCompiler().ParseCache); var modules = project == null ? project.LocalFileCache as IEnumerable <IAbstractSyntaxTree> : new[] { (Ide.IdeApp.Workbench.ActiveDocument.ParsedDocument as MonoDevelop.D.Parser.ParsedDModule).DDom }; if (monitor != null) { monitor.BeginStepTask("Scan for references", modules.Count(), 1); } List <ISyntaxRegion> references = null; foreach (var mod in modules) { if (mod == null) { continue; } try { references = ReferencesFinder.Scan(mod, member, new ResolverContextStack(parseCache, new ResolverContext())).ToList(); if (member != null && member.NodeRoot != null && (member.NodeRoot as IAbstractSyntaxTree).FileName == mod.FileName) { references.Insert(0, new IdentifierDeclaration(member.Name) { Location = member.NameLocation, EndLocation = new CodeLocation(member.NameLocation.Column + member.Name.Length, member.NameLocation.Line) }); } if (references.Count < 1) { if (monitor != null) { monitor.Step(1); } continue; } // Sort the references by code location references.Sort(new IdLocationComparer()); // Get actual document code var targetDoc = Ide.TextFileProvider.Instance.GetTextEditorData(new FilePath(mod.FileName)); foreach (var reference in references) { CodeLocation loc; if (reference is AbstractTypeDeclaration) { loc = ((AbstractTypeDeclaration)reference).NonInnerTypeDependendLocation; } else if (reference is IExpression) { loc = ((IExpression)reference).Location; } else { continue; } searchResults.Add(new SearchResult(new FileProvider(mod.FileName, project), targetDoc.LocationToOffset(loc.Line, loc.Column), member.Name.Length)); } } catch (Exception ex) { LoggingService.LogWarning("Error during reference search", ex); } if (monitor != null) { monitor.Step(1); } } if (monitor != null) { monitor.EndTask(); } return(searchResults); }