Ejemplo n.º 1
0
 /// <summary>
 /// Tries to find token for specified BodyChange.
 /// </summary>
 /// <param name="change">Change, for which is token to be found.</param>
 /// <param name="token">Here is stored token of BodyChange.</param>
 /// <returns>True if token found.</returns>
 private bool getMethodToken(BodyChange change, out uint token)
 {
     if (change.MemberKind == SourceChangeMember.Method)
     {
         MethodDefinition def = manager.MetadataManager.FindMethod(manager.ResourceManager.OldAssembly,
                                                                   manager.ResourceManager.CurrentModule.Name, (IMethod)change.NewEntity);
         if (def != null)
         {
             token = def.MetadataToken.ToUInt32();
             return(true);
         }
     }
     else
     {
         PropertyDefinition defProp = manager.MetadataManager.FindProperty(manager.ResourceManager.OldAssembly,
                                                                           manager.ResourceManager.CurrentModule.Name, (IProperty)change.NewEntity);
         MethodDefinition def = (change.isGetter ? defProp.GetMethod : defProp.SetMethod);
         if (def != null)
         {
             token = def.MetadataToken.ToUInt32();
             return(true);
         }
     }
     token = 0;
     return(false);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Find first change in project structure. Determines which method is changed etc. .
        /// </summary>
        /// <param name="change">Additional info about change in source code text.</param>
        /// <param name="doc">Document, that was changed.</param>
        /// <returns>Instance of BodyChange, containing info about change in structure.</returns>
        private BodyChange findBodyChanges(TextChangeEventArgs change, IDocument doc)
        {
            IDocumentLine line = doc.GetLineForOffset(change.Offset);

            int row    = line.LineNumber;
            int column = change.Offset - line.Offset;

            bool       found  = false;
            BodyChange entity = null;

            foreach (IClass classEl in ParserService.CurrentProjectContent.Classes)
            {
                if (classEl is CompoundClass)
                {
                    CompoundClass compClass = classEl as CompoundClass;
                    foreach (IClass compPart in compClass.Parts)
                    {
                        if (compPart.BodyRegion.IsInside(row, column) && FileUtility.IsEqualFileName(classEl.CompilationUnit.FileName, changingFilename))
                        {
                            entity = findBodyChangesClass(compPart, row, column);
                            if (entity != null)
                            {
                                found = true;
                                break;
                            }
                        }
                    }
                    if (found)
                    {
                        break;
                    }
                }
                if (classEl.BodyRegion.IsInside(row, column) && FileUtility.IsEqualFileName(classEl.CompilationUnit.FileName, changingFilename))
                {
                    entity = findBodyChangesClass(classEl, row, column);
                    if (entity != null)
                    {
                        found = true;
                        break;
                    }
                }
            }
            return(entity);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Event callback for change in documents text.
        /// </summary>
        /// <param name="src">Document, that is being changed.</param>
        /// <param name="arg">Additional info about changes in text.</param>
        private void changingEvent(object src, TextChangeEventArgs arg)
        {
            IDocument doc = (IDocument)src;

            ITextEditorProvider provider = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorProvider;

            changingFilename = provider.TextEditor.FileName;

            if (DebuggerService.IsDebuggerStarted)
            {
                if (arg.InsertedText.Length > 0 || arg.RemovedText.Length > 0)
                {
                    if (!actualEvent.touched.Exists(changingFilename.Equals))
                    {
                        actualEvent.touched.Add(changingFilename);
                    }
                    changeMade = true;
                    uint       token;
                    BodyChange change = findBodyChanges(arg, doc);
                    if (change != null && lastProjectContent.Exist(change.NewEntity))
                    {
                        if (!actualEvent.changes.Exists(delegate(SourceChange sChange) { return(bodyChangeEquals(sChange, change.NewEntity)); }))
                        {
                            actualEvent.changes.Add(change);
                        }
                    }
                    else
                    {
                        return;
                    }
                    if (getMethodToken(change, out token))
                    {
                        BodyChangeHistory hist;
                        if (!actualEvent.sourceTextChanges.TryGetValue(token, out hist))
                        {
                            hist = new BodyChangeHistory(LineOffsetConverter.BuildConverter(change.NewEntity.BodyRegion, doc));
                            actualEvent.sourceTextChanges.Add(token, hist);
                        }
                        int bOffset = doc.PositionToOffset(change.NewEntity.BodyRegion.BeginLine, 0);

                        SourceTextChange sTchange;
                        sTchange.Offset = arg.Offset - bOffset;

                        if (arg.InsertionLength > 0)
                        {
                            sTchange.Length    = arg.InsertionLength;
                            sTchange.Removed   = false;
                            sTchange.Semicolon = semicolonFind(arg.InsertedText);
                            hist.TextChanges.Add(sTchange);
                        }
                        if (arg.RemovalLength > 0)
                        {
                            sTchange.Length    = arg.RemovalLength;
                            sTchange.Removed   = true;
                            sTchange.Semicolon = semicolonFind(arg.RemovedText);
                            hist.TextChanges.Add(sTchange);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Tries to find token for specified BodyChange.
        /// </summary>
        /// <param name="change">Change, for which is token to be found.</param>
        /// <param name="token">Here is stored token of BodyChange.</param>
        /// <returns>True if token found.</returns>
        private bool getMethodToken(BodyChange change, out uint token)
        {
            if (change.MemberKind == SourceChangeMember.Method) {
                MethodDefinition def = manager.MetadataManager.FindMethod(manager.ResourceManager.OldAssembly,
                                          manager.ResourceManager.CurrentModule.Name,(IMethod)change.NewEntity);
                if (def != null) {
                    token = def.MetadataToken.ToUInt32();
                    return true;
                }
            } else {

                PropertyDefinition defProp = manager.MetadataManager.FindProperty(manager.ResourceManager.OldAssembly,
                                          manager.ResourceManager.CurrentModule.Name, (IProperty)change.NewEntity);
                MethodDefinition def = (change.isGetter ? defProp.GetMethod : defProp.SetMethod);
                if (def != null) {
                    token = def.MetadataToken.ToUInt32();
                    return true;
                }
            }
            token = 0;
            return false;
        }