Ejemplo n.º 1
0
        private static IEnumerable <StatementSyntax> InsertStatement(BlockSyntax block, StatementSyntax statement, SyntaxNode before, SyntaxNode after)
        {
            Debug.Assert(before != null || after != null);

            string target = before != null?
                            RoslynCompiler.NodeMark(before) :
                                RoslynCompiler.NodeMark(after);

            Debug.Assert(target != null);

            foreach (var st in block.Statements)
            {
                string id = RoslynCompiler.NodeMark(st);
                if (id == target)
                {
                    if (before != null)
                    {
                        yield return(statement);

                        yield return(st);
                    }
                    else
                    {
                        yield return(st);

                        yield return(statement);
                    }
                }
                else
                {
                    yield return(st);
                }
            }
        }
Ejemplo n.º 2
0
        public FileLinePositionSpan OriginalPosition(Location location)
        {
            var tree = location.SourceTree;

            if (tree == null)
            {
                return(default(FileLinePositionSpan));
            }

            var errorNode = tree.GetRoot().FindNode(location.SourceSpan);

            if (errorNode == null)
            {
                return(default(FileLinePositionSpan));
            }

            string nodeID = RoslynCompiler.NodeMark(errorNode);

            if (nodeID == null)
            {
                return(default(FileLinePositionSpan));
            }

            var originalNode = RoslynCompiler.FindNode(_original, nodeID);

            if (originalNode == null)
            {
                return(default(FileLinePositionSpan));
            }

            location = originalNode.SyntaxTree.GetLocation(originalNode.Span);
            return(location.GetMappedLineSpan());
        }
Ejemplo n.º 3
0
 //td: !!! refactor the marking
 public static SyntaxNode UnMark(SyntaxNode node)
 {
     return(node.ReplaceNodes(node.DescendantNodesAndSelf(), (oldNode, newNode) =>
     {
         var id = RoslynCompiler.NodeMark(oldNode);
         return newNode
         .WithoutAnnotations(RoslynCompiler.NodeIdAnnotation)
         .WithoutAnnotations(RoslynCompiler.NodeIdAnnotation + id);
     }));
 }
Ejemplo n.º 4
0
        private static IEnumerable <StatementSyntax> ExplodeStatements(SyntaxList <StatementSyntax> statements, SyntaxNode toReplace, BlockSyntax block)
        {
            var nodeID = RoslynCompiler.NodeMark(toReplace);

            foreach (var statement in statements)
            {
                var innerID = RoslynCompiler.NodeMark(statement);
                if (innerID == nodeID)
                {
                    foreach (var inner in block.Statements)
                    {
                        yield return(inner);
                    }
                }
                else
                {
                    yield return(statement);
                }
            }
        }
Ejemplo n.º 5
0
 public string GetExcessStringId(SyntaxNode node)
 {
     return(RoslynCompiler.NodeMark(node));
 }
Ejemplo n.º 6
0
        public int GetExcessId(SyntaxNode node)
        {
            string xsStr = RoslynCompiler.NodeMark(node);

            return(xsStr == null ? -1 : int.Parse(xsStr));
        }