Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.ExtLibs/HeuristicLab.NRefactory/5.5.0/NRefactory.CSharp-5.5.0/Resolver/ReducedExtensionMethod.cs @ 12515

Last change on this file since 12515 was 11700, checked in by jkarder, 10 years ago

#2077: created branch and added first version

File size: 8.6 KB
Line 
1//
2// ReducedExtensionMethod.cs
3//
4// Author:
5//       Mike Krüger <mkrueger@xamarin.com>
6//
7// Copyright (c) 2013 Xamarin Inc. (http://xamarin.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.
26using System;
27using ICSharpCode.NRefactory.TypeSystem;
28using System.Collections.Generic;
29using System.Linq;
30using ICSharpCode.NRefactory.TypeSystem.Implementation;
31
32namespace ICSharpCode.NRefactory.CSharp
33{
34  /// <summary>
35  /// An invocated extension method hides the extension parameter in its parameter list.
36  /// It's used to hide the internals of extension method invocation in certain situation to simulate the
37  /// syntactic way of writing extension methods on semantic level.
38  /// </summary>
39  public class ReducedExtensionMethod : IMethod
40  {
41    readonly IMethod baseMethod;
42
43    public ReducedExtensionMethod(IMethod baseMethod)
44    {
45      this.baseMethod = baseMethod;
46    }
47
48    public override bool Equals(object obj)
49    {
50      var other = obj as ReducedExtensionMethod;
51      if (other == null)
52        return false;
53      return baseMethod.Equals(other.baseMethod);
54    }
55   
56    public override int GetHashCode()
57    {
58      unchecked {
59        return baseMethod.GetHashCode() + 1;
60      }
61    }
62
63    public override string ToString()
64    {
65      return string.Format("[ReducedExtensionMethod: ReducedFrom={0}]", ReducedFrom);
66    }
67
68    #region IMember implementation
69
70    [Serializable]
71    public sealed class ReducedExtensionMethodMemberReference : IMemberReference
72    {
73      readonly IMethod baseMethod;
74
75      public ReducedExtensionMethodMemberReference (IMethod baseMethod)
76      {
77        this.baseMethod = baseMethod;
78      }
79
80      public IMember Resolve(ITypeResolveContext context)
81      {
82        return new ReducedExtensionMethod ((IMethod)baseMethod.ToReference ().Resolve (context));
83      }
84     
85      ISymbol ISymbolReference.Resolve(ITypeResolveContext context)
86      {
87        return Resolve(context);
88      }
89
90      public ITypeReference DeclaringTypeReference {
91        get {
92          return baseMethod.ToReference ().DeclaringTypeReference;
93        }
94      }
95    }
96
97    public IMemberReference ToMemberReference()
98    {
99      return new ReducedExtensionMethodMemberReference (baseMethod);
100    }
101   
102    public IMemberReference ToReference()
103    {
104      return new ReducedExtensionMethodMemberReference (baseMethod);
105    }
106   
107    ISymbolReference ISymbol.ToReference()
108    {
109      return ToReference();
110    }
111
112    public IMember MemberDefinition {
113      get {
114        return baseMethod.MemberDefinition;
115      }
116    }
117
118    public IUnresolvedMember UnresolvedMember {
119      get {
120        return baseMethod.UnresolvedMember;
121      }
122    }
123
124    public IType ReturnType {
125      get {
126        return baseMethod.ReturnType;
127      }
128    }
129
130    public System.Collections.Generic.IList<IMember> ImplementedInterfaceMembers {
131      get {
132        return baseMethod.ImplementedInterfaceMembers;
133      }
134    }
135
136    public bool IsExplicitInterfaceImplementation {
137      get {
138        return baseMethod.IsExplicitInterfaceImplementation;
139      }
140    }
141
142    public bool IsVirtual {
143      get {
144        return baseMethod.IsVirtual;
145      }
146    }
147
148    public bool IsOverride {
149      get {
150        return baseMethod.IsOverride;
151      }
152    }
153
154    public bool IsOverridable {
155      get {
156        return baseMethod.IsOverridable;
157      }
158    }
159
160    public TypeParameterSubstitution Substitution {
161      get {
162        return baseMethod.Substitution;
163      }
164    }
165
166    public IMethod Specialize(TypeParameterSubstitution substitution)
167    {
168      return new ReducedExtensionMethod((IMethod)baseMethod.Specialize(substitution));
169    }
170   
171    IMember IMember.Specialize(TypeParameterSubstitution substitution)
172    {
173      return Specialize(substitution);
174    }
175   
176    public bool IsParameterized {
177      get  { return baseMethod.IsParameterized; }
178    }
179
180    #endregion
181
182    #region IMethod implementation
183
184    public System.Collections.Generic.IList<IUnresolvedMethod> Parts {
185      get {
186        return baseMethod.Parts;
187      }
188    }
189
190    public System.Collections.Generic.IList<IAttribute> ReturnTypeAttributes {
191      get {
192        return baseMethod.ReturnTypeAttributes;
193      }
194    }
195
196    public System.Collections.Generic.IList<ITypeParameter> TypeParameters {
197      get {
198        return baseMethod.TypeParameters;
199      }
200    }
201
202    public bool IsExtensionMethod {
203      get {
204        return true;
205      }
206    }
207
208    public bool IsConstructor {
209      get {
210        return baseMethod.IsConstructor;
211      }
212    }
213
214    public bool IsDestructor {
215      get {
216        return baseMethod.IsDestructor;
217      }
218    }
219
220    public bool IsOperator {
221      get {
222        return baseMethod.IsOperator;
223      }
224    }
225
226    public bool IsPartial {
227      get {
228        return baseMethod.IsPartial;
229      }
230    }
231
232    public bool IsAsync {
233      get {
234        return baseMethod.IsAsync;
235      }
236    }
237
238    public bool HasBody {
239      get {
240        return baseMethod.HasBody;
241      }
242    }
243
244    public bool IsAccessor {
245      get {
246        return baseMethod.IsAccessor;
247      }
248    }
249
250    public IMember AccessorOwner {
251      get {
252        return baseMethod.AccessorOwner;
253      }
254    }
255
256    public IMethod ReducedFrom {
257      get {
258        return baseMethod;
259      }
260    }
261
262    public IList<IType> TypeArguments {
263      get {
264        return baseMethod.TypeArguments;
265      }
266    }
267    #endregion
268
269    #region IParameterizedMember implementation
270    List<IParameter> parameters;
271    public System.Collections.Generic.IList<IParameter> Parameters {
272      get {
273        if (parameters == null)
274          parameters = new List<IParameter> (baseMethod.Parameters.Skip (1));
275        return parameters;
276      }
277    }
278
279    #endregion
280
281    #region IEntity implementation
282
283    public SymbolKind SymbolKind {
284      get {
285        return baseMethod.SymbolKind;
286      }
287    }
288
289    [Obsolete("Use the SymbolKind property instead.")]
290    public EntityType EntityType {
291      get {
292        return baseMethod.EntityType;
293      }
294    }
295   
296    public DomRegion Region {
297      get {
298        return baseMethod.Region;
299      }
300    }
301
302    public DomRegion BodyRegion {
303      get {
304        return baseMethod.BodyRegion;
305      }
306    }
307
308    public ITypeDefinition DeclaringTypeDefinition {
309      get {
310        return baseMethod.DeclaringTypeDefinition;
311      }
312    }
313
314    public IType DeclaringType {
315      get {
316        return baseMethod.DeclaringType;
317      }
318    }
319
320    public IAssembly ParentAssembly {
321      get {
322        return baseMethod.ParentAssembly;
323      }
324    }
325
326    public System.Collections.Generic.IList<IAttribute> Attributes {
327      get {
328        return baseMethod.Attributes;
329      }
330    }
331
332    public ICSharpCode.NRefactory.Documentation.DocumentationComment Documentation {
333      get {
334        return baseMethod.Documentation;
335      }
336    }
337
338    public bool IsStatic {
339      get {
340        return false;
341      }
342    }
343
344    public bool IsAbstract {
345      get {
346        return baseMethod.IsAbstract;
347      }
348    }
349
350    public bool IsSealed {
351      get {
352        return baseMethod.IsSealed;
353      }
354    }
355
356    public bool IsShadowing {
357      get {
358        return baseMethod.IsShadowing;
359      }
360    }
361
362    public bool IsSynthetic {
363      get {
364        return baseMethod.IsSynthetic;
365      }
366    }
367
368    #endregion
369
370    #region IHasAccessibility implementation
371
372    public Accessibility Accessibility {
373      get {
374        return baseMethod.Accessibility;
375      }
376    }
377
378    public bool IsPrivate {
379      get {
380        return baseMethod.IsPrivate;
381      }
382    }
383
384    public bool IsPublic {
385      get {
386        return baseMethod.IsPublic;
387      }
388    }
389
390    public bool IsProtected {
391      get {
392        return baseMethod.IsProtected;
393      }
394    }
395
396    public bool IsInternal {
397      get {
398        return baseMethod.IsInternal;
399      }
400    }
401
402    public bool IsProtectedOrInternal {
403      get {
404        return baseMethod.IsProtectedOrInternal;
405      }
406    }
407
408    public bool IsProtectedAndInternal {
409      get {
410        return baseMethod.IsProtectedAndInternal;
411      }
412    }
413
414    #endregion
415
416    #region INamedElement implementation
417
418    public string FullName {
419      get {
420        return baseMethod.FullName;
421      }
422    }
423
424    public string Name {
425      get {
426        return baseMethod.Name;
427      }
428    }
429
430    public string ReflectionName {
431      get {
432        return baseMethod.ReflectionName;
433      }
434    }
435
436    public string Namespace {
437      get {
438        return baseMethod.Namespace;
439      }
440    }
441
442    #endregion
443
444    #region ICompilationProvider implementation
445
446    public ICompilation Compilation {
447      get {
448        return baseMethod.Compilation;
449      }
450    }
451
452    #endregion
453  }
454}
455
Note: See TracBrowser for help on using the repository browser.