-
Notifications
You must be signed in to change notification settings - Fork 0
/
TypeCollector.cs
32 lines (27 loc) · 976 Bytes
/
TypeCollector.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
namespace CodeContextCollector
{
internal class TypeCollector : CSharpSyntaxWalker
{
private readonly SemanticModel _semanticModel;
public TypeCollector(SemanticModel semanticModel)
{
_semanticModel = semanticModel;
}
public HashSet<INamedTypeSymbol> TypeSymbols { get; } = new HashSet<INamedTypeSymbol>(SymbolEqualityComparer.Default);
public override void VisitIdentifierName(IdentifierNameSyntax node)
{
var symbolInfo = _semanticModel.GetSymbolInfo(node);
if (symbolInfo.Symbol is INamedTypeSymbol symbol && symbol.Locations.Any(loc => loc.IsInSource))
{
TypeSymbols.Add(symbol);
}
base.VisitIdentifierName(node);
}
}
}