Beispiel #1
0
        public virtual XSharpToken Create(Tuple <ITokenSource, ICharStream> source, int type, string text, int channel, int start, int stop, int line, int charPositionInLine)
        {
            XSharpToken t = new XSharpToken(source, type, channel, start, stop);

            t.Line   = line;
            t.Column = charPositionInLine;
            //t.SourceFileName = source.Item1.SourceName;
            if (text != null)
            {
                t.Text = text;
            }
            else
            {
                if (copyText && source.Item2 != null)
                {
                    t.Text = source.Item2.GetText(Interval.Of(start, stop));
                }
            }
            return(t);
        }
        public SyntaxTriviaList GetLeadingTrivia(CSharpSyntaxNode parent, CompilationUnitSyntax cu)
        {
            var list = new SyntaxTriviaList();

            if (cu == null || cu.XTokens == null)
            {
                return(list);
            }
            var options = ((CSharpParseOptions)cu.SyntaxTree.Options);

            if (!cu.HasDocComments && options.TargetDLL == XSharpTargetDLL.Other)
            {
                return(list);
            }
            XSharpToken start  = this.Start as XSharpToken;
            var         tokens = ((BufferedTokenStream)cu.XTokens).GetTokens();
            // find offset of first token in the tokenlist
            int startindex = start.OriginalTokenIndex;

            if (startindex >= 0)
            {
                startindex -= 1;
                var endindex = startindex;
                var sb       = new System.Text.StringBuilder();
                while (startindex >= 0)
                {
                    switch (tokens[startindex].Channel)
                    {
                    case XSharpLexer.XMLDOCCHANNEL:
                        sb.Insert(0, tokens[startindex].Text + "\r\n");
                        break;

                    case XSharpLexer.DefaultTokenChannel:
                        // exit the loop
                        startindex = 0;
                        break;
                    }
                    startindex--;
                }
                // when compiling the runtime we generate blank xml comments for enum members, defines and double underscores without xml comments

                if (sb.Length == 0 && options.TargetDLL != XSharpTargetDLL.Other)
                {
                    XSharpParser.IEntityContext entity = null;
                    if (this is XSharpParser.EntityContext ec)
                    {
                        if (ec.GetChild(0) is XSharpParser.IEntityContext iec)
                        {
                            entity = iec;
                        }
                    }
                    if (this is XSharpParser.ClassmemberContext cmc)
                    {
                        if (cmc.GetChild(0) is XSharpParser.IEntityContext iec)
                        {
                            entity = iec;
                        }
                    }
                    if (entity == null && this is XSharpParser.FoxclassmemberContext fmc)
                    {
                        if (fmc.GetChild(0) is XSharpParser.IEntityContext iec)
                        {
                            entity = iec;
                        }
                    }
                    if (entity == null && this is XSharpParser.XppclassMemberContext xmc)
                    {
                        if (xmc.GetChild(0) is XSharpParser.IEntityContext iec)
                        {
                            entity = iec;
                        }
                    }
                    if (entity == null && this is XSharpParser.IEntityContext ec2)
                    {
                        entity = ec2;
                    }
                    if (entity != null && entity.ShortName.StartsWith("__"))
                    {
                        sb.Append("/// <exclude/>");
                    }

                    if (this is XSharpParser.EnummemberContext ||
                        this is XSharpParser.VodefineContext)
                    {
                        if (sb.Length == 0)
                        {
                            sb.Append("/// <summary></summary>");
                        }
                    }
                }
                if (sb.Length > 0)
                {
                    string text   = sb.ToString();
                    var    source = MCT.SourceText.From(text);
                    var    lexer  = new Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.Lexer(source, CSharpParseOptions.Default);
                    list = lexer.LexSyntaxLeadingTrivia();
                    lexer.Dispose();
                }
            }
            return(list);
        }