コード例 #1
0
ファイル: DiffChain.cs プロジェクト: chrisparnin/Codegrams
        public static DiffChain ConstructBackwardDiffChain(FileSnapshot a, FileSnapshot next, int right)
        {
            DiffChain backward = new DiffChain();

            backward.Start     = right;
            backward.StartSnap = next;
            backward.EndSnap   = a;
            backward.End       = null;
            int?left = next.GetRightToLeft(right);  // left is a's right

            if (left == null)
            {
                backward.Kind = DiffChainType.Null;
                return(backward);
            }
            //left++; // backward chaining drift?

            var aStatus    = backward.RightFromLeftStatus(a, left.Value);
            var nextStatus = backward.SelfStatusFromRight(next, right);
            var chainType  = backward.DetermineChainType(aStatus, nextStatus);

            backward.Kind = chainType;
            backward.End  = left;
            return(backward);
        }
コード例 #2
0
ファイル: DiffChain.cs プロジェクト: chrisparnin/Codegrams
        protected DiffChainCapType RightFromLeftStatus(FileSnapshot snapshot, int otherLeft)
        {
            // Transform to local index.
            int localRight = otherLeft;
            // TODO: Is this bounded at end?
            var difference = snapshot.Differences.Where(d => localRight >= d.Right.Start && localRight < d.Right.Start + d.Right.Length).SingleOrDefault();

            if (difference == null)
            {
                return(DiffChainCapType.Bottom);
            }

            if (difference.DifferenceType == DifferenceType.Add)
            {
                // Transduce to bottom.
                //return DiffChainCapType.Bottom;
                return(DiffChainCapType.Add);
            }

            if (difference.DifferenceType == DifferenceType.Change)
            {
                return(DiffChainCapType.Mod);
            }

            if (difference.DifferenceType == DifferenceType.Remove)
            {
                return(DiffChainCapType.Del);
            }
            throw new ArgumentException("Invalid argument to RightToLeftStatus");
        }
コード例 #3
0
ファイル: DiffChain.cs プロジェクト: chrisparnin/Codegrams
        protected DiffChainCapType SelfStatusFromRight(FileSnapshot snapshot, int right)
        {
            int localRight = right;

            var difference = snapshot.Differences.Where(d => localRight >= d.Right.Start && localRight < d.Right.Start + d.Right.Length).SingleOrDefault();

            if (difference == null)
            {
                difference = snapshot.Differences.Where(d => d.DifferenceType == DifferenceType.Remove && d.Right.Start == localRight).SingleOrDefault();
            }

            if (difference == null)
            {
                return(DiffChainCapType.Bottom);
            }

            if (difference.DifferenceType == DifferenceType.Add)
            {
                // Transduce to bottom.
                //return DiffChainCapType.Bottom;
                return(DiffChainCapType.Add);
            }

            if (difference.DifferenceType == DifferenceType.Change)
            {
                return(DiffChainCapType.Mod);
            }

            if (difference.DifferenceType == DifferenceType.Remove)
            {
                return(DiffChainCapType.Del);
            }
            throw new ArgumentException("Invalid argument to RightToLeftStatus");
        }
コード例 #4
0
ファイル: DiffChain.cs プロジェクト: chrisparnin/Codegrams
        protected DiffChainCapType LeftFromRightStatus(FileSnapshot snapshot, int otherRight)
        {
            // Transform to local index.
            int localLeft  = otherRight;
            var difference = snapshot.Differences.Where(d => localLeft >= d.Left.Start && localLeft < d.Left.Start + d.Left.Length).SingleOrDefault();

            if (difference == null)
            {
                difference = snapshot.Differences.Where(d => d.DifferenceType == DifferenceType.Add && d.Left.Start == localLeft).SingleOrDefault();
            }

            if (difference == null)
            {
                return(DiffChainCapType.Bottom);
            }

            if (difference.DifferenceType == DifferenceType.Add)
            {
                // Transduce to bottom.
                //return DiffChainCapType.Bottom;
                return(DiffChainCapType.Add);
            }

            if (difference.DifferenceType == DifferenceType.Change)
            {
                return(DiffChainCapType.Mod);
            }

            if (difference.DifferenceType == DifferenceType.Remove)
            {
                return(DiffChainCapType.Del);
            }
            throw new ArgumentException("Invalid argument to LeftToRightStatus");
        }
コード例 #5
0
ファイル: DiffChain.cs プロジェクト: chrisparnin/Codegrams
        public static DiffChain ConstructForwardDiffChain(FileSnapshot a, FileSnapshot next, int right)
        {
            try
            {
                var chain = new DiffChain()
                {
                };
                var aStatus    = chain.SelfStatusFromRight(a, right);
                var nextStatus = chain.LeftFromRightStatus(next, right);
                var chainType  = chain.DetermineChainType(aStatus, nextStatus);

                chain.Kind      = chainType;
                chain.Start     = right;
                chain.End       = next.GetLeftToRight(right);
                chain.StartSnap = a;
                chain.EndSnap   = next;
                return(chain);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
                return(null);
            }
        }
コード例 #6
0
        public static void Main(String[] args)
        {
            FileSnapshot snapshot = new FileSnapshot("test.cs");

            Difference d = new Difference()
            {
                Left = new Span()
                {
                    Start = 0, Length = 2
                },
                Right = new Span()
                {
                    Start = 0, Length = 4
                }
            };

            snapshot.LeftTextLines = new String[]
            {
                "Difference d = new Difference(new VisualStudio.Text.Span(0,2), new VisualStudio.Text.Span(0,4), null, null );\n",
                "}"
            }.ToList();
            snapshot.RightTextLines = new String[]
            {
                "Difference d = new Difference(new VisualStudio.Text.Span(0,2), new VisualStudio.Text.Span(0,4), null, null );\n",
                "\n",
                "// Hello bob\n",
                "}"
            }.ToList();

            var dict = snapshot.ForwardMatchChangeLinesAcrossDiff(d);

            foreach (var entry in dict)
            {
                Console.WriteLine(entry.Key + ":" + entry.Value);
            }
        }