|
7 | 7 | using System.Collections.Immutable; |
8 | 8 | using System.Diagnostics; |
9 | 9 | using System.Diagnostics.CodeAnalysis; |
10 | | -using System.Globalization; |
11 | 10 | using System.Linq; |
12 | | -using System.Text; |
13 | 11 | using System.Threading; |
14 | | -using Microsoft.CodeAnalysis.FindSymbols; |
15 | 12 | using Microsoft.CodeAnalysis.PooledObjects; |
16 | 13 | using Microsoft.CodeAnalysis.Shared.Extensions; |
17 | 14 | using Microsoft.CodeAnalysis.Shared.Utilities; |
|
20 | 17 |
|
21 | 18 | namespace Microsoft.CodeAnalysis.LanguageServices |
22 | 19 | { |
23 | | - internal abstract class AbstractDeclaredSymbolInfoFactoryService : IDeclaredSymbolInfoFactoryService |
24 | | - { |
25 | | - private const string GenericTypeNameManglingString = "`"; |
26 | | - private static readonly string[] s_aritySuffixesOneToNine = { "`1", "`2", "`3", "`4", "`5", "`6", "`7", "`8", "`9" }; |
27 | | - |
28 | | - private readonly static ObjectPool<List<Dictionary<string, string>>> s_aliasMapListPool |
29 | | - = SharedPools.Default<List<Dictionary<string, string>>>(); |
30 | | - |
31 | | - // Note: these names are stored case insensitively. That way the alias mapping works |
32 | | - // properly for VB. It will mean that our inheritance maps may store more links in them |
33 | | - // for C#. However, that's ok. It will be rare in practice, and all it means is that |
34 | | - // we'll end up examining slightly more types (likely 0) when doing operations like |
35 | | - // Find all references. |
36 | | - private readonly static ObjectPool<Dictionary<string, string>> s_aliasMapPool |
37 | | - = SharedPools.StringIgnoreCaseDictionary<string>(); |
38 | | - |
39 | | - protected static List<Dictionary<string, string>> AllocateAliasMapList() |
40 | | - => s_aliasMapListPool.Allocate(); |
41 | | - |
42 | | - protected static void FreeAliasMapList(List<Dictionary<string, string>> list) |
43 | | - { |
44 | | - if (list != null) |
45 | | - { |
46 | | - foreach (var aliasMap in list) |
47 | | - { |
48 | | - FreeAliasMap(aliasMap); |
49 | | - } |
50 | | - |
51 | | - s_aliasMapListPool.ClearAndFree(list); |
52 | | - } |
53 | | - } |
54 | | - |
55 | | - protected static void FreeAliasMap(Dictionary<string, string> aliasMap) |
56 | | - { |
57 | | - if (aliasMap != null) |
58 | | - { |
59 | | - s_aliasMapPool.ClearAndFree(aliasMap); |
60 | | - } |
61 | | - } |
62 | | - |
63 | | - protected static Dictionary<string, string> AllocateAliasMap() |
64 | | - => s_aliasMapPool.Allocate(); |
65 | | - |
66 | | - protected static void AppendTokens(SyntaxNode node, StringBuilder builder) |
67 | | - { |
68 | | - foreach (var child in node.ChildNodesAndTokens()) |
69 | | - { |
70 | | - if (child.IsToken) |
71 | | - { |
72 | | - builder.Append(child.AsToken().Text); |
73 | | - } |
74 | | - else |
75 | | - { |
76 | | - AppendTokens(child.AsNode(), builder); |
77 | | - } |
78 | | - } |
79 | | - } |
80 | | - |
81 | | - protected static void Intern(StringTable stringTable, ArrayBuilder<string> builder) |
82 | | - { |
83 | | - for (int i = 0, n = builder.Count; i < n; i++) |
84 | | - { |
85 | | - builder[i] = stringTable.Add(builder[i]); |
86 | | - } |
87 | | - } |
88 | | - |
89 | | - public static string GetMetadataAritySuffix(int arity) |
90 | | - { |
91 | | - Debug.Assert(arity > 0); |
92 | | - return (arity <= s_aritySuffixesOneToNine.Length) |
93 | | - ? s_aritySuffixesOneToNine[arity - 1] |
94 | | - : string.Concat(GenericTypeNameManglingString, arity.ToString(CultureInfo.InvariantCulture)); |
95 | | - } |
96 | | - |
97 | | - public abstract bool TryGetDeclaredSymbolInfo(StringTable stringTable, SyntaxNode node, string rootNamespace, out DeclaredSymbolInfo declaredSymbolInfo); |
98 | | - |
99 | | - /// <summary> |
100 | | - /// Get the name of the target type of specified extension method declaration. |
101 | | - /// The node provided must be an extension method declaration, i.e. calling `TryGetDeclaredSymbolInfo()` |
102 | | - /// on `node` should return a `DeclaredSymbolInfo` of kind `ExtensionMethod`. |
103 | | - /// If the return value is null, then it means this is a "complex" method (as described at <see cref="SyntaxTreeIndex.ExtensionMethodInfo"/>). |
104 | | - /// </summary> |
105 | | - public abstract string GetTargetTypeName(SyntaxNode node); |
106 | | - |
107 | | - public abstract bool TryGetAliasesFromUsingDirective(SyntaxNode node, out ImmutableArray<(string aliasName, string name)> aliases); |
108 | | - |
109 | | - public abstract string GetRootNamespace(CompilationOptions compilationOptions); |
110 | | - } |
111 | | - |
112 | 20 | internal abstract class AbstractSyntaxFactsService |
113 | 21 | { |
114 | 22 | private readonly static ObjectPool<Stack<(SyntaxNodeOrToken nodeOrToken, bool leading, bool trailing)>> s_stackPool |
|
0 commit comments