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

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.CSharp/Ast/SimpleType.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.Resolver;
 
32
using ICSharpCode.NRefactory.CSharp.TypeSystem;
 
33
using ICSharpCode.NRefactory.TypeSystem;
 
34
 
 
35
namespace ICSharpCode.NRefactory.CSharp
 
36
{
 
37
        public class SimpleType : AstType
 
38
        {
 
39
                #region Null
 
40
                public new static readonly SimpleType Null = new NullSimpleType ();
 
41
                
 
42
                sealed class NullSimpleType : SimpleType
 
43
                {
 
44
                        public override bool IsNull {
 
45
                                get {
 
46
                                        return true;
 
47
                                }
 
48
                        }
 
49
                        
 
50
                        public override void AcceptVisitor (IAstVisitor visitor)
 
51
                        {
 
52
                        }
 
53
                        
 
54
                        public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
 
55
                        {
 
56
                                return default (T);
 
57
                        }
 
58
                        
 
59
                        public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
 
60
                        {
 
61
                                return default (S);
 
62
                        }
 
63
                        
 
64
                        protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
 
65
                        {
 
66
                                return other == null || other.IsNull;
 
67
                        }
 
68
                        
 
69
                        public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider)
 
70
                        {
 
71
                                return SpecialType.UnknownType;
 
72
                        }
 
73
                }
 
74
                #endregion
 
75
                
 
76
                public SimpleType()
 
77
                {
 
78
                }
 
79
                
 
80
                public SimpleType(string identifier)
 
81
                {
 
82
                        this.Identifier = identifier;
 
83
                }
 
84
                
 
85
                public SimpleType (Identifier identifier)
 
86
                {
 
87
                        this.IdentifierToken = identifier;
 
88
                }
 
89
                
 
90
                public SimpleType(string identifier, TextLocation location)
 
91
                {
 
92
                        SetChildByRole (Roles.Identifier, CSharp.Identifier.Create (identifier, location));
 
93
                }
 
94
                
 
95
                public SimpleType (string identifier, IEnumerable<AstType> typeArguments)
 
96
                {
 
97
                        this.Identifier = identifier;
 
98
                        foreach (var arg in typeArguments) {
 
99
                                AddChild (arg, Roles.TypeArgument);
 
100
                        }
 
101
                }
 
102
                
 
103
                public SimpleType (string identifier, params AstType[] typeArguments) : this (identifier, (IEnumerable<AstType>)typeArguments)
 
104
                {
 
105
                }
 
106
                
 
107
                public string Identifier {
 
108
                        get {
 
109
                                return GetChildByRole (Roles.Identifier).Name;
 
110
                        }
 
111
                        set {
 
112
                                SetChildByRole (Roles.Identifier, CSharp.Identifier.Create (value));
 
113
                        }
 
114
                }
 
115
                
 
116
                public Identifier IdentifierToken {
 
117
                        get {
 
118
                                return GetChildByRole (Roles.Identifier);
 
119
                        }
 
120
                        set {
 
121
                                SetChildByRole (Roles.Identifier, value);
 
122
                        }
 
123
                }
 
124
                
 
125
                public AstNodeCollection<AstType> TypeArguments {
 
126
                        get { return GetChildrenByRole (Roles.TypeArgument); }
 
127
                }
 
128
                
 
129
                public override void AcceptVisitor (IAstVisitor visitor)
 
130
                {
 
131
                        visitor.VisitSimpleType (this);
 
132
                }
 
133
                
 
134
                public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
 
135
                {
 
136
                        return visitor.VisitSimpleType (this);
 
137
                }
 
138
                
 
139
                public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
 
140
                {
 
141
                        return visitor.VisitSimpleType (this, data);
 
142
                }
 
143
                
 
144
                protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
 
145
                {
 
146
                        SimpleType o = other as SimpleType;
 
147
                        return o != null && MatchString(this.Identifier, o.Identifier) && this.TypeArguments.DoMatch(o.TypeArguments, match);
 
148
                }
 
149
                
 
150
                public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider = null)
 
151
                {
 
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));
 
157
                        }
 
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;
 
162
                        }
 
163
                        var t = new SimpleTypeOrNamespaceReference(identifier, interningProvider.InternList(typeArguments), lookupMode);
 
164
                        return interningProvider.Intern(t);
 
165
                }
 
166
        }
 
167
}
 
168