public override void VisitIdentifierName(IdentifierNameSyntax node) { var refSymbol = RoslynUtils.GetReferenceSymbol(node, _semanticModel); if (refSymbol != null && RoslynUtils.IsVariableSymbol(refSymbol) && refSymbol.Locations[0].IsInSource) { var typeSymbol = RoslynUtils.GetVariableTypeSymbol(refSymbol); if (typeSymbol.ToString() == _targetType) { _inScopeSymbols.Add(_tokenToLocation(node.GetLocation(), node.ToString()), new ScopeData(SymbolToString(refSymbol), new HashSet <String>(_semanticModel.LookupSymbols(node.GetLocation().SourceSpan.End).Where(s => RoslynUtils.IsVariableSymbol(s)). Where(s => s.Locations[0].IsInSource). Where(s => RoslynUtils.GetVariableTypeSymbol(s).ToString() == _targetType).Select(s => SymbolToString(s))))); } } base.VisitIdentifierName(node); }
public string GetNodeType(SyntaxNodeOrToken node) { if (!_nodeToTypeStringCache.TryGetValue(node, out var res)) { // Handle some literal types: if (node.IsKind(SyntaxKind.StringLiteralToken)) { res = "string"; } else if (node.IsKind(SyntaxKind.CharacterLiteralToken)) { res = "char"; } else if (node.IsKind(SyntaxKind.NumericLiteralToken)) { res = node.AsToken().Value.GetType().Name.ToLower(); } else { var syntaxNode = node.IsNode ? node.AsNode() : node.AsToken().Parent; if (syntaxNode != null) { ISymbol symbol = RoslynUtils.GetReferenceSymbol(syntaxNode, SemanticModel); if (RoslynUtils.GetTypeSymbol(symbol, out var typeSymbol)) { res = typeSymbol.ToString(); } else { res = NOTYPE_NAME; } } else { res = NOTYPE_NAME; } } _nodeToTypeStringCache[node] = res; } return(res); }