Example #1
0
        public void FindNextCalls(List <ReferencedSymbol> b, TreeViewItem v)
        {
            TreeViewItem v0 = CreateTreeViewItem(kind.method, "method");
            TreeViewItem v1 = CreateTreeViewItem(kind.folder, "folder");

            foreach (var s in b)
            {
                if (s.Locations != null)
                {
                    foreach (var pl in s.Locations)
                    {
                        if (!pl.Location.IsInSource)
                        {
                            continue;
                        }
                        SourceRefData d = new SourceRefData();
                        {
                            int    length = 10;
                            string cs     = pl.Location.SourceTree.GetRoot().GetText().ToString();
                            var    method = pl.Location.SourceTree.GetRoot().FindNode(pl.Location.SourceSpan).FirstAncestorOrSelf <BaseMethodDeclarationSyntax>();
                            {
                                if (method is ConstructorDeclarationSyntax)
                                {
                                    d.Offset = ((ConstructorDeclarationSyntax)method).Identifier.SpanStart;
                                    length   = ((ConstructorDeclarationSyntax)method).Identifier.Span.Length;
                                }
                                else if (method is DestructorDeclarationSyntax)
                                {
                                    d.Offset = ((DestructorDeclarationSyntax)method).Identifier.SpanStart;
                                    length   = ((DestructorDeclarationSyntax)method).Identifier.Span.Length;
                                }
                                else if (method is MethodDeclarationSyntax)
                                {
                                    d.Offset = ((MethodDeclarationSyntax)method).Identifier.SpanStart;
                                    length   = ((MethodDeclarationSyntax)method).Identifier.Span.Length;
                                }
                                else
                                {
                                    continue;
                                }

                                var lineNumber = cs.Take(d.Offset).Count(c => c == '\n');
                                d.name = cs.Split("\n".ToCharArray())[lineNumber].Trim();
                                d.Line = lineNumber.ToString();
                                d.Span = new Microsoft.CodeAnalysis.Text.TextSpan(lineNumber, length);
                            }
                        }
                        int Line  = pl.Location.GetLineSpan().StartLinePosition.Line;
                        var Lines = pl.Location.SourceTree.GetText().Lines;
                        d.Name = pl.Location.SourceTree.GetText().Lines[Line].ToString().Trim();

                        d.File     = Path.GetFileName(pl.Location.SourceTree.FilePath);
                        d.FileName = pl.Location.SourceTree.FilePath;
                        int    line = pl.Location.GetLineSpan().StartLinePosition.Line;
                        string bcs  = pl.Location.SourceTree.GetRoot().GetText().ToString();
                        line    -= StringReplace.FindExtended(bcs, pl.Location.SourceSpan.Start);
                        d.Line   = line.ToString();
                        d.Column = pl.Location.GetLineSpan().StartLinePosition.Character.ToString();
                        d.refs   = pl;
                        TreeViewItem v2 = CreateTreeViewItem(kind.none, d.name);
                        TreeViewItem v3 = CreateTreeViewItem(kind.folder, "Folder");
                        TreeViewItem v4 = CreateTreeViewItem(kind.folder, "Searching for calls");
                        v3.Items.Add(v4);
                        v2.Expanded += V3_Expanded;
                        v3.Tag       = d;
                        v2.Items.Add(v3);
                        v2.Tag       = d;
                        v2.Selected += V2_Selected;
                        v.Items.Add(v2);
                    }
                }
            }
        }
