public static GetId ( ISymbol symbol ) : string | ||
symbol | ISymbol | |
Résultat | string |
public override MetadataItem VisitAssembly(IAssemblySymbol symbol) { var item = new MetadataItem { Name = VisitorHelper.GetId(symbol), RawComment = symbol.GetDocumentationCommentXml(), Language = Language, }; item.DisplayNames = new SortedList <SyntaxLanguage, string> { { SyntaxLanguage.Default, symbol.MetadataName }, }; item.DisplayQualifiedNames = new SortedList <SyntaxLanguage, string> { { SyntaxLanguage.Default, symbol.MetadataName }, }; item.Type = MemberType.Assembly; _references = new Dictionary <string, ReferenceItem>(); var namespaces = symbol.GlobalNamespace.GetNamespaceMembers().ToList(); if (namespaces.Count == 0) { Logger.LogWarning($"No namespace is found in assembly {symbol.MetadataName}. DocFX currently only supports generating metadata with namespace defined."); } item.Items = VisitDescendants( namespaces, ns => ns.GetMembers().OfType <INamespaceSymbol>(), ns => ns.GetMembers().OfType <INamedTypeSymbol>().Any(t => FilterVisitor.CanVisitApi(t))); item.References = _references; return(item); }
public bool ContainedIn(ISymbol symbol) { bool result = false; var attributes = symbol.GetAttributes(); foreach (var attribute in attributes) { INamedTypeSymbol attributeClass = attribute.AttributeClass; if (Uid != VisitorHelper.GetId(attributeClass)) { continue; } // arguments need to be a total match of the config IEnumerable <string> arguments = attribute.ConstructorArguments.Select(arg => GetLiteralString(arg)); if (!ConstructorArguments.SequenceEqual(arguments)) { continue; } // namedarguments need to be a superset of the config Dictionary <string, string> namedArguments = attribute.NamedArguments.ToDictionary(pair => pair.Key, pair => GetLiteralString(pair.Value)); if (!ConstructorNamedArguments.Except(namedArguments).Any()) { result = true; break; } } return(result); }
protected override void AddLinkItems(INamedTypeSymbol symbol, bool withGenericeParameter) { var id = VisitorHelper.GetId(symbol); if (withGenericeParameter) { ReferenceItem.Parts[SyntaxLanguage.VB].Add(new LinkItem { DisplayName = NameVisitorCreator.GetVB(NameOptions.WithGenericParameter).GetName(symbol), DisplayNamesWithType = NameVisitorCreator.GetVB(NameOptions.WithType | NameOptions.WithGenericParameter).GetName(symbol), DisplayQualifiedNames = NameVisitorCreator.GetVB(NameOptions.Qualified | NameOptions.WithGenericParameter).GetName(symbol), Name = id, IsExternalPath = symbol.IsExtern || symbol.DeclaringSyntaxReferences.Length == 0, }); } else { ReferenceItem.Parts[SyntaxLanguage.VB].Add(new LinkItem { DisplayName = NameVisitorCreator.GetVB(NameOptions.None).GetName(symbol), DisplayNamesWithType = NameVisitorCreator.GetVB(NameOptions.WithType).GetName(symbol), DisplayQualifiedNames = NameVisitorCreator.GetVB(NameOptions.Qualified).GetName(symbol), Name = id, IsExternalPath = symbol.IsExtern || symbol.DeclaringSyntaxReferences.Length == 0, }); } }
public override void VisitMethod(IMethodSymbol 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, }); 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 = ")", }); }
internal string AddSpecReference( ISymbol symbol, IReadOnlyList <string> typeGenericParameters, IReadOnlyList <string> methodGenericParameters, Dictionary <string, ReferenceItem> references, SymbolVisitorAdapter adapter, bool useDef = false) { var id = useDef ? VisitorHelper.GetId(symbol) : SpecIdHelper.GetSpecId(symbol, typeGenericParameters, methodGenericParameters); ReferenceItem reference = new ReferenceItem(); reference.Parts = new SortedList <SyntaxLanguage, List <LinkItem> >(); GenerateReferenceInternal(symbol, reference, adapter); reference.IsDefinition = symbol.IsDefinition; if (!symbol.IsDefinition) { var def = symbol.OriginalDefinition; var typeParameters = def.Accept(TypeGenericParameterNameVisitor.Instance); reference.Definition = AddSpecReference(def, typeParameters, null, references, adapter, true); } reference.Parent = GetReferenceParent(symbol, typeGenericParameters, methodGenericParameters, references, adapter); if (!references.ContainsKey(id)) { references[id] = reference; } else { references[id].Merge(reference); } return(id); }
public static SymbolFilterData GetSymbolFilterData(ISymbol symbol) { return(new SymbolFilterData { Id = VisitorHelper.GetId(symbol), Kind = GetExtendedSymbolKindFromSymbol(symbol), Attributes = symbol.GetAttributes().Select(GetAttributeFilterData) }); }
/// <summary> /// spec extension method's receiver type. /// for below overload: M(this A), M(this A, A), AddReference applies to the first method and AddSpecReference applies to the second method might get same id without prepending receiver type. /// </summary> /// <param name="symbol">symbol</param> /// <param name="id">id</param> /// <returns>id prefixed with receiver type</returns> private static string SpecExtensionMethodReceiverType(IMethodSymbol symbol, string id) { if (symbol.ReducedFrom == null || symbol.ReceiverType == null) { return(id); } return(VisitorHelper.GetId(symbol.ReceiverType) + "." + id); }
public override MetadataItem DefaultVisit(ISymbol symbol) { if (!FilterVisitor.CanVisitApi(symbol)) { return(null); } var item = new MetadataItem { Name = VisitorHelper.GetId(symbol), CommentId = VisitorHelper.GetCommentId(symbol), RawComment = symbol.GetDocumentationCommentXml(), Language = Language, }; item.DisplayNames = new SortedList <SyntaxLanguage, string>(); item.DisplayNamesWithType = 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, exceptions.CommentId); } } if (item.Sees != null) { foreach (var i in item.Sees.Where(l => l.LinkType == LinkType.CRef)) { AddReference(i.LinkId, i.CommentId); } } if (item.SeeAlsos != null) { foreach (var i in item.SeeAlsos.Where(l => l.LinkType == LinkType.CRef)) { AddReference(i.LinkId, i.CommentId); } } _generator.DefaultVisit(symbol, item, this); return(item); }
public static AttributeFilterData GetAttributeFilterData(AttributeData attribute) { return(new AttributeFilterData { Id = VisitorHelper.GetId(attribute.AttributeClass), ConstructorArguments = attribute.ConstructorArguments.Select(GetLiteralString), ConstructorNamedArguments = attribute.NamedArguments.ToDictionary(pair => pair.Key, pair => GetLiteralString(pair.Value)) }); }
public bool IsMatch(ISymbol symbol) { if (symbol == null) { throw new ArgumentNullException("symbol"); } return((_uidRegex == null || _uidRegex.IsMatch(VisitorHelper.GetId(symbol))) && (Kind == null || Kind.Value.Contains(symbol)) && (Attribute == null || Attribute.ContainedIn(symbol))); }
public override void VisitDynamicType(IDynamicTypeSymbol symbol) { var id = VisitorHelper.GetId(symbol.OriginalDefinition); ReferenceItem.Parts[SyntaxLanguage.CSharp].Add(new LinkItem { DisplayName = NameVisitorCreator.GetCSharp(NameOptions.None).GetName(symbol), DisplayNamesWithType = NameVisitorCreator.GetCSharp(NameOptions.WithType).GetName(symbol), DisplayQualifiedNames = NameVisitorCreator.GetCSharp(NameOptions.Qualified).GetName(symbol), Name = id, }); }
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, }); }
internal string AddSpecReference( ISymbol symbol, IReadOnlyList <string> typeGenericParameters, IReadOnlyList <string> methodGenericParameters, Dictionary <string, ReferenceItem> references, SymbolVisitorAdapter adapter) { var rawId = VisitorHelper.GetId(symbol); var id = SpecIdHelper.GetSpecId(symbol, typeGenericParameters, methodGenericParameters); if (string.IsNullOrEmpty(id)) { throw new InvalidDataException($"Fail to parse id for symbol {symbol.MetadataName} in namespace {symbol.ContainingSymbol?.MetadataName}."); } ReferenceItem reference = new ReferenceItem() { Parts = new SortedList <SyntaxLanguage, List <LinkItem> >() }; GenerateReferenceInternal(symbol, reference, adapter); var originalSymbol = symbol; var reducedFrom = (symbol as IMethodSymbol)?.ReducedFrom; if (reducedFrom != null) { originalSymbol = reducedFrom; } reference.IsDefinition = (originalSymbol == symbol) && (id == rawId) && (symbol.IsDefinition || VisitorHelper.GetId(symbol.OriginalDefinition) == rawId); if (!reference.IsDefinition.Value && rawId != null) { reference.Definition = AddReference(originalSymbol.OriginalDefinition, references, adapter); } reference.Parent = GetReferenceParent(originalSymbol, typeGenericParameters, methodGenericParameters, references, adapter); reference.CommentId = VisitorHelper.GetCommentId(originalSymbol); if (!references.ContainsKey(id)) { references[id] = reference; } else { references[id].Merge(reference); } return(id); }
private static string GetLiteralString(TypedConstant constant) { if (constant.Kind == TypedConstantKind.Enum) { var namedType = (INamedTypeSymbol)constant.Type; var name = (from member in namedType.GetMembers().OfType <IFieldSymbol>() where member.IsConst && member.HasConstantValue where constant.Value.Equals(member.ConstantValue) select member.Name).FirstOrDefault(); if (name != null) { return($"{VisitorHelper.GetId(namedType)}.{name}"); } // todo : define filter data format (language neutral), just use number for combine case by now. // e.g.: [Flags] public enum E { X=1,Y=2,Z=4,YZ=6 } // Case: [E(E.X | E.Y)] // Case: [E((E)99)] // Case: [E(E.X | E.YZ)] return(constant.Value.ToString()); } if (constant.Kind == TypedConstantKind.Array) { if (constant.Values.IsDefaultOrEmpty) { return(""); } return(string.Join(",", constant.Values.Select(GetLiteralString))); } var value = constant.Value; if (value is ISymbol) { return(VisitorHelper.GetId(constant.Value as ISymbol)); } return(value?.ToString() ?? "null"); }
internal string AddSpecReference( ISymbol symbol, IReadOnlyList <string> typeGenericParameters, IReadOnlyList <string> methodGenericParameters, Dictionary <string, ReferenceItem> references, SymbolVisitorAdapter adapter) { var rawId = VisitorHelper.GetId(symbol); var id = SpecIdHelper.GetSpecId(symbol, typeGenericParameters, methodGenericParameters); ReferenceItem reference = new ReferenceItem(); reference.Parts = new SortedList <SyntaxLanguage, List <LinkItem> >(); GenerateReferenceInternal(symbol, reference, adapter); var originalSymbol = symbol; var reducedFrom = (symbol as IMethodSymbol)?.ReducedFrom; if (reducedFrom != null) { originalSymbol = reducedFrom; } reference.IsDefinition = (originalSymbol == symbol) && (id == rawId) && symbol.IsDefinition; if (!reference.IsDefinition.Value && rawId != null) { reference.Definition = AddReference(originalSymbol.OriginalDefinition, references, adapter); } reference.Parent = GetReferenceParent(originalSymbol, typeGenericParameters, methodGenericParameters, references, adapter); reference.CommentId = VisitorHelper.GetCommentId(originalSymbol); if (!references.ContainsKey(id)) { references[id] = reference; } else { references[id].Merge(reference); } return(id); }
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 MetadataItem VisitAssembly(IAssemblySymbol symbol) { var item = new MetadataItem { Name = VisitorHelper.GetId(symbol), RawComment = symbol.GetDocumentationCommentXml(), Language = Language, }; item.DisplayNames = new SortedList <SyntaxLanguage, string> { { SyntaxLanguage.Default, symbol.MetadataName }, }; item.DisplayQualifiedNames = new SortedList <SyntaxLanguage, string> { { SyntaxLanguage.Default, symbol.MetadataName }, }; item.Type = MemberType.Assembly; _references = new Dictionary <string, ReferenceItem>(); IEnumerable <INamespaceSymbol> namespaces; if (!string.IsNullOrEmpty(VisitorHelper.GlobalNamespaceId)) { namespaces = Enumerable.Repeat(symbol.GlobalNamespace, 1); } else { namespaces = symbol.GlobalNamespace.GetNamespaceMembers(); } item.Items = VisitDescendants( namespaces, ns => ns.GetMembers().OfType <INamespaceSymbol>(), ns => ns.GetMembers().OfType <INamedTypeSymbol>().Any(t => FilterVisitor.CanVisitApi(t))); item.References = _references; return(item); }
private static string GetLiteralString(TypedConstant constant) { var type = constant.Type; var value = constant.Value; if (type.TypeKind == TypeKind.Enum) { var namedType = (INamedTypeSymbol)type; var pairs = (from member in namedType.GetMembers().OfType <IFieldSymbol>() where member.IsConst && member.HasConstantValue select Tuple.Create(member.Name, member.ConstantValue)).ToDictionary(tuple => tuple.Item2, tuple => tuple.Item1); return($"{VisitorHelper.GetId(namedType)}.{pairs[value]}"); } if (value is ITypeSymbol) { return(VisitorHelper.GetId((ITypeSymbol)value)); } return(value.ToString()); }
public override MetadataItem VisitAssembly(IAssemblySymbol symbol) { var item = new MetadataItem { Name = VisitorHelper.GetId(symbol), RawComment = symbol.GetDocumentationCommentXml(), Language = Language, }; item.DisplayNames = new SortedList <SyntaxLanguage, string> { { SyntaxLanguage.Default, symbol.MetadataName }, }; item.DisplayQualifiedNames = new SortedList <SyntaxLanguage, string> { { SyntaxLanguage.Default, symbol.MetadataName }, }; item.Type = MemberType.Assembly; _references = new Dictionary <string, ReferenceItem>(); var typeMembers = symbol.GlobalNamespace.GetTypeMembers(); if (typeMembers.Any()) { Logger.LogWarning($"DocFX currently only supports generating metadata with namespace defined. The following types in assembly \"{symbol.MetadataName}\" will have no metadata generated: {string.Join(", ", typeMembers.Select(m => m.MetadataName))}. "); } var namespaces = symbol.GlobalNamespace.GetNamespaceMembers().ToList(); item.Items = VisitDescendants( namespaces, ns => ns.GetMembers().OfType <INamespaceSymbol>(), ns => ns.GetMembers().OfType <INamedTypeSymbol>().Any(t => FilterVisitor.CanVisitApi(t))); item.References = _references; return(item); }
public override string DefaultVisit(ISymbol symbol) { return(VisitorHelper.GetId(symbol)); }
public override void VisitProperty(IPropertySymbol symbol) { var id = _asOverload ? VisitorHelper.GetOverloadId(symbol.OriginalDefinition) : VisitorHelper.GetId(symbol.OriginalDefinition); ReferenceItem.Parts[SyntaxLanguage.CSharp].Add(new LinkItem { DisplayName = NameVisitorCreator.GetCSharp(NameOptions.WithTypeGenericParameter).GetName(symbol), DisplayNamesWithType = NameVisitorCreator.GetCSharp(NameOptions.WithType | NameOptions.WithTypeGenericParameter).GetName(symbol), DisplayQualifiedNames = NameVisitorCreator.GetCSharp(NameOptions.Qualified | NameOptions.WithTypeGenericParameter).GetName(symbol), Name = id, IsExternalPath = symbol.IsExtern || symbol.DeclaringSyntaxReferences.Length == 0, }); if (symbol.Parameters.Length > 0 && !_asOverload) { ReferenceItem.Parts[SyntaxLanguage.CSharp].Add(new LinkItem { DisplayName = "[", DisplayNamesWithType = "[", DisplayQualifiedNames = "[", }); for (int i = 0; i < symbol.Parameters.Length; i++) { if (i > 0) { ReferenceItem.Parts[SyntaxLanguage.CSharp].Add(new LinkItem { DisplayName = ", ", DisplayNamesWithType = ", ", DisplayQualifiedNames = ", ", }); } symbol.Parameters[i].Type.Accept(this); } ReferenceItem.Parts[SyntaxLanguage.CSharp].Add(new LinkItem { DisplayName = "]", DisplayNamesWithType = "]", DisplayQualifiedNames = "]", }); } }