Пример #1
0
        internal static DocumentedElement LoadFromSyntaxNode(VariableDeclarationSyntax variable, SyntaxTriviaList syntaxTriviaList)
        {
            SyntaxToken syntaxToken = variable
                                      .ChildNodes().First(token => token.IsKind(SyntaxKind.VariableDeclarator))
                                      .ChildTokens().First(token => token.IsKind(SyntaxKind.IdentifierToken));

            return(DocumentedElement.LoadFromSyntaxTokenAndTrivia(syntaxToken, syntaxTriviaList));
        }
Пример #2
0
        public static PropertySpec LoadFromSyntaxNode(PropertyDeclarationSyntax node)
        {
            PropertySpec propertySpec = new PropertySpec();

            propertySpec.IsStatic = node.Modifiers.Any(modifier => modifier.IsKind(SyntaxKind.StaticKeyword));
            propertySpec.Type     = node.Type.ToString();
            propertySpec.Name     = DocumentedElement.LoadFromSyntaxNode(node);
            return(propertySpec);
        }
Пример #3
0
        internal static ConstructorSpec LoadFromSyntaxNode(ConstructorDeclarationSyntax node)
        {
            ConstructorSpec constructorSpec = new ConstructorSpec();

            foreach (ParameterSyntax parameter in node.ParameterList.Parameters)
            {
                constructorSpec.Parameters.Add(ParameterSpec.LoadFromSyntaxNode(parameter));
            }

            constructorSpec.Name = DocumentedElement.LoadFromSyntaxNode(node);
            return(constructorSpec);
        }
Пример #4
0
        internal static MethodSpec LoadFromSyntaxNode(MethodDeclarationSyntax node)
        {
            MethodSpec methodSpec = new MethodSpec();

            foreach (ParameterSyntax parameter in node.ParameterList.Parameters)
            {
                methodSpec.Parameters.Add(ParameterSpec.LoadFromSyntaxNode(parameter));
            }

            methodSpec.Name       = DocumentedElement.LoadFromSyntaxNode(node);
            methodSpec.ReturnType = node.ReturnType.ToString();
            return(methodSpec);
        }
Пример #5
0
        private static DocumentedElement LoadFromSyntaxTokenAndTrivia(SyntaxToken token, SyntaxTriviaList triviaList)
        {
            DocumentedElement element = new DocumentedElement();

            element.Name = token.Text;

            // Break apart lines that come as a single group, remove empty lines, and trim whitespace overall.
            element.Documentation = triviaList.SelectMany(line => line.ToFullString().Split(new[] { '\r', '\n' })).ToList();
            element.Documentation = element.Documentation
                                    .Where(line => !string.IsNullOrWhiteSpace(line))
                                    .Select(line => line.Trim()).ToList();

            return(element);
        }
Пример #6
0
        public static FieldSpec LoadFromSyntaxNode(FieldDeclarationSyntax node)
        {
            FieldSpec fieldSpec = new FieldSpec();

            fieldSpec.IsConst    = node.Modifiers.Any(modifier => modifier.IsKind(SyntaxKind.ConstKeyword));
            fieldSpec.IsReadonly = node.Modifiers.Any(modifier => modifier.IsKind(SyntaxKind.ReadOnlyKeyword));
            fieldSpec.IsStatic   = node.Modifiers.Any(modifier => modifier.IsKind(SyntaxKind.StaticKeyword));

            // Null access will throw and be caught in our overall analyzer handler.
            VariableDeclarationSyntax variable = node.ChildNodes()
                                                 .FirstOrDefault(childNode => childNode.IsKind(SyntaxKind.VariableDeclaration)) as VariableDeclarationSyntax;

            fieldSpec.Type = variable.Type.ToString();
            fieldSpec.Name = DocumentedElement.LoadFromSyntaxNode(variable, node.GetLeadingTrivia());
            return(fieldSpec);
        }
Пример #7
0
        internal static DocumentedElement LoadFromSyntaxNode(PropertyDeclarationSyntax node)
        {
            SyntaxToken syntaxToken = node.ChildTokens().First(token => token.IsKind(SyntaxKind.IdentifierToken));

            return(DocumentedElement.LoadFromSyntaxTokenAndTrivia(syntaxToken, node.GetLeadingTrivia()));
        }