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

« back to all changes in this revision

Viewing changes to contrib/ICSharpCode.NRefactory.CSharp/Ast/MemberType.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
 
// 
2
 
// FullTypeName.cs
3
 
//
4
 
// Author:
5
 
//       Mike Krüger <mkrueger@novell.com>
6
 
// 
7
 
// Copyright (c) 2010 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
 
 
27
 
using System;
28
 
using System.Collections.Generic;
29
 
using System.Linq;
30
 
using System.Text;
31
 
using ICSharpCode.NRefactory.CSharp.TypeSystem;
32
 
using ICSharpCode.NRefactory.TypeSystem;
33
 
 
34
 
namespace ICSharpCode.NRefactory.CSharp
35
 
{
36
 
        public class MemberType : AstType
37
 
        {
38
 
                public static readonly Role<AstType> TargetRole = new Role<AstType>("Target", AstType.Null);
39
 
                
40
 
                bool isDoubleColon;
41
 
                
42
 
                public bool IsDoubleColon {
43
 
                        get { return isDoubleColon; }
44
 
                        set {
45
 
                                ThrowIfFrozen();
46
 
                                isDoubleColon = value;
47
 
                        }
48
 
                }
49
 
                
50
 
                public AstType Target {
51
 
                        get { return GetChildByRole(TargetRole); }
52
 
                        set { SetChildByRole(TargetRole, value); }
53
 
                }
54
 
                
55
 
                public string MemberName {
56
 
                        get {
57
 
                                return GetChildByRole (Roles.Identifier).Name;
58
 
                        }
59
 
                        set {
60
 
                                SetChildByRole (Roles.Identifier, Identifier.Create (value));
61
 
                        }
62
 
                }
63
 
                
64
 
                public Identifier MemberNameToken {
65
 
                        get {
66
 
                                return GetChildByRole (Roles.Identifier);
67
 
                        }
68
 
                        set {
69
 
                                SetChildByRole (Roles.Identifier, value);
70
 
                        }
71
 
                }
72
 
                
73
 
                public AstNodeCollection<AstType> TypeArguments {
74
 
                        get { return GetChildrenByRole (Roles.TypeArgument); }
75
 
                }
76
 
                
77
 
                public MemberType ()
78
 
                {
79
 
                }
80
 
                
81
 
                public MemberType (AstType target, string memberName)
82
 
                {
83
 
                        this.Target = target;
84
 
                        this.MemberName = memberName;
85
 
                }
86
 
                
87
 
                public MemberType (AstType target, string memberName, IEnumerable<AstType> typeArguments)
88
 
                {
89
 
                        this.Target = target;
90
 
                        this.MemberName = memberName;
91
 
                        foreach (var arg in typeArguments) {
92
 
                                AddChild (arg, Roles.TypeArgument);
93
 
                        }
94
 
                }
95
 
                
96
 
                public MemberType (AstType target, string memberName, params AstType[] typeArguments) : this (target, memberName, (IEnumerable<AstType>)typeArguments)
97
 
                {
98
 
                }
99
 
                
100
 
                public override void AcceptVisitor (IAstVisitor visitor)
101
 
                {
102
 
                        visitor.VisitMemberType (this);
103
 
                }
104
 
                
105
 
                public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
106
 
                {
107
 
                        return visitor.VisitMemberType (this);
108
 
                }
109
 
                
110
 
                public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
111
 
                {
112
 
                        return visitor.VisitMemberType (this, data);
113
 
                }
114
 
                
115
 
                protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
116
 
                {
117
 
                        MemberType o = other as MemberType;
118
 
                        return o != null && this.IsDoubleColon == o.IsDoubleColon && MatchString(this.MemberName, o.MemberName) && this.Target.DoMatch(o.Target, match);
119
 
                }
120
 
                
121
 
                public override string ToString()
122
 
                {
123
 
                        StringBuilder b = new StringBuilder();
124
 
                        b.Append(this.Target);
125
 
                        if (IsDoubleColon)
126
 
                                b.Append("::");
127
 
                        else
128
 
                                b.Append('.');
129
 
                        b.Append(this.MemberName);
130
 
                        if (this.TypeArguments.Any()) {
131
 
                                b.Append('<');
132
 
                                b.Append(string.Join(", ", this.TypeArguments));
133
 
                                b.Append('>');
134
 
                        }
135
 
                        return b.ToString();
136
 
                }
137
 
                
138
 
                public override ITypeReference ToTypeReference(NameLookupMode lookupMode = NameLookupMode.Type)
139
 
                {
140
 
                        TypeOrNamespaceReference t;
141
 
                        if (this.IsDoubleColon) {
142
 
                                SimpleType st = this.Target as SimpleType;
143
 
                                if (st != null) {
144
 
                                        t = new AliasNamespaceReference(st.Identifier);
145
 
                                } else {
146
 
                                        t = null;
147
 
                                }
148
 
                        } else {
149
 
                                t = this.Target.ToTypeReference(lookupMode) as TypeOrNamespaceReference;
150
 
                        }
151
 
                        if (t == null)
152
 
                                return SpecialType.UnknownType;
153
 
                        var typeArguments = new List<ITypeReference>();
154
 
                        foreach (var ta in this.TypeArguments) {
155
 
                                typeArguments.Add(ta.ToTypeReference(lookupMode));
156
 
                        }
157
 
                        return new MemberTypeOrNamespaceReference(t, this.MemberName, typeArguments, lookupMode);
158
 
                }
159
 
        }
160
 
}
161