Esempio n. 1
0
            public bool Filter(object model)
            {
                SyntaxWrapper wrapper = (SyntaxWrapper)model;

                return(!((wrapper.GetSyntaxObject() is SyntaxToken && !_tokens) ||
                         (wrapper.GetSyntaxObject() is SyntaxTrivia && !_trivia)));
            }
Esempio n. 2
0
        // Returns the last used id
        private int PopulateGraph(Graph graph, SyntaxWrapper wrapper, int id, string parentId)
        {
            // Check if filtering
            if ((wrapper.GetSyntaxObject() is SyntaxToken && _syntaxTokenCheckBox != null && !_syntaxTokenCheckBox.Checked) ||
                (wrapper.GetSyntaxObject() is SyntaxTrivia && _syntaxTriviaCheckBox != null && !_syntaxTriviaCheckBox.Checked))
            {
                return(id);
            }

            // Create the node
            string nodeId = id.ToString();
            Node   node   = new Node(nodeId);
            Color  color  = wrapper.GetColor();

            node.Attr.FillColor   = new Microsoft.Msagl.Drawing.Color(color.R, color.G, color.B);
            node.Attr.LabelMargin = 10;
            node.LabelText        = wrapper.GetGraphText();
            node.Label.FontColor  = Microsoft.Msagl.Drawing.Color.White;
            node.Label.FontStyle  = (Microsoft.Msagl.Drawing.FontStyle)(int) wrapper.GetGraphFontStyle();
            graph.AddNode(node);

            // Add the edge
            if (parentId != null)
            {
                graph.AddEdge(parentId, nodeId);
            }

            // Descend
            IEnumerable children = wrapper.GetChildren();

            if (children != null)
            {
                // Note that we have to iterate children in reverse order to get them to layout in the correct order
                foreach (SyntaxWrapper childWrapper in children.Cast <SyntaxWrapper>().Reverse())
                {
                    id = PopulateGraph(graph, childWrapper, id + 1, nodeId);
                }
            }
            return(id);
        }
