Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: pkg/compiler/lib/src/elements/names.dart

Issue 1313893004: Move isPrivateName and isPublicName to Name. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/elements/modelx.dart ('k') | pkg/compiler/lib/src/js_backend/backend.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 49
50 LibraryElement get library; 50 LibraryElement get library;
51
52
53 /// Returns `true` when [s] is private if used as an identifier.
54 static bool isPrivateName(String s) => !s.isEmpty && s.codeUnitAt(0) == $_;
55
56 /// Returns `true` when [s] is public if used as an identifier.
57 static bool isPublicName(String s) => !isPrivateName(s);
51 } 58 }
52 59
53 class PublicName implements Name { 60 class PublicName implements Name {
54 final String text; 61 final String text;
55 final bool isSetter; 62 final bool isSetter;
56 63
57 const PublicName(this.text, {this.isSetter: false}); 64 const PublicName(this.text, {this.isSetter: false});
58 65
59 Name get getter => isSetter ? new PublicName(text) : this; 66 Name get getter => isSetter ? new PublicName(text) : this;
60 67
61 Name get setter => isSetter ? this : new PublicName(text, isSetter: true); 68 Name get setter => isSetter ? this : new PublicName(text, isSetter: true);
62 69
63 bool isAccessibleFrom(LibraryElement element) => true; 70 bool isAccessibleFrom(LibraryElement element) => true;
64 71
65 bool get isPrivate => false; 72 bool get isPrivate => false;
66 73
67 int get hashCode => similarHashCode; 74 int get hashCode => similarHashCode;
68 75
69 bool operator ==(other) { 76 bool operator ==(other) {
70 if (other is! PublicName) return false; 77 if (other is! PublicName) return false;
71 return isSimilarTo(other); 78 return isSimilarTo(other);
72 } 79 }
73 80
74 bool isSimilarTo(Name other) => 81 bool isSimilarTo(Name other) =>
75 text == other.text && isSetter == other.isSetter; 82 text == other.text && isSetter == other.isSetter;
76 int get similarHashCode => text.hashCode + 11 * isSetter.hashCode; 83 int get similarHashCode => text.hashCode + 11 * isSetter.hashCode;
77 84
78 LibraryElement get library => null; 85 LibraryElement get library => null;
79 86
80 String toString() => isSetter ? '$text=' : text; 87 String toString() => isSetter ? '$text=' : text;
81 } 88 }
82 89
83 class PrivateName extends PublicName { 90 class PrivateName extends PublicName {
84 final LibraryElement library; 91 final LibraryElement library;
85 92
86 PrivateName(String text, this.library, {bool isSetter: false}) 93 PrivateName(String text, this.library, {bool isSetter: false})
87 : super(text, isSetter: isSetter); 94 : super(text, isSetter: isSetter);
(...skipping 10 matching lines...) Expand all
98 105
99 int get hashCode => super.hashCode + 13 * library.hashCode; 106 int get hashCode => super.hashCode + 13 * library.hashCode;
100 107
101 bool operator ==(other) { 108 bool operator ==(other) {
102 if (other is! PrivateName) return false; 109 if (other is! PrivateName) return false;
103 return super==(other) && library == other.library; 110 return super==(other) && library == other.library;
104 } 111 }
105 112
106 String toString() => '${library.getLibraryName()}#${super.toString()}'; 113 String toString() => '${library.getLibraryName()}#${super.toString()}';
107 } 114 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/elements/modelx.dart ('k') | pkg/compiler/lib/src/js_backend/backend.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698