Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 protected Identifier(string name, AstLocation location)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     this.Name          = name;
     this.startLocation = location;
 }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
 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;
 }
Ejemplo n.º 7
0
        /// <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;
            }));
        }
Ejemplo n.º 8
0
 public UsingScope GetUsingScope(AstLocation location)
 {
     foreach (UsingScope scope in usingScopes)
     {
         if (scope.Region.IsInside(location.Line, location.Column))
         {
             return(scope);
         }
     }
     return(rootUsingScope);
 }
Ejemplo n.º 9
0
 public ITypeDefinition GetTopLevelTypeDefinition(AstLocation location)
 {
     foreach (ITypeDefinition typeDef in topLevelTypeDefinitions)
     {
         if (typeDef.Region.IsInside(location.Line, location.Column))
         {
             return(typeDef);
         }
     }
     return(null);
 }
Ejemplo n.º 10
0
 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));
 }
Ejemplo n.º 11
0
        public ITypeDefinition GetTypeDefinition(AstLocation location)
        {
            ITypeDefinition parent = null;
            ITypeDefinition type   = GetTopLevelTypeDefinition(location);

            while (type != null)
            {
                parent = type;
                type   = FindEntity(parent.NestedTypes, location);
            }
            return(parent);
        }
Ejemplo n.º 12
0
 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);
 }
Ejemplo n.º 13
0
        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));
        }
Ejemplo n.º 14
0
        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));
        }
Ejemplo n.º 15
0
        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> ()));
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
 public IdentifierExpression(string identifier, AstLocation location)
 {
     SetChildByRole(Roles.Identifier, CSharp.Identifier.Create(identifier, location));
 }
Ejemplo n.º 18
0
 public ITypeDefinition GetTopLevelTypeDefinition(AstLocation location)
 {
     return(FindEntity(topLevelTypeDefinitions, location));
 }
Ejemplo n.º 19
0
 public CSharpTokenNode(AstLocation location, int tokenLength)
 {
     this.startLocation = location;
     this.tokenLength   = tokenLength;
 }
Ejemplo n.º 20
0
 public CSharpModifierToken(AstLocation location, Modifiers modifier) : base(location, 0)
 {
     this.Modifier = modifier;
 }
Ejemplo n.º 21
0
 void IRelocatable.SetStartLocation(AstLocation startLocation)
 {
     this.startLocation = startLocation;
 }
Ejemplo n.º 22
0
 public SimpleType(string identifier, AstLocation location)
 {
     SetChildByRole(Roles.Identifier, CSharp.Identifier.Create (identifier, location));
 }
Ejemplo n.º 23
0
 public IdentifierExpression(string identifier, AstLocation location)
 {
     SetChildByRole(Roles.Identifier, new Identifier(identifier, location));
 }
Ejemplo n.º 24
0
 public VerbatimIdentifier(string name, AstLocation location) : base(name, location)
 {
 }
Ejemplo n.º 25
0
 public SimpleType(string identifier, AstLocation location)
 {
     SetChildByRole(Roles.Identifier, new Identifier(identifier, location));
 }
Ejemplo n.º 26
0
 public bool Contains(AstLocation location)
 {
     return(this.StartLocation <= location && location < this.EndLocation);
 }
Ejemplo n.º 27
0
 DomRegion MakeRegion(AstLocation start, AstLocation end)
 {
     return(new DomRegion(parsedFile.FileName, start.Line, start.Column, end.Line, end.Column));
 }
Ejemplo n.º 28
0
 public EmptyExpression(AstLocation location)
 {
     this.location = location;
 }
Ejemplo n.º 29
0
 public PrimitiveType(string keyword, AstLocation location)
 {
     this.Keyword  = keyword;
     this.Location = location;
 }