1
ļ»æ// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
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:
9
// The above copyright notice and this permission notice shall be included in all copies or
10
// substantial portions of the Software.
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.
20
using System.Collections.Generic;
24
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
27
/// Default implementation of <see cref="IUnresolvedMethod" /> interface.
30
public class DefaultUnresolvedMethod : AbstractUnresolvedMember, IUnresolvedMethod
32
IList<IUnresolvedAttribute> returnTypeAttributes;
33
IList<IUnresolvedTypeParameter> typeParameters;
34
IList<IUnresolvedParameter> parameters;
36
protected override void FreezeInternal()
38
returnTypeAttributes = FreezableHelper.FreezeListAndElements(returnTypeAttributes);
39
typeParameters = FreezableHelper.FreezeListAndElements(typeParameters);
40
parameters = FreezableHelper.FreezeListAndElements(parameters);
41
base.FreezeInternal();
44
public override void ApplyInterningProvider(IInterningProvider provider)
46
base.ApplyInterningProvider(provider);
47
if (provider != null) {
48
returnTypeAttributes = provider.InternList(returnTypeAttributes);
49
typeParameters = provider.InternList(typeParameters);
50
parameters = provider.InternList(parameters);
54
public DefaultUnresolvedMethod()
56
this.EntityType = EntityType.Method;
59
public DefaultUnresolvedMethod(IUnresolvedTypeDefinition declaringType, string name)
61
this.EntityType = EntityType.Method;
62
this.DeclaringTypeDefinition = declaringType;
64
if (declaringType != null)
65
this.ParsedFile = declaringType.ParsedFile;
68
public IList<IUnresolvedAttribute> ReturnTypeAttributes {
70
if (returnTypeAttributes == null)
71
returnTypeAttributes = new List<IUnresolvedAttribute>();
72
return returnTypeAttributes;
76
public IList<IUnresolvedTypeParameter> TypeParameters {
78
if (typeParameters == null)
79
typeParameters = new List<IUnresolvedTypeParameter>();
80
return typeParameters;
84
public bool IsExtensionMethod {
85
get { return flags[FlagExtensionMethod]; }
88
flags[FlagExtensionMethod] = value;
92
public bool IsConstructor {
93
get { return this.EntityType == EntityType.Constructor; }
96
public bool IsDestructor {
97
get { return this.EntityType == EntityType.Destructor; }
100
public bool IsOperator {
101
get { return this.EntityType == EntityType.Operator; }
104
public bool IsPartialMethodDeclaration {
105
get { return flags[FlagPartialMethodDeclaration]; }
108
flags[FlagPartialMethodDeclaration] = value;
112
public bool IsPartialMethodImplementation {
113
get { return flags[FlagPartialMethodImplemenation]; }
116
flags[FlagPartialMethodImplemenation] = value;
120
public IList<IUnresolvedParameter> Parameters {
122
if (parameters == null)
123
parameters = new List<IUnresolvedParameter>();
128
public override string ToString()
130
StringBuilder b = new StringBuilder("[");
131
b.Append(EntityType.ToString());
133
if (DeclaringTypeDefinition != null) {
134
b.Append(DeclaringTypeDefinition.Name);
139
b.Append(string.Join(", ", this.Parameters));
141
b.Append(ReturnType.ToString());
146
public override IMember CreateResolved(ITypeResolveContext context)
148
return new DefaultResolvedMethod(this, context);
151
public override IMember Resolve(ITypeResolveContext context)
153
ITypeReference interfaceTypeReference = null;
154
if (this.IsExplicitInterfaceImplementation && this.ExplicitInterfaceImplementations.Count == 1)
155
interfaceTypeReference = this.ExplicitInterfaceImplementations[0].DeclaringTypeReference;
156
return Resolve(ExtendContextForType(context, this.DeclaringTypeDefinition),
157
this.EntityType, this.Name, interfaceTypeReference,
158
this.TypeParameters.Select(tp => tp.Name).ToList(),
159
this.Parameters.Select(p => p.Type).ToList());
162
IMethod IUnresolvedMethod.Resolve(ITypeResolveContext context)
164
return (IMethod)Resolve(context);
167
public static DefaultUnresolvedMethod CreateDefaultConstructor(IUnresolvedTypeDefinition typeDefinition)
169
if (typeDefinition == null)
170
throw new ArgumentNullException("typeDefinition");
171
DomRegion region = typeDefinition.Region;
172
region = new DomRegion(region.FileName, region.BeginLine, region.BeginColumn); // remove endline/endcolumn
173
return new DefaultUnresolvedMethod(typeDefinition, ".ctor") {
174
EntityType = EntityType.Constructor,
175
Accessibility = typeDefinition.IsAbstract ? Accessibility.Protected : Accessibility.Public,
178
ReturnType = KnownTypeReference.Void
182
static readonly IUnresolvedMethod dummyConstructor = CreateDummyConstructor();
185
/// Returns a dummy constructor instance:
188
/// A public instance constructor with IsSynthetic=true and no declaring type.
190
public static IUnresolvedMethod DummyConstructor {
191
get { return dummyConstructor; }
194
static IUnresolvedMethod CreateDummyConstructor()
196
var m = new DefaultUnresolvedMethod {
197
EntityType = EntityType.Constructor,
199
Accessibility = Accessibility.Public,
201
ReturnType = KnownTypeReference.Void