5
// Mike Krüger <mkrueger@novell.com>
7
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
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:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
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
28
using System.Collections.Generic;
31
using ICSharpCode.NRefactory.CSharp.TypeSystem;
32
using ICSharpCode.NRefactory.TypeSystem;
34
namespace ICSharpCode.NRefactory.CSharp
36
public class MemberType : AstType
38
public static readonly Role<AstType> TargetRole = new Role<AstType>("Target", AstType.Null);
42
public bool IsDoubleColon {
43
get { return isDoubleColon; }
46
isDoubleColon = value;
50
public AstType Target {
51
get { return GetChildByRole(TargetRole); }
52
set { SetChildByRole(TargetRole, value); }
55
public string MemberName {
57
return GetChildByRole (Roles.Identifier).Name;
60
SetChildByRole (Roles.Identifier, Identifier.Create (value));
64
public Identifier MemberNameToken {
66
return GetChildByRole (Roles.Identifier);
69
SetChildByRole (Roles.Identifier, value);
73
public AstNodeCollection<AstType> TypeArguments {
74
get { return GetChildrenByRole (Roles.TypeArgument); }
81
public MemberType (AstType target, string memberName)
84
this.MemberName = memberName;
87
public MemberType (AstType target, string memberName, IEnumerable<AstType> typeArguments)
90
this.MemberName = memberName;
91
foreach (var arg in typeArguments) {
92
AddChild (arg, Roles.TypeArgument);
96
public MemberType (AstType target, string memberName, params AstType[] typeArguments) : this (target, memberName, (IEnumerable<AstType>)typeArguments)
100
public override void AcceptVisitor (IAstVisitor visitor)
102
visitor.VisitMemberType (this);
105
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
107
return visitor.VisitMemberType (this);
110
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
112
return visitor.VisitMemberType (this, data);
115
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
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);
121
public override string ToString()
123
StringBuilder b = new StringBuilder();
124
b.Append(this.Target);
129
b.Append(this.MemberName);
130
if (this.TypeArguments.Any()) {
132
b.Append(string.Join(", ", this.TypeArguments));
138
public override ITypeReference ToTypeReference(NameLookupMode lookupMode = NameLookupMode.Type)
140
TypeOrNamespaceReference t;
141
if (this.IsDoubleColon) {
142
SimpleType st = this.Target as SimpleType;
144
t = new AliasNamespaceReference(st.Identifier);
149
t = this.Target.ToTypeReference(lookupMode) as TypeOrNamespaceReference;
152
return SpecialType.UnknownType;
153
var typeArguments = new List<ITypeReference>();
154
foreach (var ta in this.TypeArguments) {
155
typeArguments.Add(ta.ToTypeReference(lookupMode));
157
return new MemberTypeOrNamespaceReference(t, this.MemberName, typeArguments, lookupMode);