protected override void Analyze()

in resharper/resharper-unity/src/Unity/CSharp/Daemon/Stages/Analysis/PreferAddressByIdToGraphicsParamsAnalyzer.cs [56:109]


        protected override void Analyze(IInvocationExpression expression, ElementProblemAnalyzerData data,
            IHighlightingConsumer consumer)
        {
            var sourceFile = expression.GetSourceFile();
            if (sourceFile == null)
                return;

            var reference = expression.Reference;
            var arguments = expression.Arguments;

            // cheap check for uninteresting methods
            if (expression.TypeArguments.Count != 0 || arguments.Count == 0)
                return;

            var info = reference.Resolve();
            if (info.ResolveErrorType == ResolveErrorType.OK && info.DeclaredElement is IMethod stringMethod)
            {
                if (HasOverloadWithIntParameter(stringMethod, expression, out var argumentIndex,
                        out var containingType) && containingType != null)
                {
                    // extract argument for replace
                    var argument = arguments[argumentIndex];
                    var argumentValue = argument.Value;
                    var methodType = ourTypes[containingType.GetClrName()];

                    if (argumentValue is IInvocationExpression) //nameof
                        return;

                    if (argumentValue is IReferenceExpression referenceExpression)
                    {
                        // prevent extract local values, e.g local constant.
                        var declaration = referenceExpression.Reference.Resolve().DeclaredElement
                            ?.GetDeclarationsIn(sourceFile).FirstOrDefault();
                        if (declaration == null || declaration.GetContainingNode<IParametersOwnerDeclaration>() != null
                                                || declaration.GetContainingNode<IAccessorOwnerDeclaration>() != null)
                        {
                            return;
                        }
                    }

                    // TODO: Use conditional access when the monorepo build uses a more modern C# compiler
                    // Currently (as of 01/2023) the monorepo build for Unity uses C#9 compiler, which will complain
                    // that the out variable is uninitialised when we use conditional access
                    // See also https://youtrack.jetbrains.com/issue/RSRP-489147
                    if (argument.Expression != null &&
                        argument.Expression.ConstantValue.IsNotNullString(out var literal))
                    {
                        var (typeName, methodName) = ourSubstitutionMethodSignature[methodType];
                        consumer.AddHighlighting(new PreferAddressByIdToGraphicsParamsWarning(expression, argument,
                            argument.Expression, literal, typeName.FullName, methodName));
                    }
                }
            }
        }