예제 #1
0
        private static void Test(CSharpCompilation compilation, Func <string, bool> predicate, bool includeNamespace, bool includeType, bool includeMember, int count)
        {
            SymbolFilter filter = ComputeFilter(includeNamespace, includeType, includeMember);

            Assert.Equal(count > 0, compilation.ContainsSymbolsWithName(predicate, filter));
            Assert.Equal(count, compilation.GetSymbolsWithName(predicate, filter).Count());
        }
예제 #2
0
        private static void Test(CSharpCompilation compilation, Func <string, bool> predicate, bool includeNamespace, bool includeType, bool includeMember, int count)
        {
            var filter = SymbolFilter.None;

            filter = includeNamespace ? filter | SymbolFilter.Namespace : filter;
            filter = includeType ? filter | SymbolFilter.Type : filter;
            filter = includeMember ? filter | SymbolFilter.Member : filter;

            Assert.Equal(count > 0, compilation.ContainsSymbolsWithName(predicate, filter));
            Assert.Equal(count, compilation.GetSymbolsWithName(predicate, filter).Count());
        }
예제 #3
0
        private static void Test(CSharpCompilation compilation, Func<string, bool> predicate, bool includeNamespace, bool includeType, bool includeMember, int count)
        {
            var filter = SymbolFilter.None;
            filter = includeNamespace ? filter | SymbolFilter.Namespace : filter;
            filter = includeType ? filter | SymbolFilter.Type : filter;
            filter = includeMember ? filter | SymbolFilter.Member : filter;

            Assert.Equal(count > 0, compilation.ContainsSymbolsWithName(predicate, filter));
            Assert.Equal(count, compilation.GetSymbolsWithName(predicate, filter).Count());
        }
