Пример #1
0
        internal string AddReference(ISymbol symbol, MemberType type, string summary, Dictionary <string, ReferenceItem> references, SymbolVisitorAdapter adapter)
        {
            var id = VisitorHelper.GetId(symbol);

            ReferenceItem reference = new ReferenceItem();

            reference.Type         = type;
            reference.Summary      = summary;
            reference.Parts        = new SortedList <SyntaxLanguage, List <LinkItem> >();
            reference.IsDefinition = symbol.IsDefinition;
            GenerateReferenceInternal(symbol, reference, adapter);

            if (!references.ContainsKey(id))
            {
                references[id] = reference;
            }
            else
            {
                references[id].Merge(reference);
            }

            return(id);
        }
Пример #2
0
 public virtual void GenerateEvent(IEventSymbol symbol, MetadataItem item, SymbolVisitorAdapter adapter)
 {
 }
Пример #3
0
 public virtual void GenerateProperty(IPropertySymbol symbol, MetadataItem item, SymbolVisitorAdapter adapter)
 {
 }
Пример #4
0
 public virtual void GenerateMethod(IMethodSymbol symbol, MetadataItem item, SymbolVisitorAdapter adapter)
 {
 }
Пример #5
0
 public virtual void GenerateField(IFieldSymbol symbol, MetadataItem item, SymbolVisitorAdapter adapter)
 {
 }
Пример #6
0
 public virtual void DefaultVisit(ISymbol symbol, MetadataItem item, SymbolVisitorAdapter adapter)
 {
 }
Пример #7
0
 public virtual void GenerateNamedType(INamedTypeSymbol symbol, MetadataItem item, SymbolVisitorAdapter adapter)
 {
 }
Пример #8
0
 internal abstract void GenerateReferenceInternal(ISymbol symbol, ReferenceItem reference, SymbolVisitorAdapter adapter);
Пример #9
0
 internal abstract void GenerateSyntax(MemberType type, ISymbol symbol, SyntaxDetail syntax, SymbolVisitorAdapter adapter);
