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

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

Issue 693183006: Revert "Move dart2js from sdk/lib/_internal/compiler to pkg/compiler" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « pkg/compiler/lib/src/elements/modelx.dart ('k') | pkg/compiler/lib/src/elements/visitor.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 /// Returns `true` if an entity of this name is accessible from library
39 /// [element].
40 bool isAccessibleFrom(LibraryElement element);
41
42 /// Returns `true` if this name is private.
43 bool get isPrivate;
44
45 /// Returns `true` if this name is the same as [other] not taking the library
46 /// privacy into account.
47 bool isSimilarTo(Name other);
48 int get similarHashCode;
49 }
50
51 class PublicName implements Name {
52 final String text;
53 final bool isSetter;
54
55 const PublicName(this.text, {this.isSetter: false});
56
57 Name get getter => isSetter ? new PublicName(text) : this;
58
59 Name get setter => isSetter ? this : new PublicName(text, isSetter: true);
60
61 bool isAccessibleFrom(LibraryElement element) => true;
62
63 bool get isPrivate => false;
64
65 int get hashCode => similarHashCode;
66
67 bool operator ==(other) {
68 if (other is! PublicName) return false;
69 return isSimilarTo(other);
70 }
71
72 bool isSimilarTo(Name other) =>
73 text == other.text && isSetter == other.isSetter;
74 int get similarHashCode => text.hashCode + 11 * isSetter.hashCode;
75
76 String toString() => isSetter ? '$text=' : text;
77 }
78
79 class PrivateName extends PublicName {
80 final LibraryElement library;
81
82 PrivateName(String text, this.library, {bool isSetter: false})
83 : super(text, isSetter: isSetter);
84
85 Name get getter => isSetter ? new PrivateName(text, library) : this;
86
87 Name get setter {
88 return isSetter ? this : new PrivateName(text, library, isSetter: true);
89 }
90
91 bool isAccessibleFrom(LibraryElement element) => library == element;
92
93 bool get isPrivate => true;
94
95 int get hashCode => super.hashCode + 13 * library.hashCode;
96
97 bool operator ==(other) {
98 if (other is! PrivateName) return false;
99 return super==(other) && library == other.library;
100 }
101
102 String toString() => '${library.getLibraryName()}#${super.toString()}';
103 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/elements/modelx.dart ('k') | pkg/compiler/lib/src/elements/visitor.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698