public override MetadataItem DefaultVisit(ISymbol symbol) { if (!VisitorHelper.CanVisit(symbol)) { return(null); } var item = new MetadataItem { Name = VisitorHelper.GetId(symbol), RawComment = symbol.GetDocumentationCommentXml(), Language = Language, }; item.DisplayNames = new SortedList <SyntaxLanguage, string>(); item.DisplayQualifiedNames = new SortedList <SyntaxLanguage, string>(); item.Source = VisitorHelper.GetSourceDetail(symbol); var assemblyName = symbol.ContainingAssembly?.Name; item.AssemblyNameList = string.IsNullOrEmpty(assemblyName) ? null : new List <string> { assemblyName }; if (!(symbol is INamespaceSymbol)) { var namespaceName = VisitorHelper.GetId(symbol.ContainingNamespace); item.NamespaceName = string.IsNullOrEmpty(namespaceName) ? null : namespaceName; } VisitorHelper.FeedComments(item, GetTripleSlashCommentParserContext(item, _preserveRawInlineComments)); if (item.Exceptions != null) { foreach (var exceptions in item.Exceptions) { AddReference(exceptions.Type); } } if (item.Sees != null) { foreach (var i in item.Sees) { AddReference(i.Type); } } if (item.SeeAlsos != null) { foreach (var i in item.SeeAlsos) { AddReference(i.Type); } } _generator.DefaultVisit(symbol, item, this); return(item); }
public override void VisitField(IFieldSymbol symbol) { var id = VisitorHelper.GetId(symbol.OriginalDefinition); ReferenceItem.Parts[SyntaxLanguage.VB].Add(new LinkItem { DisplayName = NameVisitorCreator.GetVB(NameOptions.WithGenericParameter).GetName(symbol), DisplayQualifiedNames = NameVisitorCreator.GetVB(NameOptions.Qualified | NameOptions.WithGenericParameter).GetName(symbol), Name = id, IsExternalPath = symbol.IsExtern || symbol.DeclaringSyntaxReferences.Length == 0, }); }
public override MetadataItem VisitProperty(IPropertySymbol symbol) { MetadataItem result = GetYamlItem(symbol); if (result == null) { return(null); } if (result.Syntax == null) { result.Syntax = new SyntaxDetail { Content = new SortedList <SyntaxLanguage, string>() }; } if (result.Syntax.Parameters == null) { result.Syntax.Parameters = new List <ApiParameter>(); } if (result.Syntax.Content == null) { result.Syntax.Content = new SortedList <SyntaxLanguage, string>(); } _generator.GenerateSyntax(result.Type, symbol, result.Syntax, this); var typeGenericParameters = symbol.ContainingType.IsGenericType ? symbol.ContainingType.Accept(TypeGenericParameterNameVisitor.Instance) : EmptyListOfString; if (symbol.Parameters.Length > 0) { foreach (var p in symbol.Parameters) { var id = AddSpecReference(p.Type, typeGenericParameters); var param = VisitorHelper.GetParameterDescription(p, result, id, false, GetTripleSlashCommentParserContext(result, _preserveRawInlineComments)); Debug.Assert(param.Type != null); result.Syntax.Parameters.Add(param); } } { var id = AddSpecReference(symbol.Type, typeGenericParameters); result.Syntax.Return = VisitorHelper.GetParameterDescription(symbol, result, id, true, GetTripleSlashCommentParserContext(result, _preserveRawInlineComments)); Debug.Assert(result.Syntax.Return.Type != null); } if (symbol.IsOverride && symbol.OverriddenProperty != null) { result.Overridden = AddSpecReference(symbol.OverriddenProperty, typeGenericParameters); } _generator.GenerateProperty(symbol, result, this); return(result); }
public override MetadataItem VisitMethod(IMethodSymbol symbol) { MetadataItem result = GetYamlItem(symbol); if (result == null) { return(null); } if (result.Syntax == null) { result.Syntax = new SyntaxDetail { Content = new SortedList <SyntaxLanguage, string>() }; } if (symbol.TypeParameters.Length > 0) { if (result.Syntax.TypeParameters == null) { result.Syntax.TypeParameters = new List <ApiParameter>(); } foreach (var p in symbol.TypeParameters) { var param = VisitorHelper.GetTypeParameterDescription(p, result, GetTripleSlashCommentParserContext(result, _preserveRawInlineComments)); result.Syntax.TypeParameters.Add(param); } } var typeGenericParameters = symbol.ContainingType.IsGenericType ? symbol.ContainingType.Accept(TypeGenericParameterNameVisitor.Instance) : EmptyListOfString; var methodGenericParameters = symbol.IsGenericMethod ? (from p in symbol.TypeParameters select p.Name).ToList() : EmptyListOfString; AddMethodSyntax(symbol, result, typeGenericParameters, methodGenericParameters); if (result.Syntax.Content == null) { result.Syntax.Content = new SortedList <SyntaxLanguage, string>(); } _generator.GenerateSyntax(result.Type, symbol, result.Syntax, this); _generator.GenerateMethod(symbol, result, this); if (symbol.IsOverride && symbol.OverriddenMethod != null) { result.Overridden = AddSpecReference(symbol.OverriddenMethod, typeGenericParameters, methodGenericParameters); } return(result); }
private void AddInheritedMembers(INamedTypeSymbol symbol, INamedTypeSymbol type, Dictionary <string, string> dict, IReadOnlyList <string> typeParamterNames) { foreach (var m in from m in type.GetMembers() where !(m is INamedTypeSymbol) where VisitorHelper.CanVisit(m, symbol == type || !symbol.IsSealed || symbol.TypeKind != TypeKind.Struct) where IsInheritable(m) select m) { var sig = MemberSigRegex.Replace(SpecIdHelper.GetSpecId(m, typeParamterNames), string.Empty); if (!dict.ContainsKey(sig)) { dict.Add(sig, type == symbol ? null : AddSpecReference(m, typeParamterNames)); } } }
private ImplementsClauseSyntax GetImplementsClause(IPropertySymbol symbol) { if (symbol.ExplicitInterfaceImplementations.Length == 0) { return(null); } var list = (from eii in symbol.ExplicitInterfaceImplementations where VisitorHelper.CanVisit(eii) select SyntaxFactory.QualifiedName(GetQualifiedNameSyntax(eii.ContainingType), (SimpleNameSyntax)SyntaxFactory.ParseName(eii.Name))).ToList(); if (list.Count == 0) { return(null); } return(SyntaxFactory.ImplementsClause(SyntaxFactory.SeparatedList(list.ToArray()))); }
private static string GetEiiContainerTypeName(IPropertySymbol symbol) { if (symbol.ExplicitInterfaceImplementations.Length == 0) { return(null); } for (int i = 0; i < symbol.ExplicitInterfaceImplementations.Length; i++) { if (VisitorHelper.CanVisit(symbol.ExplicitInterfaceImplementations[i])) { return(NameVisitorCreator.GetCSharp(NameOptions.UseAlias | NameOptions.WithGenericParameter).GetName(symbol.ExplicitInterfaceImplementations[i].ContainingType)); } } Debug.Fail("Should not be here!"); return(null); }
private static string GetMemberName(IPropertySymbol symbol) { string name = symbol.Name; if (symbol.ExplicitInterfaceImplementations.Length == 0) { return(symbol.Name); } for (int i = 0; i < symbol.ExplicitInterfaceImplementations.Length; i++) { if (VisitorHelper.CanVisit(symbol.ExplicitInterfaceImplementations[i])) { return(symbol.ExplicitInterfaceImplementations[i].Name); } } Debug.Fail("Should not be here!"); return(symbol.Name); }
internal string AddReference(ISymbol symbol, Dictionary <string, ReferenceItem> references, SymbolVisitorAdapter adapter) { var id = VisitorHelper.GetId(symbol); ReferenceItem reference = new ReferenceItem(); 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); }
public override void VisitProperty(IPropertySymbol symbol) { var id = VisitorHelper.GetId(symbol.OriginalDefinition); ReferenceItem.Parts[SyntaxLanguage.VB].Add(new LinkItem { DisplayName = NameVisitorCreator.GetVB(NameOptions.WithGenericParameter).GetName(symbol), DisplayQualifiedNames = NameVisitorCreator.GetVB(NameOptions.Qualified | NameOptions.WithGenericParameter).GetName(symbol), Name = id, IsExternalPath = symbol.IsExtern || symbol.DeclaringSyntaxReferences.Length == 0, }); if (symbol.Parameters.Length > 0) { ReferenceItem.Parts[SyntaxLanguage.VB].Add(new LinkItem { DisplayName = "(", DisplayQualifiedNames = "(", }); for (int i = 0; i < symbol.Parameters.Length; i++) { if (i > 0) { ReferenceItem.Parts[SyntaxLanguage.VB].Add(new LinkItem { DisplayName = ", ", DisplayQualifiedNames = ", ", }); } symbol.Parameters[i].Type.Accept(this); } ReferenceItem.Parts[SyntaxLanguage.VB].Add(new LinkItem { DisplayName = ")", DisplayQualifiedNames = ")", }); } }
private void AddMethodSyntax(IMethodSymbol symbol, MetadataItem result, IReadOnlyList <string> typeGenericParameters, IReadOnlyList <string> methodGenericParameters) { if (!symbol.ReturnsVoid) { var id = AddSpecReference(symbol.ReturnType, typeGenericParameters, methodGenericParameters); result.Syntax.Return = VisitorHelper.GetParameterDescription(symbol, result, id, true, GetTripleSlashCommentParserContext(result, _preserveRawInlineComments)); } if (symbol.Parameters.Length > 0) { if (result.Syntax.Parameters == null) { result.Syntax.Parameters = new List <ApiParameter>(); } foreach (var p in symbol.Parameters) { var id = AddSpecReference(p.Type, typeGenericParameters, methodGenericParameters); var param = VisitorHelper.GetParameterDescription(p, result, id, false, GetTripleSlashCommentParserContext(result, _preserveRawInlineComments)); Debug.Assert(param.Type != null); result.Syntax.Parameters.Add(param); } } }
private MemberType GetMemberTypeFromSymbol(ISymbol symbol) { switch (symbol.Kind) { case SymbolKind.Namespace: return(MemberType.Namespace); case SymbolKind.NamedType: INamedTypeSymbol nameTypeSymbol = symbol as INamedTypeSymbol; Debug.Assert(nameTypeSymbol != null); if (nameTypeSymbol != null) { return(VisitorHelper.GetMemberTypeFromTypeKind(nameTypeSymbol.TypeKind)); } else { return(MemberType.Default); } case SymbolKind.Event: return(MemberType.Event); case SymbolKind.Field: return(MemberType.Field); case SymbolKind.Property: return(MemberType.Property); case SymbolKind.Method: { var methodSymbol = symbol as IMethodSymbol; Debug.Assert(methodSymbol != null); if (methodSymbol == null) { return(MemberType.Default); } switch (methodSymbol.MethodKind) { case MethodKind.AnonymousFunction: case MethodKind.DelegateInvoke: case MethodKind.Destructor: case MethodKind.ExplicitInterfaceImplementation: case MethodKind.Ordinary: case MethodKind.ReducedExtension: case MethodKind.DeclareMethod: return(MemberType.Method); case MethodKind.BuiltinOperator: case MethodKind.UserDefinedOperator: case MethodKind.Conversion: return(MemberType.Operator); case MethodKind.Constructor: case MethodKind.StaticConstructor: return(MemberType.Constructor); // ignore: Property's get/set, and event's add/remove/raise case MethodKind.PropertyGet: case MethodKind.PropertySet: case MethodKind.EventAdd: case MethodKind.EventRemove: case MethodKind.EventRaise: default: return(MemberType.Default); } } default: return(MemberType.Default); } }
public override string DefaultVisit(ISymbol symbol) { return(VisitorHelper.GetId(symbol)); }