Esempio n. 1
0
        private static CodeItem MapMethod(MethodDeclarationSyntax member)
        {
            if (member == null)
            {
                return(null);
            }

            CodeItem item;

            var statements = member.Body?.Statements.Select(StatementMapper.MapStatement).ToList();

            FilterNullItems(statements);

            if (Settings.Default.ShowSwitch && statements != null && statements.Any())
            {
                item = MapBase <CodeClassItem>(member, member.Identifier, member.Modifiers);
                ((CodeClassItem)item).Members.AddRange(statements);
                ((CodeClassItem)item).BorderBrush = CreateSolidColorBrush(Colors.DarkGray);
            }
            else
            {
                item = MapBase <CodeFunctionItem>(member, member.Identifier, member.Modifiers);
                ((CodeFunctionItem)item).Type       = TypeMapper.Map(member.ReturnType);
                ((CodeFunctionItem)item).Parameters = MapParameters(member.ParameterList);
                item.Tooltip = TooltipMapper.Map(item.Access, ((CodeFunctionItem)item).Type, item.Name, member.ParameterList);
            }

            item.Id      = MapId(item.FullName, member.ParameterList);
            item.Kind    = CodeItemKindEnum.Method;
            item.Moniker = MapMoniker(item.Kind, item.Access);

            return(item);
        }
Esempio n. 2
0
        public static CodeItem MapMethod(MethodDeclarationSyntax member, CodeViewUserControl control, SemanticModel semanticModel)
        {
            if (member == null)
            {
                return(null);
            }

            CodeItem item;

            var statementsCodeItems = StatementMapper.MapStatement(member.Body, control, semanticModel);

            if (VisibilityHelper.ShouldBeVisible(CodeItemKindEnum.Switch) && statementsCodeItems.Any())
            {
                // Map method as item containing statements
                item = BaseMapper.MapBase <CodeClassItem>(member, member.Identifier, member.Modifiers, control, semanticModel);
                ((CodeClassItem)item).Members.AddRange(statementsCodeItems);
                ((CodeClassItem)item).BorderBrush = ColorHelper.ToBrush(Colors.DarkGray);
            }
            else
            {
                // Map method as single item
                item = BaseMapper.MapBase <CodeFunctionItem>(member, member.Identifier, member.Modifiers, control, semanticModel);
                ((CodeFunctionItem)item).Type       = TypeMapper.Map(member.ReturnType);
                ((CodeFunctionItem)item).Parameters = ParameterMapper.MapParameters(member.ParameterList);
                item.Tooltip = TooltipMapper.Map(item.Access, ((CodeFunctionItem)item).Type, item.Name, member.ParameterList);
            }

            item.Id      = IdMapper.MapId(item.FullName, member.ParameterList);
            item.Kind    = CodeItemKindEnum.Method;
            item.Moniker = IconMapper.MapMoniker(item.Kind, item.Access);

            return(item);
        }
Esempio n. 3
0
        public static CodePropertyItem MapProperty(PropertyDeclarationSyntax member,
                                                   CodeViewUserControl control, SemanticModel semanticModel)
        {
            if (member == null)
            {
                return(null);
            }

            var item = BaseMapper.MapBase <CodePropertyItem>(member, member.Identifier, member.Modifiers, control, semanticModel);

            item.Type = TypeMapper.Map(member.Type);

            if (member.AccessorList != null)
            {
                if (member.AccessorList.Accessors.Any(a => a.Kind() == SyntaxKind.GetAccessorDeclaration))
                {
                    item.Parameters += "get";
                }

                if (member.AccessorList.Accessors.Any(a => a.Kind() == SyntaxKind.SetAccessorDeclaration))
                {
                    item.Parameters += string.IsNullOrEmpty(item.Parameters) ? "set" : ",set";
                }

                if (!string.IsNullOrEmpty(item.Parameters))
                {
                    item.Parameters = $" {{{item.Parameters}}}";
                }
            }

            item.Tooltip = TooltipMapper.Map(item.Access, item.Type, item.Name, item.Parameters);
            item.Kind    = CodeItemKindEnum.Property;
            item.Moniker = IconMapper.MapMoniker(item.Kind, item.Access);
            return(item);
        }
