Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2389-EpsLexicase/HeuristicLab.ExtLibs/HeuristicLab.NRefactory/5.5.0/NRefactory.CSharp-5.5.0/Ast/GeneralScope/UsingDeclaration.cs

Last change on this file was 11700, checked in by jkarder, 10 years ago

#2077: created branch and added first version

File size: 3.4 KB
Line 
1//
2// UsingDeclaration.cs
3//
4// Author:
5//       Mike Krüger <mkrueger@novell.com>
6//
7// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
8//
9// Permission is hereby granted, free of charge, to any person obtaining a copy
10// of this software and associated documentation files (the "Software"), to deal
11// in the Software without restriction, including without limitation the rights
12// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13// copies of the Software, and to permit persons to whom the Software is
14// furnished to do so, subject to the following conditions:
15//
16// The above copyright notice and this permission notice shall be included in
17// all copies or substantial portions of the Software.
18//
19// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25// THE SOFTWARE.
26
27using System;
28using System.Linq;
29using System.Text;
30using System.Collections.Generic;
31
32namespace ICSharpCode.NRefactory.CSharp
33{
34  /// <summary>
35  /// using Import;
36  /// </summary>
37  public class UsingDeclaration : AstNode
38  {
39    public static readonly TokenRole UsingKeywordRole = new TokenRole ("using");
40    public static readonly Role<AstType> ImportRole = new Role<AstType>("Import", AstType.Null);
41   
42    public override NodeType NodeType {
43      get {
44        return NodeType.Unknown;
45      }
46    }
47   
48    public CSharpTokenNode UsingToken {
49      get { return GetChildByRole (UsingKeywordRole); }
50    }
51   
52    public AstType Import {
53      get { return GetChildByRole (ImportRole); }
54      set { SetChildByRole (ImportRole, value); }
55    }
56   
57    public string Namespace {
58      get { return ConstructNamespace (Import); }
59    }
60
61    internal static string ConstructNamespace (AstType type)
62    {
63      var stack = new Stack<string>();
64      while (type is MemberType) {
65        var mt = (MemberType)type;
66        stack.Push(mt.MemberName);
67        type = mt.Target;
68        if (mt.IsDoubleColon) {
69          stack.Push("::");
70        } else {
71          stack.Push(".");
72        }
73      }
74      if (type is SimpleType)
75        stack.Push(((SimpleType)type).Identifier);
76
77      var result = new StringBuilder();
78      while (stack.Count > 0)
79        result.Append(stack.Pop());
80      return result.ToString();
81    }
82   
83    public CSharpTokenNode SemicolonToken {
84      get { return GetChildByRole (Roles.Semicolon); }
85    }
86   
87    public UsingDeclaration ()
88    {
89    }
90   
91    public UsingDeclaration (string nameSpace)
92    {
93      AddChild (AstType.Create (nameSpace), ImportRole);
94    }
95   
96    public UsingDeclaration (AstType import)
97    {
98      AddChild (import, ImportRole);
99    }
100   
101    public override void AcceptVisitor (IAstVisitor visitor)
102    {
103      visitor.VisitUsingDeclaration (this);
104    }
105     
106    public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
107    {
108      return visitor.VisitUsingDeclaration (this);
109    }
110   
111    public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
112    {
113      return visitor.VisitUsingDeclaration (this, data);
114    }
115   
116    protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
117    {
118      UsingDeclaration o = other as UsingDeclaration;
119      return o != null && this.Import.DoMatch(o.Import, match);
120    }
121  }
122}
Note: See TracBrowser for help on using the repository browser.