Пример #1
0
        /// <summary>
        /// Determines whether the given source location occurs within this location.
        /// This will be determined using the XPath, if set.
        /// </summary>
        /// <param name="otherLoc">The SourceLocation to test</param>
        /// <returns>True if this location subsumes the given location, False otherwise.</returns>
        public override bool Contains(SourceLocation otherLoc) {
            if(otherLoc == null) throw new ArgumentNullException("otherLoc");

            var otherSrcMLLoc = otherLoc as SrcMLLocation;
            if(otherSrcMLLoc != null && !string.IsNullOrWhiteSpace(XPath) && !string.IsNullOrWhiteSpace(otherSrcMLLoc.XPath)) {
                //return XPath.StartsWith(otherSrcMLLoc.XPath);
                return otherSrcMLLoc.XPath.StartsWith(this.XPath);
            }
            return base.Contains(otherLoc);
        }
Пример #2
0
        /// <summary>
        /// Determines whether the given source location occurs within this location.
        /// </summary>
        /// <param name="otherLoc">The SourceLocation to test</param>
        /// <returns>True if this location subsumes the given location, False otherwise.</returns>
        public virtual bool Contains(SourceLocation otherLoc) {
            if(otherLoc == null) throw new ArgumentNullException("otherLoc");

            if(string.Compare(this.SourceFileName, otherLoc.SourceFileName, StringComparison.InvariantCultureIgnoreCase) != 0) {
                //files not equal
                return false;
            }
            if(EndingLineNumber < otherLoc.StartingLineNumber ||
                (EndingLineNumber == otherLoc.StartingLineNumber && EndingColumnNumber <= otherLoc.StartingColumnNumber)) {
                //otherLoc starts after this location ends    
                return false;
            }
            if((StartingLineNumber < otherLoc.StartingLineNumber ||
                (StartingLineNumber == otherLoc.StartingLineNumber && StartingColumnNumber <= otherLoc.StartingColumnNumber))
               &&
               (otherLoc.EndingLineNumber < EndingLineNumber ||
                (otherLoc.EndingLineNumber == EndingLineNumber && otherLoc.EndingColumnNumber <= EndingColumnNumber))) {
                return true;
            }

            return false;
        }
Пример #3
0
 public static string GetLocation(SourceLocation location) {
     return string.Format("{0}:{1}:{2}", location.SourceFileName, location.StartingLineNumber, location.StartingColumnNumber);
 }
Пример #4
0
       /// <summary>
       /// Get a method object from (file, line number, column number)
       /// </summary>
       /// <param name="fileName"></param>
       /// <param name="lineNum"></param>
       /// <param name="colNum"></param>
       /// <returns>if the cursor is in a method, return true; otherwise return false</returns>
       private bool GetMethod(string fileName, int lineNum, int colNum)
       {
           bool isInMethod = false;

           if (null == _dataService)
               return false;
             
           var data = _dataService.CurrentDataArchive.GetData(fileName);
           
           if (null != data)
           {
               var methods = data.GetDescendants<MethodDefinition>();
               foreach (var methoddef in methods)
               {
                   SourceLocation cursorPos = new SourceLocation(fileName, lineNum, colNum);
                   if (methoddef.ContainsLocation(cursorPos))
                   {
                       isInMethod = true;
                       _currentMethod = new Method(methoddef);
                       break;
                       //assert(outMethod.filePath.equals(fileName))
                   }
               }
           }

           return isInMethod;
       }