예제 #1
0
        public static ValueTuple <SyntaxToken, SyntaxToken> GetFirstAndLastMemberDeclarationTokensAfterAttributes(this MemberDeclarationSyntax node)
        {
            Contract.ThrowIfNull(node);

            // there are no attributes associated with the node. return back first and last token of the node.
            var attributes = node.GetAttributes();

            if (attributes.Count == 0)
            {
                return(ValueTuple.Create(node.GetFirstToken(includeZeroWidth: true), node.GetLastToken(includeZeroWidth: true)));
            }

            var lastToken          = node.GetLastToken(includeZeroWidth: true);
            var lastAttributeToken = attributes.Last().GetLastToken(includeZeroWidth: true);

            if (lastAttributeToken.Equals(lastToken))
            {
                return(ValueTuple.Create(default(SyntaxToken), default(SyntaxToken)));
            }

            var firstTokenAfterAttribute = lastAttributeToken.GetNextToken(includeZeroWidth: true);

            // there are attributes, get first token after the tokens belong to attributes
            return(ValueTuple.Create(firstTokenAfterAttribute, lastToken));
        }