public static SymbolKeyResolution Resolve(SymbolKeyReader reader, out string?failureReason)
            {
                var name             = reader.ReadString() !;
                var targetResolution = reader.ReadSymbolKey(out var targetFailureReason);
                var filePath         = reader.ReadString() !;

                if (targetFailureReason != null)
                {
                    failureReason = $"({nameof(AliasSymbolKey)} {nameof(targetResolution)} failed -> {targetFailureReason})";
                    return(default);
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var assemblyName = reader.ReadString();

                return(CreateSymbolInfo(GetAssemblySymbols(
                                            assemblyName, reader.Compilation, reader.IgnoreAssemblyKey)));
            }
Exemple #3
0
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var isCref = reader.ReadBoolean();

                if (isCref)
                {
                    var location   = reader.ReadLocation();
                    var resolution = reader.ResolveLocation(location);
                    return(resolution.GetValueOrDefault());
                }
                else
                {
                    var metadataName = reader.ReadString();
                    var containingSymbolResolution = reader.ReadSymbolKey();

                    using var result = PooledArrayBuilder <ITypeParameterSymbol> .GetInstance();

                    foreach (var containingSymbol in containingSymbolResolution)
                    {
                        foreach (var typeParam in containingSymbol.GetTypeParameters())
                        {
                            if (typeParam.MetadataName == metadataName)
                            {
                                result.AddIfNotNull(typeParam);
                            }
                        }
                    }

                    return(CreateResolution(result));
                }
            }
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var metadataName = reader.ReadString();
                var containingSymbolResolution = reader.ReadSymbolKey();
                var isIndexer = reader.ReadBoolean();
                var refKinds  = reader.ReadRefKindArray();
                var originalParameterTypes = reader.ReadSymbolKeyArray().Select(
                    r => GetFirstSymbol <ITypeSymbol>(r)).ToArray();

                if (originalParameterTypes.Any(s_typeIsNull))
                {
                    return(default(SymbolKeyResolution));
                }

                var properties = containingSymbolResolution.GetAllSymbols().OfType <INamedTypeSymbol>()
                                 .SelectMany(t => t.GetMembers())
                                 .OfType <IPropertySymbol>()
                                 .Where(p => p.Parameters.Length == refKinds.Length &&
                                        p.MetadataName == metadataName &&
                                        p.IsIndexer == isIndexer);
                var matchingProperties = properties.Where(p =>
                                                          ParameterRefKindsMatch(p.OriginalDefinition.Parameters, refKinds) &&
                                                          reader.ParameterTypesMatch(p.OriginalDefinition.Parameters, originalParameterTypes));

                return(CreateSymbolInfo(matchingProperties));
            }
Exemple #5
0
            protected sealed override SymbolKeyResolution Resolve(
                SymbolKeyReader reader, IAssemblySymbol?contextualSymbol, out string?failureReason)
            {
                var assemblyName      = reader.ReadString();
                var compilation       = reader.Compilation;
                var ignoreAssemblyKey = reader.IgnoreAssemblyKey;

                using var result = PooledArrayBuilder <IAssemblySymbol> .GetInstance();

                if (ignoreAssemblyKey || compilation.Assembly.Identity.Name == assemblyName)
                {
                    result.AddIfNotNull(compilation.Assembly);
                }

                // Might need keys for symbols from previous script compilations.
                foreach (var assembly in compilation.GetReferencedAssemblySymbols())
                {
                    if (ignoreAssemblyKey || assembly.Identity.Name == assemblyName)
                    {
                        result.AddIfNotNull(assembly);
                    }
                }

                return(CreateResolution(result, $"({nameof(AssemblySymbolKey)} '{assemblyName}' not found)", out failureReason));
            }