Esempio n. 4
0
        public static CodeClassItem MapClass(VisualBasicSyntax.TypeBlockSyntax member,
                                             CodeViewUserControl control, SemanticModel semanticModel, SyntaxTree tree)
        {
            if (member == null)
            {
                return(null);
            }

            var item = BaseMapper.MapBase <CodeClassItem>(member, member.BlockStatement.Identifier,
                                                          member.BlockStatement.Modifiers, control, semanticModel);

            item.Kind        = CodeItemKindEnum.Class;
            item.Moniker     = IconMapper.MapMoniker(item.Kind, item.Access);
            item.Parameters  = MapInheritance(member);
            item.BorderBrush = ColorHelper.ToBrush(Colors.DarkGray);
            item.Tooltip     = TooltipMapper.Map(item.Access, string.Empty, item.Name, item.Parameters);

            var regions = RegionMapper.MapRegions(tree, member.Span);
            var implementedInterfaces = InterfaceMapper.MapImplementedInterfaces(member, semanticModel);

            foreach (var classMember in member.Members)
            {
                var memberItem = SyntaxMapper.MapMember(classMember);
                if (memberItem != null && !InterfaceMapper.IsPartOfImplementedInterface(implementedInterfaces, memberItem) &&
                    !RegionMapper.AddToRegion(regions, memberItem))
                {
                    item.Members.Add(memberItem);
                }
            }

            // Add implemented interfaces to class or region if they have a interface member inside them
            if (implementedInterfaces.Any())
            {
                foreach (var interfaceItem in implementedInterfaces)
                {
                    if (interfaceItem.Members.Any())
                    {
                        if (!RegionMapper.AddToRegion(regions, interfaceItem))
                        {
                            item.Members.Add(interfaceItem);
                        }
                    }
                }
            }

            // Add regions to class if they have a region member inside them
            if (regions.Any())
            {
                foreach (var region in regions)
                {
                    if (region.Members.Any())
                    {
                        item.Members.Add(region);
                    }
                }
            }

            return(item);
        }
Esempio n. 5
0
        private static CodeClassItem MapClass(ClassDeclarationSyntax member)
        {
            if (member == null)
            {
                return(null);
            }

            var item = MapBase <CodeClassItem>(member, member.Identifier, member.Modifiers);

            item.Kind        = CodeItemKindEnum.Class;
            item.Moniker     = MapMoniker(item.Kind, item.Access);
            item.Parameters  = MapInheritance(member);
            item.BorderBrush = CreateSolidColorBrush(Colors.DarkGray);
            item.Tooltip     = TooltipMapper.Map(item.Access, string.Empty, item.Name, item.Parameters);

            var regions = MapRegions(member.Span);
            var implementedInterfaces = MapImplementedInterfaces(member);

            foreach (var classMember in member.Members)
            {
                var memberItem = MapMember(classMember);
                if (memberItem != null && !IsPartOfImplementedInterface(implementedInterfaces, memberItem) &&
                    !AddToRegion(regions, memberItem))
                {
                    item.Members.Add(memberItem);
                }
            }

            // Add implemented interfaces to class or region if they have a interface member inside them
            if (implementedInterfaces.Any())
            {
                foreach (var interfaceItem in implementedInterfaces)
                {
                    if (interfaceItem.Members.Any())
                    {
                        if (!AddToRegion(regions, interfaceItem))
                        {
                            item.Members.Add(interfaceItem);
                        }
                    }
                }
            }

            // Add regions to class if they have a region member inside them
            if (regions.Any())
            {
                foreach (var region in regions)
                {
                    if (region.Members.Any())
                    {
                        item.Members.Add(region);
                    }
                }
            }

            return(item);
        }
Esempio n. 6
0
        /// <summary>
        /// Map the individual cases within a switch statement
        /// </summary>
        /// <param name="section"></param>
        /// <param name="control"></param>
        /// <param name="semanticModel"></param>
        /// <returns></returns>
        private static CodeItem MapSwitchSection(SwitchSectionSyntax section, CodeViewUserControl control, SemanticModel semanticModel)
        {
            if (section == null)
            {
                return(null);
            }

            var item = BaseMapper.MapBase <CodePropertyItem>(section, section.Labels.First().ToString(), control, semanticModel);

            item.Tooltip = TooltipMapper.Map(item.Access, item.Type, item.Name, string.Empty);
            item.Id      = IdMapper.MapId(item.FullName, null);
            item.Kind    = CodeItemKindEnum.SwitchSection;
            item.Moniker = IconMapper.MapMoniker(item.Kind, item.Access);

            return(item);
        }