예제 #4
0
        // Returns the name of the declared API if the node is the type of node that should have an XML doc comment
        // otherwise returns null;
        public string GetAPIForNode(SyntaxNode node)
        {
            switch (node.Kind())
            {
            case SyntaxKind.ConstructorDeclaration:
            {
                ConstructorDeclarationSyntax syntax = (ConstructorDeclarationSyntax)node;
                // assume only one field/identifier
                string text = syntax.Identifier.Text;
                // for now assume only one match
                if (m_compilation.ContainsSymbolsWithName(symbolName => symbolName == text))
                {
                    var symbols = m_compilation.GetSymbolsWithName(symbolName => symbolName == text);
                    // but which one is the right one?
                    var symbol = symbols.Single();
                    return(symbol.GetDocumentationCommentId());
                }
                return(null);
            }

            case SyntaxKind.ConversionOperatorDeclaration:
            {
                ConversionOperatorDeclarationSyntax syntax = (ConversionOperatorDeclarationSyntax)node;
                // assume only one field/identifier
                string text = syntax.OperatorKeyword.Text;
                // for now assume only one match
                if (m_compilation.ContainsSymbolsWithName(symbolName => symbolName == text))
                {
                    var symbols = m_compilation.GetSymbolsWithName(symbolName => symbolName == text);
                    // but which one is the right one?
                    var symbol = symbols.Single();
                    return(symbol.GetDocumentationCommentId());
                }
                return(null);
            }

            case SyntaxKind.DelegateDeclaration:
            {
                DelegateDeclarationSyntax syntax = (DelegateDeclarationSyntax)node;
                // assume only one field/identifier
                string text = syntax.Identifier.Text;
                // for now assume only one match
                if (m_compilation.ContainsSymbolsWithName(symbolName => symbolName == text))
                {
                    var symbols = m_compilation.GetSymbolsWithName(symbolName => symbolName == text);
                    // but which one is the right one?
                    var symbol = symbols.Single();
                    return(symbol.GetDocumentationCommentId());
                }
                return(null);
            }

            case SyntaxKind.EnumDeclaration:
            {
                EnumDeclarationSyntax syntax = (EnumDeclarationSyntax)node;
                // assume only one field/identifier
                string text = syntax.Identifier.Text;
                // for now assume only one match
                if (m_compilation.ContainsSymbolsWithName(symbolName => symbolName == text))
                {
                    var symbols = m_compilation.GetSymbolsWithName(symbolName => symbolName == text);
                    // but which one is the right one?
                    var symbol = symbols.Single();
                    return(symbol.GetDocumentationCommentId());
                }
                return(null);
            }

            case SyntaxKind.EventDeclaration:
            {
                /* EventDeclarationSyntax syntax = (EventDeclarationSyntax)node;
                 *
                 * string text = syntax.Identifier.Text;
                 * // for now assume only one match
                 * if (m_compilation.ContainsSymbolsWithName(symbolName => symbolName == text))
                 * {
                 *   var symbols = m_compilation.GetSymbolsWithName(symbolName => symbolName == text);
                 *   // but which one is the right one?
                 *   var symbol = symbols.Single();
                 *   return symbol.GetDocumentationCommentId();
                 * }*/
                return(null);
            }

            case SyntaxKind.FieldDeclaration:
            {
                FieldDeclarationSyntax syntax = (FieldDeclarationSyntax)node;
                // assume only one field/identifier
                string text = syntax.Declaration.Variables.First().Identifier.Text;
                // for now assume only one match
                if (m_compilation.ContainsSymbolsWithName(symbolName => symbolName == text))
                {
                    var symbols = m_compilation.GetSymbolsWithName(symbolName => symbolName == text);
                    // but which one is the right one?
                    var symbol = symbols.Single();
                    return(symbol.GetDocumentationCommentId());
                }
                return(null);
            }

            case SyntaxKind.IndexerDeclaration:
            {
                IndexerDeclarationSyntax syntax = (IndexerDeclarationSyntax)node;
                string text = syntax.ThisKeyword.Text;
                // for now assume only one match
                if (m_compilation.ContainsSymbolsWithName(symbolName => symbolName == text))
                {
                    var symbols = m_compilation.GetSymbolsWithName(symbolName => symbolName == text);
                    // but which one is the right one?
                    var symbol = symbols.Single();
                    return(symbol.GetDocumentationCommentId());
                }
                return(null);
            }

            case SyntaxKind.InterfaceDeclaration:
            {
                InterfaceDeclarationSyntax syntax = (InterfaceDeclarationSyntax)node;
                string text = syntax.Identifier.Text;
                // for now assume only one match
                if (m_compilation.ContainsSymbolsWithName(symbolName => symbolName == text))
                {
                    var symbols = m_compilation.GetSymbolsWithName(symbolName => symbolName == text);
                    // but which one is the right one?
                    var symbol = symbols.Single();
                    return(symbol.GetDocumentationCommentId());
                }
                return(null);
            }

            case SyntaxKind.MethodDeclaration:
            {
                MethodDeclarationSyntax methodDeclarationSyntax = (MethodDeclarationSyntax)node;
                string text       = methodDeclarationSyntax.Identifier.Text;
                var    parameters = methodDeclarationSyntax.ParameterList.Parameters;

                if (m_compilation.ContainsSymbolsWithName(symbolName => symbolName == text))
                {
                    var symbols = m_compilation.GetSymbolsWithName(symbolName => symbolName == text);

                    // select the symbol whose declaring syntax reference matches the node's syntax reference.
                    //var symbol = symbols.Where(s => s.DeclaringSyntaxReferences.Contains(node.GetReference())).Single();

                    foreach (var symbol in symbols)
                    {
                        var references = symbol.DeclaringSyntaxReferences;
                        foreach (var reference in references)
                        {
                            SyntaxNode testNode = reference.GetSyntax();
                            if (testNode.Equals(node))
                            {
                                Console.WriteLine("Matched nodes.");
                            }
                        }
                    }

                    // find the one that corresponds to this syntax node.
                    //foreach (var symbol in symbols)
                    //{
                    //     IMethodSymbol methodsymbol = (IMethodSymbol)symbol;
                    //     symbol.DeclaringSyntaxReferences.Select(syntaxReference => syntaxReference == node.GetReference());
                    //
                    //}
                    return(symbols.First().GetDocumentationCommentId());
                }
                return(null);
            }

            case SyntaxKind.NamespaceDeclaration:     // doesn't work
            {
                NamespaceDeclarationSyntax syntax = (NamespaceDeclarationSyntax)node;
                NameSyntax nameSyntax             = syntax.Name;
                string     text = nameSyntax.ToFullString();
                // for now assume only one match
                if (m_compilation.ContainsSymbolsWithName(symbolName => symbolName == text))
                {
                    var symbols = m_compilation.GetSymbolsWithName(symbolName => symbolName == text);
                    // but which one is the right one?
                    var symbol = symbols.Single();
                    return(symbol.GetDocumentationCommentId());
                }
                return(null);
            }

            case SyntaxKind.OperatorDeclaration:
            {
                OperatorDeclarationSyntax syntax = (OperatorDeclarationSyntax)node;
                // this won't work, it needs to be figured out.
                string text = syntax.OperatorKeyword.Text + syntax.OperatorToken.Text;
                // for now assume only one match
                if (m_compilation.ContainsSymbolsWithName(symbolName => symbolName == text))
                {
                    var symbols = m_compilation.GetSymbolsWithName(symbolName => symbolName == text);
                    // but which one is the right one?
                    var symbol = symbols.Single();
                    return(symbol.GetDocumentationCommentId());
                }
                return(null);
            }

            case SyntaxKind.PropertyDeclaration:
            {
                PropertyDeclarationSyntax syntax = (PropertyDeclarationSyntax)node;
                string text = syntax.Identifier.Text;
                // for now assume only one match
                if (m_compilation.ContainsSymbolsWithName(symbolName => symbolName == text))
                {
                    var symbols = m_compilation.GetSymbolsWithName(symbolName => symbolName == text);
                    // but which one is the right one?
                    var symbol = symbols.Single();
                    return(symbol.GetDocumentationCommentId());
                }
                return(null);
            }

            case SyntaxKind.ClassDeclaration:
            {
                Microsoft.CodeAnalysis.CSharp.Syntax.ClassDeclarationSyntax classSyntax = (ClassDeclarationSyntax)node;
                string text      = classSyntax.Identifier.Text;
                string valueText = classSyntax.Identifier.ValueText;
                // for now assume only one match
                var symbols = m_compilation.GetSymbolsWithName(symbolName => symbolName == text);
                // but which one is the right one?
                var symbol = symbols.Single();
                return(symbol.GetDocumentationCommentId());
            }

            case SyntaxKind.StructDeclaration:
            {
                Microsoft.CodeAnalysis.CSharp.Syntax.StructDeclarationSyntax structSyntax = (StructDeclarationSyntax)node;
                string text      = structSyntax.Identifier.Text;
                string valueText = structSyntax.Identifier.ValueText;

                // for now assume only one match
                var symbols = m_compilation.GetSymbolsWithName(symbolName => symbolName == text);
                // but which one is the right one?
                var symbol = symbols.Single();
                return(symbol.GetDocumentationCommentId());
            }

            default:
                return(null);
            }


            //var types = m_compilation.GlobalNamespace.GetTypeMembers(name);
            //m_compilation.GetTypeByMetadataName()
            //string docCommentId = classSymbol.GetDocumentationCommentId();
            return("");
        }