private void CleanupFileAndNamespaces_Execute(ExecuteEventArgs ea) { using (var action = CodeRush.Documents.ActiveTextDocument.NewCompoundAction("Cleanup File and Namespaces")) { // Store Address var Address = NavigationServices.GetCurrentAddress(); // Find first NamespaceReference ElementEnumerable Enumerable = new ElementEnumerable(CodeRush.Source.ActiveFileNode, LanguageElementType.NamespaceReference, true); NamespaceReference Reference = Enumerable.OfType<NamespaceReference>().FirstOrDefault(); if (Reference == null) { // No Namespace References to sort. return; } // Move caret CodeRush.Caret.MoveTo(Reference.Range.Start); CleanupFile(); InvokeRefactoring(); // Restore Location NavigationServices.ResolveAddress(Address).Show(); } }
public static IEnumerable <TagPrefix> FindMatching(LanguageElement scope, TagPrefix tagPrefix) { if (tagPrefix == null) { return(null); } List <TagPrefix> result = new List <TagPrefix>(); ElementEnumerable e = new ElementEnumerable(scope, true); foreach (LanguageElement node in e) { IEnumerable <TagPrefix> nodeTagPrefixes = GetAll(node); if (nodeTagPrefixes != null) { foreach (TagPrefix nodeTagPrefix in nodeTagPrefixes) { if (nodeTagPrefix.Name == tagPrefix.Name) { result.Add(nodeTagPrefix); } } } } return(result); }
private void AddNamespaceReference(string NamespaceName) { TextDocument ActiveDoc = CodeRush.Documents.ActiveTextDocument; var finder = new ElementEnumerable(ActiveDoc.FileNode, LanguageElementType.NamespaceReference, true); var NamespaceReferences = finder.OfType <NamespaceReference>(); if (NamespaceReferences.Any(ns => ns.Name == NamespaceName)) { return; } // Calculate Insert Location SourcePoint InsertionPoint; if (ActiveDoc.NamespaceReferences.Count <= 0) { InsertionPoint = ActiveDoc.Range.Start; } else { InsertionPoint = NamespaceReferences.Last().Range.Start; } // Generate new NamespaceReference var Code = CodeRush.CodeMod.GenerateCode(new NamespaceReference(NamespaceName)); ActiveDoc.QueueInsert(InsertionPoint, Code); }
private void CollapseXML_Execute(ExecuteEventArgs ea) { var Doc = CodeRush.Documents.ActiveTextDocument; var elements = new ElementEnumerable(Doc.FileNode, LanguageElementType.HtmlElement, true); foreach (SP.HtmlElement html in elements.OfType<SP.HtmlElement>()) { var attributes = html.Attributes.OfType<SP.HtmlAttribute>().ToList(); if (attributes.Any(at => at.Name.ToLower() == "id" || at.Name.ToLower() == "name")) html.CollapseInView(Doc.ActiveView); } }
private IEnumerable<PrimitiveExpression> FindMatching(LanguageElement scope, PrimitiveExpression primitiveExpression) { if (scope == null || primitiveExpression == null) yield break; ElementEnumerable primitivesEnumerable = new ElementEnumerable(scope, new PrimitiveFilter(primitiveExpression), true); if (primitivesEnumerable == null) yield break; foreach (object element in primitivesEnumerable) if (element is PrimitiveExpression) yield return (PrimitiveExpression)element; }
private int GetMethodCallCount(LanguageElement LanguageElement) { var Types = new Type[] { typeof(MethodCall), typeof(MethodCallExpression), typeof(ElementReferenceExpression) }; // Create Enumerator of certain types of LanguageElement. var Enumerator = new ElementEnumerable(LanguageElement, Types, true); // Count elements which qualify as calls to methods. return (from LanguageElement Item in Enumerator where IsMethodCall(Item) select Item).Count(); }
private bool HasErrorsInChildren(LanguageElement element) { ElementEnumerable enumerable = new ElementEnumerable(element); foreach (var item in enumerable) { LanguageElement current = (LanguageElement)item; if (element.HasErrors) { return(true); } } return(false); }
private void XMLRefSearch_SearchReferences(Object Sender, DevExpress.CodeRush.Core.SearchEventArgs ea) { // Store Value of initial XmlAttribute TextDocument activeDoc = CodeRush.Documents.ActiveTextDocument; string StartValue = ((XmlAttribute)activeDoc.GetNodeAt(CodeRush.Caret.Line, CodeRush.Caret.Offset)).Value; // Iterate LanguageElements in solution SolutionElement activeSolution = CodeRush.Source.ActiveSolution; foreach (ProjectElement project in activeSolution.AllProjects) { foreach (SourceFile sourceFile in project.AllFiles) { SourceFile activeFile = CodeRush.Source.ActiveSourceFile; ElementEnumerable Enumerator = new ElementEnumerable(sourceFile, new XMLAttributeFilter(StartValue, _Attributes), true); foreach (XmlAttribute CurrentAttribute in Enumerator) { ea.AddRange(new FileSourceRange(CurrentAttribute.FileNode, CurrentAttribute.ValueRange)); } } } }
private SourcePoint GetInsertionPoint(TypeDeclaration activeType, LanguageElementType elementType, RelativeLocation relativeLocation, DefaultLocation defaultLocation) { LanguageElementType[] elementTypes; if (elementType == LanguageElementType.Variable) { elementTypes = new LanguageElementType[2]; elementTypes[0] = LanguageElementType.Variable; elementTypes[1] = LanguageElementType.InitializedVariable; } else { elementTypes = new LanguageElementType[1]; elementTypes[0] = elementType; } ElementEnumerable elementEnumerable = new ElementEnumerable(activeType, elementTypes); LanguageElement lastElement = null; foreach (LanguageElement element in elementEnumerable) { if (relativeLocation == RelativeLocation.Before) return element.GetFullBlockCutRange().Top; else // RelativeLocation.After... lastElement = element; } if (lastElement != null) return lastElement.GetFullBlockCutRange().Bottom; if (defaultLocation == DefaultLocation.Top) return activeType.BlockCodeRange.Top; else // Bottom... return activeType.BlockCodeRange.Bottom; }
private bool HasErrorsInChildren(LanguageElement element) { ElementEnumerable enumerable = new ElementEnumerable(element); foreach (var item in enumerable) { LanguageElement current = (LanguageElement)item; if (element.HasErrors) { return true; } } return false; }
public static IEnumerable<TagPrefix> FindMatching(LanguageElement scope, TagPrefix tagPrefix) { if (tagPrefix == null) return null; List<TagPrefix> result = new List<TagPrefix>(); ElementEnumerable e = new ElementEnumerable(scope, true); foreach (LanguageElement node in e) { IEnumerable<TagPrefix> nodeTagPrefixes = GetAll(node); if (nodeTagPrefixes != null) { foreach (TagPrefix nodeTagPrefix in nodeTagPrefixes) if (nodeTagPrefix.Name == tagPrefix.Name) result.Add(nodeTagPrefix); } } return result; }
private void XMLRefSearch_SearchReferences(Object Sender, DevExpress.CodeRush.Core.SearchEventArgs ea) { // Store Value of initial XmlAttribute TextDocument activeDoc = CodeRush.Documents.ActiveTextDocument; string StartValue = ((XmlAttribute)activeDoc.GetNodeAt(CodeRush.Caret.Line, CodeRush.Caret.Offset)).Value; // Iterate LanguageElements in solution SolutionElement activeSolution = CodeRush.Source.ActiveSolution; foreach (ProjectElement project in activeSolution.AllProjects) { foreach (SourceFile sourceFile in project.AllFiles) { SourceFile activeFile = CodeRush.Source.ActiveSourceFile; ElementEnumerable Enumerator = new ElementEnumerable(sourceFile, new XMLAttributeFilter(StartValue, _Attributes), true); foreach (XmlAttribute CurrentAttribute in Enumerator) { ea.AddRange(new FileSourceRange(CurrentAttribute.FileNode, CurrentAttribute.ValueRange)); } } } }
private static ElementEnumerable GetPrimitives(SourceRange SelectRange) { // Find all literals in SelectRange. var RangePrimitives = new ElementEnumerable(CodeRush.Source.ActiveFileNode, new TypeInRangeFilter(LanguageElementType.PrimitiveExpression, SelectRange), true); return RangePrimitives; }
private static IEnumerable<InitializedVariable> GetInitializedVars(string literalName) { var InitializedVars = new ElementEnumerable(CodeRush.Source.ActiveFileNode, new InitializedVarFilter(literalName), true); return InitializedVars.OfType<InitializedVariable>(); }
private void AddNamespaceReference(string NamespaceName) { TextDocument ActiveDoc = CodeRush.Documents.ActiveTextDocument; var finder = new ElementEnumerable(ActiveDoc.FileNode, LanguageElementType.NamespaceReference, true); var NamespaceReferences = finder.OfType<NamespaceReference>(); if (NamespaceReferences.Any(ns => ns.Name == NamespaceName)) return; // Calculate Insert Location SourcePoint InsertionPoint; if (ActiveDoc.NamespaceReferences.Count <= 0) { InsertionPoint = ActiveDoc.Range.Start; } else { InsertionPoint = NamespaceReferences.Last().Range.Start; } // Generate new NamespaceReference var Code = CodeRush.CodeMod.GenerateCode(new NamespaceReference(NamespaceName)); ActiveDoc.QueueInsert(InsertionPoint, Code); }