Skip to content

Commit dd19218

Browse files
authored
Merge pull request #41514 from CyrusNajmabadi/extractType
Extract type into its own file.
2 parents 49652a3 + 1539613 commit dd19218

File tree

2 files changed

+104
-92
lines changed

2 files changed

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

src/Workspaces/Core/Portable/LanguageServices/SyntaxFactsService/AbstractSyntaxFactsService.cs

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@
77
using System.Collections.Immutable;
88
using System.Diagnostics;
99
using System.Diagnostics.CodeAnalysis;
10-
using System.Globalization;
1110
using System.Linq;
12-
using System.Text;
1311
using System.Threading;
14-
using Microsoft.CodeAnalysis.FindSymbols;
1512
using Microsoft.CodeAnalysis.PooledObjects;
1613
using Microsoft.CodeAnalysis.Shared.Extensions;
1714
using Microsoft.CodeAnalysis.Shared.Utilities;
@@ -20,95 +17,6 @@
2017

2118
namespace Microsoft.CodeAnalysis.LanguageServices
2219
{
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-
11220
internal abstract class AbstractSyntaxFactsService
11321
{
11422
private readonly static ObjectPool<Stack<(SyntaxNodeOrToken nodeOrToken, bool leading, bool trailing)>> s_stackPool

0 commit comments

Comments
 (0)