OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart2js.resolution.compute_members; | 5 part of dart2js.resolution.compute_members; |
6 | 6 |
7 class DeclaredMember implements Member { | 7 class DeclaredMember implements Member { |
8 final Name name; | 8 final Name name; |
9 final Element element; | 9 final Element element; |
10 final InterfaceType declarer; | 10 final InterfaceType declarer; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 | 131 |
132 Member get implementation => this; | 132 Member get implementation => this; |
133 | 133 |
134 DartType get type => declaration.type.substByContext(instance); | 134 DartType get type => declaration.type.substByContext(instance); |
135 | 135 |
136 FunctionType get functionType { | 136 FunctionType get functionType { |
137 return declaration.functionType.substByContext(instance); | 137 return declaration.functionType.substByContext(instance); |
138 } | 138 } |
139 | 139 |
140 DeclaredMember inheritFrom(InterfaceType newInstance) { | 140 DeclaredMember inheritFrom(InterfaceType newInstance) { |
141 assert(() { | 141 assert(invariant(declaration.element, () { |
142 // Assert that if [instance] contains type variables, then these are | 142 // Assert that if [instance] contains type variables, then these are |
143 // defined in the declaration of [newInstance] and will therefore be | 143 // defined in the declaration of [newInstance] and will therefore be |
144 // substituted into the context of [newInstance] in the created member. | 144 // substituted into the context of [newInstance] in the created member. |
145 ClassElement contextClass = Types.getClassContext(instance); | 145 ClassElement contextClass = Types.getClassContext(instance); |
146 return contextClass == null || contextClass == newInstance.element; | 146 return contextClass == null || contextClass == newInstance.element; |
147 }); | 147 }, message: () { |
| 148 return "Context mismatch: Context class " |
| 149 "${Types.getClassContext(instance)} from $instance does match " |
| 150 "the new instance $newInstance."; |
| 151 })); |
148 return _newInheritedMember(newInstance); | 152 return _newInheritedMember(newInstance); |
149 } | 153 } |
150 | 154 |
151 InheritedMember _newInheritedMember(InterfaceType newInstance) { | 155 InheritedMember _newInheritedMember(InterfaceType newInstance) { |
152 return new InheritedMember( | 156 return new InheritedMember( |
153 declaration, instance.substByContext(newInstance)); | 157 declaration, instance.substByContext(newInstance)); |
154 } | 158 } |
155 | 159 |
156 Iterable<Member> get declarations => <Member>[this]; | 160 Iterable<Member> get declarations => <Member>[this]; |
157 | 161 |
158 int get hashCode => declaration.hashCode + 17 * instance.hashCode; | 162 int get hashCode => declaration.hashCode + 17 * instance.hashCode; |
159 | 163 |
160 bool operator ==(other) { | 164 bool operator ==(other) { |
161 if (other is! InheritedMember) return false; | 165 if (other is! InheritedMember) return false; |
162 return declaration == other.declaration && instance == other.instance; | 166 return declaration == other.declaration && instance == other.instance; |
163 } | 167 } |
164 | 168 |
165 void printOn(StringBuffer sb, DartType type) { | 169 void printOn(StringBuffer sb, DartType type) { |
166 declaration.printOn(sb, type); | 170 declaration.printOn(sb, type); |
167 sb.write(' inherited from $instance'); | 171 sb.write(' inherited from $instance'); |
168 } | 172 } |
169 | 173 |
170 String toString() { | 174 String toString() { |
171 StringBuffer sb = new StringBuffer(); | 175 StringBuffer sb = new StringBuffer(); |
172 printOn(sb, instance); | 176 printOn(sb, type); |
173 return sb.toString(); | 177 return sb.toString(); |
174 } | 178 } |
175 } | 179 } |
176 | 180 |
177 class InheritedAbstractMember extends InheritedMember { | 181 class InheritedAbstractMember extends InheritedMember { |
178 final DeclaredMember implementation; | 182 final DeclaredMember implementation; |
179 | 183 |
180 InheritedAbstractMember( | 184 InheritedAbstractMember( |
181 DeclaredMember declaration, InterfaceType instance, this.implementation) | 185 DeclaredMember declaration, InterfaceType instance, this.implementation) |
182 : super(declaration, instance); | 186 : super(declaration, instance); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 | 241 |
238 bool get isGetter => false; | 242 bool get isGetter => false; |
239 | 243 |
240 bool get isMethod => false; | 244 bool get isMethod => false; |
241 | 245 |
242 bool get isMalformed => true; | 246 bool get isMalformed => true; |
243 | 247 |
244 String toString() => "erroneous member '$name' synthesized " | 248 String toString() => "erroneous member '$name' synthesized " |
245 "from ${inheritedMembers}"; | 249 "from ${inheritedMembers}"; |
246 } | 250 } |
OLD | NEW |