Esempio n. 7
0
        private static CodeItem MapSwitchSection(SwitchSectionSyntax section)
        {
            if (section == null)
            {
                return(null);
            }

            var item = SyntaxMapper.MapBase <CodePropertyItem>(section, section.Labels.First().ToString());

            item.Tooltip = TooltipMapper.Map(item.Access, item.Type, item.Name, string.Empty);
            item.Id      = SyntaxMapper.MapId(item.FullName, null);
            item.Kind    = CodeItemKindEnum.SwitchSection;
            item.Moniker = SyntaxMapper.MapMoniker(item.Kind, item.Access);

            return(item);
        }
Esempio n. 8
0
        private static CodeItem MapConstructor(ConstructorDeclarationSyntax member)
        {
            if (member == null)
            {
                return(null);
            }

            var item = MapBase <CodeFunctionItem>(member, member.Identifier, member.Modifiers);

            item.Parameters     = MapParameters(member.ParameterList);
            item.Tooltip        = TooltipMapper.Map(item.Access, item.Type, item.Name, member.ParameterList);
            item.Id             = MapId(member.Identifier, member.ParameterList);
            item.Kind           = CodeItemKindEnum.Constructor;
            item.Moniker        = MapMoniker(item.Kind, item.Access);
            item.OverlayMoniker = KnownMonikers.Add;

            return(item);
        }
Esempio n. 9
0
        public static CodeItem MapConstructor(VisualBasicSyntax.ConstructorBlockSyntax member, CodeViewUserControl control, SemanticModel semanticModel)
        {
            if (member == null)
            {
                return(null);
            }

            var item = BaseMapper.MapBase <CodeFunctionItem>(member, member.SubNewStatement.NewKeyword, member.SubNewStatement.Modifiers, control, semanticModel);

            item.Parameters     = ParameterMapper.MapParameters(member.SubNewStatement.ParameterList, semanticModel);
            item.Tooltip        = TooltipMapper.Map(item.Access, item.Type, item.Name, member.SubNewStatement.ParameterList, semanticModel);
            item.Id             = IdMapper.MapId(member.SubNewStatement.NewKeyword, member.SubNewStatement.ParameterList, semanticModel);
            item.Kind           = CodeItemKindEnum.Constructor;
            item.Moniker        = IconMapper.MapMoniker(item.Kind, item.Access);
            item.OverlayMoniker = KnownMonikers.Add;

            return(item);
        }
Esempio n. 10
0
        public static CodeItem MapConstructor(ConstructorDeclarationSyntax member, ICodeViewUserControl control, SemanticModel semanticModel)
        {
            if (member == null)
            {
                return(null);
            }

            var item = BaseMapper.MapBase <CodeFunctionItem>(member, member.Identifier, member.Modifiers, control, semanticModel);

            item.Parameters     = ParameterMapper.MapParameters(member.ParameterList);
            item.Tooltip        = TooltipMapper.Map(item.Access, item.Type, item.Name, member.ParameterList);
            item.Id             = IdMapper.MapId(member.Identifier, member.ParameterList);
            item.Kind           = CodeItemKindEnum.Constructor;
            item.Moniker        = IconMapper.MapMoniker(item.Kind, item.Access);
            item.OverlayMoniker = KnownMonikers.Add;

            return(item);
        }
Esempio n. 11
0
        public static CodePropertyItem MapProperty(VisualBasicSyntax.PropertyBlockSyntax member,
                                                   ICodeViewUserControl control, SemanticModel semanticModel)
        {
            if (member == null)
            {
                return(null);
            }

            var item = BaseMapper.MapBase <CodePropertyItem>(member, member.PropertyStatement.Identifier,
                                                             member.PropertyStatement.Modifiers, control, semanticModel);

            var symbol = SymbolHelper.GetSymbol <IPropertySymbol>(semanticModel, member);

            item.Type = TypeMapper.Map(symbol?.Type);

            if (member.Accessors != null)
            {
                if (member.Accessors.Any(a => a.Kind() == VisualBasic.SyntaxKind.GetAccessorBlock))
                {
                    item.Parameters += "get";
                }

                if (member.Accessors.Any(a => a.Kind() == VisualBasic.SyntaxKind.SetAccessorBlock))
                {
                    item.Parameters += string.IsNullOrEmpty(item.Parameters) ? "set" : ",set";
                }

                if (!string.IsNullOrEmpty(item.Parameters))
                {
                    item.Parameters = $" {{{item.Parameters}}}";
                }
            }

            item.Tooltip = TooltipMapper.Map(item.Access, item.Type, item.Name, item.Parameters);
            item.Kind    = CodeItemKindEnum.Property;
            item.Moniker = IconMapper.MapMoniker(item.Kind, item.Access);

            if (TriviaSummaryMapper.HasSummary(member) && SettingsHelper.UseXMLComments)
            {
                item.Tooltip = TriviaSummaryMapper.Map(member);
            }

            return(item);
        }
