Esempio n. 1
0
        public override Evaluation VisitNameMemberCref(NameMemberCrefSyntax node)
        {
            node.Name?.Accept <Evaluation>(this);
            node.Parameters?.Accept <Evaluation>(this);

            return(base.VisitNameMemberCref(node));
        }
        private bool SeeTagIsCorrect(XmlEmptyElementSyntax classReferencePart, BaseMethodDeclarationSyntax constructorDeclarationSyntax)
        {
            if (classReferencePart.Name.ToString() == XmlCommentHelper.SeeXmlTag)
            {
                XmlCrefAttributeSyntax crefAttribute = classReferencePart.Attributes.OfType <XmlCrefAttributeSyntax>().FirstOrDefault();

                if (crefAttribute != null)
                {
                    NameMemberCrefSyntax nameMember = crefAttribute.Cref as NameMemberCrefSyntax;

                    if (nameMember != null && nameMember.Parameters == null)
                    {
                        ClassDeclarationSyntax classDeclarationSyntax = constructorDeclarationSyntax.FirstAncestorOrSelf <ClassDeclarationSyntax>();

                        if (classDeclarationSyntax != null &&
                            classDeclarationSyntax.Identifier.ToString() == this.GetName(nameMember.Name))
                        {
                            // Check if type parameters are called the same
                            if (TypeParameterNamesMatch(classDeclarationSyntax, nameMember.Name))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
Esempio n. 3
0
        private ImmutableArray <Symbol> BindNameMemberCref(NameMemberCrefSyntax syntax, NamespaceOrTypeSymbol?containerOpt, out Symbol?ambiguityWinner, BindingDiagnosticBag diagnostics)
        {
            SimpleNameSyntax?nameSyntax = syntax.Name as SimpleNameSyntax;

            int    arity;
            string memberName;
            string memberNameText;

            if (nameSyntax != null)
            {
                arity          = nameSyntax.Arity;
                memberName     = nameSyntax.Identifier.ValueText;
                memberNameText = nameSyntax.Identifier.Text;
            }
            else
            {
                // If the name isn't a SimpleNameSyntax, then we must have a type name followed by a parameter list.
                // Thus, we're looking for a constructor.
                Debug.Assert((object?)containerOpt == null);

                // Could be an error type, but we'll just lookup fail below.
                containerOpt = BindNamespaceOrTypeSymbolInCref(syntax.Name);

                arity      = 0;
                memberName = memberNameText = WellKnownMemberNames.InstanceConstructorName;
            }

            if (string.IsNullOrEmpty(memberName))
            {
                ambiguityWinner = null;
                return(ImmutableArray <Symbol> .Empty);
            }

            ImmutableArray <Symbol> sortedSymbols = ComputeSortedCrefMembers(syntax, containerOpt, memberName, memberNameText, arity, syntax.Parameters != null, diagnostics);

            if (sortedSymbols.IsEmpty)
            {
                ambiguityWinner = null;
                return(ImmutableArray <Symbol> .Empty);
            }

            return(ProcessCrefMemberLookupResults(
                       sortedSymbols,
                       arity,
                       syntax,
                       typeArgumentListSyntax: arity == 0 ? null : ((GenericNameSyntax)nameSyntax !).TypeArgumentList,
                       parameterListSyntax: syntax.Parameters,
                       ambiguityWinner: out ambiguityWinner,
                       diagnostics: diagnostics));
        }
Esempio n. 4
0
        public override void VisitNameMemberCref(NameMemberCrefSyntax node)
        {
            if (!PreVisit(node))
            {
                return;
            }

            node.Name?.Accept(this);
            node.Parameters?.Accept(this);

            base.VisitNameMemberCref(node);

            PostVisit(node);
        }
        internal void HandleCref(NameMemberCrefSyntax cref)
        {
            var symbolInfo = semanticModel.GetSymbolInfo(cref, cancellationToken);

            if (symbolInfo.Symbol is IMethodSymbol method && cref.Parameters != null)
            {
                foreach (var(crefParam, param) in cref.Parameters.Parameters.Zip(method.Parameters))
                {
                    var crefType   = crefParam.Type.Accept(this);
                    var symbolType = typeSystem.GetSymbolType(param, ignoreAttributes: true);
                    // create bidirectional edge between both
                    typeSystemBuilder.CreateTypeEdge(crefType, symbolType, null, VarianceKind.None, new EdgeLabel("cref", crefParam));
                }
            }
        }
Esempio n. 6
0
        /// <inheritdoc/>
        public override SyntaxNode?VisitNameMemberCref(NameMemberCrefSyntax node)
        {
            SymbolInfo info = SemanticModel.GetSymbolInfo(node);

            if (info.Symbol is not INamedTypeSymbol symbol)
            {
                return(base.VisitNameMemberCref(node));
            }

            string[] namespaces = symbol.GetContainingNamespacesAndTypes().Select(n => n.Name).ToArray();

            if (namespaces.Length == 0)
            {
                return(base.VisitNameMemberCref(node));
            }
            else if (namespaces.Length == 1)
            {
                return(QualifiedCref(IdentifierName(namespaces[0]), node.WithoutTrivia()).WithTriviaFrom(node));
            }
            else
            {
                return(QualifiedCref(AnalysisUtilities.JoinIntoQualifiedName(namespaces) !, node.WithoutTrivia()).WithTriviaFrom(node));
            }
        }
            public override SyntaxNode VisitNameMemberCref(NameMemberCrefSyntax node)
            {
                _cancellationToken.ThrowIfCancellationRequested();
                var rewrittenname = (TypeSyntax)this.Visit(node.Name);
                var parameters = (CrefParameterListSyntax)this.Visit(node.Parameters);

                if (rewrittenname.Kind() == SyntaxKind.QualifiedName)
                {
                    return node.CopyAnnotationsTo(SyntaxFactory.QualifiedCref(
                        ((QualifiedNameSyntax)rewrittenname).Left
                            .WithAdditionalAnnotations(Simplifier.Annotation),
                        SyntaxFactory.NameMemberCref(((QualifiedNameSyntax)rewrittenname).Right, parameters)
                        .WithLeadingTrivia(SyntaxTriviaList.Empty))
                            .WithLeadingTrivia(node.GetLeadingTrivia())
                            .WithTrailingTrivia(node.GetTrailingTrivia()))
                            .WithAdditionalAnnotations(Simplifier.Annotation);
                }
                else if (rewrittenname.Kind() == SyntaxKind.AliasQualifiedName)
                {
                    return node.CopyAnnotationsTo(SyntaxFactory.TypeCref(
                        rewrittenname).WithLeadingTrivia(node.GetLeadingTrivia())
                        .WithTrailingTrivia(node.GetTrailingTrivia()))
                        .WithAdditionalAnnotations(Simplifier.Annotation);
                }

                return node.Update(rewrittenname, parameters);
            }
        private ImmutableArray<Symbol> BindNameMemberCref(NameMemberCrefSyntax syntax, NamespaceOrTypeSymbol containerOpt, out Symbol ambiguityWinner, DiagnosticBag diagnostics)
        {
            SimpleNameSyntax nameSyntax = syntax.Name as SimpleNameSyntax;

            int arity;
            string memberName;

            if (nameSyntax != null)
            {
                arity = nameSyntax.Arity;
                memberName = nameSyntax.Identifier.ValueText;
            }
            else
            {
                // If the name isn't a SimpleNameSyntax, then we must have a type name followed by a parameter list.
                // Thus, we're looking for a constructor.
                Debug.Assert((object)containerOpt == null);

                // Could be an error type, but we'll just lookup fail below.
                containerOpt = BindNamespaceOrTypeSymbolInCref(syntax.Name);

                arity = 0;
                memberName = WellKnownMemberNames.InstanceConstructorName;
            }

            if (string.IsNullOrEmpty(memberName))
            {
                ambiguityWinner = null;
                return ImmutableArray<Symbol>.Empty;
            }

            ImmutableArray<Symbol> sortedSymbols = ComputeSortedCrefMembers(syntax, containerOpt, memberName, arity, syntax.Parameters != null, diagnostics);

            if (sortedSymbols.IsEmpty)
            {
                ambiguityWinner = null;
                return ImmutableArray<Symbol>.Empty;
            }

            return ProcessCrefMemberLookupResults(
                sortedSymbols,
                arity,
                syntax,
                typeArgumentListSyntax: arity == 0 ? null : ((GenericNameSyntax)nameSyntax).TypeArgumentList,
                parameterListSyntax: syntax.Parameters,
                ambiguityWinner: out ambiguityWinner,
                diagnostics: diagnostics);
        }
 public override void VisitNameMemberCref(NameMemberCrefSyntax node)
 {
     base.VisitNameMemberCref(node);
     var sym = parent.semanticModel.GetSymbolInfo(node).Symbol;
     if (sym == null)
         parent.AddXmlIssue(node.Span.Start, node.Span.Length, string.Format(GettextCatalog.GetString("Cannot find reference '{0}'"), node.Name));
 }
Esempio n. 10
0
 public override void VisitNameMemberCref(NameMemberCrefSyntax node)
 {
     base.VisitNameMemberCref(node);
 }
 public override SyntaxNode VisitNameMemberCref(NameMemberCrefSyntax node)
 {
     node = (NameMemberCrefSyntax)base.VisitNameMemberCref(node);
     Classes.Add(node);
     return(node);
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="node"></param>
 public override sealed void VisitNameMemberCref(NameMemberCrefSyntax node)
 {
     this.OnNodeVisited(node, this.type.IsInstanceOfType(node));
     base.VisitNameMemberCref(node);
 }
Esempio n. 13
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="node"></param>
 public override sealed void VisitNameMemberCref(NameMemberCrefSyntax node)
 {
     this.OnNodeVisited(node);
     if (!this.traverseRootOnly) base.VisitNameMemberCref(node);
 }
 //
 // Summary:
 //     Called when the visitor visits a NameMemberCrefSyntax node.
 public virtual void VisitNameMemberCref(NameMemberCrefSyntax node);
        private static void Analyze(SyntaxNodeAnalysisContext context, CrefSyntax cref, NameMemberCrefSyntax nameMemberCref)
        {
            if (nameMemberCref.Name is not IdentifierNameSyntax identifierName)
            {
                return;
            }

            if (!SupportsPredefinedType(identifierName))
            {
                return;
            }

            if (context.SemanticModel.GetSymbol(identifierName, context.CancellationToken) is not ITypeSymbol typeSymbol)
            {
                return;
            }

            if (!CSharpFacts.IsPredefinedType(typeSymbol.SpecialType))
            {
                return;
            }

            IAliasSymbol aliasSymbol = context.SemanticModel.GetAliasInfo(identifierName, context.CancellationToken);

            if (aliasSymbol != null)
            {
                return;
            }

            ReportDiagnostic(context, cref);
        }