Esempio n. 1
0
        public static SyntaxList <TypeParameterConstraintClauseSyntax> GetTypeParameterConstraintList(
            IEnumerable <SyntaxNode> typeParamsAndConstraints,
            Whitespace2Collection whitespace2Set,
            WhitespaceKindLookup whitespaceLookup)
        {
            var typeParameters = typeParamsAndConstraints
                                 .OfType <TypeParameterSyntax>()
                                 .ToList();
            var typeConstraintClauses = typeParamsAndConstraints
                                        .OfType <TypeParameterConstraintClauseSyntax>()
                                        .ToList();
            var clauses = new List <TypeParameterConstraintClauseSyntax>();

            foreach (var typeParameter in typeParameters)
            {
                var name       = typeParameter.Identifier.ToString();
                var constraint = typeConstraintClauses
                                 .Where(x => x.Name.ToString() == name &&
                                        x.Constraints.Any())
                                 .ToList()
                                 .SingleOrDefault();
                if (constraint != null)
                {
                    clauses.Add(constraint);
                }
            }
            return(SyntaxFactory.List(clauses));
        }
Esempio n. 2
0
        internal T AttachWhitespace <T>(T syntaxNode, Whitespace2Collection whitespace2Set,
                                        WhitespaceKindLookup whitespaceLookup, LanguagePart languagePart)
            where T : SyntaxNode
        {
            var ret               = syntaxNode;
            var whitespaceList    = whitespace2Set.Where(x => x.LanguagePart == languagePart);
            var missingWhitespace = whitespaceLookup.NotUsedInWhitespaceList(whitespaceList);

            whitespaceList = whitespaceList
                             .Union(missingWhitespace
                                    .Select(x => new Whitespace2(languagePart, x)));
            foreach (var whitespace in whitespaceList)
            {
                ret = AttachWhitespaceItem(ret, whitespace, whitespaceLookup);
            }
            // Not sure the functional approah is best here
            ret = CheckToken <T>(ret,
                                 x => x.GetLastToken(),
                                 t => t.TrailingTrivia,
                                 s => SyntaxFactory.ParseTrailingTrivia(s),
                                 (t, trivia) => t.WithTrailingTrivia(trivia),
                                 whitespace2Set.ForceTrailing);
            ret = CheckToken <T>(ret,
                                 x => x.GetFirstToken(),
                                 t => t.LeadingTrivia,
                                 s => SyntaxFactory.ParseLeadingTrivia(s),
                                 (t, trivia) => t.WithLeadingTrivia(trivia),
                                 whitespace2Set.ForceLeading);
            return(ret);
        }
Esempio n. 3
0
        public static TypeParameterListSyntax GetTypeParameterSyntaxList(
            IEnumerable <SyntaxNode> typeParamsAndConstraints,
            Whitespace2Collection whitespace2Set,
            WhitespaceKindLookup whitespaceLookup)
        {
            var typeParameters = typeParamsAndConstraints
                                 .OfType <TypeParameterSyntax>()
                                 .ToList();

            if (typeParameters.Any())
            {
                var typeParameterListSyntax = SyntaxFactory.TypeParameterList(
                    SyntaxFactory.SeparatedList <TypeParameterSyntax>(typeParameters));
                typeParameterListSyntax = AttachWhitespace(
                    typeParameterListSyntax, whitespace2Set,
                    whitespaceLookup);
                return(typeParameterListSyntax);;
            }
            return(null);
        }
Esempio n. 4
0
 public static T AttachWhitespace <T>(T syntaxNode, Whitespace2Collection whitespace2Set, WhitespaceKindLookup whitespaceLookup, LanguagePart languagePart)
     where T : SyntaxNode
 {
     return(triviaManager.AttachWhitespace(syntaxNode, whitespace2Set, whitespaceLookup, languagePart));
 }
Esempio n. 5
0
 private void Initialize()
 {
     Whitespace2Set = new Whitespace2Collection();
 }
Esempio n. 6
0
 internal T AttachWhitespace <T>(T syntaxNode, Whitespace2Collection whitespace2Set,
                                 WhitespaceKindLookup whitespaceLookup)
     where T : SyntaxNode
 {
     return(AttachWhitespace(syntaxNode, whitespace2Set, whitespaceLookup, LanguagePart.Current));
 }
Esempio n. 7
0
 protected RDomBase()
 {
     Whitespace2Set = new Whitespace2Collection();
 }