public IEnumerable <AstNode> GetNodesBetween(AstLocation start, AstLocation end) { AstNode node = this; while (node != null) { AstNode next; if (start <= node.StartLocation && node.EndLocation <= end) { // Remember next before yielding node. // This allows iteration to continue when the caller removes/replaces the node. next = node.NextSibling; yield return(node); } else { if (node.EndLocation < start) { next = node.NextSibling; } else { next = node.FirstChild; } } if (next != null && next.StartLocation > end) { yield break; } node = next; } }
/// <summary> /// Gets the node specified by T at location. This is useful for getting a specific node from the tree. For example searching /// the current method declaration. /// </summary> public T GetNodeAt <T> (AstLocation location) where T : AstNode { T result = null; AstNode node = this; while (node.FirstChild != null) { var child = node.FirstChild; while (child != null) { if (child.StartLocation <= location && location < child.EndLocation) { if (child is T) { result = (T)child; } node = child; break; } child = child.NextSibling; } // found no better child node - therefore the parent is the right one. if (child == null) { break; } } return(result); }
public AstNode GetNodeAt(AstLocation location, Predicate <AstNode> pred = null) { AstNode result = null; AstNode node = this; while (node.FirstChild != null) { var child = node.FirstChild; while (child != null) { if (child.StartLocation <= location && location < child.EndLocation) { if (pred == null || pred(child)) { result = child; } node = child; break; } child = child.NextSibling; } // found no better child node - therefore the parent is the right one. if (child == null) { break; } } return(result); }
protected Identifier(string name, AstLocation location) { if (name == null) { throw new ArgumentNullException("name"); } this.Name = name; this.startLocation = location; }
public Identifier(string name, AstLocation location) { if (name == null) { throw new ArgumentNullException("name"); } IsVerbatim = name.Length > 0 && name[0] == '@'; this.Name = IsVerbatim ? name.Substring(1) : name; this.startLocation = location; }
public Identifier(string name, AstLocation location) { if (name == null) { throw new ArgumentNullException("name"); } IsQuoted = name.StartsWith("@"); this.Name = IsQuoted ? name.Substring(1) : name; this.startLocation = location; }
/// <summary> /// Gets a node that can be resolved at location. /// </summary> public AstNode GetResolveableNodeAt(AstLocation location) { return(GetNodeAt(location, delegate(AstNode n) { if (n is TypeDeclaration) { var decl = (TypeDeclaration)n; return decl.NameToken.StartLocation <= location && location <= decl.NameToken.EndLocation; } if (n is DelegateDeclaration) { var decl = (DelegateDeclaration)n; return decl.NameToken.StartLocation <= location && location <= decl.NameToken.EndLocation; } if (n is MemberDeclaration) { var decl = (MemberDeclaration)n; return decl.NameToken.StartLocation <= location && location <= decl.NameToken.EndLocation; } if (n is ConstructorDeclaration) { var decl = (ConstructorDeclaration)n; return decl.IdentifierToken.StartLocation <= location && location <= decl.IdentifierToken.EndLocation; } if (n is DestructorDeclaration) { var decl = (DestructorDeclaration)n; return decl.IdentifierToken.StartLocation <= location && location <= decl.IdentifierToken.EndLocation; } if (n is VariableInitializer) { var decl = (VariableInitializer)n; return decl.NameToken.StartLocation <= location && location <= decl.NameToken.EndLocation; } if (n is ParameterDeclaration) { var decl = (ParameterDeclaration)n; return decl.NameToken.StartLocation <= location && location <= decl.NameToken.EndLocation; } if (n is MemberReferenceExpression) { var decl = (MemberReferenceExpression)n; return decl.MemberNameToken.StartLocation <= location && location <= decl.MemberNameToken.EndLocation; } return n is IdentifierExpression || n is AstType; })); }
public UsingScope GetUsingScope(AstLocation location) { foreach (UsingScope scope in usingScopes) { if (scope.Region.IsInside(location.Line, location.Column)) { return(scope); } } return(rootUsingScope); }
public ITypeDefinition GetTopLevelTypeDefinition(AstLocation location) { foreach (ITypeDefinition typeDef in topLevelTypeDefinitions) { if (typeDef.Region.IsInside(location.Line, location.Column)) { return(typeDef); } } return(null); }
public static Identifier Create(string name, AstLocation location) { if (name == null) { throw new ArgumentNullException("name"); } if (name.Length > 0 && name[0] == '@') { return(new VerbatimIdentifier(name.Substring(1), location)); } return(new Identifier(name, location)); }
public ITypeDefinition GetTypeDefinition(AstLocation location) { ITypeDefinition parent = null; ITypeDefinition type = GetTopLevelTypeDefinition(location); while (type != null) { parent = type; type = FindEntity(parent.NestedTypes, location); } return(parent); }
static T FindEntity <T>(IList <T> list, AstLocation location) where T : class, IEntity { // This could be improved using a binary search foreach (T entity in list) { if (entity.Region.IsInside(location.Line, location.Column)) { return(entity); } } return(null); }
public IMember GetMember(AstLocation location) { ITypeDefinition type = GetTypeDefinition(location); if (type == null) { return(null); } return(FindEntity(type.Methods, location) ?? FindEntity(type.Fields, location) ?? FindEntity(type.Properties, location) ?? (IMember)FindEntity(type.Events, location)); }
public static Identifier Create(string name, AstLocation location, bool isVerbatim) { if (name == null) { throw new ArgumentNullException("name"); } if (isVerbatim) { return(new VerbatimIdentifier(name, location)); } return(new Identifier(name, location)); }
public FixableResult GetFixableResult(ICS.AstLocation location, IBaseMember node, string name) { IList <string> suggestedFixes; var error = GetErrorMessage(name, out suggestedFixes); var fixes = new List <RenameMemberFix> (); fixes.Add(new RenameMemberFix(node, name, null)); if (suggestedFixes != null) { fixes.AddRange(suggestedFixes.Select(f => new RenameMemberFix(node, name, f))); } return(new FixableResult( new DomRegion(location.Line, location.Column, location.Line, location.Column + name.Length), error, MonoDevelop.SourceEditor.QuickTaskSeverity.Warning, ResultCertainty.High, ResultImportance.Medium, fixes.ToArray <IAnalysisFix> ())); }
public AstNode GetNodeAt(AstLocation location) { AstNode node = this; while (node.FirstChild != null) { var child = node.FirstChild; while (child != null) { if (child.StartLocation <= location && location < child.EndLocation) { node = child; break; } child = child.NextSibling; } // found no better child node - therefore the parent is the right one. if (child == null) { break; } } return(node); }
public IdentifierExpression(string identifier, AstLocation location) { SetChildByRole(Roles.Identifier, CSharp.Identifier.Create(identifier, location)); }
public ITypeDefinition GetTopLevelTypeDefinition(AstLocation location) { return(FindEntity(topLevelTypeDefinitions, location)); }
public CSharpTokenNode(AstLocation location, int tokenLength) { this.startLocation = location; this.tokenLength = tokenLength; }
public CSharpModifierToken(AstLocation location, Modifiers modifier) : base(location, 0) { this.Modifier = modifier; }
void IRelocatable.SetStartLocation(AstLocation startLocation) { this.startLocation = startLocation; }
public SimpleType(string identifier, AstLocation location) { SetChildByRole(Roles.Identifier, CSharp.Identifier.Create (identifier, location)); }
public IdentifierExpression(string identifier, AstLocation location) { SetChildByRole(Roles.Identifier, new Identifier(identifier, location)); }
public VerbatimIdentifier(string name, AstLocation location) : base(name, location) { }
public SimpleType(string identifier, AstLocation location) { SetChildByRole(Roles.Identifier, new Identifier(identifier, location)); }
public bool Contains(AstLocation location) { return(this.StartLocation <= location && location < this.EndLocation); }
DomRegion MakeRegion(AstLocation start, AstLocation end) { return(new DomRegion(parsedFile.FileName, start.Line, start.Column, end.Line, end.Column)); }
public EmptyExpression(AstLocation location) { this.location = location; }
public PrimitiveType(string keyword, AstLocation location) { this.Keyword = keyword; this.Location = location; }