Esempio n. 1
0
        private void actAddLogging_Execute(ExecuteEventArgs ea)
        {
            try
            {
                Class activeClass = CodeRush.Source.ActiveClass;

                //IEnumerable<Method> methods = (IEnumerable<Method>)activeClass.AllMethods;

                fileChangeCollection = new FileChangeCollection();

                foreach (var method in activeClass.AllMethods)
                {
                    Method methodDetails = (Method)method;

                    System.Diagnostics.Debug.WriteLine(string.Format("Method:  Name:>{0}<  Type:>{1}<", methodDetails.Name, methodDetails.MethodType));
                    AddLoggingToMethod((DevExpress.CodeRush.StructuralParser.Method)method);
                }

                //Method activeMethod = CodeRush.Source.ActiveMethod;

                //AddLoggingToMethod(activeMethod);

                CodeRush.File.ApplyChanges(fileChangeCollection);
                CodeRush.Source.ParseIfTextChanged();

            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
        }
Esempio n. 2
0
        private void Apply(string displayName, HtmlElement original, HtmlElement newElement, string tabsBefore)
        {
            if ((!string.IsNullOrEmpty(displayName) && (original != null)) && (newElement != null))
            {
                int         num            = original.NameRange.End.Offset - original.StartOffset;
                SourceRange insertionRange = GetInsertionRange(original);
                string      s = CodeRush.Language.GenerateElement(newElement);
                s = CodeRush.StrUtil.RemoveLastLineTerminator(s);
                if (Options.PutCloseTagOnOwnLine)
                {
                    var terminator = @"/>";
                    if (!s.EndsWith(terminator))
                    {
                        terminator = @">";
                    }

                    s  = s.Substring(0, s.Length - terminator.Length);
                    s += string.Format("\r\n{0}{1}", tabsBefore, terminator);
                }
                insertionRange.BindToCode(CodeRush.Documents.Active as TextDocument);
                ICompoundAction         action = CodeRush.TextBuffers.NewMultiFileCompoundAction(displayName, true);
                IMultiLidContainerGroup group  = CodeRush.LinkedIdentifiers.OpenMultiLidContainerGroup();
                try
                {
                    FileChangeCollection changes = new FileChangeCollection();
                    changes.Add(new FileChange(original.FileNode.Name, insertionRange, s));
                    CodeRush.File.ApplyChanges(changes, false, true);
                    CodeRush.Caret.MoveTo(insertionRange.Start.Line, (int)(insertionRange.Start.Offset + num));
                }
                catch (Exception exception)
                {
                    LogBase <Log> .SendException(displayName, exception);
                }
                finally
                {
                    if (_breakApartPreview != null)
                    {
                        _breakApartPreview.Clear();
                        _breakApartPreview = null;
                    }

                    group.Close();
                    action.Close();
                    insertionRange.RemoveAllBindings();
                }
            }
        }
 private FileChangeCollection GetChanges()
 {
     _NumTypesChanged = 0;
     _NumMembersChanged = 0;
     _NumReferencesChanged = 0;
     Cursor saveCursor = Cursor.Current;
     try
     {
         Cursor.Current = Cursors.WaitCursor;
         FileChangeCollection result;
         result = new FileChangeCollection();
         SolutionElement activeSolution = CodeRush.Source.ActiveSolution;
         foreach (TypeDeclaration type in activeSolution.AllTypes)
         {
             bool countedThisType = false;
             foreach (Member member in type.AllMembers)
             {
                 string newName = GetNewName(member);
                 if (!String.IsNullOrEmpty(newName) && member.Name != newName)
                 {
                     if (!countedThisType)
                     {
                         countedThisType = true;
                         _NumTypesChanged++;
                     }
                     _NumMembersChanged++;
                     GetChanges(result, member, newName);
                 }
             }
         }
         return result;
     }
     finally
     {
         Cursor.Current = saveCursor;
     }
 }
 private void GetChanges(FileChangeCollection result, Member member, string newName)
 {
     result.Add(new FileChange(member.FileNode.Name, member.NameRange, newName));
     CascadeReferenceSearcher cascadeReferenceSearcher = new CascadeReferenceSearcher();
     IElementCollection references = cascadeReferenceSearcher.FindCascadeReferences(CodeRush.Source.ActiveSolution, member);
     foreach (IElement reference in references)
     {
         _NumReferencesChanged++;
         result.Add(new FileChange(reference.FirstFile.Name, reference.FirstNameRange, newName));
     }
 }
 public void AddQualifyingReferences(FileChangeCollection fileChangeCollection)
 {
     AddFileChanges(fileChangeCollection, _QualifyingReferences);
 }
 public void AddNamespaceImports(FileChangeCollection fileChangeCollection)
 {
     AddFileChanges(fileChangeCollection, _NamespaceImports);
 }
 private void AddFileChanges(FileChangeCollection fileChangeCollection, Dictionary<string, List<LanguageElement>> references)
 {
     foreach (KeyValuePair<string, List<LanguageElement>> referenceList in references)
     {
         string expectedNamespace = referenceList.Key;
         List<LanguageElement> allReferences = referenceList.Value;
         foreach (LanguageElement reference in allReferences)
             fileChangeCollection.Add(new FileChange(reference.FileNode.Name, reference.Range, expectedNamespace));
     }
 }
 public void RemoveOldNamespaceImports(FileChangeCollection fileChangeCollection)
 {
     foreach (NamespaceReference namespaceReference in _NamespacesToRemove)
         fileChangeCollection.Add(new FileChange(namespaceReference.FileNode.Name, namespaceReference.Range, String.Empty));
 }
        private void cdeCreateConstructorCall_Apply(object sender, ApplyContentEventArgs ea)
        {
            FileChange newFileChange = new FileChange();
            newFileChange.Path = CodeRush.Documents.ActiveTextDocument.FileNode.Name;
            newFileChange.Range = _DeleteRange;
            newFileChange.Text = _NewCall;
            CodeRush.Markers.Drop(_DeleteRange.Start, MarkerStyle.Transient);
            if (_Changes == null)
                _Changes = new FileChangeCollection();
            else
                _Changes.Clear();

            _Changes.Add(newFileChange);

            TextDocument textDocument = CodeRush.Documents.Get(_TypeElement.FirstFile.Name) as TextDocument;
            if (textDocument == null)
            {
                _WaitingForViewActivate = true;
                CodeRush.File.Activate(_TypeElement.FirstFile.Name);
                return;
            }

            StartTargetPicker(textDocument);
        }
        private void Apply(string displayName, HtmlElement original, HtmlElement newElement, string tabsBefore)
        {
            if ((!string.IsNullOrEmpty(displayName) && (original != null)) && (newElement != null))
            {
                int num = original.NameRange.End.Offset - original.StartOffset;
                SourceRange insertionRange = GetInsertionRange(original);
                string s = CodeRush.Language.GenerateElement(newElement);
                s = CodeRush.StrUtil.RemoveLastLineTerminator(s);
                if (Options.PutCloseTagOnOwnLine)
                {
                    var terminator = @"/>";
                    if(!s.EndsWith(terminator))
                    {
                        terminator = @">";
                    }

                    s = s.Substring(0, s.Length - terminator.Length);
                    s += string.Format("\r\n{0}{1}", tabsBefore, terminator);
                }
                insertionRange.BindToCode(CodeRush.Documents.Active as TextDocument);
                ICompoundAction action = CodeRush.TextBuffers.NewMultiFileCompoundAction(displayName, true);
                IMultiLidContainerGroup group = CodeRush.LinkedIdentifiers.OpenMultiLidContainerGroup();
                try
                {
                    FileChangeCollection changes = new FileChangeCollection();
                    changes.Add(new FileChange(original.FileNode.Name, insertionRange, s));
                    CodeRush.File.ApplyChanges(changes, false, true);
                    CodeRush.Caret.MoveTo(insertionRange.Start.Line, (int)(insertionRange.Start.Offset + num));
                }
                catch (Exception exception)
                {
                    LogBase<Log>.SendException(displayName, exception);
                }
                finally
                {
                    if (_breakApartPreview != null)
                    {
                        _breakApartPreview.Clear();
                        _breakApartPreview = null;
                    }

                    group.Close();
                    action.Close();
                    insertionRange.RemoveAllBindings();
                }
            }
        }