Esempio n. 1
0
        protected static (int startIndex, int endIndex) GetIndexes(SeparatedSyntaxList <TNode> list, TextSpan span)
        {
            SeparatedSyntaxList <TNode> .Enumerator en = list.GetEnumerator();

            if (en.MoveNext())
            {
                int i = 0;

                while (span.Start >= en.Current.FullSpan.End &&
                       en.MoveNext())
                {
                    i++;
                }

                if (span.Start >= en.Current.FullSpan.Start &&
                    span.Start <= en.Current.Span.Start)
                {
                    int j = i;

                    while (span.End > GetEndIndex(list, en.Current, j) &&
                           en.MoveNext())
                    {
                        j++;
                    }

                    if (span.End >= en.Current.Span.End &&
                        span.End <= GetEndIndex(list, en.Current, j))
                    {
                        return(i, j);
                    }
                }
            }

            return(-1, -1);
        }
Esempio n. 2
0
        public static ParameterListSyntax ToMultiLine(ParameterListSyntax parameterList, CancellationToken cancellationToken = default(CancellationToken))
        {
            string indent = GetIncreasedLineIndent(parameterList.Parent, cancellationToken);

            SyntaxTriviaList trivia = ParseLeadingTrivia(indent);

            var nodesAndTokens = new List <SyntaxNodeOrToken>();

            SeparatedSyntaxList <ParameterSyntax> .Enumerator en = parameterList.Parameters.GetEnumerator();

            if (en.MoveNext())
            {
                nodesAndTokens.Add(en.Current.WithLeadingTrivia(trivia));

                while (en.MoveNext())
                {
                    nodesAndTokens.Add(CommaToken().WithTrailingTrivia(NewLine()));

                    nodesAndTokens.Add(en.Current.WithLeadingTrivia(trivia));
                }
            }

            return(ParameterList(
                       OpenParenToken().WithTrailingTrivia(NewLine()),
                       SeparatedList <ParameterSyntax>(nodesAndTokens),
                       parameterList.CloseParenToken));
        }
Esempio n. 3
0
        private static AttributeArgumentListSyntax ToMultiLine(AttributeArgumentListSyntax argumentList, CancellationToken cancellationToken = default(CancellationToken))
        {
            string indent = GetIncreasedLineIndent(argumentList.Parent, cancellationToken);

            SyntaxTriviaList leadingTrivia = ParseLeadingTrivia(indent);

            var nodesAndTokens = new List <SyntaxNodeOrToken>();

            SeparatedSyntaxList <AttributeArgumentSyntax> .Enumerator en = argumentList.Arguments.GetEnumerator();

            if (en.MoveNext())
            {
                nodesAndTokens.Add(en.Current
                                   .TrimTrailingTrivia()
                                   .WithLeadingTrivia(leadingTrivia));

                while (en.MoveNext())
                {
                    nodesAndTokens.Add(CommaToken().WithTrailingTrivia(NewLine()));

                    nodesAndTokens.Add(en.Current
                                       .TrimTrailingTrivia()
                                       .WithLeadingTrivia(leadingTrivia));
                }
            }

            return(AttributeArgumentList(
                       OpenParenToken().WithTrailingTrivia(NewLine()),
                       SeparatedList <AttributeArgumentSyntax>(nodesAndTokens),
                       argumentList.CloseParenToken.WithoutLeadingTrivia()));
        }
Esempio n. 4
0
        public static ArgumentListSyntax ToMultiLine(ArgumentListSyntax argumentList, CancellationToken cancellationToken = default)
        {
            SyntaxTriviaList leadingTrivia = GetIncreasedIndentationTriviaList(argumentList, cancellationToken);

            var nodesAndTokens = new List <SyntaxNodeOrToken>();

            SeparatedSyntaxList <ArgumentSyntax> .Enumerator en = argumentList.Arguments.GetEnumerator();

            SyntaxTrivia endOfLine = DetermineEndOfLine(argumentList);

            if (en.MoveNext())
            {
                nodesAndTokens.Add(en.Current
                                   .TrimTrailingTrivia()
                                   .WithLeadingTrivia(leadingTrivia));

                while (en.MoveNext())
                {
                    nodesAndTokens.Add(CommaToken().WithTrailingTrivia(endOfLine));

                    nodesAndTokens.Add(en.Current
                                       .TrimTrailingTrivia()
                                       .WithLeadingTrivia(leadingTrivia));
                }
            }

            return(ArgumentList(
                       OpenParenToken().WithTrailingTrivia(endOfLine),
                       SeparatedList <ArgumentSyntax>(nodesAndTokens),
                       argumentList.CloseParenToken.WithoutLeadingTrivia()));
        }
