OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Mixins that implement convenience methods on [Element] subclasses. | 5 /// Mixins that implement convenience methods on [Element] subclasses. |
6 | 6 |
7 library elements.common; | 7 library elements.common; |
8 | 8 |
9 import '../common/names.dart' show | 9 import '../common/names.dart' show |
10 Names, | 10 Names, |
11 Uris; | 11 Uris; |
12 import '../compiler.dart' show | |
13 Compiler, | |
14 isPrivateName; | |
15 import '../dart_types.dart' show | 12 import '../dart_types.dart' show |
16 DartType, | 13 DartType, |
17 InterfaceType, | 14 InterfaceType, |
18 FunctionType; | 15 FunctionType; |
19 import '../util/util.dart' show | 16 import '../util/util.dart' show |
20 Link; | 17 Link; |
21 | 18 |
22 import 'elements.dart'; | 19 import 'elements.dart'; |
23 | 20 |
24 abstract class ElementCommon implements Element { | 21 abstract class ElementCommon implements Element { |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 return lookupSuperMemberInLibrary(memberName, library); | 269 return lookupSuperMemberInLibrary(memberName, library); |
273 } | 270 } |
274 | 271 |
275 /** | 272 /** |
276 * Lookup super members for the class that is accessible in [library]. | 273 * Lookup super members for the class that is accessible in [library]. |
277 * This will ignore constructors. | 274 * This will ignore constructors. |
278 */ | 275 */ |
279 @override | 276 @override |
280 Element lookupSuperMemberInLibrary(String memberName, | 277 Element lookupSuperMemberInLibrary(String memberName, |
281 LibraryElement library) { | 278 LibraryElement library) { |
282 bool isPrivate = isPrivateName(memberName); | 279 bool isPrivate = Name.isPrivateName(memberName); |
283 for (ClassElement s = superclass; s != null; s = s.superclass) { | 280 for (ClassElement s = superclass; s != null; s = s.superclass) { |
284 // Private members from a different library are not visible. | 281 // Private members from a different library are not visible. |
285 if (isPrivate && !identical(library, s.library)) continue; | 282 if (isPrivate && !identical(library, s.library)) continue; |
286 Element e = s.lookupLocalMember(memberName); | 283 Element e = s.lookupLocalMember(memberName); |
287 if (e == null) continue; | 284 if (e == null) continue; |
288 // Static members are not inherited. | 285 // Static members are not inherited. |
289 if (e.isStatic) continue; | 286 if (e.isStatic) continue; |
290 return e; | 287 return e; |
291 } | 288 } |
292 return null; | 289 return null; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 * Returns true if the [fieldMember] shadows another field. The given | 378 * Returns true if the [fieldMember] shadows another field. The given |
382 * [fieldMember] must be a member of this class, i.e. if there is a field of | 379 * [fieldMember] must be a member of this class, i.e. if there is a field of |
383 * the same name in the superclass chain. | 380 * the same name in the superclass chain. |
384 * | 381 * |
385 * This method also works if the [fieldMember] is private. | 382 * This method also works if the [fieldMember] is private. |
386 */ | 383 */ |
387 @override | 384 @override |
388 bool hasFieldShadowedBy(Element fieldMember) { | 385 bool hasFieldShadowedBy(Element fieldMember) { |
389 assert(fieldMember.isField); | 386 assert(fieldMember.isField); |
390 String fieldName = fieldMember.name; | 387 String fieldName = fieldMember.name; |
391 bool isPrivate = isPrivateName(fieldName); | 388 bool isPrivate = Name.isPrivateName(fieldName); |
392 LibraryElement memberLibrary = fieldMember.library; | 389 LibraryElement memberLibrary = fieldMember.library; |
393 ClassElement lookupClass = this.superclass; | 390 ClassElement lookupClass = this.superclass; |
394 while (lookupClass != null) { | 391 while (lookupClass != null) { |
395 Element foundMember = lookupClass.lookupLocalMember(fieldName); | 392 Element foundMember = lookupClass.lookupLocalMember(fieldName); |
396 if (foundMember != null) { | 393 if (foundMember != null) { |
397 if (foundMember.isField) { | 394 if (foundMember.isField) { |
398 if (!isPrivate || memberLibrary == foundMember.library) { | 395 if (!isPrivate || memberLibrary == foundMember.library) { |
399 // Private fields can only be shadowed by a field declared in the | 396 // Private fields can only be shadowed by a field declared in the |
400 // same library. | 397 // same library. |
401 return true; | 398 return true; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 // this signature must not have more required parameters. Having more | 490 // this signature must not have more required parameters. Having more |
494 // optional parameters is not a problem, they simply are never provided | 491 // optional parameters is not a problem, they simply are never provided |
495 // by call sites of a call to a method with the other signature. | 492 // by call sites of a call to a method with the other signature. |
496 int otherTotalCount = signature.parameterCount; | 493 int otherTotalCount = signature.parameterCount; |
497 return requiredParameterCount <= otherTotalCount | 494 return requiredParameterCount <= otherTotalCount |
498 && parameterCount >= otherTotalCount; | 495 && parameterCount >= otherTotalCount; |
499 } | 496 } |
500 return true; | 497 return true; |
501 } | 498 } |
502 } | 499 } |
OLD | NEW |