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

« back to all changes in this revision

Viewing changes to contrib/ICSharpCode.NRefactory.CSharp/TypeSystem/ResolvedUsingScope.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
 
ļ»æ// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
2
 
// 
3
 
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4
 
// software and associated documentation files (the "Software"), to deal in the Software
5
 
// without restriction, including without limitation the rights to use, copy, modify, merge,
6
 
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7
 
// to whom the Software is furnished to do so, subject to the following conditions:
8
 
// 
9
 
// The above copyright notice and this permission notice shall be included in all copies or
10
 
// substantial portions of the Software.
11
 
// 
12
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13
 
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14
 
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15
 
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
 
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17
 
// DEALINGS IN THE SOFTWARE.
18
 
 
19
 
using System;
20
 
using System.Collections.Concurrent;
21
 
using System.Collections.Generic;
22
 
using System.Collections.ObjectModel;
23
 
using System.Diagnostics;
24
 
using ICSharpCode.NRefactory.CSharp.Resolver;
25
 
using ICSharpCode.NRefactory.Semantics;
26
 
using ICSharpCode.NRefactory.TypeSystem;
27
 
using ICSharpCode.NRefactory.Utils;
28
 
 
29
 
namespace ICSharpCode.NRefactory.CSharp.TypeSystem
30
 
