OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #library('elements'); | 5 #library('elements'); |
6 | 6 |
7 #import('../tree/tree.dart'); | 7 #import('../tree/tree.dart'); |
8 #import('../scanner/scannerlib.dart'); | 8 #import('../scanner/scannerlib.dart'); |
9 #import('../leg.dart'); // TODO(karlklose): we only need type. | 9 #import('../leg.dart'); // TODO(karlklose): we only need type. |
10 #import('../util/util.dart'); | 10 #import('../util/util.dart'); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 bool isTypedef() => kind === ElementKind.TYPEDEF; | 132 bool isTypedef() => kind === ElementKind.TYPEDEF; |
133 bool isTypeVariable() => kind === ElementKind.TYPE_VARIABLE; | 133 bool isTypeVariable() => kind === ElementKind.TYPE_VARIABLE; |
134 bool isField() => kind === ElementKind.FIELD; | 134 bool isField() => kind === ElementKind.FIELD; |
135 bool isGetter() => kind === ElementKind.GETTER; | 135 bool isGetter() => kind === ElementKind.GETTER; |
136 bool isSetter() => kind === ElementKind.SETTER; | 136 bool isSetter() => kind === ElementKind.SETTER; |
137 bool isAccessor() => isGetter() || isSetter(); | 137 bool isAccessor() => isGetter() || isSetter(); |
138 bool isForeign() => kind === ElementKind.FOREIGN; | 138 bool isForeign() => kind === ElementKind.FOREIGN; |
139 bool impliesType() => (kind.category & ElementCategory.IMPLIES_TYPE) != 0; | 139 bool impliesType() => (kind.category & ElementCategory.IMPLIES_TYPE) != 0; |
140 bool isExtendable() => (kind.category & ElementCategory.IS_EXTENDABLE) != 0; | 140 bool isExtendable() => (kind.category & ElementCategory.IS_EXTENDABLE) != 0; |
141 | 141 |
| 142 // TODO(johnniwinther): This breaks for libraries (for which enclosing |
| 143 // elements are null) and is invalid for top level variable declarations for |
| 144 // which the enclosing element is a VariableDeclarations and not a compilation |
| 145 // unit. |
142 bool isTopLevel() => enclosingElement.isCompilationUnit(); | 146 bool isTopLevel() => enclosingElement.isCompilationUnit(); |
143 | 147 |
144 bool isAssignable() { | 148 bool isAssignable() { |
145 if (modifiers != null && modifiers.isFinal()) return false; | 149 if (modifiers != null && modifiers.isFinal()) return false; |
146 if (isFunction() || isGenerativeConstructor()) return false; | 150 if (isFunction() || isGenerativeConstructor()) return false; |
147 return true; | 151 return true; |
148 } | 152 } |
149 | 153 |
150 Token position() => null; | 154 Token position() => null; |
151 | 155 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 if (e.isMember() || e.isTopLevel()) { | 204 if (e.isMember() || e.isTopLevel()) { |
201 return e; | 205 return e; |
202 } | 206 } |
203 } | 207 } |
204 return null; | 208 return null; |
205 } | 209 } |
206 | 210 |
207 String toString() { | 211 String toString() { |
208 // TODO(johnniwinther): Test for nullness of name, or make non-nullness an | 212 // TODO(johnniwinther): Test for nullness of name, or make non-nullness an |
209 // invariant for all element types. | 213 // invariant for all element types. |
210 if (!isTopLevel()) { | 214 if (enclosingElement !== null && !isTopLevel()) { |
211 String holderName = enclosingElement.name.slowToString(); | 215 String holderName = enclosingElement.name.slowToString(); |
212 return '$kind($holderName#${name.slowToString()})'; | 216 return '$kind($holderName#${name.slowToString()})'; |
213 } else { | 217 } else { |
214 return '$kind(${name.slowToString()})'; | 218 return '$kind(${name.slowToString()})'; |
215 } | 219 } |
216 } | 220 } |
217 | 221 |
218 bool _isNative = false; | 222 bool _isNative = false; |
219 void setNative() { _isNative = true; } | 223 void setNative() { _isNative = true; } |
220 bool isNative() => _isNative; | 224 bool isNative() => _isNative; |
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 final Node node; | 1140 final Node node; |
1137 Type bound; | 1141 Type bound; |
1138 Type type; | 1142 Type type; |
1139 TypeVariableElement(name, Element enclosing, this.node, this.type, | 1143 TypeVariableElement(name, Element enclosing, this.node, this.type, |
1140 [this.bound]) | 1144 [this.bound]) |
1141 : super(name, ElementKind.TYPE_VARIABLE, enclosing); | 1145 : super(name, ElementKind.TYPE_VARIABLE, enclosing); |
1142 Type computeType(compiler) => type; | 1146 Type computeType(compiler) => type; |
1143 Node parseNode(compiler) => node; | 1147 Node parseNode(compiler) => node; |
1144 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; | 1148 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; |
1145 } | 1149 } |
OLD | NEW |