Ejemplo n.º 1
0
        public static TextSpan GetTrailingTriviaSpan(this SyntaxNode node)
        {
            var trailingTrivia = node.GetTrailingTrivia().Node;

            return(trailingTrivia != null ?
                   new TextSpan(node.Start + node.FullWidth - trailingTrivia.Width, trailingTrivia.Width) :
                   new TextSpan(node.Start + node.FullWidth, 0));
        }
Ejemplo n.º 2
0
            private void AddTrivia(SyntaxNode node, SyntaxToken token)
            {
                if ((this._options & SyntaxRemoveOptions.KeepLeadingTrivia) != 0)
                {
                    this.AddResidualTrivia(node.GetLeadingTrivia());
                }
                else if ((this._options & SyntaxRemoveOptions.KeepEndOfLine) != 0 && HasEndOfLine(node.GetLeadingTrivia()))
                {
                    this.AddEndOfLine();
                }

                if ((this._options & SyntaxRemoveOptions.KeepTrailingTrivia) != 0)
                {
                    this.AddResidualTrivia(node.GetTrailingTrivia());
                    this.AddResidualTrivia(token.GetLeadingTrivia());
                    this.AddResidualTrivia(token.GetTrailingTrivia());
                }
                else if ((this._options & SyntaxRemoveOptions.KeepEndOfLine) != 0 && (HasEndOfLine(node.GetTrailingTrivia()) || HasEndOfLine(token.GetLeadingTrivia()) || HasEndOfLine(token.GetTrailingTrivia())))
                {
                    this.AddEndOfLine();
                }
            }
Ejemplo n.º 3
0
            private void AddTrivia(SyntaxNode node)
            {
                if ((this._options & SyntaxRemoveOptions.KeepLeadingTrivia) != 0)
                {
                    this.AddResidualTrivia(node.GetLeadingTrivia());
                }
                else if ((this._options & SyntaxRemoveOptions.KeepEndOfLine) != 0 && HasEndOfLine(node.GetLeadingTrivia()))
                {
                    this.AddEndOfLine();
                }
                if ((this._options & SyntaxRemoveOptions.KeepTrailingTrivia) != 0)
                {
                    this.AddResidualTrivia(node.GetTrailingTrivia());
                }
                else if ((this._options & SyntaxRemoveOptions.KeepEndOfLine) != 0 && HasEndOfLine(node.GetTrailingTrivia()))
                {
                    this.AddEndOfLine();
                }

                /*if ((this._options & SyntaxRemoveOptions.AddElasticMarker) != 0)
                 *  this.AddResidualTrivia(SyntaxFactory.TriviaList(SyntaxFactory.ElasticMarker));*/
            }
Ejemplo n.º 4
0
        private int GetSimilarity(SyntaxNode node1, SyntaxNode node2)
        {
            // count the characters in the common/identical nodes
            int w = 0;

            _nodeSimilaritySet.Clear();
            _tokenTextSimilaritySet.Clear();

            if (node1.IsToken && node2.IsToken)
            {
                var text1 = node1.ToString();
                var text2 = node2.ToString();

                if (text1 == text2)
                {
                    // main text of token is the same
                    w += text1.Length;
                }

                foreach (var tr in node1.GetLeadingTrivia())
                {
                    _nodeSimilaritySet.Add(tr.GreenNode);
                }

                foreach (var tr in node1.GetTrailingTrivia())
                {
                    _nodeSimilaritySet.Add(tr.GreenNode);
                }

                foreach (var tr in node2.GetLeadingTrivia())
                {
                    if (_nodeSimilaritySet.Contains(tr.GreenNode))
                    {
                        w += tr.FullSpan.Length;
                    }
                }

                foreach (var tr in node2.GetTrailingTrivia())
                {
                    if (_nodeSimilaritySet.Contains(tr.GreenNode))
                    {
                        w += tr.FullSpan.Length;
                    }
                }
            }
            else
            {
                foreach (var n1 in node1.ChildNodesAndTokens())
                {
                    _nodeSimilaritySet.Add(n1.GreenNode);

                    if (n1.IsToken)
                    {
                        _tokenTextSimilaritySet.Add(n1.ToString());
                    }
                }

                foreach (var n2 in node2.ChildNodesAndTokens())
                {
                    if (_nodeSimilaritySet.Contains(n2.GreenNode))
                    {
                        w += n2.FullSpan.Length;
                    }
                    else if (n2.IsToken)
                    {
                        var tokenText = n2.ToString();
                        if (_tokenTextSimilaritySet.Contains(tokenText))
                        {
                            w += tokenText.Length;
                        }
                    }
                }
            }

            return(w);
        }