public static List <CodeItem> MapFunction(Node function, NodeArray <ParameterDeclaration> parameters, string id, ICodeViewUserControl control) { if (function == null) { return(null); } List <CodeItem> children; try { children = function.Children .FirstOrDefault(c => c.Kind == SyntaxKind.Block)?.Children .SelectMany(SyntaxMapperJS.MapMember) .ToList(); } catch (NullReferenceException) { return(new List <CodeItem>()); } if (children != null && children.Any()) { SyntaxMapper.FilterNullItems(children); var item = BaseMapperJS.MapBase <CodeClassItem>(function, id, control); item.BorderColor = Colors.DarkGray; item.Kind = CodeItemKindEnum.Method; item.Parameters = $"({string.Join(", ", parameters.Select(p => p.IdentifierStr))})"; item.Tooltip = TooltipMapper.Map(item.Access, null, item.Name, item.Parameters); item.Id = IdMapper.MapId(item.FullName, parameters); item.Moniker = IconMapper.MapMoniker(item.Kind, item.Access); item.Members = children; return(new List <CodeItem> { item }); } CodeFunctionItem functionItem = BaseMapperJS.MapBase <CodeFunctionItem>(function, id, control); functionItem.Kind = CodeItemKindEnum.Method; functionItem.Parameters = $"({string.Join(", ", parameters.Select(p => p.IdentifierStr))})"; functionItem.Tooltip = TooltipMapper.Map(functionItem.Access, null, functionItem.Name, functionItem.Parameters); functionItem.Id = IdMapper.MapId(functionItem.FullName, parameters); functionItem.Moniker = IconMapper.MapMoniker(functionItem.Kind, functionItem.Access); return(new List <CodeItem> { functionItem }); }
private static List <CodeItem> MapVariable(VariableStatement variable) { var declarator = variable.DeclarationList.Declarations.First(); if (declarator.Initializer != null) { switch (declarator.Initializer.Kind) { case SyntaxKind.FunctionExpression: return(FunctionMapperJS.MapFunctionExpression(declarator, _control)); case SyntaxKind.ArrowFunction: return(FunctionMapperJS.MapArrowFunctionExpression(declarator, _control)); case SyntaxKind.NewExpression: return(FunctionMapperJS.MapNewExpression(declarator, _control)); default: break; } } if (variable.Parent.Kind != SyntaxKind.SourceFile) { return(new List <CodeItem>()); } var item = BaseMapperJS.MapBase <CodeItem>(variable, declarator.IdentifierStr, _control); item.Kind = CodeItemKindEnum.Variable; item.Moniker = IconMapper.MapMoniker(item.Kind, item.Access); return(new List <CodeItem> { item }); }