Ejemplo n.º 1
0
        /// <summary>
        /// Processes a base list. It is ignored, as they are not interesting to the overall overview.
        /// </summary>
        public static void ProcessNode(IncompleteMemberSyntax node, ItemCollection itemCollection, int?index = null)
        {
            var item = new TreeViewItem
            {
                Header = new TreeElement(
                    node.Type.ToString(),
                    node.Span,
                    TreeImages.GetImage(ElementType.Unknown, GetModifiers(node)))
            };

            AddOrInsert(itemCollection, item, index);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Processes any other type of syntax node. This means it is not understood, and the type is shown with
        /// a question mark.
        /// </summary>
        public static void ProcessNode(SyntaxNode node, ItemCollection itemCollection, int?index = null)
        {
            var item = new TreeViewItem
            {
                Header = new TreeElement(
                    $"{node.GetType()}",
                    node.Span,
                    TreeImages.GetImage(ElementType.Unknown))
            };

            AddOrInsert(itemCollection, item, index);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Processes an operator declaration.
        /// </summary>
        public static void ProcessNode(ConversionOperatorDeclarationSyntax node, ItemCollection itemCollection, int?index = null)
        {
            var item = new TreeViewItem
            {
                Header = new TreeElement(
                    $"{node.Type}({string.Join(", ", node.ParameterList.Parameters.Select(p => p.Type))})",
                    node.Span,
                    TreeImages.GetImage(ElementType.Operator, GetModifiers(node)))
            };

            AddOrInsert(itemCollection, item, index);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Processes an enum member declaration.
        /// </summary>
        public static void ProcessNode(EnumMemberDeclarationSyntax node, ItemCollection itemCollection, int?index = null)
        {
            var item = new TreeViewItem
            {
                Header = new TreeElement(
                    string.Join(", ", node.Identifier.ToString()),
                    node.Span,
                    TreeImages.GetImage(ElementType.EnumValue))
            };

            AddOrInsert(itemCollection, item, index);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Processes a property declaration.
        /// </summary>
        public static void ProcessNode(PropertyDeclarationSyntax node, ItemCollection itemCollection, int?index = null)
        {
            var item = new TreeViewItem
            {
                Header = new TreeElement(
                    $"{node.Identifier.ToString()}: {node.Type}",
                    node.Span,
                    TreeImages.GetImage(ElementType.Property, GetModifiers(node)))
            };

            AddOrInsert(itemCollection, item, index);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Processes a field declaration.
        /// </summary>
        public static void ProcessNode(FieldDeclarationSyntax node, ItemCollection itemCollection, int?index = null)
        {
            var item = new TreeViewItem
            {
                Header = new TreeElement(
                    $"{string.Join(", ", node.Declaration.Variables.Select(v => $"{v.Identifier}"))}: {node.Declaration.Type}",
                    node.Span,
                    TreeImages.GetImage(ElementType.Field, GetModifiers(node)))
            };

            AddOrInsert(itemCollection, item, index);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Builds a region tree from a list of <see cref="RegionDirectiveTriviaSyntax"/> and
        /// <see cref="EndRegionDirectiveTriviaSyntax"/> elements. Builds up the item collections with only regions.
        /// </summary>
        /// <param name="directives">The directives to build the region tree from.</param>
        /// <returns>The built region tree.</returns>
        public RegionTree Create(IEnumerator <DirectiveTriviaSyntax> directives)
        {
            var result = this;

            while (directives.MoveNext())
            {
                if (directives.Current is RegionDirectiveTriviaSyntax start)
                {
                    // A new region is started, so try finding sub-regions inside it.
                    // Note that if there are more start-regions than end-regions, this will result the outermost
                    // region being ended at the same time as the last region that was ended.
                    var item = new TreeViewItem {
                        IsExpanded = true
                    };
                    var child = new RegionTree(start.ToString(), start.FullSpan, item.Items).Create(directives);
                    result      = result.AddChild(child);
                    item.Header = new TreeElement(
                        child.Name.Substring("#region ".Length),
                        new TextSpan(child.SpanStart, child.SpanEnd - child.SpanStart),
                        TreeImages.GetImage(ElementType.Region),
                        regionId: child.Id)
                    {
                        TextColor = "#666"
                    };

                    this.ItemCollection.Add(item);
                }
                else if (directives.Current is EndRegionDirectiveTriviaSyntax end)
                {
                    // We return the region currently being built up with its span-end filled in.
                    // Note that an additional endregion syntax will exit this method early, resulting in fewer regions
                    // being returned. But that is okay, since the syntax is not correct anyway.
                    return(result.SetSpanEnd(end.FullSpan.End));
                }
            }

            // For the root, don't update the span end, it was set when creating the region.
            // Otherwise, there are end-region directives missing, so end the current region at the end of its
            // child regions (if it has any).
            var lastChild = result.Children.LastOrDefault();

            if (result.IsRoot || lastChild == null)
            {
                return(result);
            }
            else
            {
                return(result.SetSpanEnd(lastChild.SpanEnd));
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Processes an enum declaration. Also detects regions inside the element.
        /// </summary>
        public static void ProcessNode(EnumDeclarationSyntax node, ItemCollection itemCollection, int?index = null)
        {
            var item = new TreeViewItem
            {
                Header = new TreeElement(
                    node.Identifier.ToString(),
                    node.Span,
                    TreeImages.GetImage(ElementType.Enum, GetModifiers(node))),
                IsExpanded = true
            };

            HandleChildrenWithRegions(node, item.Items);

            AddOrInsert(itemCollection, item, index);
        }