~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.VB/Ast/General/CompilationUnit.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
Import upstream version 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using System.Collections.Generic;
 
6
 
 
7
namespace ICSharpCode.NRefactory.VB.Ast
 
8
{
 
9
        public class CompilationUnit : AstNode 
 
10
        {
 
11
                public static readonly Role<AstNode> MemberRole = new Role<AstNode>("Member", AstNode.Null);
 
12
                
 
13
                public CompilationUnit ()
 
14
                {
 
15
                }
 
16
                
 
17
                protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
 
18
                {
 
19
                        CompilationUnit o = other as CompilationUnit;
 
20
                        return o != null && GetChildrenByRole(MemberRole).DoMatch(o.GetChildrenByRole(MemberRole), match);
 
21
                }
 
22
                
 
23
                public AstNode GetNodeAt (int line, int column)
 
24
                {
 
25
                        return GetNodeAt (new TextLocation (line, column));
 
26
                }
 
27
                
 
28
                public AstNode GetNodeAt (TextLocation location)
 
29
                {
 
30
                        AstNode node = this;
 
31
                        while (node.FirstChild != null) {
 
32
                                var child = node.FirstChild;
 
33
                                while (child != null) {
 
34
                                        if (child.StartLocation <= location && location < child.EndLocation) {
 
35
                                                node = child;
 
36
                                                break;
 
37
                                        }
 
38
                                        child = child.NextSibling;
 
39
                                }
 
40
                                // found no better child node - therefore the parent is the right one.
 
41
                                if (child == null)
 
42
                                        break;
 
43
                        }
 
44
                        return node;
 
45
                }
 
46
                
 
47
                public IEnumerable<AstNode> GetNodesBetween (int startLine, int startColumn, int endLine, int endColumn)
 
48
                {
 
49
                        return GetNodesBetween (new TextLocation (startLine, startColumn), new TextLocation (endLine, endColumn));
 
50
                }
 
51
                
 
52
                public IEnumerable<AstNode> GetNodesBetween (TextLocation start, TextLocation end)
 
53
                {
 
54
                        AstNode node = this;
 
55
                        while (node != null) {
 
56
                                AstNode next;
 
57
                                if (start <= node.StartLocation && node.EndLocation <= end) {
 
58
                                        // Remember next before yielding node.
 
59
                                        // This allows iteration to continue when the caller removes/replaces the node.
 
60
                                        next = node.NextSibling;
 
61
                                        yield return node;
 
62
                                } else {
 
63
                                        if (node.EndLocation < start) {
 
64
                                                next = node.NextSibling; 
 
65
                                        } else {
 
66
                                                next = node.FirstChild;
 
67
                                        }
 
68
                                }
 
69
                                
 
70
                                if (next != null && next.StartLocation > end)
 
71
                                        yield break;
 
72
                                node = next;
 
73
                        }
 
74
                }
 
75
                
 
76
                public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
 
77
                {
 
78
                        return visitor.VisitCompilationUnit (this, data);
 
79
                }
 
80
        }
 
81
}