Esempio n. 5
0
        public static BracketedParameterListSyntax WrapParameters(BracketedParameterListSyntax parameterList, CancellationToken cancellationToken = default)
        {
            SyntaxTriviaList leadingTrivia = GetIncreasedIndentationTriviaList(parameterList, cancellationToken);

            var nodesAndTokens = new List <SyntaxNodeOrToken>();

            SeparatedSyntaxList <ParameterSyntax> .Enumerator en = parameterList.Parameters.GetEnumerator();

            SyntaxTrivia endOfLine = DetermineEndOfLine(parameterList);

            if (en.MoveNext())
            {
                nodesAndTokens.Add(en.Current.WithLeadingTrivia(leadingTrivia));

                while (en.MoveNext())
                {
                    nodesAndTokens.Add(CommaToken().WithTrailingTrivia(endOfLine));

                    nodesAndTokens.Add(en.Current.WithLeadingTrivia(leadingTrivia));
                }
            }

            return(BracketedParameterList(
                       OpenParenToken().WithTrailingTrivia(endOfLine),
                       SeparatedList <ParameterSyntax>(nodesAndTokens),
                       parameterList.CloseBracketToken));
        }
Esempio n. 6
0
        public static SelectionResult Create <TNode>(SeparatedSyntaxList <TNode> list, TextSpan span) where TNode : SyntaxNode
        {
            SeparatedSyntaxList <TNode> .Enumerator en = list.GetEnumerator();

            if (en.MoveNext())
            {
                int i = 0;

                while (span.Start >= en.Current.FullSpan.End &&
                       en.MoveNext())
                {
                    i++;
                }

                if (span.Start >= en.Current.FullSpan.Start &&
                    span.Start <= en.Current.SpanStart)
                {
                    int j = i;

                    while (span.End > GetLastIndex(en.Current, j) &&
                           en.MoveNext())
                    {
                        j++;
                    }

                    if (span.End >= en.Current.Span.End &&
                        span.End <= GetLastIndex(en.Current, j))
                    {
                        return(new SelectionResult(i, j));
                    }
                }
            }

            return(Fail);

            int GetLastIndex(TNode node, int i)
            {
                if (i < list.Count - 1 ||
                    list.Count == list.SeparatorCount)
                {
                    return(list.GetSeparator(i).FullSpan.End);
                }

                return(node.FullSpan.End);
            }
        }
        private static IEnumerable <SyntaxNodeOrToken> CreateNodesAndTokens(ParameterListSyntax list)
        {
            SyntaxTriviaList trivia = list.Parent.GetIndentTrivia().Add(SyntaxHelper.DefaultIndent);

            SeparatedSyntaxList <ParameterSyntax> .Enumerator en = list.Parameters.GetEnumerator();

            if (en.MoveNext())
            {
                yield return(en.Current.WithLeadingTrivia(trivia));

                while (en.MoveNext())
                {
                    yield return(Token(SyntaxKind.CommaToken).WithTrailingNewLine());

                    yield return(en.Current.WithLeadingTrivia(trivia));
                }
            }
        }
        private static IEnumerable<SyntaxNodeOrToken> CreateMultilineNodesAndTokens(ArgumentListSyntax argumentList)
        {
            SyntaxTriviaList trivia = argumentList.Parent.GetIndentTrivia().Add(SyntaxHelper.DefaultIndent);

            SeparatedSyntaxList<ArgumentSyntax>.Enumerator en = argumentList.Arguments.GetEnumerator();

            if (en.MoveNext())
            {
                yield return en.Current
                    .TrimTrailingWhitespace()
                    .WithLeadingTrivia(trivia);

                while (en.MoveNext())
                {
                    yield return Token(SyntaxKind.CommaToken)
                        .WithTrailingNewLine();

                    yield return en.Current
                        .TrimTrailingWhitespace()
                        .WithLeadingTrivia(trivia);
                }
            }
        }
        private static IEnumerable <SyntaxNodeOrToken> CreateMultilineNodesAndTokens(ArgumentListSyntax argumentList)
        {
            SyntaxTriviaList trivia = SyntaxUtility.GetIndentTrivia(argumentList.Parent).Add(CSharpFactory.IndentTrivia());

            SeparatedSyntaxList <ArgumentSyntax> .Enumerator en = argumentList.Arguments.GetEnumerator();

            if (en.MoveNext())
            {
                yield return(en.Current
                             .TrimTrailingTrivia()
                             .WithLeadingTrivia(trivia));

                while (en.MoveNext())
                {
                    yield return(Token(SyntaxKind.CommaToken)
                                 .WithTrailingNewLine());

                    yield return(en.Current
                                 .TrimTrailingTrivia()
                                 .WithLeadingTrivia(trivia));
                }
            }
        }
        public int Calculate(TypeDeclarationSyntax type)
        {
            int num = 0;

            if (type.BaseList != null)
            {
                SeparatedSyntaxList <BaseTypeSyntax> .Enumerator enumerator = type.BaseList.Types.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    BaseTypeSyntax current    = enumerator.Current;
                    SymbolInfo     symbolInfo = ModelExtensions.GetSymbolInfo(this.semanticModel, current, new CancellationToken());
                    for (INamedTypeSymbol i = symbolInfo.Symbol as INamedTypeSymbol; i != null; i = i.BaseType)
                    {
                        if (this.inheritableTypes.Any <TypeKind>((TypeKind x) => x == i.TypeKind))
                        {
                            num = checked (num + 1);
                        }
                    }
                }
            }
            return(num);
        }