Пример #10
0

        
Пример #11
0

        
Пример #12
0

        
Пример #13
0

        
Пример #14
0
        protected override string GetSyntaxContent(MemberType typeKind, ISymbol symbol, SymbolVisitorAdapter adapter)
        {
            string syntaxStr = null;

            switch (typeKind)
            {
            case MemberType.Class:
            {
                var typeSymbol = (INamedTypeSymbol)symbol;
                syntaxStr = SyntaxFactory.ClassDeclaration(
                    new SyntaxList <AttributeListSyntax>(),
                    SyntaxFactory.TokenList(GetTypeModifiers(typeSymbol)),
                    SyntaxFactory.Identifier(typeSymbol.Name),
                    GetTypeParameters(typeSymbol),
                    GetBaseTypeList(typeSymbol),
                    SyntaxFactory.List(GetTypeParameterConstraints(typeSymbol)),
                    new SyntaxList <MemberDeclarationSyntax>())
                            .NormalizeWhitespace()
                            .ToString();
                syntaxStr = RemoveBraces(syntaxStr);
                break;
            }

            case MemberType.Enum:
            {
                var typeSymbol = (INamedTypeSymbol)symbol;
                syntaxStr = SyntaxFactory.EnumDeclaration(
                    new SyntaxList <AttributeListSyntax>(),
                    SyntaxFactory.TokenList(GetTypeModifiers(typeSymbol)),
                    SyntaxFactory.Identifier(typeSymbol.Name),
                    GetEnumBaseTypeList(typeSymbol),
                    new SeparatedSyntaxList <EnumMemberDeclarationSyntax>())
                            .NormalizeWhitespace()
                            .ToString();
                syntaxStr = RemoveBraces(syntaxStr);
                break;
            }

            case MemberType.Interface:
            {
                var typeSymbol = (INamedTypeSymbol)symbol;
                syntaxStr = SyntaxFactory.InterfaceDeclaration(
                    new SyntaxList <AttributeListSyntax>(),
                    SyntaxFactory.TokenList(GetTypeModifiers(typeSymbol)),
                    SyntaxFactory.Identifier(typeSymbol.Name),
                    GetTypeParameters(typeSymbol),
                    GetBaseTypeList(typeSymbol),
                    SyntaxFactory.List(GetTypeParameterConstraints(typeSymbol)),
                    new SyntaxList <MemberDeclarationSyntax>())
                            .NormalizeWhitespace()
                            .ToString();
                syntaxStr = RemoveBraces(syntaxStr);
                break;
            }

            case MemberType.Struct:
            {
                var typeSymbol = (INamedTypeSymbol)symbol;
                syntaxStr = SyntaxFactory.StructDeclaration(
                    new SyntaxList <AttributeListSyntax>(),
                    SyntaxFactory.TokenList(GetTypeModifiers(typeSymbol)),
                    SyntaxFactory.Identifier(typeSymbol.Name),
                    GetTypeParameters(typeSymbol),
                    GetBaseTypeList(typeSymbol),
                    SyntaxFactory.List(GetTypeParameterConstraints(typeSymbol)),
                    new SyntaxList <MemberDeclarationSyntax>())
                            .NormalizeWhitespace()
                            .ToString();
                syntaxStr = RemoveBraces(syntaxStr);
                break;
            }

            case MemberType.Delegate:
            {
                var typeSymbol = (INamedTypeSymbol)symbol;
                syntaxStr = SyntaxFactory.DelegateDeclaration(
                    new SyntaxList <AttributeListSyntax>(),
                    SyntaxFactory.TokenList(GetTypeModifiers(typeSymbol)),
                    GetTypeSyntax(typeSymbol.DelegateInvokeMethod.ReturnType),
                    SyntaxFactory.Identifier(typeSymbol.Name),
                    GetTypeParameters(typeSymbol),
                    SyntaxFactory.ParameterList(
                        SyntaxFactory.SeparatedList(
                            from p in typeSymbol.DelegateInvokeMethod.Parameters
                            select GetParameter(p))),
                    SyntaxFactory.List(GetTypeParameterConstraints(typeSymbol)))
                            .NormalizeWhitespace()
                            .ToString();
                break;
            }

            case MemberType.Method:
            {
                var methodSymbol = (IMethodSymbol)symbol;
                ExplicitInterfaceSpecifierSyntax eii = null;
                if (methodSymbol.ExplicitInterfaceImplementations.Length > 0)
                {
                    eii = SyntaxFactory.ExplicitInterfaceSpecifier(SyntaxFactory.ParseName(GetEiiContainerTypeName(methodSymbol)));
                }
                syntaxStr = SyntaxFactory.MethodDeclaration(
                    new SyntaxList <AttributeListSyntax>(),
                    SyntaxFactory.TokenList(GetMemberModifiers(methodSymbol)),
                    GetTypeSyntax(methodSymbol.ReturnType),
                    eii,
                    SyntaxFactory.Identifier(GetMemberName(methodSymbol)),
                    GetTypeParameters(methodSymbol),
                    SyntaxFactory.ParameterList(
                        SyntaxFactory.SeparatedList(
                            from p in methodSymbol.Parameters
                            select GetParameter(p))),
                    SyntaxFactory.List(GetTypeParameterConstraints(methodSymbol)),
                    null,
                    null)
                            .NormalizeWhitespace()
                            .ToString();
                break;
            }

            case MemberType.Operator:
            {
                var methodSymbol  = (IMethodSymbol)symbol;
                var operatorToken = GetOperatorToken(methodSymbol);
                if (operatorToken == null)
                {
                    syntaxStr = "Not supported in c#";
                }
                else if (operatorToken.Value.Kind() == SyntaxKind.ImplicitKeyword || operatorToken.Value.Kind() == SyntaxKind.ExplicitKeyword)
                {
                    syntaxStr = SyntaxFactory.ConversionOperatorDeclaration(
                        new SyntaxList <AttributeListSyntax>(),
                        SyntaxFactory.TokenList(GetMemberModifiers(methodSymbol)),
                        operatorToken.Value,
                        GetTypeSyntax(methodSymbol.ReturnType),
                        SyntaxFactory.ParameterList(
                            SyntaxFactory.SeparatedList(
                                from p in methodSymbol.Parameters
                                select GetParameter(p))),
                        null,
                        null)
                                .NormalizeWhitespace()
                                .ToString();
                }
                else
                {
                    syntaxStr = SyntaxFactory.OperatorDeclaration(
                        new SyntaxList <AttributeListSyntax>(),
                        SyntaxFactory.TokenList(GetMemberModifiers(methodSymbol)),
                        GetTypeSyntax(methodSymbol.ReturnType),
                        operatorToken.Value,
                        SyntaxFactory.ParameterList(
                            SyntaxFactory.SeparatedList(
                                from p in methodSymbol.Parameters
                                select GetParameter(p))),
                        null,
                        null)
                                .NormalizeWhitespace()
                                .ToString();
                }
                break;
            }

            case MemberType.Constructor:
            {
                var methodSymbol = (IMethodSymbol)symbol;
                syntaxStr = SyntaxFactory.ConstructorDeclaration(
                    new SyntaxList <AttributeListSyntax>(),
                    SyntaxFactory.TokenList(GetMemberModifiers(methodSymbol)),
                    SyntaxFactory.Identifier(methodSymbol.ContainingType.Name),
                    SyntaxFactory.ParameterList(
                        SyntaxFactory.SeparatedList(
                            from p in methodSymbol.Parameters
                            select GetParameter(p))),
                    null,
                    null)
                            .NormalizeWhitespace()
                            .ToString();
                break;
            };

            case MemberType.Field:
            {
                var fieldSymbol = (IFieldSymbol)symbol;
                if (fieldSymbol.ContainingType.TypeKind == TypeKind.Enum)
                {
                    syntaxStr = SyntaxFactory.EnumMemberDeclaration(
                        new SyntaxList <AttributeListSyntax>(),
                        SyntaxFactory.Identifier(fieldSymbol.Name),
                        GetDefaultValueClause(fieldSymbol))
                                .NormalizeWhitespace()
                                .ToString();
                }
                else
                {
                    syntaxStr = SyntaxFactory.FieldDeclaration(
                        new SyntaxList <AttributeListSyntax>(),
                        SyntaxFactory.TokenList(GetMemberModifiers(fieldSymbol)),
                        SyntaxFactory.VariableDeclaration(
                            GetTypeSyntax(fieldSymbol.Type),
                            SyntaxFactory.SingletonSeparatedList(
                                SyntaxFactory.VariableDeclarator(
                                    SyntaxFactory.Identifier(fieldSymbol.Name)))))
                                .NormalizeWhitespace()
                                .ToString()
                                .TrimEnd(';');
                }
                break;
            };

            case MemberType.Event:
            {
                var eventSymbol = (IEventSymbol)symbol;
                ExplicitInterfaceSpecifierSyntax eii = null;
                if (eventSymbol.ExplicitInterfaceImplementations.Length > 0)
                {
                    eii = SyntaxFactory.ExplicitInterfaceSpecifier(SyntaxFactory.ParseName(GetEiiContainerTypeName(eventSymbol)));
                }
                syntaxStr = SyntaxFactory.EventDeclaration(
                    new SyntaxList <AttributeListSyntax>(),
                    SyntaxFactory.TokenList(GetMemberModifiers(eventSymbol)),
                    SyntaxFactory.Token(SyntaxKind.EventKeyword),
                    GetTypeSyntax(eventSymbol.Type),
                    eii,
                    SyntaxFactory.Identifier(GetMemberName(eventSymbol)),
                    SyntaxFactory.AccessorList())
                            .NormalizeWhitespace()
                            .ToString();
                syntaxStr = RemoveBraces(syntaxStr);
                break;
            };

            case MemberType.Property:
            {
                var propertySymbol = (IPropertySymbol)symbol;
                ExplicitInterfaceSpecifierSyntax eii = null;
                if (propertySymbol.ExplicitInterfaceImplementations.Length > 0)
                {
                    eii = SyntaxFactory.ExplicitInterfaceSpecifier(SyntaxFactory.ParseName(GetEiiContainerTypeName(propertySymbol)));
                }
                if (propertySymbol.IsIndexer)
                {
                    syntaxStr = SyntaxFactory.IndexerDeclaration(
                        new SyntaxList <AttributeListSyntax>(),
                        SyntaxFactory.TokenList(GetMemberModifiers(propertySymbol)),
                        GetTypeSyntax(propertySymbol.Type),
                        eii,
                        SyntaxFactory.BracketedParameterList(
                            SyntaxFactory.SeparatedList(
                                from p in propertySymbol.Parameters
                                select GetParameter(p))),
                        SyntaxFactory.AccessorList(SyntaxFactory.List(GetPropertyAccessors(propertySymbol))))
                                .NormalizeWhitespace()
                                .ToString();
                }
                else
                {
                    syntaxStr = SyntaxFactory.PropertyDeclaration(
                        new SyntaxList <AttributeListSyntax>(),
                        SyntaxFactory.TokenList(GetMemberModifiers(propertySymbol)),
                        GetTypeSyntax(propertySymbol.Type),
                        eii,
                        SyntaxFactory.Identifier(GetMemberName(propertySymbol)),
                        SyntaxFactory.AccessorList(SyntaxFactory.List(GetPropertyAccessors(propertySymbol))))
                                .NormalizeWhitespace()
                                .ToString();
                }
                break;
            };
            }

            return(syntaxStr);
        }
Пример #15
0
 protected override void GenerateReference(ISymbol symbol, ReferenceItem reference, SymbolVisitorAdapter adapter)
 {
     symbol.Accept(new CSReferenceItemVisitor(reference));
 }
Пример #16
0
 public override void DefaultVisit(ISymbol symbol, MetadataItem item, SymbolVisitorAdapter adapter)
 {
     item.DisplayNames[SyntaxLanguage.CSharp]          = NameVisitorCreator.GetCSharp(NameOptions.WithGenericParameter | NameOptions.WithParameter).GetName(symbol);
     item.DisplayQualifiedNames[SyntaxLanguage.CSharp] = NameVisitorCreator.GetCSharp(NameOptions.Qualified | NameOptions.WithGenericParameter | NameOptions.WithParameter).GetName(symbol);
 }