| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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 elements; | 5 part of elements; |
| 6 | 6 |
| 7 /// A [Name] represents the abstraction of a Dart identifier which takes privacy | 7 /// A [Name] represents the abstraction of a Dart identifier which takes privacy |
| 8 /// and setter into account. | 8 /// and setter into account. |
| 9 // TODO(johnniwinther): Try to share logic with [Selector]. | 9 // TODO(johnniwinther): Try to share logic with [Selector]. |
| 10 abstract class Name { | 10 abstract class Name { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 /// [element]. | 39 /// [element]. |
| 40 bool isAccessibleFrom(LibraryElement element); | 40 bool isAccessibleFrom(LibraryElement element); |
| 41 | 41 |
| 42 /// Returns `true` if this name is private. | 42 /// Returns `true` if this name is private. |
| 43 bool get isPrivate; | 43 bool get isPrivate; |
| 44 | 44 |
| 45 /// Returns `true` if this name is the same as [other] not taking the library | 45 /// Returns `true` if this name is the same as [other] not taking the library |
| 46 /// privacy into account. | 46 /// privacy into account. |
| 47 bool isSimilarTo(Name other); | 47 bool isSimilarTo(Name other); |
| 48 int get similarHashCode; | 48 int get similarHashCode; |
| 49 | |
| 50 LibraryElement get library; | |
| 51 } | 49 } |
| 52 | 50 |
| 53 class PublicName implements Name { | 51 class PublicName implements Name { |
| 54 final String text; | 52 final String text; |
| 55 final bool isSetter; | 53 final bool isSetter; |
| 56 | 54 |
| 57 const PublicName(this.text, {this.isSetter: false}); | 55 const PublicName(this.text, {this.isSetter: false}); |
| 58 | 56 |
| 59 Name get getter => isSetter ? new PublicName(text) : this; | 57 Name get getter => isSetter ? new PublicName(text) : this; |
| 60 | 58 |
| 61 Name get setter => isSetter ? this : new PublicName(text, isSetter: true); | 59 Name get setter => isSetter ? this : new PublicName(text, isSetter: true); |
| 62 | 60 |
| 63 bool isAccessibleFrom(LibraryElement element) => true; | 61 bool isAccessibleFrom(LibraryElement element) => true; |
| 64 | 62 |
| 65 bool get isPrivate => false; | 63 bool get isPrivate => false; |
| 66 | 64 |
| 67 int get hashCode => similarHashCode; | 65 int get hashCode => similarHashCode; |
| 68 | 66 |
| 69 bool operator ==(other) { | 67 bool operator ==(other) { |
| 70 if (other is! PublicName) return false; | 68 if (other is! PublicName) return false; |
| 71 return isSimilarTo(other); | 69 return isSimilarTo(other); |
| 72 } | 70 } |
| 73 | 71 |
| 74 bool isSimilarTo(Name other) => | 72 bool isSimilarTo(Name other) => |
| 75 text == other.text && isSetter == other.isSetter; | 73 text == other.text && isSetter == other.isSetter; |
| 76 int get similarHashCode => text.hashCode + 11 * isSetter.hashCode; | 74 int get similarHashCode => text.hashCode + 11 * isSetter.hashCode; |
| 77 | |
| 78 LibraryElement get library => null; | |
| 79 | 75 |
| 80 String toString() => isSetter ? '$text=' : text; | 76 String toString() => isSetter ? '$text=' : text; |
| 81 } | 77 } |
| 82 | 78 |
| 83 class PrivateName extends PublicName { | 79 class PrivateName extends PublicName { |
| 84 final LibraryElement library; | 80 final LibraryElement library; |
| 85 | 81 |
| 86 PrivateName(String text, this.library, {bool isSetter: false}) | 82 PrivateName(String text, this.library, {bool isSetter: false}) |
| 87 : super(text, isSetter: isSetter); | 83 : super(text, isSetter: isSetter); |
| 88 | 84 |
| 89 Name get getter => isSetter ? new PrivateName(text, library) : this; | 85 Name get getter => isSetter ? new PrivateName(text, library) : this; |
| 90 | 86 |
| 91 Name get setter { | 87 Name get setter { |
| 92 return isSetter ? this : new PrivateName(text, library, isSetter: true); | 88 return isSetter ? this : new PrivateName(text, library, isSetter: true); |
| 93 } | 89 } |
| 94 | 90 |
| 95 bool isAccessibleFrom(LibraryElement element) => library == element; | 91 bool isAccessibleFrom(LibraryElement element) => library == element; |
| 96 | 92 |
| 97 bool get isPrivate => true; | 93 bool get isPrivate => true; |
| 98 | 94 |
| 99 int get hashCode => super.hashCode + 13 * library.hashCode; | 95 int get hashCode => super.hashCode + 13 * library.hashCode; |
| 100 | 96 |
| 101 bool operator ==(other) { | 97 bool operator ==(other) { |
| 102 if (other is! PrivateName) return false; | 98 if (other is! PrivateName) return false; |
| 103 return super==(other) && library == other.library; | 99 return super==(other) && library == other.library; |
| 104 } | 100 } |
| 105 | 101 |
| 106 String toString() => '${library.getLibraryName()}#${super.toString()}'; | 102 String toString() => '${library.getLibraryName()}#${super.toString()}'; |
| 107 } | 103 } |
| OLD | NEW |