/// <summary> /// Constructor. /// </summary> /// <param name="eventType">position change, or add/change/delete a method</param> /// <param name="methodObj">method name, type, file FilePath, start line number of the method</param> /// <param name="curLine">current line number of the method</param> /// <param name="curColumn">current column of the method</param> public MethodEventRaisedArgs(MethodEventType eventType, Method methodObj, Method oldMethod, int curLine, int curColumn) { this.EventType = eventType; this.method = methodObj; this.oldMethod = oldMethod; this.curLine = curLine; this.curColumn = curColumn; }
public MethodEventRaisedArgs(MethodEventType eventType, Method methodObj, Method oldMethod) : this(eventType, methodObj, oldMethod, 0, 0) { }
public MethodEventRaisedArgs(Method methodObj, Method oldMethod, int curLine, int curColumn) : this(MethodEventType.PositionChanged, methodObj, oldMethod, curLine, curColumn) { }
private static bool CompareMethodDefinitions(Method a, Method b) { if (a == null || b == null) return false; if (a.Name == b.Name && ParameterTypesMatch(a.ParameterTypes, b.ParameterTypes) ) { return a.StartLineNumber == b.StartLineNumber; } else return false; }
public bool Equals(Method b) { if(null == b) { return false; } return CompareMethodDefinitions(this, b); }
/// <summary> /// Determine if two methods have the same signatures (name, paramtertype) /// </summary> /// <param name="b"></param> /// <returns></returns> public bool SignatureEquals(Method b) { if (null == b) { return false; } return (this.Name == b.Name && ParameterTypesMatch(this.ParameterTypes, b.ParameterTypes)); }
private void DeleteMethodsInDeletedFile(string deletedFilePath) { if (_currentMethod.FilePath == deletedFilePath) _currentMethod = new Method(); foreach (var method in _navigatedMethods) { if (method.FilePath == deletedFilePath) { _navigatedMethods.Remove(method); OnMethodUpdatedEvent(new MethodEventRaisedArgs(MethodEventType.MethodDeleted, null, method)); } } }
public MethodTrack(IServiceProvider sp) { _serviceProvider = sp; _dataService = sp.GetService(typeof(SSrcMLDataService)) as ISrcMLDataService; _srcmlService = sp.GetService(typeof(SSrcMLGlobalService)) as ISrcMLGlobalService; _cursorMonitor = sp.GetService(typeof(SCursorMonitorService)) as ICursorMonitorService; _currentMethod = new Method(); _navigatedMethods = new List<Method>(); _currentCursor = new CursorPos("", 0, 0); if (null != _cursorMonitor) _cursorMonitor.PropertyChanged += OnCursorMoving; if(null != _srcmlService) _srcmlService.SourceFileChanged += OnFileChanged; }
/// <summary> /// Determine the state of a previously navigated method in the file which it was located at /// </summary> /// <param name="preNavigatedMethod">a previously navigated method</param> /// <param name="newAllMethods">collection of all methods after a file change (where the previously navigate method wass located)</param> /// <param name="newMethod">a new method object is also returned if the function returns 1</param> /// <returns>0 - unchanged, 1 - still there but changed, 2 - deleted</returns> private int MethodUpdatedState(Method preNavigatedMethod, List<Method> newAllMethods, out Method newMethod) { //method change: "name", "type" and "prameter type" remain the same but startline number changes //method deletion: no longer find a method with the same (type + name + parameter type) //todo: method rename is a special case might be handled later (it may need a comparision of the method body) newMethod = new Method(); foreach (var method in newAllMethods) { if (method.SignatureEquals(preNavigatedMethod) && method.Type == preNavigatedMethod.Type) { if (method.Equals(preNavigatedMethod)) //StartLineNumber comparison return 0; else { newMethod = method; return 1; } } } return 2; }
private void ChangeMethodsInChangedFile(string oldFilePath) { List<Method> allMethods; GetAllMethods(oldFilePath, out allMethods); for (int i=0; i < _navigatedMethods.Count; i++) { if (_navigatedMethods[i].FilePath == oldFilePath) { var method = _navigatedMethods[i]; Method newMethod; var updateType = MethodUpdatedState(method, allMethods, out newMethod); switch (updateType) { case 0: // unchanged break; case 1: // stays but changed _navigatedMethods[i] = newMethod; OnMethodUpdatedEvent(new MethodEventRaisedArgs(MethodEventType.MethodChanged, newMethod, method)); if (_currentMethod.Equals(method)) _currentMethod = newMethod; break; case 2: // deleted _navigatedMethods.RemoveAt(i); OnMethodUpdatedEvent(new MethodEventRaisedArgs(MethodEventType.MethodDeleted, null, method)); if (_currentMethod.Equals(method)) _currentMethod = new Method(); break; } } } }
private void ChangeMethodsInRenamedFile(string oldFilePath, string newFilePath) { if(oldFilePath == newFilePath) return; for (var i=0; i< _navigatedMethods.Count; i++) { if (_navigatedMethods[i].FilePath == oldFilePath) { var oldmethod = _navigatedMethods[i]; _navigatedMethods[i].FilePath = newFilePath; var method = _navigatedMethods[i]; OnMethodUpdatedEvent(new MethodEventRaisedArgs(MethodEventType.MethodChanged, method, oldmethod)); if (_currentMethod.SignatureEquals(method)) _currentMethod = method; } } }
private void AddMethodToHistoryList(Method currentMethod) { if(! _navigatedMethods.Contains(_currentMethod)) _navigatedMethods.Add(currentMethod); }
/// <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; }