Exemple #1
0
        public virtual SyntaxList <TNode> VisitList <TNode>(SyntaxList <TNode> list) where TNode : SyntaxNode
        {
            SyntaxListBuilder alternate = null;

            for (int i = 0, n = list.Count; i < n; i++)
            {
                var item    = list[i];
                var visited = VisitListElement(item);
                if (item != visited && alternate == null)
                {
                    alternate = new SyntaxListBuilder(n);
                    alternate.AddRange(list, 0, i);
                }

                if (alternate != null && visited != null)
                {
                    alternate.Add(visited);
                }
            }

            if (alternate != null)
            {
                return(alternate.ToList());
            }

            return(list);
        }
        private SyntaxList <RazorSyntaxNode> GetLegacyChildren()
        {
            // This method returns the children of this start tag in legacy format.
            // This is needed to generate the same classified spans as the legacy syntax tree.
            var builder = new SyntaxListBuilder(5);
            var tokens  = SyntaxListBuilder <SyntaxToken> .Create();

            var context = this.GetSpanContext();

            // We want to know if this tag contains non-whitespace attribute content to set the appropriate AcceptedCharacters.
            // The prefix of a start tag(E.g '|<foo| attr>') will have 'Any' accepted characters if non-whitespace attribute content exists.
            var acceptsAnyContext = new SpanContext(context.ChunkGenerator, SpanEditHandler.CreateDefault());

            acceptsAnyContext.EditHandler.AcceptedCharacters = AcceptedCharactersInternal.Any;
            var containsAttributesContent = false;

            foreach (var attribute in Attributes)
            {
                if (!string.IsNullOrWhiteSpace(attribute.GetContent()))
                {
                    containsAttributesContent = true;
                    break;
                }
            }

            if (!OpenAngle.IsMissing)
            {
                tokens.Add(OpenAngle);
            }
            if (Bang != null)
            {
                builder.Add(SyntaxFactory.MarkupTextLiteral(tokens.Consume()).WithSpanContext(acceptsAnyContext));

                tokens.Add(Bang);
                var acceptsNoneContext = new SpanContext(context.ChunkGenerator, SpanEditHandler.CreateDefault());
                acceptsNoneContext.EditHandler.AcceptedCharacters = AcceptedCharactersInternal.None;
                builder.Add(SyntaxFactory.RazorMetaCode(tokens.Consume()).WithSpanContext(acceptsNoneContext));
            }
            if (!Name.IsMissing)
            {
                tokens.Add(Name);
            }

            builder.Add(SyntaxFactory.MarkupTextLiteral(tokens.Consume()).WithSpanContext(containsAttributesContent ? acceptsAnyContext : context));

            builder.AddRange(Attributes);

            if (ForwardSlash != null)
            {
                tokens.Add(ForwardSlash);
            }
            if (!CloseAngle.IsMissing)
            {
                tokens.Add(CloseAngle);
            }

            if (tokens.Count > 0)
            {
                builder.Add(SyntaxFactory.MarkupTextLiteral(tokens.Consume()).WithSpanContext(context));
            }

            return(new SyntaxList <RazorSyntaxNode>(builder.ToListNode().CreateRed(this, Position)));
        }