internal async Task<IEnumerable<ISymbol>> GetMatchingTypesAsync( Microsoft.CodeAnalysis.Project project, SemanticModel semanticModel, SyntaxNode node, CancellationToken cancellationToken) { // Can't be on the right hand side of binary expression (like 'dot'). cancellationToken.ThrowIfCancellationRequested(); string name; int arity; node.GetNameAndArityOfSimpleName(out name, out arity); var symbols = await SymbolFinder.FindDeclarationsAsync(project, name, this.IgnoreCase, SymbolFilter.Type, cancellationToken).ConfigureAwait(false); // also lookup type symbols with the "Attribute" suffix. var inAttributeContext = node.IsAttributeName(); if (inAttributeContext) { symbols = symbols.Concat( await SymbolFinder.FindDeclarationsAsync(project, name + "Attribute", this.IgnoreCase, SymbolFilter.Type, cancellationToken).ConfigureAwait(false)); } var accessibleTypeSymbols = symbols .OfType<INamedTypeSymbol>() .Where(s => (arity == 0 || s.GetArity() == arity) && s.IsAccessibleWithin(semanticModel.Compilation.Assembly) && (!inAttributeContext || s.IsAttribute()) && HasValidContainer(s)) .ToList(); return accessibleTypeSymbols; }
internal async Task<IEnumerable<ISymbol>> GetMatchingNamespacesAsync( Microsoft.CodeAnalysis.Project project, SemanticModel semanticModel, SyntaxNode simpleName, CancellationToken cancellationToken) { if (simpleName.IsAttributeName()) { return null; } string name; int arity; simpleName.GetNameAndArityOfSimpleName(out name, out arity); if (cancellationToken.IsCancellationRequested) { return null; } var symbols = await SymbolFinder.FindDeclarationsAsync(project, name, this.IgnoreCase, SymbolFilter.Namespace, cancellationToken).ConfigureAwait(false); var namespaces = symbols .OfType<INamespaceSymbol>() .Where(n => !n.IsGlobalNamespace && HasAccessibleTypes(n, semanticModel, cancellationToken)); return namespaces; }
private static void CalculateContext(SyntaxNode node, out string name, out int arity, out bool inAttributeContext, out bool hasIncompleteParentMember) { // Has to be a simple identifier or generic name. node.GetNameAndArityOfSimpleName(out name, out arity); inAttributeContext = node.IsAttributeName(); hasIncompleteParentMember = node.HasIncompleteParentMember(); }