private static FileSourceRangeCollection GetAllPropertyReferences(LanguageElement startElement) { FileSourceRangeCollection allReferences = new FileSourceRangeCollection(); Property property; PrimitiveExpression primitiveExpression; if (!GetPrimitiveExpressionAndProperty(startElement, out primitiveExpression, out property)) { return(allReferences); } // Add references found... IElementCollection allPropertyReferences = property.FindAllReferences(); foreach (IElement element in allPropertyReferences) { allReferences.Add(new FileSourceRange(element.FirstFile as SourceFile, element.FirstNameRange)); } // Add the contents of the string primitive... SourceRange primitiveRange = primitiveExpression.NameRange; int nameStart = primitiveExpression.Name.IndexOf(property.Name); int nameEndMargin = primitiveExpression.Name.Length - property.Name.Length - nameStart; primitiveRange.Start.Offset += nameStart; primitiveRange.End.Offset -= nameEndMargin; allReferences.Add(new FileSourceRange(primitiveExpression.FileNode, primitiveRange)); // Add the NameRange of the property declaration itself.... allReferences.Add(new FileSourceRange(property.FileNode, property.NameRange)); return(allReferences); }
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 bool IsMethodCall(LanguageElement Item) { if (Item is MethodCall) { // Calls which discard any returned value. return true; } if (Item is MethodCallExpression) { // Method calls which are themselves passed to other methods. return true; } // C# requires parenthesis for it's method calls. This makes identifying method calls very easy. // Other languages (VB.Net for example) do not share this requirement. // References to Methods and Variables end up looking exactly the same to the parser. // ElementReferenceExpressions may potentially refer to Methods. if (!(Item is ElementReferenceExpression)) return false; // This forces us to locate the declaration of the item the reference points at. // Once there we can confirm if the Item in question is a Method. if (!(Item.GetDeclaration() is IMethodElement)) return false; // Finally we need to confirm that the method reference is in fact a call. // We do this by eliminating the other purpose of a method reference: That of a Method pointer. // No parent AddressOf operator. Therefore not a method pointer. if (!(Item.Parent is AddressOfExpression)) return true; return false; }
/// <summary> /// Add a return statement /// </summary> /// <param name="functionBody"><see cref="FunctionBody"/> to add to</param> /// <param name="returnValue"><see cref="LanguageElement"/> representing the returnvalue</param> /// <returns>Chained <see cref="FunctionBody"/> to keep building on</returns> public static FunctionBody Return(this FunctionBody functionBody, LanguageElement returnValue) { var returnStatement = new Return(returnValue); functionBody.AddChild(returnStatement); return(functionBody); }
} // IsXpoProperty(property) /// <summary> /// Refactoring provider check availability /// </summary> private void refactoringProvider_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea) { LanguageElement element = ea.Element; if (element == null) { return; } if (element.InsideClass && element is Property) { _Property = (Property)element; _IsXpoProperty = IsXpoProperty(_Property); _IsAutoImplemented = _Property.IsAutoImplemented; if (_IsAutoImplemented || _IsXpoProperty) { ea.Available = true; if (_IsAutoImplemented) { ea.AddSubMenuItem(MenuItem_ConvertTo_XPOProperty, "XPO property"); } ea.AddSubMenuItem(MenuItem_ConvertTo_DelayedProperty, "Delayed property"); } } // if } // refactoringProvider_CheckAvailability(sender, ea)
private static IList <DelimiterCapableBlock> GetBlocksOnLine(DelimiterCapableBlock firstBlockOnLine) { IList <DelimiterCapableBlock> blocksOnLine = new List <DelimiterCapableBlock>(); /* we always want to add the first block :-P */ blocksOnLine.Add(firstBlockOnLine); /* iterate through every block after our first block until they are * not on the same line. the idea is to get every delimiter capable block * that ends on the same line.*/ LanguageElement siblingElement = firstBlockOnLine.NextCodeSibling; while (siblingElement != null) { if (siblingElement.EndLine != firstBlockOnLine.EndLine) { break; } if (siblingElement is DelimiterCapableBlock) { DelimiterCapableBlock siblingBlock = siblingElement as DelimiterCapableBlock; if (siblingBlock.HasDelimitedBlock) { blocksOnLine.Add(siblingBlock); } } /* now assign the next element to the next code sibling. this prevents infinite looping.*/ siblingElement = siblingElement.NextCodeSibling; } return(blocksOnLine); }
public Whitespace2 this[LanguageElement languageElement] { get { return(this[LanguagePart.Current, languageElement]); } set { this[LanguagePart.Current, languageElement] = value; } }
public void Load(LanguageElement element) { Reset(); if (!OnCall(element)) { return; } IElement declaration = element.GetDeclaration(); if (declaration == null) { return; } Class declaringType = declaration.Parent as Class; if (declaringType == null) { return; } if (declaringType is Interface || (declaringType.IsAbstract)) { LoadImplementors(declaringType); } }
/// <summary> /// Get a statement language element that matches the location and the line number /// </summary> /// <param name="location">What location to look for</param> /// <param name="failAtLine">The line that the location should be on</param> /// <returns></returns> /// <remarks>Assumes that the location is in the active file.</remarks> internal static LanguageElement GetStatement(string location, int failAtLine) { try { if (CodeRush.Source.ActiveSourceFile == null) { return(null); } LanguageElement node = CodeRush.Source.ActiveSourceFile.GetNodeAt(new SourcePoint(failAtLine, 0)); if (node != null) { if (location == node.RootNamespaceLocation || location.StartsWith(node.RootNamespaceLocation)) { LanguageElement statement = node.FirstChild; while (statement != null) { if (statement.StartLine == failAtLine) { return(statement); } statement = statement.NextCodeSibling; } } } } catch {// eat exceptions } return(null); }
private bool elementParentIsObjectCreationExpression(LanguageElement element) { //the caret is over something like this "Class1 c1 = new Cla|ss1()" return((element.ElementType == LanguageElementType.TypeReferenceExpression) && (element.Parent != null) && (element.Parent.ElementType == LanguageElementType.ObjectCreationExpression)); }
public static string ToSummary(this string summary, int lcid) { string language = new LanguageElement(lcid).ToString(); summary = ToCalendarString(summary, true, true, 0); return($"{language}{summary}"); }
public void Scan() { _ElementType = LanguageElementType.Unknown; _ElementsFound = 0; _TopNode = null; CodeRush.Source.IterateNodesInSelection(NodeIterator); }
public override IDeepCopyable CopyTo(IDeepCopyable other) { var dest = other as Expression; if (dest == null) { throw new ArgumentException("Can only copy to an object of the same type", "other"); } base.CopyTo(dest); if (DescriptionElement != null) { dest.DescriptionElement = (Hl7.Fhir.Model.FhirString)DescriptionElement.DeepCopy(); } if (NameElement != null) { dest.NameElement = (Hl7.Fhir.Model.Id)NameElement.DeepCopy(); } if (LanguageElement != null) { dest.LanguageElement = (Hl7.Fhir.Model.Code)LanguageElement.DeepCopy(); } if (ExpressionElement != null) { dest.ExpressionElement = (Hl7.Fhir.Model.FhirString)ExpressionElement.DeepCopy(); } if (ReferenceElement != null) { dest.ReferenceElement = (Hl7.Fhir.Model.FhirUri)ReferenceElement.DeepCopy(); } return(dest); }
public Whitespace2 this[LanguagePart languagePart, LanguageElement languageElement] { get { return(list .Where(x => x.LanguageElement == languageElement && x.LanguagePart == languagePart) .FirstOrDefault()); } set { var old = this[languagePart, languageElement]; var pos = -1; if (old != null) { pos = list.IndexOf(old); } if (pos < 0) { list.Add(value); } else { list.RemoveAt(pos); list.Insert(pos, value); } } }
private HtmlElement GetActiveHtmlElement(LanguageElement element, bool sortAttr) { if (element != null) { HtmlElement element2 = element as HtmlElement; HtmlAttribute attribute = element as HtmlAttribute; if ((element2 != null) || (attribute != null)) { while ((element2 == null) && (element != null)) { element = element.Parent; element2 = element as HtmlElement; } if (element2 == null) { return(null); } ////if (sortAttr) ////{ //// element2.Attributes.Sort(new AttrSorter()); ////} return(element2); } } return(null); }
/// <summary> /// Gets a PrimitiveExpression and a parenting property provided the PrimitiveExpression is of type System.String and the caret is inside that string. /// Returns true if both values are found and the contents of the string matches the name of the property. /// </summary> private static bool GetPrimitiveExpressionAndProperty(LanguageElement element) { PrimitiveExpression primitiveExpression; Property property; return(GetPrimitiveExpressionAndProperty(element, out primitiveExpression, out property)); }
/// <summary> /// Adds the interface namespace references to the container referred to by /// <paramref name="cursor"/>. /// </summary> /// <param name="cursor">The cursor.</param> /// <param name="namespaceNodes">The namespace nodes.</param> /// <returns>A reference to the object on which the method was invoked.</returns> public static LanguageElement AddNamespaceReferences( this LanguageElement cursor, IEnumerable <NamespaceReference> namespaceNodes) { if (cursor == null) { throw new ArgumentNullException("cursor", "cursor is null."); } if (namespaceNodes == null) { throw new ArgumentNullException("namespaceNodes", "namespaceNodes is null."); } Contract.EndContractBlock(); foreach (NamespaceReference ns in namespaceNodes) { Contract.Assert(cursor != null); if (ns == null) { continue; } if (ns.Comments != null) { ns.Comments.Clear(); } cursor.AddNode(ns); } return(cursor); }
} // IsClass /// <summary> /// Get class base type /// </summary> private static TypeReferenceExpression GetClassBaseType(LanguageElement classElement) { LanguageElement current = classElement.FirstDetail; while (current != null && !IsClass(current)) current = current.NextSibling; return (TypeReferenceExpression)current; } // GetClassBaseType
/// <summary>Applies this tag to the given language.</summary> /// <param name="language">The language that this tag came from.</param> /// <param name="element">The element from the language file that contains the language name and code as attributes.</param> public void Apply(LanguageSet language, LanguageElement element) { language.Name = element["name"]; string code = element["code"]; if (code != null) { language.Code = (code).Trim().ToLower(); } string direction = element["direction"]; if (direction == null) { direction = element["dir"]; } if (direction != null) { direction = direction.Trim().ToLower(); language.GoesLeftwards = (direction == "rtl" || direction == "righttoleft" || direction == "leftwards" || direction == "left"); } else { language.GoesLeftwards = false; } string group = element["group"]; if (group != null) { language.Group = group; } }
void EventNexus_DecorateLanguageElement(object sender, DecorateLanguageElementEventArgs args) { //Debug.WriteLine("EventNexus_DecorateLanguageElement"); var settings = DrawLinesBetweenMethodsSettings.Current; if (!settings.Enabled) { return; } LanguageElement langElement = args.LanguageElement; //CodeRush.Documents.ActiveTextDocument.ge if ((langElement is Class) && settings.EnableOnClass || (langElement is Property) && settings.EnableOnProperty || (langElement is Method) && settings.EnableOnMethod || (langElement is Enumeration) && settings.EnableOnEnum) { //Debug.WriteLine("langElement: " + langElement); // Skip up over Comment, AttributeSection, XmlDocComment var commentsAndStuff = previousSiblings(langElement) .TakeWhile(sibling => sibling is Comment || sibling is XmlDocComment || sibling is AttributeSection); langElement = commentsAndStuff.LastOrDefault() ?? langElement; //Debug.WriteLine(" > AddBackgroundAdornment ..."); var adornment = new HorizontalLineDocAdornment(langElement); args.AddBackgroundAdornment(adornment); } }
internal void StoreListMemberWhitespace(SyntaxNode syntax, SyntaxKind sepKind, LanguageElement elementType, IDom newItem) { var prevNodeOrToken = syntax.Parent .ChildNodesAndTokens() .PreviousSiblings(syntax) .LastOrDefault(); if (prevNodeOrToken.CSharpKind() == sepKind) { var commaToken = prevNodeOrToken.AsToken(); var whitespace2 = newItem.Whitespace2Set[elementType]; if (whitespace2 == null) { throw new NotImplementedException(); } var newLeadingWhitespace = commaToken.TrailingTrivia.ToString();; if (string.IsNullOrEmpty(whitespace2.LeadingWhitespace) || newLeadingWhitespace.EndsWith("\r\n")) { whitespace2.LeadingWhitespace = newLeadingWhitespace + whitespace2.LeadingWhitespace; } //if (string.IsNullOrEmpty(whitespace2.LeadingWhitespace)) //{ whitespace2.LeadingWhitespace = commaToken.TrailingTrivia.ToString(); } } }
private void ImplementInterfaceIfNotPresent(TextDocument classFile, LanguageElement classExpression, bool redeclareInterface) { if (classFile == null || classExpression == null) { return; } bool interfaceImplemented = CodeRush.Source.Implements(classExpression as ITypeElement, "System.ComponentModel.INotifyPropertyChanged"); ITypeElement[] baseTypes = CodeRush.Source.GetBaseTypes(classExpression as ITypeElement); bool interfaceImplementedOnType = (from bt in baseTypes where bt.Name.Contains("INotifyPropertyChanged") select bt).FirstOrDefault() != null; bool propChangedImplementedOnType = CodeRush.Source.GetMember(classExpression as ITypeElement, "PropertyChanged", false) != null; bool propChangedImplementedOnBaseType = CodeRush.Source.GetMember(classExpression as ITypeElement, "PropertyChanged", true) != null; if ((!interfaceImplemented && !interfaceImplementedOnType) || (redeclareInterface && !interfaceImplementedOnType)) { CodeRush.Source.DeclareNamespaceReference("System.ComponentModel"); CodeRush.Source.ImplementInterface(classExpression as TypeDeclaration, new Interface("INotifyPropertyChanged")); } if ((!propChangedImplementedOnType && !propChangedImplementedOnBaseType) || (!propChangedImplementedOnType && redeclareInterface)) { AddPropertyChangedMember(classFile, classExpression); } }
/// <summary> /// Gets a collection of namespace references from the element's /// parent document and namespace. /// </summary> /// <param name="source">The source.</param> /// <returns>A collection of namespace references from the element's /// parent document and namespace.</returns> public static IEnumerable <NamespaceReference> AllNamespaceNodes(this LanguageElement source) { if (source == null) { throw new ArgumentNullException("source", "source is null."); } Contract.Ensures(Contract.Result <IEnumerable <NamespaceReference> >() != null, "Result will not be null."); var namespaceNodes = Enumerable.Empty <NamespaceReference>(); if (source.InsideNamespace) { var parentNamespace = source.GetNamespace(); if (parentNamespace != null) { namespaceNodes = parentNamespace.NamespaceReferences(); } } var parentDocument = source.GetParentDocument(); if (parentDocument != null) { namespaceNodes = parentDocument.NamespaceReferences().Concat(namespaceNodes); } return(namespaceNodes); }
public SyntaxKind Lookup(LanguageElement languageElement) { SyntaxKind ret = SyntaxKind.None; languageElementToKind.TryGetValue(languageElement, out ret); return(ret); }
/// <summary> /// Checks to see if there is any implementation in the get or set blocks beyond just the member variable get/set /// </summary> private bool IsSimpleProperty(Property activeProperty) { if (activeProperty == null) { return(false); } if (activeProperty.IsAutoImplemented) { return(true); } Set setter = activeProperty.Setter; Get getter = activeProperty.Getter; if (setter == null || setter.NodeCount != 1) { return(false); } if (getter == null || getter.NodeCount != 1) { return(false); } LanguageElement setterNode = (LanguageElement)setter.Nodes[0]; LanguageElement getterNode = (LanguageElement)getter.Nodes[0]; return(setterNode is Assignment && getterNode is Return); }
public void Setup_SetLanguage(WPFLanguage language) { if (language == null) { return; } foreach (var gridColumn in DataGridCustomerDemographics.Columns) { if (gridColumn.Header == null) { continue; } //The replace is done because FK values in Grid are 'MyTable.MyColumn' but in json are 'MyTable_MyColumn' string actualHeaderValue = gridColumn.Header.ToString().Replace(".", "_"); LanguageElement languageElement = language.LanguageElementsFromDB.Where(x => x.OriginalValue.ToLower() == actualHeaderValue.ToLower()).FirstOrDefault(); if (languageElement == null) { continue; } gridColumn.Header = languageElement.TranslatedValue; } }
public LanguageElement Lookup(SyntaxKind syntaxKind) { LanguageElement ret = LanguageElement.NotApplicable; kindToLanguageElement.TryGetValue(syntaxKind, out ret); return(ret); }
public string RenderToEditor(LanguageElement RootNode) { string str = this.Render(RootNode); CodeRush.Documents.ActiveTextView.Selection.Text = str; return(str); }
private static FileSourceRangeCollection GetAllPropertyReferences(LanguageElement startElement) { FileSourceRangeCollection allReferences = new FileSourceRangeCollection(); Property property; PrimitiveExpression primitiveExpression; if (!GetPrimitiveExpressionAndProperty(startElement, out primitiveExpression, out property)) return allReferences; // Add references found... IElementCollection allPropertyReferences = property.FindAllReferences(); foreach (IElement element in allPropertyReferences) allReferences.Add(new FileSourceRange(element.FirstFile as SourceFile, element.FirstNameRange)); // Add the contents of the string primitive... SourceRange primitiveRange = primitiveExpression.NameRange; int nameStart = primitiveExpression.Name.IndexOf(property.Name); int nameEndMargin = primitiveExpression.Name.Length - property.Name.Length - nameStart; primitiveRange.Start.Offset += nameStart; primitiveRange.End.Offset -= nameEndMargin; allReferences.Add(new FileSourceRange(primitiveExpression.FileNode, primitiveRange)); // Add the NameRange of the property declaration itself.... allReferences.Add(new FileSourceRange(property.FileNode, property.NameRange)); return allReferences; }
public override IDeepCopyable CopyTo(IDeepCopyable other) { var dest = other as Resource; if (dest == null) { throw new ArgumentException("Can only copy to an object of the same type", "other"); } base.CopyTo(dest); if (IdElement != null) { dest.IdElement = (Hl7.Fhir.Model.Id)IdElement.DeepCopy(); } if (Meta != null) { dest.Meta = (Hl7.Fhir.Model.Meta)Meta.DeepCopy(); } if (ImplicitRulesElement != null) { dest.ImplicitRulesElement = (Hl7.Fhir.Model.FhirUri)ImplicitRulesElement.DeepCopy(); } if (LanguageElement != null) { dest.LanguageElement = (Hl7.Fhir.Model.Code)LanguageElement.DeepCopy(); } return(dest); }
private static IEnumerable <TagPrefix> GetAll(LanguageElement node) { if (node == null) { yield break; } IEnumerable <TagPrefix> tagPrefixes = FromServerControl(node); foreach (TagPrefix tagPrefix in tagPrefixes) { yield return(tagPrefix); } tagPrefixes = FromAttribute(node); foreach (TagPrefix tagPrefix in tagPrefixes) { yield return(tagPrefix); } tagPrefixes = FromAttributeValue(node); foreach (TagPrefix tagPrefix in tagPrefixes) { yield return(tagPrefix); } }
public virtual ErrorList Validate() { var result = new ErrorList(); result.AddRange(ValidateRules()); if (Extension != null) { Extension.ForEach(elem => result.AddRange(elem.Validate())); } if (LanguageElement != null) { result.AddRange(LanguageElement.Validate()); } if (Text != null) { result.AddRange(Text.Validate()); } if (Contained != null) { Contained.ForEach(elem => result.AddRange(elem.Validate())); } if (LocalIdElement != null) { result.AddRange(LocalIdElement.Validate()); } return(result); }
private bool IsValidReferenceAndQualifier(LanguageElement activeRerence, out ITypeElement callerType, out Expression qualifier) { qualifier = null; callerType = null; if (!(activeRerence is IHasQualifier)) return false; // should be undeclared.... IElement declaration = activeRerence.GetDeclaration(false); if (declaration != null) return false; qualifier = (activeRerence as IHasQualifier).Qualifier; if (qualifier is MethodReferenceExpression) qualifier = (qualifier as MethodReferenceExpression).Qualifier; if (qualifier == null) return false; callerType = qualifier.Resolve(ParserServices.SourceTreeResolver) as ITypeElement; if (callerType == null) return false; return true; }
public void StoreListMemberWhitespace(SyntaxNode syntax, SyntaxKind syntaxKind, LanguageElement elementType, IDom newItem) { triviaManager.StoreListMemberWhitespace(syntax, syntaxKind, elementType, newItem); }
private static IEnumerable <TagPrefix> FromServerControl(LanguageElement element) { ServerControlElement serverControl = element as ServerControlElement; if (serverControl == null) { yield break; } if (!serverControl.TagPrefixRange.IsEmpty) { yield return new TagPrefix() { Name = serverControl.TagPrefix, Range = serverControl.TagPrefixRange } } ; if (!serverControl.CloseTagPrefixRange.IsEmpty) { yield return new TagPrefix() { Name = serverControl.TagPrefix, Range = serverControl.CloseTagPrefixRange } } ; }
private LanguageElement PromoteIfReference(LanguageElement element) { if (element.ElementType == LanguageElementType.MethodReferenceExpression) if (element.Parent.ElementType == LanguageElementType.MethodCallExpression) return element.Parent; return element; }
private ElementReferenceExpression GetNamespaceReference(LanguageElement element) { MethodReferenceExpression methodReference = element as MethodReferenceExpression; MethodCall methodCall = methodReference.Parent as MethodCall; ElementReferenceExpression classReference = methodReference.Nodes[0] as ElementReferenceExpression; ElementReferenceExpression namespaceReference = classReference.Nodes[0] as ElementReferenceExpression; return namespaceReference; }
private void events_LanguageElementActivated(LanguageElementActivatedEventArgs ea) { LanguageElement activeMember = CodeRush.Source.ActiveMember; if (lastMember == activeMember) return; lastMember = activeMember; ShowCode(); }
public SourcePoint GetBestLocation(LanguageElement element) { int smallestLineDeltaSoFar = int.MaxValue; int smallestOffsetDeltaSoFar = int.MaxValue; ElementLocation location = this; SourcePoint result = SourcePoint.Empty; LanguageElement parent = null; while (location != null && element != null) { CaretVector vector = location._Vector; int lineDeltaSize = Math.Abs(vector.LineDelta); int offsetDeltaSize = Math.Abs(vector.OffsetDelta); if (lineDeltaSize < smallestLineDeltaSoFar || (lineDeltaSize == smallestLineDeltaSoFar && offsetDeltaSize < smallestOffsetDeltaSoFar)) { // Found a smaller vector... SourcePoint newPosition = GetSourcePoint(element, vector); if (newPosition != SourcePoint.Empty) { result = newPosition; smallestLineDeltaSoFar = lineDeltaSize; smallestOffsetDeltaSoFar = offsetDeltaSize; if (lineDeltaSize == 0 && offsetDeltaSize == 0) if (vector.ElementPosition != ElementPosition.LastDetailEnd || element.ElementType != LanguageElementType.Method && element.ElementType != LanguageElementType.Property) return result; } } location = location._Child; parent = element; element = GetChildElement(element, location); if (location != null && element == null) { // We were expecting a child but found nothing... if (location._ElementType == LanguageElementType.Parameter) { Method method = parent as Method; if (method != null) return method.ParamOpenRange.End; else { Property property = parent as Property; if (property != null) return property.NameRange.End; } } else { SourcePoint newDefaultPosition = GetDefaultPosition(parent); if (newDefaultPosition != SourcePoint.Empty) return newDefaultPosition; } } } return result; }
/// <summary> /// Gets the type reference pointed to by a qualifying namespace reference. /// </summary> private static TypeReferenceExpression GetTypeReference(LanguageElement namespaceReference) { LanguageElement parentTypeReference = namespaceReference.Parent; while (parentTypeReference is TypeReferenceExpression && parentTypeReference.IsDetailNode && parentTypeReference.Parent != null && parentTypeReference.Parent is TypeReferenceExpression) parentTypeReference = parentTypeReference.Parent; if (parentTypeReference is TypeReferenceExpression /* && !parentTypeReference.IsDetailNode */) // We've found the class reference... return (TypeReferenceExpression)parentTypeReference; return null; }
protected override bool IsValidSelection(LanguageElement element, TextViewSelection selection) { if ((element == null) || (selection == null)) return false; if (selection.Exists) return false; var creationExpression = element.Parent as ObjectCreationExpression; return creationExpression != null && element.GetDeclaration() == null; }
private static AssignmentExpression GetAssignmentExpression(LanguageElement element) { // Rory is right. ea.Element will not always be equal to CodeRush.Source.Active. // Also, CodeProviders can be called programmatically, targeting other places. // Rory recommends always exhausting the ea.Xxxxxxx methods and properties, before looking elsewhere. AssignmentExpression assignmentExpression = element as AssignmentExpression; if (assignmentExpression == null) assignmentExpression = element.GetParent(LanguageElementType.AssignmentExpression) as AssignmentExpression; return assignmentExpression; }
private static bool IsApproveCall(LanguageElement element) { if (element.ElementType == LanguageElementType.MethodCall && element.Name.Contains("Approve")) return true; if (element.Parent != null) return IsApproveCall(element.Parent); return false; }
private string CurrentNamespace(LanguageElement element) { var names = new List<string>(); while (element != null && element.ElementType == LanguageElementType.Namespace) { names.Add(element.Name); element = element.Parent; } return string.Join(".", names.Reverse<string>().ToArray()); }
private void AddAttribute(LanguageElement element, string AttributeName) { var Builder = new ElementBuilder(); var Attribute = Builder.BuildAttribute(AttributeName); var Section = Builder.BuildAttributeSection(); Section.AddAttribute(Attribute); var Code = CodeRush.CodeMod.GenerateCode(Section, false); SourcePoint InsertionPoint = new SourcePoint(element.Range.Start.Line, 1); CodeRush.Documents.ActiveTextDocument.QueueInsert(InsertionPoint, Code); }
/// <summary> /// Returns true if the specified caret position is located inside either the start or end tag of the specified HtmlElement. /// </summary> private static bool IsCaretOnPairedHtmlTag(LanguageElement element, SourcePoint caret) { DevExpress.CodeRush.StructuralParser.HtmlElement htmlElement = element as DevExpress.CodeRush.StructuralParser.HtmlElement; if (htmlElement == null) // Not an HtmlElement return false; if (htmlElement.CloseTagNameRange == SourceRange.Empty) // Not a paired Html tag. return false; return htmlElement.NameRange.Contains(caret) || htmlElement.CloseTagNameRange.Contains(caret); }
internal bool IsAvailable(LanguageElement element) { return (element.ElementType == LanguageElementType.MethodCallExpression && element.Name == "getElementById") || (element.ElementType == LanguageElementType.ElementReferenceExpression && (element.Name == "value" || element.Name == "checked") && element.NextNode.ElementType == LanguageElementType.MethodCallExpression && element.NextNode.Name == "getElementById"); }
private string GetNamespaceForElement(LanguageElement element) { IElement parent = element.Parent; while (parent != null && parent.ElementType != LanguageElementType.Namespace) { parent = parent.Parent; } return parent == null ? string.Empty : parent.Name; }
// Private implementation private Property GetActiveProperty(LanguageElement element) { if (element == null) return null; Property property = element as Property; if (property == null) property = element.GetParent(LanguageElementType.Property) as Property; return property; }
private bool IsValidSelection(LanguageElement member, TextViewSelection selection, SourcePoint caret) { if ((member == null) || (selection == null)) { return false; } if (selection.Exists) { return false; } return (member.NameRange.Contains(caret) || CodeRush.Source.GetStartWordRange(member).Contains(caret)); }
/// <summary> /// Force a redraw of the class which contains the given language element /// </summary> /// <param name="element">what to invalidate</param> internal static void Invalidate(LanguageElement element) { if (element != null) { TextView view = element.View as TextView; view.Invalidate(element);//(element.StartLine - 1, 0, element.EndLine + 1, 0); } else { CodeRush.TextViews.Active.Invalidate(); } }
private IEnumerable<NamespaceReference> BuildNamespaceReferences(LanguageElement element) { IList<NamespaceReference> namespaceReferences = new List<NamespaceReference>(); ElementBuilder builder = new ElementBuilder(); foreach (var nsr in CodeRush.Source.NamespaceReferences.Keys) { namespaceReferences.Add(builder.AddNamespaceReference(element.FileNode, CodeRush.Source.NamespaceReferences[nsr].ToString())); } return namespaceReferences; }
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 LanguageElement GetActiveMethodReference(LanguageElement element) { if (element == null) return null; if (IsMethodCallReference(element)) return element; if (IsMethodCallReference(element.Parent)) return element.Parent; return null; }
private static IElement GetElementDeclaration(LanguageElement element) { IElement declaration; if (elementIsReference(element.ElementType)) declaration = element.GetDeclaration(); else declaration = element; if (declaration != null && elementTypeIsSupported(declaration.ElementType)) return declaration; return null; }
private void ConvertProperty(TextDocument textDocument, Property property, bool baseClassVersion, LanguageElement classExpression) { if (textDocument == null || property == null) return; Property propertyClone = (Property)property.Clone(); string newPropertyCode = ChangeProperty(propertyClone, baseClassVersion, classExpression); SourceRange propertyRange = property.Range.Clone(); textDocument.DeleteText(propertyRange); SourceRange newPropertyRange = textDocument.InsertText(propertyRange.Start, newPropertyCode); textDocument.Format(newPropertyRange); }
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 static methods... #region AtSourcePoint private static TagPrefix AtSourcePoint(LanguageElement activeElement, SourcePoint sourcePoint) { if (activeElement == null) return null; IEnumerable<TagPrefix> prefixes = TagPrefix.GetAll(activeElement); if (prefixes == null) return null; foreach (TagPrefix prefix in prefixes) if (prefix.Range.Contains(sourcePoint)) return prefix; return null; }
private static ExpressionCollection getArguments(LanguageElement parent) { ExpressionCollection arguments = null; if (parent.ElementType == LanguageElementType.MethodCall) { // do something arguments = (parent as MethodCall).Arguments; } else if (parent.ElementType == LanguageElementType.MethodCallExpression) { //do something else arguments = (parent as MethodCallExpression).Arguments; } return arguments; }
/// <summary> /// Gets a PrimitiveExpression and a parenting property provided the PrimitiveExpression is of type System.String and the caret is inside that string. /// Returns true if both values are found and the contents of the string matches the name of the property. /// </summary> private static bool GetPrimitiveExpressionAndProperty(LanguageElement element, out PrimitiveExpression primitiveExpression, out Property property) { property = null; primitiveExpression = element as PrimitiveExpression; if (primitiveExpression == null) return false; if (primitiveExpression.ExpressionTypeName != "System.String") return false; property = primitiveExpression.GetParentProperty(); if (property == null) return false; return property.Name == (string)primitiveExpression.PrimitiveValue; }