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

« back to all changes in this revision

Viewing changes to contrib/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedMethod.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.Generic;
21
 
using System.Linq;
22
 
using System.Text;
23
 
 
24
 
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
25
 
{
26
 
        /// <summary>
27
 
        /// Default implementation of <see cref="IUnresolvedMethod" /> interface.
28
 
        /// </summary>
29
 
        [Serializable]
30
 
        public class DefaultUnresolvedMethod : AbstractUnresolvedMember, IUnresolvedMethod
31
 
        {
32
 
                IList<IUnresolvedAttribute> returnTypeAttributes;
33
 
                IList<IUnresolvedTypeParameter> typeParameters;
34
 
                IList<IUnresolvedParameter> parameters;
35
 
                
36
 
                protected override void FreezeInternal()
37
 
                {
38
 
                        returnTypeAttributes = FreezableHelper.FreezeListAndElements(returnTypeAttributes);
39
 
                        typeParameters = FreezableHelper.FreezeListAndElements(typeParameters);
40
 
                        parameters = FreezableHelper.FreezeListAndElements(parameters);
41
 
                        base.FreezeInternal();
42
 
                }
43
 
                
44
 
                public override void ApplyInterningProvider(IInterningProvider provider)
45
 
                {
46
 
                        base.ApplyInterningProvider(provider);
47
 
                        if (provider != null) {
48
 
                                returnTypeAttributes = provider.InternList(returnTypeAttributes);
49
 
                                typeParameters = provider.InternList(typeParameters);
50
 
                                parameters = provider.InternList(parameters);
51
 
                        }
52
 
                }
53
 
                
54
 
                public DefaultUnresolvedMethod()
55
 
                {
56
 
                        this.EntityType = EntityType.Method;
57
 
                }
58
 
                
59
 
                public DefaultUnresolvedMethod(IUnresolvedTypeDefinition declaringType, string name)
60
 
                {
61
 
                        this.EntityType = EntityType.Method;
62
 
                        this.DeclaringTypeDefinition = declaringType;
63
 
                        this.Name = name;
64
 
                        if (declaringType != null)
65
 
                                this.ParsedFile = declaringType.ParsedFile;
66
 
                }
67
 
                
68
 
                public IList<IUnresolvedAttribute> ReturnTypeAttributes {
69
 
                        get {
70
 
                                if (returnTypeAttributes == null)
71
 
                                        returnTypeAttributes = new List<IUnresolvedAttribute>();
72
 
                                return returnTypeAttributes;
73
 
                        }
74
 
                }
75
 
                
76
 
                public IList<IUnresolvedTypeParameter> TypeParameters {
77
 
                        get {
78
 
                                if (typeParameters == null)
79
 
                                        typeParameters = new List<IUnresolvedTypeParameter>();
80
 
                                return typeParameters;
81
 
                        }
82
 
                }
83
 
                
84
 
                public bool IsExtensionMethod {
85
 
                        get { return flags[FlagExtensionMethod]; }
86
 
                        set {
87
 
                                ThrowIfFrozen();
88
 
                                flags[FlagExtensionMethod] = value;
89
 
                        }
90
 
                }
91
 
                
92
 
                public bool IsConstructor {
93
 
                        get { return this.EntityType == EntityType.Constructor; }
94
 
                }
95
 
                
96
 
                public bool IsDestructor {
97
 
                        get { return this.EntityType == EntityType.Destructor; }
98
 
                }
99
 
                
100
 
                public bool IsOperator {
101
 
                        get { return this.EntityType == EntityType.Operator; }
102
 
                }
103
 
                
104
 
                public bool IsPartialMethodDeclaration {
105
 
                        get { return flags[FlagPartialMethodDeclaration]; }
106
 
                        set {
107
 
                                ThrowIfFrozen();
108
 
                                flags[FlagPartialMethodDeclaration] = value;
109
 
                        }
110
 
                }
111
 
                
112
 
                public bool IsPartialMethodImplementation {
113
 
                        get { return flags[FlagPartialMethodImplemenation]; }
114
 
                        set {
115
 
                                ThrowIfFrozen();
116
 
                                flags[FlagPartialMethodImplemenation] = value;
117
 
                        }
118
 
                }
119
 
                
120
 
                public IList<IUnresolvedParameter> Parameters {
121
 
                        get {
122
 
                                if (parameters == null)
123
 
                                        parameters = new List<IUnresolvedParameter>();
124
 
                                return parameters;
125
 
                        }
126
 
                }
127
 
                
128
 
                public override string ToString()
129
 
                {
130
 
                        StringBuilder b = new StringBuilder("[");
131
 
                        b.Append(EntityType.ToString());
132
 
                        b.Append(' ');
133
 
                        if (DeclaringTypeDefinition != null) {
134
 
                                b.Append(DeclaringTypeDefinition.Name);
135
 
                                b.Append('.');
136
 
                        }
137
 
                        b.Append(Name);
138
 
                        b.Append('(');
139
 
                        b.Append(string.Join(", ", this.Parameters));
140
 
                        b.Append("):");
141
 
                        b.Append(ReturnType.ToString());
142
 
                        b.Append(']');
143
 
                        return b.ToString();
144
 
                }
145
 
                
146
 
                public override IMember CreateResolved(ITypeResolveContext context)
147
 
                {
148
 
                        return new DefaultResolvedMethod(this, context);
149
 
                }
150
 
                
151
 
                public override IMember Resolve(ITypeResolveContext context)
152
 
                {
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());
160
 
                }
161
 
                
162
 
                IMethod IUnresolvedMethod.Resolve(ITypeResolveContext context)
163
 
                {
164
 
                        return (IMethod)Resolve(context);
165
 
                }
166
 
                
167
 
                public static DefaultUnresolvedMethod CreateDefaultConstructor(IUnresolvedTypeDefinition typeDefinition)
168
 
                {
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,
176
 
                                IsSynthetic = true,
177
 
                                Region = region,
178
 
                                ReturnType = KnownTypeReference.Void
179
 
                        };
180
 
                }
181
 
                
182
 
                static readonly IUnresolvedMethod dummyConstructor = CreateDummyConstructor();
183
 
                
184
 
                /// <summary>
185
 
                /// Returns a dummy constructor instance:
186
 
                /// </summary>
187
 
                /// <returns>
188
 
                /// A public instance constructor with IsSynthetic=true and no declaring type.
189
 
                /// </returns>
190
 
                public static IUnresolvedMethod DummyConstructor {
191
 
                        get { return dummyConstructor; }
192
 
                }
193
 
                
194
 
                static IUnresolvedMethod CreateDummyConstructor()
195
 
                {
196
 
                        var m = new DefaultUnresolvedMethod {
197
 
                                EntityType = EntityType.Constructor,
198
 
                                Name = ".ctor",
199
 
                                Accessibility = Accessibility.Public,
200
 
                                IsSynthetic = true,
201
 
                                ReturnType = KnownTypeReference.Void
202
 
                        };
203
 
                        m.Freeze();
204
 
                        return m;
205
 
                }
206
 
        }
207
 
}