| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 /** | 5 /** |
| 6 * Any abstract representation of a dart element. This includes | 6 * Any abstract representation of a dart element. This includes |
| 7 * [Library], [Type] and [Member]. | 7 * [Library], [Type] and [Member]. |
| 8 */ | 8 */ |
| 9 class Element implements Hashable { | 9 class Element implements Hashable { |
| 10 // TODO(jimhug): Make name final when we can do it for Library. | 10 // TODO(jimhug): Make name final when we can do it for Library. |
| 11 /** The user-visible name of this [Element]. */ | 11 /** The user-visible name of this [Element]. */ |
| 12 String name; | 12 String name; |
| 13 | 13 |
| 14 /** A safe name to use for this [Element] in generated JS code. */ | 14 /** A safe name to use for this [Element] in generated JS code. */ |
| 15 String _jsname; | 15 String _jsname; |
| 16 | 16 |
| 17 /** The lexically/logically enclosing [Element] for lookups. */ | 17 /** The lexically/logically enclosing [Element] for lookups. */ |
| 18 Element _enclosingElement; | 18 Element _enclosingElement; |
| 19 | 19 |
| 20 Element(this.name, this._enclosingElement) { | 20 Element(this.name, this._enclosingElement) { |
| 21 _jsname = world.toJsIdentifier(name); | 21 if (name !== null) { |
| 22 String mangled = mangleJsName(); |
| 23 assert(!mangled.contains(':')); |
| 24 _jsname = mangled; |
| 25 } |
| 22 } | 26 } |
| 23 | 27 |
| 24 // TODO - walk tree | 28 // TODO - walk tree |
| 25 Library get library() => null; | 29 Library get library() => null; |
| 26 | 30 |
| 27 /** A source location for messages to the user about this [Element]. */ | 31 /** A source location for messages to the user about this [Element]. */ |
| 28 SourceSpan get span() => null; | 32 SourceSpan get span() => null; |
| 29 | 33 |
| 30 /** Should this element be treated as native JS? */ | 34 /** Should this element be treated as native JS? */ |
| 31 bool get isNative() => false; | 35 bool get isNative() => false; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 44 /** | 48 /** |
| 45 * [jsname] priority of this element, if two elements conflict. | 49 * [jsname] priority of this element, if two elements conflict. |
| 46 * Higher one gets the name. | 50 * Higher one gets the name. |
| 47 */ | 51 */ |
| 48 int get jsnamePriority() => isNative ? 2 : (library.isCore ? 1 : 0); | 52 int get jsnamePriority() => isNative ? 2 : (library.isCore ? 1 : 0); |
| 49 | 53 |
| 50 /** Resolve types and other references in the [Element]. */ | 54 /** Resolve types and other references in the [Element]. */ |
| 51 void resolve() {} | 55 void resolve() {} |
| 52 | 56 |
| 53 /** | 57 /** |
| 58 * By default we mangle the JS name of an element to avoid |
| 59 * giving them names that clash with JS keywords. |
| 60 */ |
| 61 String mangleJsName() => world.toJsIdentifier(name); |
| 62 |
| 63 /** |
| 54 * Any type parameters that this element defines to setup a generic | 64 * Any type parameters that this element defines to setup a generic |
| 55 * type resolution context. This is currently used for both generic | 65 * type resolution context. This is currently used for both generic |
| 56 * types and the semi-magical generic factory methods - but it will | 66 * types and the semi-magical generic factory methods - but it will |
| 57 * not be used for any other members in the current dart language. | 67 * not be used for any other members in the current dart language. |
| 58 */ | 68 */ |
| 59 // TODO(jimhug): Confirm whether or not these are still on factories. | 69 // TODO(jimhug): Confirm whether or not these are still on factories. |
| 60 List<ParameterType> get typeParameters() => null; | 70 List<ParameterType> get typeParameters() => null; |
| 61 | 71 |
| 62 List<Type> get typeArgsInOrder() => const []; | 72 List<Type> get typeArgsInOrder() => const []; |
| 63 | 73 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 /** This must be the highest possible priority. */ | 174 /** This must be the highest possible priority. */ |
| 165 int get jsnamePriority() => 10; | 175 int get jsnamePriority() => 10; |
| 166 | 176 |
| 167 /** A source location for messages to the user about this [Element]. */ | 177 /** A source location for messages to the user about this [Element]. */ |
| 168 SourceSpan get span() => declaringElement.span; | 178 SourceSpan get span() => declaringElement.span; |
| 169 | 179 |
| 170 /** A library for messages. */ | 180 /** A library for messages. */ |
| 171 Library get library() => declaringElement.library; | 181 Library get library() => declaringElement.library; |
| 172 | 182 |
| 173 } | 183 } |
| OLD | NEW |