Пример #1
0
        public ImmutableArray <int> GetMethodParameterLines(IWorkSession session, int lineInMethod, int columnInMethod)
        {
            var declaration = RoslynAdapterHelper.FindSyntaxNodeInSession(session, lineInMethod, columnInMethod)
                              ?.AncestorsAndSelf()
                              .FirstOrDefault(x => x is MethodBlockBaseSyntax || x is LambdaExpressionSyntax);

            var parameters = declaration switch
            {
                MethodBlockBaseSyntax m => m.BlockStatement.ParameterList.Parameters,
                LambdaExpressionSyntax l => l.SubOrFunctionHeader.ParameterList.Parameters,
                _ => SyntaxFactory.SeparatedList <ParameterSyntax>()
            };

            if (parameters.Count == 0)
            {
                return(ImmutableArray <int> .Empty);
            }

            var results = new int[parameters.Count];

            for (var i = 0; i < parameters.Count; i++)
            {
                results[i] = parameters[i].GetLocation().GetLineSpan().StartLinePosition.Line + 1;
            }
            return(ImmutableArray.Create(results));
        }
Пример #2
0
        public ImmutableArray <string?> GetCallArgumentIdentifiers([NotNull] IWorkSession session, int callStartLine, int callStartColumn)
        {
            var call = RoslynAdapterHelper.FindSyntaxNodeInSession(session, callStartLine, callStartColumn)
                       ?.AncestorsAndSelf()
                       .OfType <InvocationExpressionSyntax>()
                       .FirstOrDefault();

            if (call == null)
            {
                return(ImmutableArray <string?> .Empty);
            }

            var arguments = call.ArgumentList.Arguments;

            if (arguments.Count == 0)
            {
                return(ImmutableArray <string?> .Empty);
            }

            var results = new string?[arguments.Count];

            for (var i = 0; i < arguments.Count; i++)
            {
                results[i] = (arguments[i].Expression is IdentifierNameSyntax n) ? n.Identifier.ValueText : null;
            }
            return(ImmutableArray.Create(results));
        }
Пример #3
0
        public ImmutableArray <int> GetMethodParameterLines(IWorkSession session, int lineInMethod, int columnInMethod)
        {
            var declaration = RoslynAdapterHelper.FindSyntaxNodeInSession(session, lineInMethod, columnInMethod)
                              ?.AncestorsAndSelf()
                              .FirstOrDefault(m => m is MemberDeclarationSyntax ||
                                              m is AnonymousFunctionExpressionSyntax ||
                                              m is LocalFunctionStatementSyntax);

            var parameters = declaration switch {
                BaseMethodDeclarationSyntax m => m.ParameterList.Parameters,
                ParenthesizedLambdaExpressionSyntax l => l.ParameterList.Parameters,
                SimpleLambdaExpressionSyntax l => SyntaxFactory.SingletonSeparatedList(l.Parameter),
                LocalFunctionStatementSyntax f => f.ParameterList.Parameters,
                _ => SyntaxFactory.SeparatedList <ParameterSyntax>()
            };

            if (parameters.Count == 0)
            {
                return(ImmutableArray <int> .Empty);
            }

            var results = new int[parameters.Count];

            for (var i = 0; i < parameters.Count; i++)
            {
                results[i] = parameters[i].GetLocation().GetLineSpan().StartLinePosition.Line + 1;
            }
            return(ImmutableArray.Create(results));
        }
Пример #4
0
        public ImmutableArray <int> GetMethodParameterLines(IWorkSession session, int lineInMethod, int columnInMethod)
        {
            var declaration = RoslynAdapterHelper.FindSyntaxNodeInSession(session, lineInMethod, columnInMethod)
                              ?.AncestorsAndSelf()
                              .OfType <MemberDeclarationSyntax>()
                              .FirstOrDefault();

            if (!(declaration is BaseMethodDeclarationSyntax method))
            {
                return(ImmutableArray <int> .Empty);
            }

            var parameters = method.ParameterList.Parameters;
            var results    = new int[parameters.Count];

            for (int i = 0; i < parameters.Count; i++)
            {
                results[i] = parameters[i].GetLocation().GetLineSpan().StartLinePosition.Line + 1;
            }
            return(ImmutableArray.Create(results));
        }