{
31
 
        /// <summary>
32
 
        /// Resolved version of using scope.
33
 
        /// </summary>
34
 
        public class ResolvedUsingScope
35
 
        {
36
 
                readonly CSharpTypeResolveContext parentContext;
37
 
                readonly UsingScope usingScope;
38
 
                
39
 
                internal readonly ConcurrentDictionary<string, ResolveResult> ResolveCache = new ConcurrentDictionary<string, ResolveResult>();
40
 
                internal List<List<IMethod>> AllExtensionMethods;
41
 
                
42
 
                public ResolvedUsingScope(CSharpTypeResolveContext context, UsingScope usingScope)
43
 
                {
44
 
                        if (context == null)
45
 
                                throw new ArgumentNullException("context");
46
 
                        if (usingScope == null)
47
 
                                throw new ArgumentNullException("usingScope");
48
 
                        this.parentContext = context;
49
 
                        this.usingScope = usingScope;
50
 
                        if (usingScope.Parent != null) {
51
 
                                if (context.CurrentUsingScope == null)
52
 
                                        throw new InvalidOperationException();
53
 
                        } else {
54
 
                                if (context.CurrentUsingScope != null)
55
 
                                        throw new InvalidOperationException();
56
 
                        }
57
 
                }
58
 
                
59
 
                public UsingScope UnresolvedUsingScope {
60
 
                        get { return usingScope; }
61
 
                }
62
 
                
63
 
                INamespace @namespace;
64
 
                
65
 
                public INamespace Namespace {
66
 
                        get {
67
 
                                INamespace result = LazyInit.VolatileRead(ref this.@namespace);
68
 
                                if (result != null) {
69
 
                                        return result;
70
 
                                } else {
71
 
                                        if (parentContext.CurrentUsingScope != null) {
72
 
                                                result = parentContext.CurrentUsingScope.Namespace.GetChildNamespace(usingScope.ShortNamespaceName);
73
 
                                                if (result == null)
74
 
                                                        result = new DummyNamespace(parentContext.CurrentUsingScope.Namespace, usingScope.ShortNamespaceName);
75
 
                                        } else {
76
 
                                                result = parentContext.Compilation.RootNamespace;
77
 
                                        }
78
 
                                        Debug.Assert(result != null);
79
 
                                        return LazyInit.GetOrSet(ref this.@namespace, result);
80
 
                                }
81
 
                        }
82
 
                }
83
 
                
84
 
                public ResolvedUsingScope Parent {
85
 
                        get { return parentContext.CurrentUsingScope; }
86
 
                }
87
 
                
88
 
                IList<INamespace> usings;
89
 
                
90
 
                public IList<INamespace> Usings {
91
 
                        get {
92
 
                                var result = LazyInit.VolatileRead(ref this.usings);
93
 
                                if (result != null) {
94
 
                                        return result;
95
 
                                } else {
96
 
                                        result = new List<INamespace>();
97
 
                                        CSharpResolver resolver = new CSharpResolver(parentContext.WithUsingScope(this));
98
 
                                        foreach (var u in usingScope.Usings) {
99
 
                                                INamespace ns = u.ResolveNamespace(resolver);
100
 
                                                if (ns != null)
101
 
                                                        result.Add(ns);
102
 
                                        }
103
 
                                        return LazyInit.GetOrSet(ref this.usings, new ReadOnlyCollection<INamespace>(result));
104
 
                                }
105
 
                        }
106
 
                }
107
 
                
108
 
                IList<KeyValuePair<string, ResolveResult>> usingAliases;
109
 
                
110
 
                public IList<KeyValuePair<string, ResolveResult>> UsingAliases {
111
 
                        get {
112
 
                                var result = LazyInit.VolatileRead(ref this.usingAliases);
113
 
                                if (result != null) {
114
 
                                        return result;
115
 
                                } else {
116
 
                                        CSharpResolver resolver = new CSharpResolver(parentContext.WithUsingScope(this));
117
 
                                        result = new KeyValuePair<string, ResolveResult>[usingScope.UsingAliases.Count];
118
 
                                        for (int i = 0; i < result.Count; i++) {
119
 
                                                result[i] = new KeyValuePair<string, ResolveResult>(
120
 
                                                        usingScope.UsingAliases[i].Key,
121
 
                                                        usingScope.UsingAliases[i].Value.Resolve(resolver)
122
 
                                                );
123
 
                                        }
124
 
                                        return LazyInit.GetOrSet(ref this.usingAliases, result);
125
 
                                }
126
 
                        }
127
 
                }
128
 
                
129
 
                public IList<string> ExternAliases {
130
 
                        get { return usingScope.ExternAliases; }
131
 
                }
132
 
                
133
 
                /// <summary>
134
 
                /// Gets whether this using scope has an alias (either using or extern)
135
 
                /// with the specified name.
136
 
                /// </summary>
137
 
                public bool HasAlias(string identifier)
138
 
                {
139
 
                        return usingScope.HasAlias(identifier);
140
 
                }
141
 
                
142
 
                sealed class DummyNamespace : INamespace
143
 
                {
144
 
                        readonly INamespace parentNamespace;
145
 
                        readonly string name;
146
 
                        
147
 
                        public DummyNamespace(INamespace parentNamespace, string name)
148
 
                        {
149
 
                                this.parentNamespace = parentNamespace;
150
 
                                this.name = name;
151
 
                        }
152
 
                        
153
 
                        public string ExternAlias { get; set; }
154
 
                        
155
 
                        string INamespace.FullName {
156
 
                                get { return NamespaceDeclaration.BuildQualifiedName(parentNamespace.FullName, name); }
157
 
                        }
158
 
                        
159
 
                        string INamespace.Name {
160
 
                                get { return name; }
161
 
                        }
162
 
                        
163
 
                        INamespace INamespace.ParentNamespace {
164
 
                                get { return parentNamespace; }
165
 
                        }
166
 
                        
167
 
                        IEnumerable<INamespace> INamespace.ChildNamespaces {
168
 
                                get { return EmptyList<INamespace>.Instance; }
169
 
                        }
170
 
                        
171
 
                        IEnumerable<ITypeDefinition> INamespace.Types {
172
 
                                get { return EmptyList<ITypeDefinition>.Instance; }
173
 
                        }
174
 
                        
175
 
                        ICompilation IResolved.Compilation {
176
 
                                get { return parentNamespace.Compilation; }
177
 
                        }
178
 
                        
179
 
                        INamespace INamespace.GetChildNamespace(string name)
180
 
                        {
181
 
                                return null;
182
 
                        }
183
 
                        
184
 
                        ITypeDefinition INamespace.GetTypeDefinition(string name, int typeParameterCount)
185
 
                        {
186
 
                                return null;
187
 
                        }
188
 
                }
189
 
        }
190
 
}