Example #1
0
        private static ImmutableArray <SymbolDisplayPart> ToDisplayParts(
            ISymbol symbol,
            SemanticModel?semanticModelOpt,
            int positionOpt,
            SymbolDisplayFormat format,
            bool minimal
            )
        {
            if (symbol == null)
            {
                throw new ArgumentNullException(nameof(symbol));
            }

            if (minimal)
            {
                if (semanticModelOpt == null)
                {
                    throw new ArgumentException(CSharpResources.SyntaxTreeSemanticModelMust);
                }
                else if (positionOpt < 0 || positionOpt > semanticModelOpt.SyntaxTree.Length) // Note: not >= since EOF is allowed.
                {
                    throw new ArgumentOutOfRangeException(CSharpResources.PositionNotWithinTree);
                }
            }
            else
            {
                Debug.Assert(semanticModelOpt == null);
                Debug.Assert(positionOpt < 0);
            }

            // Do not leak unspeakable name of a Simple Program entry point through diagnostics,
            // and, for consistency, with other display options.
            if (
                (symbol as Symbols.PublicModel.MethodSymbol)?.UnderlyingMethodSymbol
                is SynthesizedSimpleProgramEntryPointSymbol
                )
            {
                return(ImmutableArray.Create <SymbolDisplayPart>(
                           new SymbolDisplayPart(
                               SymbolDisplayPartKind.MethodName,
                               symbol,
                               "<top-level-statements-entry-point>"
                               )
                           ));
            }

            var builder = ArrayBuilder <SymbolDisplayPart> .GetInstance();

            var visitor = new SymbolDisplayVisitor(builder, format, semanticModelOpt, positionOpt);

            symbol.Accept(visitor);

            return(builder.ToImmutableAndFree());
        }
Example #2
0
        private static ImmutableArray <SymbolDisplayPart> ToDisplayParts(
            ISymbol symbol,
            CodeAnalysis.NullableAnnotation?nullableAnnotationOpt,
            SemanticModel semanticModelOpt,
            int positionOpt,
            SymbolDisplayFormat format,
            bool minimal)
        {
            if (symbol == null)
            {
                throw new ArgumentNullException(nameof(symbol));
            }

            Debug.Assert(!nullableAnnotationOpt.HasValue || symbol is ITypeSymbol);

            if (minimal)
            {
                if (semanticModelOpt == null)
                {
                    throw new ArgumentException(CSharpResources.SyntaxTreeSemanticModelMust);
                }
                else if (positionOpt < 0 || positionOpt > semanticModelOpt.SyntaxTree.Length) // Note: not >= since EOF is allowed.
                {
                    throw new ArgumentOutOfRangeException(CSharpResources.PositionNotWithinTree);
                }
            }
            else
            {
                Debug.Assert(semanticModelOpt == null);
                Debug.Assert(positionOpt < 0);
            }

            var builder = ArrayBuilder <SymbolDisplayPart> .GetInstance();

            var visitor = new SymbolDisplayVisitor(builder, format, semanticModelOpt, positionOpt);

            if (nullableAnnotationOpt.HasValue)
            {
                visitor.VisitWithNullableAnnotation((TypeSymbol)symbol, nullableAnnotationOpt.GetValueOrDefault().ToInternalAnnotation());
            }
            else
            {
                symbol.Accept(visitor);
            }

            return(builder.ToImmutableAndFree());
        }
Example #3
0
        private static ImmutableArray <SymbolDisplayPart> ToDisplayParts(
            ISymbol symbol,
            SemanticModel semanticModelOpt,
            int positionOpt,
            SymbolDisplayFormat format,
            bool minimal)
        {
            if (symbol == null)
            {
                throw new ArgumentNullException(nameof(symbol));
            }

            if (minimal)
            {
                if (semanticModelOpt == null)
                {
                    throw new ArgumentException(CSharpResources.SyntaxTreeSemanticModelMust);
                }
                else if (positionOpt < 0 || positionOpt > semanticModelOpt.SyntaxTree.Length) // Note: not >= since EOF is allowed.
                {
                    throw new ArgumentOutOfRangeException(CSharpResources.PositionNotWithinTree);
                }
            }
            else
            {
                Debug.Assert(semanticModelOpt == null);
                Debug.Assert(positionOpt < 0);
            }

            var builder = ArrayBuilder <SymbolDisplayPart> .GetInstance();

            var visitor = new SymbolDisplayVisitor(builder, format, semanticModelOpt, positionOpt);

            symbol.Accept(visitor);

            return(builder.ToImmutableAndFree());
        }
Example #4
0
        private static ImmutableArray<SymbolDisplayPart> ToDisplayParts(
            ISymbol symbol,
            SemanticModel semanticModelOpt,
            int positionOpt,
            SymbolDisplayFormat format,
            bool minimal)
        {
            if (symbol == null)
            {
                throw new ArgumentNullException(nameof(symbol));
            }

            if (minimal)
            {
                if (semanticModelOpt == null)
                {
                    throw new ArgumentException(CSharpResources.SyntaxTreeSemanticModelMust);
                }
                else if (positionOpt < 0 || positionOpt > semanticModelOpt.SyntaxTree.Length) // Note: not >= since EOF is allowed.
                {
                    throw new ArgumentOutOfRangeException(CSharpResources.PositionNotWithinTree);
                }
            }
            else
            {
                Debug.Assert(semanticModelOpt == null);
                Debug.Assert(positionOpt < 0);
            }

            var builder = ArrayBuilder<SymbolDisplayPart>.GetInstance();
            var visitor = new SymbolDisplayVisitor(builder, format, semanticModelOpt, positionOpt);
            symbol.Accept(visitor);

            return builder.ToImmutableAndFree();
        }