| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 part of elements; |
| 6 |
| 7 /// A [Name] represents the abstraction of a Dart identifier which takes privacy |
| 8 /// and setter into account. |
| 9 // TODO(johnniwinther): Try to share logic with [Selector]. |
| 10 abstract class Name { |
| 11 /// Create a [Name] for an identifier [text]. If [text] begins with '_' a |
| 12 /// private name with respect to [library] is created. If [isSetter] is `true` |
| 13 /// the created name represents the setter name 'text='. |
| 14 factory Name(String text, LibraryElement library, {bool isSetter: false}) { |
| 15 if (isPrivateName(text)) { |
| 16 return new PrivateName(text, library, isSetter: isSetter); |
| 17 } |
| 18 return new PublicName(text, isSetter: isSetter); |
| 19 } |
| 20 |
| 21 /// The text of the name without prefixed library name or suffixed '=' if |
| 22 /// applicable. |
| 23 String get text; |
| 24 |
| 25 /// Is `true` if this name represents the name of a setter. |
| 26 bool get isSetter; |
| 27 |
| 28 /// Returns the getter name corresponding to this name. If this name is a |
| 29 /// setter name 'v=' then the name 'v' is returned, otherwise the name itself |
| 30 /// is returned. |
| 31 Name get getter; |
| 32 |
| 33 /// Returns the seeter name corresponding to this name. If this name is a |
| 34 /// getter name 'v' then the name 'v=' is returned, otherwsie the name itself |
| 35 /// is returned. |
| 36 Name get setter; |
| 37 |
| 38 /// Returned `true` an entity of this name is accessible from library |
| 39 /// [element]. |
| 40 bool isAccessibleFrom(LibraryElement element); |
| 41 } |
| 42 |
| 43 class PublicName implements Name { |
| 44 final String text; |
| 45 final bool isSetter; |
| 46 |
| 47 const PublicName(this.text, {this.isSetter: false}); |
| 48 |
| 49 Name get getter => isSetter ? new PublicName(text) : this; |
| 50 |
| 51 Name get setter => isSetter ? this : new PublicName(text, isSetter: true); |
| 52 |
| 53 bool isAccessibleFrom(LibraryElement element) => true; |
| 54 |
| 55 int get hashCode => text.hashCode + 11 * isSetter.hashCode; |
| 56 |
| 57 bool operator ==(other) { |
| 58 if (other is! PublicName) return false; |
| 59 return text == other.text && isSetter == other.isSetter; |
| 60 } |
| 61 |
| 62 String toString() => isSetter ? '$text=' : text; |
| 63 } |
| 64 |
| 65 class PrivateName extends PublicName { |
| 66 final LibraryElement library; |
| 67 |
| 68 PrivateName(String text, this.library, {bool isSetter: false}) |
| 69 : super(text, isSetter: isSetter); |
| 70 |
| 71 Name get getter => isSetter ? new PrivateName(text, library) : this; |
| 72 |
| 73 Name get setter { |
| 74 return isSetter ? this : new PrivateName(text, library, isSetter: true); |
| 75 } |
| 76 |
| 77 bool isAccessibleFrom(LibraryElement element) => library == element; |
| 78 |
| 79 int get hashCode => super.hashCode + 13 * library.hashCode; |
| 80 |
| 81 bool operator ==(other) { |
| 82 if (other is! PrivateName) return false; |
| 83 return super==(other) && library == other.library; |
| 84 } |
| 85 |
| 86 String toString() => '${library.getLibraryName()}#${super.toString()}'; |
| 87 } |
| OLD | NEW |