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.Resolver;
32
using ICSharpCode.NRefactory.CSharp.TypeSystem;
33
using ICSharpCode.NRefactory.TypeSystem;
35
namespace ICSharpCode.NRefactory.CSharp
37
public class SimpleType : AstType
40
public new static readonly SimpleType Null = new NullSimpleType ();
42
sealed class NullSimpleType : SimpleType
44
public override bool IsNull {
50
public override void AcceptVisitor (IAstVisitor visitor)
54
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
59
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
64
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
66
return other == null || other.IsNull;
69
public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider)
71
return SpecialType.UnknownType;
80
public SimpleType(string identifier)
82
this.Identifier = identifier;
85
public SimpleType (Identifier identifier)
87
this.IdentifierToken = identifier;
90
public SimpleType(string identifier, TextLocation location)
92
SetChildByRole (Roles.Identifier, CSharp.Identifier.Create (identifier, location));
95
public SimpleType (string identifier, IEnumerable<AstType> typeArguments)
97
this.Identifier = identifier;
98
foreach (var arg in typeArguments) {
99
AddChild (arg, Roles.TypeArgument);
103
public SimpleType (string identifier, params AstType[] typeArguments) : this (identifier, (IEnumerable<AstType>)typeArguments)
107
public string Identifier {
109
return GetChildByRole (Roles.Identifier).Name;
112
SetChildByRole (Roles.Identifier, CSharp.Identifier.Create (value));
116
public Identifier IdentifierToken {
118
return GetChildByRole (Roles.Identifier);
121
SetChildByRole (Roles.Identifier, value);
125
public AstNodeCollection<AstType> TypeArguments {
126
get { return GetChildrenByRole (Roles.TypeArgument); }
129
public override void AcceptVisitor (IAstVisitor visitor)
131
visitor.VisitSimpleType (this);
134
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
136
return visitor.VisitSimpleType (this);
139
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
141
return visitor.VisitSimpleType (this, data);
144
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
146
SimpleType o = other as SimpleType;
147
return o != null && MatchString(this.Identifier, o.Identifier) && this.TypeArguments.DoMatch(o.TypeArguments, match);
150
public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider = null)
152
if (interningProvider == null)
153
interningProvider = InterningProvider.Dummy;
154
var typeArguments = new List<ITypeReference>();
155
foreach (var ta in this.TypeArguments) {
156
typeArguments.Add(ta.ToTypeReference(lookupMode, interningProvider));
158
string identifier = interningProvider.Intern(this.Identifier);
159
if (typeArguments.Count == 0 && string.IsNullOrEmpty(identifier)) {
160
// empty SimpleType is used for typeof(List<>).
161
return SpecialType.UnboundTypeArgument;
163
var t = new SimpleTypeOrNamespaceReference(identifier, interningProvider.InternList(typeArguments), lookupMode);
164
return interningProvider.Intern(t);