示例#1
0
        public override void VisitInvocationExpression(InvocationExpressionSyntax node)
        {
            var invokedMethod = this.semanticModel.GetSymbolSafe(node, this.cancellationToken) as IMethodSymbol;

            if (MethodSymbolComparer.Equals(this.method, invokedMethod))
            {
                this.invocations.Add(node);
            }

            base.VisitInvocationExpression(node);
        }
示例#2
0
        internal static bool Creates(this ObjectCreationExpressionSyntax creation, ConstructorDeclarationSyntax ctor, Search search, SemanticModel semanticModel, CancellationToken cancellationToken)
        {
            var created    = semanticModel.GetSymbolSafe(creation, cancellationToken) as IMethodSymbol;
            var ctorSymbol = semanticModel.GetDeclaredSymbolSafe(ctor, cancellationToken);

            if (MethodSymbolComparer.Equals(ctorSymbol, created))
            {
                return(true);
            }

            return(search == Search.Recursive &&
                   IsRunBefore(created, ctorSymbol, semanticModel, cancellationToken));
        }
示例#3
0
        private static bool IsRunBefore(IMethodSymbol first, IMethodSymbol other, SemanticModel semanticModel, CancellationToken cancellationToken)
        {
            if (first == null ||
                other == null)
            {
                return(false);
            }

            if (TryGetInitializer(other, cancellationToken, out ConstructorInitializerSyntax initializer))
            {
                if (TypeSymbolComparer.Equals(first.ContainingType, other.ContainingType) &&
                    !initializer.ThisOrBaseKeyword.IsKind(SyntaxKind.ThisKeyword))
                {
                    return(false);
                }

                if (!other.ContainingType.Is(first.ContainingType) &&
                    initializer.ThisOrBaseKeyword.IsKind(SyntaxKind.BaseKeyword))
                {
                    return(false);
                }
            }
            else
            {
                if (TypeSymbolComparer.Equals(first.ContainingType, other.ContainingType) ||
                    !other.ContainingType.Is(first.ContainingType))
                {
                    return(false);
                }
            }

            var next = semanticModel.GetSymbolSafe(initializer, cancellationToken);

            if (MethodSymbolComparer.Equals(first, next))
            {
                return(true);
            }

            if (next == null)
            {
                if (TryGetDefault(other.ContainingType?.BaseType, out next))
                {
                    return(MethodSymbolComparer.Equals(first, next));
                }

                return(false);
            }

            return(IsRunBefore(first, next, semanticModel, cancellationToken));
        }
示例#4
0
        private bool IsValidCtor(IMethodSymbol ctor)
        {
            if (!MethodSymbolComparer.Equals(this.method, ctor))
            {
                return(false);
            }

            if (TypeSymbolComparer.Equals(this.contextType, ctor?.ContainingType))
            {
                return(true);
            }

            return(this.ctors.Contains(ctor));
        }
示例#5
0
        public static bool Equals(ISymbol x, ISymbol y)
        {
            if (ReferenceEquals(x, y))
            {
                return(true);
            }

            if (x == null ||
                y == null)
            {
                return(false);
            }

            if (x is IEventSymbol xEvent &&
                y is IEventSymbol yEvent)
            {
                return(EventSymbolComparer.Equals(xEvent, yEvent));
            }

            if (x is IFieldSymbol xField &&
                y is IFieldSymbol yField)
            {
                return(FieldSymbolComparer.Equals(xField, yField));
            }

            if (x is ILocalSymbol xLocal &&
                y is ILocalSymbol yLocal)
            {
                return(LocalSymbolComparer.Equals(xLocal, yLocal));
            }

            if (x is IMethodSymbol xMethod &&
                y is IMethodSymbol yMethod)
            {
                return(MethodSymbolComparer.Equals(xMethod, yMethod));
            }

            if (x is INamedTypeSymbol xNamedType &&
                y is INamedTypeSymbol yNamedType)
            {
                return(NamedTypeSymbolComparer.Equals(xNamedType, yNamedType));
            }

            if (x is INamespaceSymbol xNamespace &&
                y is INamespaceSymbol yNamespace)
            {
                return(NamespaceSymbolComparer.Equals(xNamespace, yNamespace));
            }

            if (x is IParameterSymbol xParameter &&
                y is IParameterSymbol yParameter)
            {
                return(ParameterSymbolComparer.Equals(xParameter, yParameter));
            }

            if (x is IPropertySymbol xProperty &&
                y is IPropertySymbol yProperty)
            {
                return(PropertySymbolComparer.Equals(xProperty, yProperty));
            }

            if (x is ITypeSymbol xType &&
                y is ITypeSymbol yType)
            {
                return(TypeSymbolComparer.Equals(xType, yType));
            }

            return(x.Equals(y));
        }