Exemple #6
0
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader, out string?failureReason)
            {
                var metadataName = reader.ReadString() !;
                var containingSymbolResolution = reader.ReadSymbolKey(out var containingSymbolFailureReason);

                if (containingSymbolFailureReason != null)
                {
                    failureReason = $"({nameof(ParameterSymbolKey)} {nameof(containingSymbolResolution)} failed -> {containingSymbolFailureReason})";
                    return(default);
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var metadataName = reader.ReadString();
                var containingSymbolResolution = reader.ReadSymbolKey();

                var parameters = GetAllSymbols(containingSymbolResolution).SelectMany(
                    s => Resolve(reader, s, metadataName));

                return(CreateSymbolInfo(parameters));
            }
Exemple #8
0
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader, out string?failureReason)
            {
                var metadataName = reader.ReadString() !;
                var isCompilationGlobalNamespace = reader.ReadBoolean();
                var containingSymbolResolution   = reader.ReadSymbolKey(out var containingSymbolFailureReason);

                if (containingSymbolFailureReason != null)
                {
                    failureReason = $"({nameof(EventSymbolKey)} {nameof(containingSymbolResolution)} failed -> {containingSymbolFailureReason})";
                    return(default);
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var name = reader.ReadString();
                var containingSymbolResolution = reader.ReadSymbolKey();
                var arity = reader.ReadInteger();

                using var typeArguments = reader.ReadSymbolKeyArray <ITypeSymbol>();
                if (typeArguments.IsDefault)
                {
                    return(default);
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var metadataName             = reader.ReadString();
                var containingTypeResolution = reader.ReadSymbolKey();

                var events = GetAllSymbols <INamedTypeSymbol>(containingTypeResolution)
                             .SelectMany(t => t.GetMembers(metadataName)).OfType <IEventSymbol>();

                return(CreateSymbolInfo(events));
            }
Exemple #11
0
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var metadataName = reader.ReadString();
                var containingSymbolResolution = reader.ReadSymbolKey();
                var isIndexer = reader.ReadBoolean();
                var refKinds  = reader.ReadRefKindArray();
                var originalParameterTypes = reader.ReadSymbolKeyArray().Select(
                    r => GetFirstSymbol <ITypeSymbol>(r)).ToArray();

                if (originalParameterTypes.Any(s_typeIsNull))
                {
                    return(default);
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var metadataName             = reader.ReadString();
                var containingTypeResolution = reader.ReadSymbolKey();
                var isIndexer = reader.ReadBoolean();

                using var refKinds       = reader.ReadRefKindArray();
                using var parameterTypes = reader.ReadSymbolKeyArray <ITypeSymbol>();

                if (parameterTypes.IsDefault)
                {
                    return(default);
Exemple #13
0
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var metadataName = reader.ReadString();
                var containingSymbolResolution = reader.ReadSymbolKey();
                var arity = reader.ReadInteger();
                var isPartialMethodImplementationPart = reader.ReadBoolean();
                var parameterRefKinds = reader.ReadRefKindArray();

                // For each method that we look at, we'll have to resolve the parameter list and
                // return type in the context of that method.  i.e. if we have Foo<T>(IList<T> list)
                // then we'll need to have marked that we're on the Foo<T> method so that we know
                // 'T' in IList<T> resolves to.
                //
                // Because of this, we keep track of where we are in the reader.  Before resolving
                // every parameter list, we'll mark which method we're on and we'll rewind to this
                // point.
                var beforeParametersPosition = reader.Position;

                var result = new List <IMethodSymbol>();

                var namedTypes = containingSymbolResolution.GetAllSymbols().OfType <INamedTypeSymbol>();

                foreach (var namedType in namedTypes)
                {
                    var method = Resolve(reader, metadataName, arity, isPartialMethodImplementationPart,
                                         parameterRefKinds, beforeParametersPosition, namedType);

                    // Note: after finding the first method that matches we stop.  That's necessary
                    // as we cache results while searching.  We don't want to override these positive
                    // matches with a negative ones if we were to continue searching.
                    if (method != null)
                    {
                        result.Add(method);
                        break;
                    }
                }

                if (reader.Position == beforeParametersPosition)
                {
                    // We didn't find any candidates.  We still need to stream through this
                    // method signature so the reader is in a proper position.

                    // Push an null-method to our stack so that any method-type-parameters
                    // can at least be read (if not resolved) properly.
                    reader.PushMethod(methodOpt: null);
                    var parameterTypeResolutions = reader.ReadSymbolKeyArray();
                    var returnType = GetFirstSymbol <ITypeSymbol>(reader.ReadSymbolKey());
                    reader.PopMethod(methodOpt: null);
                }

                return(CreateSymbolInfo(result));
            }
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader, out string?failureReason)
            {
                var cancellationToken = reader.CancellationToken;

                var name      = reader.ReadString();
                var kind      = (SymbolKind)reader.ReadInteger();
                var locations = reader.ReadLocationArray(out var locationsFailureReason);
                var ordinal   = reader.ReadInteger();

                if (locationsFailureReason != null)
                {
                    failureReason = $"({nameof(BodyLevelSymbolKey)} {nameof(locations)} failed -> {locationsFailureReason})";
                    return(default);
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader, out string?failureReason)
            {
                var metadataName = reader.ReadString() !;
                var containingSymbolResolution = reader.ReadSymbolKey(out var containingSymbolFailureReason);
                var arity = reader.ReadInteger();
                var isUnboundGenericType = reader.ReadBoolean();

                using var typeArguments = reader.ReadSymbolKeyArray <ITypeSymbol>(out var typeArgumentsFailureReason);

                if (containingSymbolFailureReason != null)
                {
                    failureReason = $"({nameof(NamedTypeSymbolKey)} {nameof(containingSymbolFailureReason)} failed -> {containingSymbolFailureReason})";
                    return(default);
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader, out string failureReason)
            {
                var name = reader.ReadString();

                var containingSymbolResolution = ResolveContainer(reader, out var containingSymbolFailureReason);
                var arity = reader.ReadInteger();

                using var typeArguments = reader.ReadSymbolKeyArray <ITypeSymbol>(out var typeArgumentsFailureReason);

                if (containingSymbolFailureReason != null)
                {
                    failureReason = $"({nameof(ErrorTypeSymbolKey)} {nameof(containingSymbolResolution)} failed -> {containingSymbolFailureReason})";
                    return(default);
Exemple #17
0
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var metadataName = reader.ReadString();
                var containingSymbolResolution = reader.ReadSymbolKey();
                var arity                = reader.ReadInteger();
                var typeKind             = (TypeKind)reader.ReadInteger();
                var isUnboundGenericType = reader.ReadBoolean();
                var typeArgumentsOpt     = reader.ReadSymbolKeyArray();

                var types = GetAllSymbols <INamespaceOrTypeSymbol>(containingSymbolResolution).SelectMany(
                    s => Resolve(reader, s, metadataName, arity, typeKind, isUnboundGenericType, typeArgumentsOpt));

                return(CreateSymbolInfo(types));
            }
Exemple #18
0
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var name             = reader.ReadString();
                var targetResolution = reader.ReadSymbolKey();
                var filePath         = reader.ReadString();

                var syntaxTree = reader.GetSyntaxTree(filePath);

                if (syntaxTree != null)
                {
                    var target = targetResolution.GetAnySymbol();
                    if (target != null)
                    {
                        var semanticModel = reader.Compilation.GetSemanticModel(syntaxTree);
                        var result        = Resolve(semanticModel, syntaxTree.GetRoot(reader.CancellationToken), name, target, reader.CancellationToken);
                        if (result.HasValue)
                        {
                            return(result.Value);
                        }
                    }
                }

                return(default);
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var metadataName = reader.ReadString();
                var isCompilationGlobalNamespace = reader.ReadBoolean();
                var containingSymbolResolution   = reader.ReadSymbolKey();

                if (isCompilationGlobalNamespace)
                {
                    return(new SymbolKeyResolution(reader.Compilation.GlobalNamespace));
                }

                var namespaces = GetAllSymbols(containingSymbolResolution).SelectMany(
                    s => Resolve(s, metadataName));

                return(CreateSymbolInfo(namespaces));
            }
Exemple #20
0
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader, out string?failureReason)
            {
                var cancellationToken = reader.CancellationToken;

                var name = reader.ReadString() !;
                var kind = (SymbolKind)reader.ReadInteger();

#pragma warning disable IDE0007 // Use implicit type
                PooledArrayBuilder <Location> locations = reader.ReadLocationArray(out var locationsFailureReason) !;
#pragma warning restore IDE0007 // Use implicit type
                var ordinal = reader.ReadInteger();

                if (locationsFailureReason != null)
                {
                    failureReason = $"({nameof(BodyLevelSymbolKey)} {nameof(locations)} failed -> {locationsFailureReason})";
                    return(default);
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var metadataName = reader.ReadString();
                var containingSymbolResolution = reader.ReadSymbolKey();

                using var result = PooledArrayBuilder <IParameterSymbol> .GetInstance();

                foreach (var container in containingSymbolResolution)
                {
                    switch (container)
                    {
                    case IMethodSymbol method:
                        Resolve(result, reader, metadataName, method.Parameters);
                        break;

                    case IPropertySymbol property:
                        Resolve(result, reader, metadataName, property.Parameters);
                        break;

                    case IEventSymbol eventSymbol:
                        // Parameters can be owned by events in VB.  i.e. it's legal in VB to have:
                        //
                        //      Public Event E(a As Integer, b As Integer);
                        //
                        // In this case it's equivalent to:
                        //
                        //      Public Delegate UnutterableCompilerName(a As Integer, b As Integer)
                        //      public Event E As UnutterableCompilerName
                        //
                        // So, in this case, to resolve the parameter, we go have to map the event,
                        // then find the delegate it returns, then find the parameter in the delegate's
                        // 'Invoke' method.
                        var delegateInvoke = (eventSymbol.Type as INamedTypeSymbol)?.DelegateInvokeMethod;

                        if (delegateInvoke != null)
                        {
                            Resolve(result, reader, metadataName, delegateInvoke.Parameters);
                        }
                        break;
                    }
                }

                return(CreateResolution(result));
            }
            protected sealed override SymbolKeyResolution Resolve(
                SymbolKeyReader reader, INamedTypeSymbol?contextualSymbol, out string?failureReason)
            {
                var containingSymbolResolution = reader.ReadSymbolKey(contextualSymbol?.ContainingSymbol, out var containingSymbolFailureReason);
                var name                 = reader.ReadRequiredString();
                var arity                = reader.ReadInteger();
                var filePath             = reader.ReadString();
                var isUnboundGenericType = reader.ReadBoolean();

                using var typeArguments = reader.ReadSymbolKeyArray <INamedTypeSymbol, ITypeSymbol>(
                          contextualSymbol,
                          getContextualSymbol: static (contextualType, i) => SafeGet(contextualType.TypeArguments, i),
                          out var typeArgumentsFailureReason);

                if (typeArgumentsFailureReason != null)
                {
                    Contract.ThrowIfFalse(typeArguments.IsDefault);

                    failureReason = $"({nameof(NamedTypeSymbolKey)} {nameof(typeArguments)} failed -> {typeArgumentsFailureReason})";
                    return(default);
Exemple #23
0
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var name = reader.ReadString();
                var containingSymbolResolution = reader.ReadSymbolKey();
                var arity = reader.ReadInteger();
                var typeArgumentResolutions = reader.ReadSymbolKeyArray();

                var errorTypes = ResolveErrorTypes(reader, containingSymbolResolution, name, arity);

                if (typeArgumentResolutions.IsDefault)
                {
                    return(CreateSymbolInfo(errorTypes));
                }

                var typeArguments = typeArgumentResolutions.Select(
                    r => GetFirstSymbol <ITypeSymbol>(r)).ToArray();

                if (typeArguments.Any(s_typeIsNull))
                {
                    return(default);
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var metadataName = reader.ReadString();
                var isCompilationGlobalNamespace = reader.ReadBoolean();
                var containingSymbolResolution   = reader.ReadSymbolKey();

                if (isCompilationGlobalNamespace)
                {
                    return(new SymbolKeyResolution(reader.Compilation.GlobalNamespace));
                }

                using var result = PooledArrayBuilder <INamespaceSymbol> .GetInstance();

                foreach (var container in containingSymbolResolution)
                {
                    switch (container)
                    {
                    case IAssemblySymbol assembly:
                        Debug.Assert(metadataName == string.Empty);
                        result.AddIfNotNull(assembly.GlobalNamespace);
                        break;

                    case IModuleSymbol module:
                        Debug.Assert(metadataName == string.Empty);
                        result.AddIfNotNull(module.GlobalNamespace);
                        break;

                    case INamespaceSymbol namespaceSymbol:
                        foreach (var member in namespaceSymbol.GetMembers(metadataName))
                        {
                            if (member is INamespaceSymbol childNamespace)
                            {
                                result.AddIfNotNull(childNamespace);
                            }
                        }
                        break;
                    }
                }

                return(CreateResolution(result));
            }
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var cancellationToken = reader.CancellationToken;

                var name      = reader.ReadString();
                var kind      = (SymbolKind)reader.ReadInteger();
                var locations = reader.ReadLocationArray();
                var ordinal   = reader.ReadInteger();

                // First check if we can recover the symbol just through the original location.
                foreach (var loc in locations)
                {
                    var resolutionOpt = reader.ResolveLocation(loc);
                    if (resolutionOpt.HasValue)
                    {
                        var resolution = resolutionOpt.Value;
                        var symbol     = resolution.GetAnySymbol();
                        if (symbol?.Kind == kind &&
                            SymbolKey.Equals(reader.Compilation, name, symbol.Name))
                        {
                            return(resolution);
                        }
                    }
                }

                // Couldn't recover.  See if we can still find a match across the textual drift.
                if (ordinal != int.MaxValue &&
                    TryGetSemanticModel(reader.Compilation, locations[0].SourceTree, out var semanticModel))
                {
                    foreach (var symbol in EnumerateSymbols(semanticModel, kind, name, cancellationToken))
                    {
                        if (symbol.ordinal == ordinal)
                        {
                            return(new SymbolKeyResolution(symbol.symbol));
                        }
                    }
                }

                return(default);
Exemple #26
0
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var localName = reader.ReadString();
                var containingSymbolResolution = reader.ReadSymbolKey();
                var ordinal = reader.ReadInteger();
                var kind    = (SymbolKind)reader.ReadInteger();

                var containingSymbol = containingSymbolResolution.Symbol;

                if (containingSymbol != null)
                {
                    foreach (var symbol in EnumerateSymbols(
                                 reader.Compilation, containingSymbol, kind, localName, reader.CancellationToken))
                    {
                        if (symbol.ordinal == ordinal)
                        {
                            return(new SymbolKeyResolution(symbol.symbol));
                        }
                    }
                }

                return(new SymbolKeyResolution());
            }
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var assemblyName      = reader.ReadString();
                var compilation       = reader.Compilation;
                var ignoreAssemblyKey = reader.IgnoreAssemblyKey;

                using var result = PooledArrayBuilder <IAssemblySymbol> .GetInstance();

                if (ignoreAssemblyKey || compilation.Assembly.Identity.Name == assemblyName)
                {
                    result.AddIfNotNull(compilation.Assembly);
                }

                // Might need keys for symbols from previous script compilations.
                foreach (var assembly in compilation.GetReferencedAssemblySymbols())
                {
                    if (ignoreAssemblyKey || assembly.Identity.Name == assemblyName)
                    {
                        result.AddIfNotNull(assembly);
                    }
                }

                return(CreateResolution(result));
            }
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var metadataName = reader.ReadString();
                var containingSymbolResolution = reader.ReadSymbolKey();

                var result = containingSymbolResolution.GetAllSymbols()
                             .SelectMany(s =>
                {
                    if (s is INamedTypeSymbol namedType)
                    {
                        return(namedType.TypeParameters.Where(p => p.MetadataName == metadataName));
                    }
                    else if (s is IMethodSymbol method)
                    {
                        return(method.TypeParameters.Where(p => p.MetadataName == metadataName));
                    }
                    else
                    {
                        return(SpecializedCollections.EmptyEnumerable <ITypeParameterSymbol>());
                    }
                });

                return(CreateSymbolInfo(result));
            }