Esempio n. 12
0
        public static CodeItem MapMethod(VisualBasicSyntax.MethodBlockSyntax member, ICodeViewUserControl control, SemanticModel semanticModel)
        {
            if (member == null)
            {
                return(null);
            }

            CodeItem item;

            var statementsCodeItems = StatementMapper.MapStatement(member.Statements, control, semanticModel);

            if (VisibilityHelper.ShouldBeVisible(CodeItemKindEnum.Switch) && statementsCodeItems.Any())
            {
                // Map method as item containing statements
                item = BaseMapper.MapBase <CodeClassItem>(member, member.SubOrFunctionStatement.Identifier,
                                                          member.SubOrFunctionStatement.Modifiers, control, semanticModel);
                ((CodeClassItem)item).Members.AddRange(statementsCodeItems);
                ((CodeClassItem)item).BorderColor = Colors.DarkGray;
            }
            else
            {
                // Map method as single item
                item = BaseMapper.MapBase <CodeFunctionItem>(member, member.SubOrFunctionStatement.Identifier,
                                                             member.SubOrFunctionStatement.Modifiers, control, semanticModel);

                var symbol = SymbolHelper.GetSymbol <IMethodSymbol>(semanticModel, member);
                ((CodeFunctionItem)item).Type       = TypeMapper.Map(symbol?.ReturnType);
                ((CodeFunctionItem)item).Parameters = ParameterMapper.MapParameters(member.SubOrFunctionStatement.ParameterList, semanticModel);
                item.Tooltip = TooltipMapper.Map(item.Access, ((CodeFunctionItem)item).Type, item.Name,
                                                 member.SubOrFunctionStatement.ParameterList, semanticModel);
            }

            item.Id      = IdMapper.MapId(item.FullName, member.SubOrFunctionStatement.ParameterList, semanticModel);
            item.Kind    = CodeItemKindEnum.Method;
            item.Moniker = IconMapper.MapMoniker(item.Kind, item.Access);

            if (TriviaSummaryMapper.HasSummary(member) && SettingsHelper.UseXMLComments)
            {
                item.Tooltip = TriviaSummaryMapper.Map(member);
            }

            return(item);
        }
Esempio n. 13
0
        private static CodePropertyItem MapProperty(PropertyDeclarationSyntax member)
        {
            if (member == null)
            {
                return(null);
            }

            var item = MapBase <CodePropertyItem>(member, member.Identifier, member.Modifiers);

            item.Type = TypeMapper.Map(member.Type);

            if (item.Access == CodeItemAccessEnum.Private)
            {
                return(null);
            }

            if (member.AccessorList != null)
            {
                if (member.AccessorList.Accessors.Any(a => a.Kind() == SyntaxKind.GetAccessorDeclaration))
                {
                    item.Parameters += "get";
                }

                if (member.AccessorList.Accessors.Any(a => a.Kind() == SyntaxKind.SetAccessorDeclaration))
                {
                    item.Parameters += string.IsNullOrEmpty(item.Parameters) ? "set" : ",set";
                }

                if (!string.IsNullOrEmpty(item.Parameters))
                {
                    item.Parameters = $" {{{item.Parameters}}}";
                }
            }

            item.Parameters = item.Name + item.Parameters;
            item.Tooltip    = TooltipMapper.Map(item.Access, item.Type, item.Name, item.Parameters);
            item.Kind       = CodeItemKindEnum.Property;
            item.Moniker    = MapMoniker(item.Kind, item.Access);
            return(item);
        }