Example #2
0
        public void LoadData(ISymbol symbol, List <ReferencedSymbol> b, VSSolution vs)
        {
            List <string> tw = editorWindow.GetTypesNames();
            List <string> kw = (List <string>)editorWindow.Words;

            object[] aw = new object[2];
            aw[0] = tw;
            aw[1] = kw;

            Dictionary <string, List <SourceData> > dict = new Dictionary <string, List <SourceData> >();

            //Sources.Clear();

            Sources = new ObservableCollection <Source>();

            Source c = new Source();

            c.Name = symbol.Name;

            List <SourceRefData> data = new List <SourceRefData>();

            // c.Data = data;

            foreach (var s in b)
            {
                if (s.Locations != null)
                {
                    foreach (var pl in s.Locations)
                    {
                        if (!pl.Location.IsInSource)
                        {
                            continue;
                        }
                        VSProject vp   = vs.GetProjectbyCompileItem(pl.Location.SourceTree.FilePath);
                        string    name = Path.GetFileNameWithoutExtension(vp.FileName);

                        if (dict.ContainsKey(name))
                        {
                            List <SourceData>    datasource = dict[name];
                            List <SourceRefData> dataref    = datasource[0].Data;
                            data = dataref;// dataref[0].Data;
                        }
                        else
                        {
                            c      = new Source();
                            c.Name = name;
                            List <SourceData> datasource = new List <SourceData>();
                            c.Data = datasource;
                            SourceData sourcedata = new SourceData();
                            sourcedata.Name = s.Definition.ToDisplayString();
                            datasource.Add(sourcedata);
                            List <SourceRefData> dataref = new List <SourceRefData>();
                            sourcedata.Data = dataref;

                            data = dataref;

                            dict.Add(name, datasource);

                            Sources.Add(c);
                        }

                        SourceRefData d     = new SourceRefData();
                        int           Line  = pl.Location.GetLineSpan().StartLinePosition.Line;
                        var           Lines = pl.Location.SourceTree.GetText().Lines;
                        d.Name = pl.Location.SourceTree.GetText().Lines[Line].ToString();
                        List <string> list  = new List <string>();
                        int           min   = Int32.MaxValue;
                        string        lines = "";
                        int           i     = Line - 3;
                        if (i < 0)
                        {
                            Line = 0;
                        }
                        while (i <= Line)
                        {
                            string loc = Lines[i].ToString();

                            loc = loc.Replace("\t", " ");
                            int pos = loc.TakeWhile(sa => char.IsWhiteSpace(sa)).Count();
                            if (pos < min)
                            {
                                min = pos;
                            }
                            //lines += Lines[i].ToString().TrimStart() + "\n";
                            list.Add(loc + "\n");
                            i++;
                        }
                        i = Line + 1;
                        while (i <= Line + 3 && i < Lines.Count - 1)
                        {
                            string loc = Lines[i].ToString();
                            loc = loc.Replace("\t", " ");
                            int pos = loc.TakeWhile(sa => char.IsWhiteSpace(sa)).Count();
                            if (pos < min)
                            {
                                min = pos;
                            }
                            list.Add(loc + "\n");
                            //lines += Lines[i].ToString().TrimStart() + "\n";
                            i++;
                        }
                        foreach (string st in list)
                        {
                            lines += " " + st.Substring(min, st.Length - min);
                        }
                        d.Lines    = lines;
                        d.Project  = Path.GetFileNameWithoutExtension(vp.FileName);
                        d.File     = Path.GetFileName(pl.Location.SourceTree.FilePath);
                        d.FileName = pl.Location.SourceTree.FilePath;
                        d.Words    = (object)aw;
                        int line = pl.Location.GetLineSpan().StartLinePosition.Line;
                        //line = editorWindow.textEditor.Document.GetLineByNumber(line).LineNumberExtended;

                        string cs = vs.GetSyntaxTreeText(pl.Location.SourceTree.FilePath);

                        line -= StringReplace.FindExtended(cs, pl.Location.SourceSpan.Start);

                        //int nw = StringReplace.FindExtended(cs, pl.Location.SourceSpan.Start);

                        d.Line   = line.ToString();
                        d.Column = pl.Location.GetLineSpan().StartLinePosition.Character.ToString();
                        d.refs   = pl;
                        data.Add(d);
                    }
                }
            }

            treeListView.ItemsSource = Sources;

            ExpandAll();
        }