Esempio n. 3
0
        private void CreateTreeList(string declarationFilter)
        {
            // Create the tree view
            _treeList = new TreeListView()
            {
                CanExpandGetter     = x => ((SyntaxWrapper)x).CanExpand(),
                ChildrenGetter      = x => ((SyntaxWrapper)x).GetChildren(),
                UseCellFormatEvents = true,
                Dock         = DockStyle.Fill,
                UseFiltering = true
            };
            _treeList.FormatCell    += (x, e) => ((SyntaxWrapper)e.CellValue).FormatCell(e);
            _treeList.BeforeSorting += (x, e) => e.Canceled = true;

            // Select - show the text
            _treeList.SelectedIndexChanged += (x, e) =>
            {
                if (_treeList.SelectedItem != null)
                {
                    SyntaxWrapper wrapper = (SyntaxWrapper)_treeList.SelectedItem.RowObject;
                    _textBox.Text = wrapper.GetSyntaxObject().ToString();
                    PopulateGraph(wrapper);
                }
            };

            // Activate - dump the syntax object
            _treeList.ItemActivate += (x, e) =>
            {
                if (_treeList.SelectedItem != null)
                {
                    SyntaxWrapper wrapper = (SyntaxWrapper)_treeList.SelectedItem.RowObject;
                    wrapper.GetSyntaxObject().Dump(wrapper.GetKind() + " " + wrapper.GetSpan());
                }
            };

            // Context menus - dump semantic nodes
            _treeList.CellRightClick += (x, e) =>
            {
                e.MenuStrip = null;
                if (_treeList.SelectedItem != null)
                {
                    SyntaxNodeWrapper wrapper = _treeList.SelectedItem.RowObject as SyntaxNodeWrapper;
                    if (wrapper != null)
                    {
                        ContextMenuStrip menuStrip  = new ContextMenuStrip();
                        SyntaxNode       syntaxNode = (SyntaxNode)wrapper.GetSyntaxObject();

                        // Dump Symbol
                        ISymbol symbol = GetSymbol(syntaxNode);
                        if (symbol != null)
                        {
                            menuStrip.Items.Add("Dump Symbol").Click +=
                                (x2, e2) => symbol.Dump(symbol.Kind + " " + wrapper.GetSpan());
                        }

                        // Dump TypeSymbol
                        ITypeSymbol typeSymbol = GetTypeSymbol(syntaxNode);
                        if (typeSymbol != null)
                        {
                            menuStrip.Items.Add("Dump TypeSymbol").Click +=
                                (x2, e2) => typeSymbol.Dump(typeSymbol.Kind + " " + wrapper.GetSpan());
                        }

                        // Dump Converted TypeSymbol
                        ITypeSymbol convertedTypeSymbol = GetConvertedTypeSymbol(syntaxNode);
                        if (convertedTypeSymbol != null)
                        {
                            menuStrip.Items.Add("Dump Converted TypeSymbol").Click +=
                                (x2, e2) => convertedTypeSymbol.Dump(convertedTypeSymbol.Kind + " " + wrapper.GetSpan());
                        }

                        // Dump AliasSymbol
                        IAliasSymbol aliasSymbol = GetAliasSymbol(syntaxNode);
                        if (aliasSymbol != null)
                        {
                            menuStrip.Items.Add("Dump AliasSymbol").Click +=
                                (x2, e2) => aliasSymbol.Dump(aliasSymbol.Kind + " " + wrapper.GetSpan());
                        }

                        // Dump ContantValue
                        object constantValue;
                        if (GetConstantValue(syntaxNode, out constantValue))
                        {
                            menuStrip.Items.Add("Show Constant Value").Click +=
                                (x2, e2) => MessageBox.Show(constantValue.ToString(), constantValue.GetType().Name + " " + wrapper.GetSpan(), MessageBoxButtons.OK);
                        }

                        // Add the menu strip if any items were added
                        if (menuStrip.Items.Count > 0)
                        {
                            e.MenuStrip = menuStrip;
                        }
                    }
                }
            };

            // Create columns
            _treeList.Columns.Add(new OLVColumn("Kind", null)
            {
                AspectGetter            = x => x,
                AspectToStringConverter = x => ((SyntaxWrapper)x).GetTreeText()
            });
            _treeList.Columns.Add(new OLVColumn("Span", null)
            {
                AspectGetter            = x => x,
                AspectToStringConverter = x => ((SyntaxWrapper)x).GetSpan()
            });
            _treeList.Columns.Add(new OLVColumn("Text", null)
            {
                AspectGetter            = x => x,
                AspectToStringConverter = x => ((SyntaxWrapper)x).GetText()
            });

            // Set the root
            SyntaxNode root;
            int        depth = 0;

            if (_syntaxTree.TryGetRoot(out root))
            {
                SetRoots(declarationFilter);
                depth = GetDepth(root);
            }

            // Calculate control width
            AutoSizeColumns(_treeList, depth, true);
            _treeList.Layout += (x, e) => AutoSizeColumns(_treeList, depth, false);
        }
        // Returns the last used id
        private int PopulateGraph(Graph graph, SyntaxWrapper wrapper, int id, string parentId)
        {
            // Check if filtering
            if ((wrapper.GetSyntaxObject() is SyntaxToken && _syntaxTokenCheckBox != null && !_syntaxTokenCheckBox.Checked)
                  || (wrapper.GetSyntaxObject() is SyntaxTrivia && _syntaxTriviaCheckBox != null && !_syntaxTriviaCheckBox.Checked))
            {
                return id;
            }

            // Create the node
            string nodeId = id.ToString();
            Node node = new Node(nodeId);
            Color color = wrapper.GetColor();
            node.Attr.FillColor = new Microsoft.Msagl.Drawing.Color(color.R, color.G, color.B);
            node.Attr.LabelMargin = 10;
            node.LabelText = wrapper.GetGraphText();
            node.Label.FontColor = Microsoft.Msagl.Drawing.Color.White;
            node.Label.FontStyle = (Microsoft.Msagl.Drawing.FontStyle)(int) wrapper.GetGraphFontStyle();
            graph.AddNode(node);

            // Add the edge
            if (parentId != null)
            {
                graph.AddEdge(parentId, nodeId);
            }

            // Descend
            IEnumerable children = wrapper.GetChildren();
            if (children != null)
            {
                // Note that we have to iterate children in reverse order to get them to layout in the correct order
                foreach (SyntaxWrapper childWrapper in children.Cast<SyntaxWrapper>().Reverse())
                {
                    id = PopulateGraph(graph, childWrapper, id + 1, nodeId);
                }
            }
            return id;
        }