Esempio n. 14
0
        private static CodeItem MapMethod(MethodDeclarationSyntax member)
        {
            if (member == null)
            {
                return(null);
            }

            CodeItem item;

            var statements = new List <CodeItem>();

            if (member.Body?.Statements != null)
            {
                foreach (var statement in member.Body?.Statements)
                {
                    statements.Add(StatementMapper.MapStatement(statement, _control, _semanticModel));
                }
                FilterNullItems(statements);
            }

            if (VisibilityHelper.ShouldBeVisible(CodeItemKindEnum.Switch) && statements != null && statements.Any())
            {
                item = BaseMapper.MapBase <CodeClassItem>(member, member.Identifier, member.Modifiers, _control, _semanticModel);
                ((CodeClassItem)item).Members.AddRange(statements);
                ((CodeClassItem)item).BorderBrush = ColorHelper.CreateSolidColorBrush(Colors.DarkGray);
            }
            else
            {
                item = BaseMapper.MapBase <CodeFunctionItem>(member, member.Identifier, member.Modifiers, _control, _semanticModel);
                ((CodeFunctionItem)item).Type       = TypeMapper.Map(member.ReturnType);
                ((CodeFunctionItem)item).Parameters = MapParameters(member.ParameterList);
                item.Tooltip = TooltipMapper.Map(item.Access, ((CodeFunctionItem)item).Type, item.Name, member.ParameterList);
            }

            item.Id      = MapId(item.FullName, member.ParameterList);
            item.Kind    = CodeItemKindEnum.Method;
            item.Moniker = IconMapper.MapMoniker(item.Kind, item.Access);

            return(item);
        }
Esempio n. 15
0
        public static CodeItem MapIndexer(IndexerDeclarationSyntax member, ICodeViewUserControl control, SemanticModel semanticModel)
        {
            if (member == null)
            {
                return(null);
            }

            var item = BaseMapper.MapBase <CodeFunctionItem>(member, member.ThisKeyword, member.Modifiers, control, semanticModel);

            item.Type       = TypeMapper.Map(member.Type);
            item.Parameters = ParameterMapper.MapParameters(member.ParameterList);
            item.Tooltip    = TooltipMapper.Map(item.Access, item.Type, item.Name, item.Parameters);
            item.Kind       = CodeItemKindEnum.Indexer;
            item.Moniker    = IconMapper.MapMoniker(item.Kind, item.Access);

            if (TriviaSummaryMapper.HasSummary(member) && SettingsHelper.UseXMLComments)
            {
                item.Tooltip = TriviaSummaryMapper.Map(member);
            }

            return(item);
        }
Esempio n. 16
0
        public static CodePropertyItem MapProperty(VisualBasicSyntax.PropertyBlockSyntax member,
                                                   CodeViewUserControl control, SemanticModel semanticModel)
        {
            if (member == null)
            {
                return(null);
            }

            var item = BaseMapper.MapBase <CodePropertyItem>(member, member.PropertyStatement.Identifier,
                                                             member.PropertyStatement.Modifiers, control, semanticModel);

            var symbol = semanticModel.GetDeclaredSymbol(member) as IPropertySymbol;

            item.Type = TypeMapper.Map(symbol.Type);

            if (member.Accessors != null)
            {
                if (member.Accessors.Any(a => a.Kind() == VisualBasic.SyntaxKind.GetAccessorBlock))
                {
                    item.Parameters += "get";
                }

                if (member.Accessors.Any(a => a.Kind() == VisualBasic.SyntaxKind.SetAccessorBlock))
                {
                    item.Parameters += string.IsNullOrEmpty(item.Parameters) ? "set" : ",set";
                }

                if (!string.IsNullOrEmpty(item.Parameters))
                {
                    item.Parameters = $" {{{item.Parameters}}}";
                }
            }

            item.Tooltip = TooltipMapper.Map(item.Access, item.Type, item.Name, item.Parameters);
            item.Kind    = CodeItemKindEnum.Property;
            item.Moniker = IconMapper.MapMoniker(item.Kind, item.Access);
            return(item);
        }
Esempio n. 17
0
        /// <summary>
        /// Map a switch statement
        /// </summary>
        /// <param name="statement"></param>
        /// <param name="control"></param>
        /// <param name="semanticModel"></param>
        /// <returns></returns>
        private static CodeItem MapSwitch(SwitchStatementSyntax statement, CodeViewUserControl control, SemanticModel semanticModel)
        {
            if (statement == null)
            {
                return(null);
            }

            var item = BaseMapper.MapBase <CodeClassItem>(statement, statement.Expression.ToString(), control, semanticModel);

            item.Name        = $"Switch {item.Name}";
            item.Kind        = CodeItemKindEnum.Switch;
            item.Moniker     = IconMapper.MapMoniker(item.Kind, item.Access);
            item.BorderBrush = ColorHelper.CreateSolidColorBrush(Colors.DarkGray);
            item.Tooltip     = TooltipMapper.Map(item.Access, string.Empty, item.Name, item.Parameters);

            // Map switch cases
            foreach (var section in statement.Sections)
            {
                item.Members.Add(MapSwitchSection(section, control, semanticModel));
            }

            return(item);
        }