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; |
49 } | 51 } |
50 | 52 |
51 class PublicName implements Name { | 53 class PublicName implements Name { |
52 final String text; | 54 final String text; |
53 final bool isSetter; | 55 final bool isSetter; |
54 | 56 |
55 const PublicName(this.text, {this.isSetter: false}); | 57 const PublicName(this.text, {this.isSetter: false}); |
56 | 58 |
57 Name get getter => isSetter ? new PublicName(text) : this; | 59 Name get getter => isSetter ? new PublicName(text) : this; |
58 | 60 |
59 Name get setter => isSetter ? this : new PublicName(text, isSetter: true); | 61 Name get setter => isSetter ? this : new PublicName(text, isSetter: true); |
60 | 62 |
61 bool isAccessibleFrom(LibraryElement element) => true; | 63 bool isAccessibleFrom(LibraryElement element) => true; |
62 | 64 |
63 bool get isPrivate => false; | 65 bool get isPrivate => false; |
64 | 66 |
65 int get hashCode => similarHashCode; | 67 int get hashCode => similarHashCode; |
66 | 68 |
67 bool operator ==(other) { | 69 bool operator ==(other) { |
68 if (other is! PublicName) return false; | 70 if (other is! PublicName) return false; |
69 return isSimilarTo(other); | 71 return isSimilarTo(other); |
70 } | 72 } |
71 | 73 |
72 bool isSimilarTo(Name other) => | 74 bool isSimilarTo(Name other) => |
73 text == other.text && isSetter == other.isSetter; | 75 text == other.text && isSetter == other.isSetter; |
74 int get similarHashCode => text.hashCode + 11 * isSetter.hashCode; | 76 int get similarHashCode => text.hashCode + 11 * isSetter.hashCode; |
| 77 |
| 78 LibraryElement get library => null; |
75 | 79 |
76 String toString() => isSetter ? '$text=' : text; | 80 String toString() => isSetter ? '$text=' : text; |
77 } | 81 } |
78 | 82 |
79 class PrivateName extends PublicName { | 83 class PrivateName extends PublicName { |
80 final LibraryElement library; | 84 final LibraryElement library; |
81 | 85 |
82 PrivateName(String text, this.library, {bool isSetter: false}) | 86 PrivateName(String text, this.library, {bool isSetter: false}) |
83 : super(text, isSetter: isSetter); | 87 : super(text, isSetter: isSetter); |
84 | 88 |
85 Name get getter => isSetter ? new PrivateName(text, library) : this; | 89 Name get getter => isSetter ? new PrivateName(text, library) : this; |
86 | 90 |
87 Name get setter { | 91 Name get setter { |
88 return isSetter ? this : new PrivateName(text, library, isSetter: true); | 92 return isSetter ? this : new PrivateName(text, library, isSetter: true); |
89 } | 93 } |
90 | 94 |
91 bool isAccessibleFrom(LibraryElement element) => library == element; | 95 bool isAccessibleFrom(LibraryElement element) => library == element; |
92 | 96 |
93 bool get isPrivate => true; | 97 bool get isPrivate => true; |
94 | 98 |
95 int get hashCode => super.hashCode + 13 * library.hashCode; | 99 int get hashCode => super.hashCode + 13 * library.hashCode; |
96 | 100 |
97 bool operator ==(other) { | 101 bool operator ==(other) { |
98 if (other is! PrivateName) return false; | 102 if (other is! PrivateName) return false; |
99 return super==(other) && library == other.library; | 103 return super==(other) && library == other.library; |
100 } | 104 } |
101 | 105 |
102 String toString() => '${library.getLibraryName()}#${super.toString()}'; | 106 String toString() => '${library.getLibraryName()}#${super.toString()}'; |
103 } | 107 } |
OLD | NEW |