Exemplo n.º 1
0
        internal static Task <ImmutableArray <SymbolAndProjectId <INamedTypeSymbol> > > FindDerivedClassesAsync(
            SymbolAndProjectId <INamedTypeSymbol> typeAndProjectId, Solution solution, IImmutableSet <Project> projects = null, CancellationToken cancellationToken = default)
        {
            var type = typeAndProjectId.Symbol;

            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (solution == null)
            {
                throw new ArgumentNullException(nameof(solution));
            }

            return(DependentTypeFinder.FindTransitivelyDerivedClassesAsync(type, solution, projects, cancellationToken));
        }
Exemplo n.º 2
0
        internal static async Task <ImmutableArray <SymbolAndProjectId> > FindImplementationsAsync(
            SymbolAndProjectId symbolAndProjectId, Solution solution, IImmutableSet <Project> projects = null, CancellationToken cancellationToken = default)
        {
            // A symbol can only have implementations if it's an interface or a
            // method/property/event from an interface.
            var symbol = symbolAndProjectId.Symbol;

            if (symbol is INamedTypeSymbol namedTypeSymbol)
            {
                var implementingTypes = await DependentTypeFinder.FindTransitivelyImplementingTypesAsync(namedTypeSymbol, solution, projects, cancellationToken).ConfigureAwait(false);

                return(implementingTypes.Select(s => (SymbolAndProjectId)s)
                       .Where(IsAccessible)
                       .ToImmutableArray());
            }
            else if (symbol.IsImplementableMember())
            {
                var containingType = symbol.ContainingType.OriginalDefinition;
                var allTypes       = await DependentTypeFinder.FindTransitivelyImplementingTypesAsync(containingType, solution, projects, cancellationToken).ConfigureAwait(false);

                ImmutableArray <SymbolAndProjectId> .Builder results = null;
                foreach (var t in allTypes.Convert <INamedTypeSymbol, ITypeSymbol>())
                {
                    foreach (var m in t.FindImplementationsForInterfaceMember(symbol, solution.Workspace, cancellationToken))
                    {
                        var sourceDef = await FindSourceDefinitionAsync(m, solution, cancellationToken).ConfigureAwait(false);

                        var bestDef = sourceDef.Symbol != null ? sourceDef : m;
                        if (IsAccessible(bestDef))
                        {
                            results = results ?? ImmutableArray.CreateBuilder <SymbolAndProjectId>();
                            results.Add(bestDef.WithSymbol(bestDef.Symbol.OriginalDefinition));
                        }
                    }
                }

                if (results != null)
                {
                    return(results.Distinct(SymbolAndProjectIdComparer.SymbolEquivalenceInstance)
                           .ToImmutableArray());
                }
            }

            return(ImmutableArray <SymbolAndProjectId> .Empty);
        }