Пример #1
0
        /// <summary>
        /// Throws MatchingException.
        /// </summary>
        public bool Match(MatchInfo matchInfo, DiffPosition inDiffPosition, out DiffPosition outDiffPosition)
        {
            if (!matchInfo.IsValid())
            {
                throw new ArgumentException(
                          String.Format("Bad match info: {0}", matchInfo.ToString()));
            }

            bool   isLeftSide   = matchInfo.IsLeftSideLineNumber;
            string currentName  = isLeftSide ? matchInfo.LeftFileName : matchInfo.RightFileName;
            string oppositeName = isLeftSide ? matchInfo.RightFileName : matchInfo.LeftFileName;

            oppositeName = getOppositeName(inDiffPosition.Refs, isLeftSide, currentName, oppositeName);

            outDiffPosition = new DiffPosition(
                isLeftSide ? currentName : oppositeName,
                isLeftSide ? oppositeName : currentName,
                inDiffPosition.LeftLine,
                inDiffPosition.RightLine,
                inDiffPosition.Refs);
            return(oppositeName != null);
        }
Пример #2
0
        /// <summary>
        /// Return DiffPosition if match succeeded and throw if match failed
        /// Throws ArgumentException in case of bad arguments.
        /// Throws MatchingException.
        /// </summary>
        public void Match(MatchInfo matchInfo, DiffPosition inDiffPosition, out DiffPosition outDiffPosition)
        {
            if (!matchInfo.IsValid())
            {
                throw new ArgumentException(
                          String.Format("Bad match info: {0}", matchInfo.ToString()));
            }

            int  currentLine = matchInfo.LineNumber;
            bool isLeftSide  = matchInfo.IsLeftSideLineNumber;

            int?oppositeLine;

            try
            {
                oppositeLine = getOppositeLine(inDiffPosition.Refs, isLeftSide, inDiffPosition.LeftPath,
                                               inDiffPosition.RightPath, currentLine);
            }
            catch (BadPosition)
            {
                throw new ArgumentException(
                          String.Format("Bad match info: {0}", matchInfo.ToString()));
            }
            catch (ContextMakingException ex)
            {
                throw new MatchingException("Cannot match lines", ex);
            }

            string currentLineAsString  = currentLine.ToString();
            string oppositeLineAsString = oppositeLine?.ToString();

            outDiffPosition = new DiffPosition(
                inDiffPosition.LeftPath,
                inDiffPosition.RightPath,
                isLeftSide ? currentLineAsString : oppositeLineAsString,
                isLeftSide ? oppositeLineAsString : currentLineAsString,
                inDiffPosition.Refs);
        }
Пример #3
0
        private DiffPosition createPosition(MatchResult matchResult, DiffRefs diffRefs, DiffToolInfo difftoolInfo)
        {
            string leftPath  = String.Empty;
            string rightPath = String.Empty;

            getPositionPaths(ref difftoolInfo, ref leftPath, ref rightPath);

            string leftLine  = String.Empty;
            string rightLine = String.Empty;

            getPositionLines(matchResult, ref leftLine, ref rightLine);

            DiffPosition position = new DiffPosition
            {
                Refs      = diffRefs,
                LeftPath  = leftPath,
                LeftLine  = leftLine,
                RightPath = rightPath,
                RightLine = rightLine
            };

            return(position);
        }