Exemple #1
0
        public override SyntaxNode VisitGenericName(GenericNameSyntax node)
        {
            node = node.WithTypeArgumentList((TypeArgumentListSyntax)VisitTypeArgumentList(node.TypeArgumentList));
            // Don't call base.VisitGenericName(), since VisitIdentifierName() may double-widen identifier

            if (AttributeMatchUtil.HasTriviaAnnotationSimple(node.GetLeadingTrivia(), WidenAttributeName))
            {
                node = (GenericNameSyntax)WidenType(node);
            }

            return(node);
        }
Exemple #2
0
            public override SyntaxNode VisitGenericName(GenericNameSyntax node)
            {
                // We only care about xml doc comments
                var leadingTrivia = CanHaveDocComments(node) ? VisitList(node.GetLeadingTrivia()) : node.GetLeadingTrivia();

                if (_namespaceMembers.Contains(node.Identifier.Text))
                {
                    // No need to visit type argument list as simplifier will expand everything
                    var expanded = Simplifier.Expand <SyntaxNode>(node, _model, _workspace, cancellationToken: _cancellationToken);
                    return(expanded.WithLeadingTrivia(leadingTrivia));
                }

                var typeArgumentList = (TypeArgumentListSyntax)base.Visit(node.TypeArgumentList);

                return(node.Update(node.Identifier.WithLeadingTrivia(leadingTrivia), typeArgumentList));
            }
Exemple #3
0
        public override SyntaxNode VisitGenericName(GenericNameSyntax node)
        {
            var symbol = semanticModel.GetSymbolInfo(node).Symbol;

            var parent = node.Parent;

            while (parent != null && !(parent is TypeDeclarationSyntax))
            {
                parent = parent.Parent;
            }

            ITypeSymbol thisType = null;

            if (parent is TypeDeclarationSyntax)
            {
                thisType = this.semanticModel.GetDeclaredSymbol(parent) as ITypeSymbol;
            }

            bool needHandle = !node.IsVar &&
                              symbol is ITypeSymbol &&
                              symbol.ContainingType != null &&
                              thisType != null &&
                              !thisType.InheritsFromOrEquals(symbol.ContainingType) &&
                              !thisType.Equals(symbol);

            var qns = node.Parent as QualifiedNameSyntax;

            if (qns != null && needHandle)
            {
                SyntaxNode n = node;
                do
                {
                    if (!qns.Left.Equals(n))
                    {
                        needHandle = false;
                    }

                    n   = qns;
                    qns = qns.Parent as QualifiedNameSyntax;
                } while (qns != null && needHandle);
            }

            node = (GenericNameSyntax)base.VisitGenericName(node);

            if (needHandle && !(node.Parent is MemberAccessExpressionSyntax))
            {
                INamedTypeSymbol namedType = symbol as INamedTypeSymbol;
                if (namedType != null && namedType.IsGenericType && namedType.TypeArguments.Length > 0 && !namedType.TypeArguments.Any(SyntaxHelper.IsAnonymous))
                {
                    return(SyntaxHelper.GenerateGenericName(SyntaxFactory.Identifier(node.GetLeadingTrivia(), symbol.FullyQualifiedName(false), node.GetTrailingTrivia()), namedType.TypeArguments));
                }

                return(SyntaxFactory.IdentifierName(SyntaxFactory.Identifier(node.GetLeadingTrivia(), symbol.FullyQualifiedName(), node.GetTrailingTrivia())));
            }

            IMethodSymbol methodSymbol = null;

            if (symbol != null && symbol.IsStatic && symbol.ContainingType != null &&
                thisType != null && !thisType.InheritsFromOrEquals(symbol.ContainingType) &&
                !(node.Parent is MemberAccessExpressionSyntax) &&
                (
                    (methodSymbol = symbol as IMethodSymbol) != null ||
                    symbol is IPropertySymbol ||
                    symbol is IFieldSymbol ||
                    symbol is IEventSymbol)
                )
            {
                if (methodSymbol != null && methodSymbol.IsGenericMethod && methodSymbol.TypeArguments.Length > 0 && !methodSymbol.TypeArguments.Any(SyntaxHelper.IsAnonymous))
                {
                    return(SyntaxHelper.GenerateGenericName(SyntaxFactory.Identifier(node.GetLeadingTrivia(), symbol.FullyQualifiedName(false), node.GetTrailingTrivia()), methodSymbol.TypeArguments));
                }

                return(SyntaxFactory.IdentifierName(SyntaxFactory.Identifier(node.GetLeadingTrivia(), symbol.FullyQualifiedName(), node.GetTrailingTrivia())));
            }

            return(node);
        }