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

Side by Side Diff: pkg/analyzer/lib/src/generated/element.dart

Issue 1519283003: Move public API for elements into a public location (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years 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/analyzer/lib/dart/element/visitor.dart ('k') | no next file » | 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 library analyzer.src.generated.element; 5 library analyzer.src.generated.element;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:math' show min; 8 import 'dart:math' show min;
9 9
10 import 'package:analyzer/dart/element/element.dart';
11 import 'package:analyzer/dart/element/type.dart';
12 import 'package:analyzer/dart/element/visitor.dart';
10 import 'package:analyzer/src/generated/ast.dart'; 13 import 'package:analyzer/src/generated/ast.dart';
11 import 'package:analyzer/src/generated/constant.dart' 14 import 'package:analyzer/src/generated/constant.dart'
12 show DartObject, EvaluationResultImpl; 15 show DartObject, EvaluationResultImpl;
13 import 'package:analyzer/src/generated/engine.dart' 16 import 'package:analyzer/src/generated/engine.dart'
14 show AnalysisContext, AnalysisEngine, AnalysisException; 17 show AnalysisContext, AnalysisEngine, AnalysisException;
15 import 'package:analyzer/src/generated/java_core.dart'; 18 import 'package:analyzer/src/generated/java_core.dart';
16 import 'package:analyzer/src/generated/java_engine.dart'; 19 import 'package:analyzer/src/generated/java_engine.dart';
17 import 'package:analyzer/src/generated/resolver.dart'; 20 import 'package:analyzer/src/generated/resolver.dart';
18 import 'package:analyzer/src/generated/scanner.dart' show Keyword; 21 import 'package:analyzer/src/generated/scanner.dart' show Keyword;
19 import 'package:analyzer/src/generated/sdk.dart' show DartSdk; 22 import 'package:analyzer/src/generated/sdk.dart' show DartSdk;
20 import 'package:analyzer/src/generated/source.dart'; 23 import 'package:analyzer/src/generated/source.dart';
21 import 'package:analyzer/src/generated/utilities_collection.dart'; 24 import 'package:analyzer/src/generated/utilities_collection.dart';
22 import 'package:analyzer/src/generated/utilities_dart.dart'; 25 import 'package:analyzer/src/generated/utilities_dart.dart';
23 import 'package:analyzer/src/generated/utilities_general.dart'; 26 import 'package:analyzer/src/generated/utilities_general.dart';
24 import 'package:analyzer/src/task/dart.dart'; 27
25 import 'package:analyzer/task/model.dart' show AnalysisTarget; 28 export 'package:analyzer/dart/element/element.dart';
29 export 'package:analyzer/dart/element/type.dart';
30 export 'package:analyzer/dart/element/visitor.dart';
26 31
27 /** 32 /**
28 * For AST nodes that could be in both the getter and setter contexts 33 * For AST nodes that could be in both the getter and setter contexts
29 * ([IndexExpression]s and [SimpleIdentifier]s), the additional resolved 34 * ([IndexExpression]s and [SimpleIdentifier]s), the additional resolved
30 * elements are stored in the AST node, in an [AuxiliaryElements]. Because 35 * elements are stored in the AST node, in an [AuxiliaryElements]. Because
31 * resolved elements are either statically resolved or resolved using propagated 36 * resolved elements are either statically resolved or resolved using propagated
32 * type information, this class is a wrapper for a pair of [ExecutableElement]s, 37 * type information, this class is a wrapper for a pair of [ExecutableElement]s,
33 * not just a single [ExecutableElement]. 38 * not just a single [ExecutableElement].
34 */ 39 */
35 class AuxiliaryElements { 40 class AuxiliaryElements {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 @override 123 @override
119 void appendTo(StringBuffer buffer) { 124 void appendTo(StringBuffer buffer) {
120 buffer.write('...'); 125 buffer.write('...');
121 } 126 }
122 127
123 @override 128 @override
124 TypeImpl pruned(List<FunctionTypeAliasElement> prune) => this; 129 TypeImpl pruned(List<FunctionTypeAliasElement> prune) => this;
125 } 130 }
126 131
127 /** 132 /**
128 * An element that represents a class.
129 */
130 abstract class ClassElement
131 implements TypeDefiningElement, TypeParameterizedElement {
132 /**
133 * An empty list of class elements.
134 */
135 static const List<ClassElement> EMPTY_LIST = const <ClassElement>[];
136
137 /**
138 * Return a list containing all of the accessors (getters and setters)
139 * declared in this class.
140 */
141 List<PropertyAccessorElement> get accessors;
142
143 /**
144 * Return a list containing all the supertypes defined for this class and its
145 * supertypes. This includes superclasses, mixins and interfaces.
146 */
147 List<InterfaceType> get allSupertypes;
148
149 /**
150 * Return a list containing all of the constructors declared in this class.
151 */
152 List<ConstructorElement> get constructors;
153
154 /**
155 * Return a list containing all of the fields declared in this class.
156 */
157 List<FieldElement> get fields;
158
159 /**
160 * Return `true` if this class or its superclass declares a non-final instance
161 * field.
162 */
163 bool get hasNonFinalField;
164
165 /**
166 * Return `true` if this class has reference to super (so, for example, cannot
167 * be used as a mixin).
168 */
169 bool get hasReferenceToSuper;
170
171 /**
172 * Return `true` if this class declares a static member.
173 */
174 bool get hasStaticMember;
175
176 /**
177 * Return a list containing all of the interfaces that are implemented by this
178 * class.
179 *
180 * <b>Note:</b> Because the element model represents the state of the code, it
181 * is possible for it to be semantically invalid. In particular, it is not
182 * safe to assume that the inheritance structure of a class does not contain a
183 * cycle. Clients that traverse the inheritance structure must explicitly
184 * guard against infinite loops.
185 */
186 List<InterfaceType> get interfaces;
187
188 /**
189 * Return `true` if this class is abstract. A class is abstract if it has an
190 * explicit `abstract` modifier. Note, that this definition of <i>abstract</i>
191 * is different from <i>has unimplemented members</i>.
192 */
193 bool get isAbstract;
194
195 /**
196 * Return `true` if this class is defined by an enum declaration.
197 */
198 bool get isEnum;
199
200 /**
201 * Return `true` if this class is a mixin application. A class is a mixin
202 * application if it was declared using the syntax "class A = B with C;".
203 */
204 bool get isMixinApplication;
205
206 /**
207 * Return `true` if this class [isProxy], or if it inherits the proxy
208 * annotation from a supertype.
209 */
210 bool get isOrInheritsProxy;
211
212 /**
213 * Return `true` if this element has an annotation of the form '@proxy'.
214 */
215 bool get isProxy;
216
217 /**
218 * Return `true` if this class can validly be used as a mixin when defining
219 * another class. The behavior of this method is defined by the Dart Language
220 * Specification in section 9:
221 * <blockquote>
222 * It is a compile-time error if a declared or derived mixin refers to super.
223 * It is a compile-time error if a declared or derived mixin explicitly
224 * declares a constructor. It is a compile-time error if a mixin is derived
225 * from a class whose superclass is not Object.
226 * </blockquote>
227 */
228 bool get isValidMixin;
229
230 /**
231 * Return a list containing all of the methods declared in this class.
232 */
233 List<MethodElement> get methods;
234
235 /**
236 * Return a list containing all of the mixins that are applied to the class
237 * being extended in order to derive the superclass of this class.
238 *
239 * <b>Note:</b> Because the element model represents the state of the code, it
240 * is possible for it to be semantically invalid. In particular, it is not
241 * safe to assume that the inheritance structure of a class does not contain a
242 * cycle. Clients that traverse the inheritance structure must explicitly
243 * guard against infinite loops.
244 */
245 List<InterfaceType> get mixins;
246
247 /**
248 * Return the superclass of this class, or `null` if the class represents the
249 * class 'Object'. All other classes will have a non-`null` superclass. If the
250 * superclass was not explicitly declared then the implicit superclass
251 * 'Object' will be returned.
252 *
253 * <b>Note:</b> Because the element model represents the state of the code, it
254 * is possible for it to be semantically invalid. In particular, it is not
255 * safe to assume that the inheritance structure of a class does not contain a
256 * cycle. Clients that traverse the inheritance structure must explicitly
257 * guard against infinite loops.
258 */
259 InterfaceType get supertype;
260
261 @override
262 InterfaceType get type;
263
264 /**
265 * Return the unnamed constructor declared in this class, or `null` if this
266 * class does not declare an unnamed constructor but does declare named
267 * constructors. The returned constructor will be synthetic if this class does
268 * not declare any constructors, in which case it will represent the default
269 * constructor for the class.
270 */
271 ConstructorElement get unnamedConstructor;
272
273 /**
274 * Return the resolved [ClassDeclaration] or [EnumDeclaration] node that
275 * declares this [ClassElement].
276 *
277 * This method is expensive, because resolved AST might be evicted from cache,
278 * so parsing and resolving will be performed.
279 */
280 @override
281 NamedCompilationUnitMember computeNode();
282
283 /**
284 * Return the field (synthetic or explicit) defined in this class that has the
285 * given [name], or `null` if this class does not define a field with the
286 * given name.
287 */
288 FieldElement getField(String name);
289
290 /**
291 * Return the element representing the getter with the given [name] that is
292 * declared in this class, or `null` if this class does not declare a getter
293 * with the given name.
294 */
295 PropertyAccessorElement getGetter(String name);
296
297 /**
298 * Return the element representing the method with the given [name] that is
299 * declared in this class, or `null` if this class does not declare a method
300 * with the given name.
301 */
302 MethodElement getMethod(String name);
303
304 /**
305 * Return the named constructor declared in this class with the given [name],
306 * or `null` if this class does not declare a named constructor with the given
307 * name.
308 */
309 ConstructorElement getNamedConstructor(String name);
310
311 /**
312 * Return the element representing the setter with the given [name] that is
313 * declared in this class, or `null` if this class does not declare a setter
314 * with the given name.
315 */
316 PropertyAccessorElement getSetter(String name);
317
318 /**
319 * Determine whether the given [constructor], which exists in the superclass
320 * of this class, is accessible to constructors in this class.
321 */
322 bool isSuperConstructorAccessible(ConstructorElement constructor);
323
324 /**
325 * Return the element representing the method that results from looking up the
326 * given [methodName] in this class with respect to the given [library],
327 * ignoring abstract methods, or `null` if the look up fails. The behavior of
328 * this method is defined by the Dart Language Specification in section
329 * 16.15.1:
330 * <blockquote>
331 * The result of looking up method <i>m</i> in class <i>C</i> with respect to
332 * library <i>L</i> is: If <i>C</i> declares an instance method named <i>m</i>
333 * that is accessible to <i>L</i>, then that method is the result of the
334 * lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the result
335 * of the lookup is the result of looking up method <i>m</i> in <i>S</i> with
336 * respect to <i>L</i>. Otherwise, we say that the lookup has failed.
337 * </blockquote>
338 */
339 MethodElement lookUpConcreteMethod(String methodName, LibraryElement library);
340
341 /**
342 * Return the element representing the getter that results from looking up the
343 * given [getterName] in this class with respect to the given [library], or
344 * `null` if the look up fails. The behavior of this method is defined by the
345 * Dart Language Specification in section 16.15.2:
346 * <blockquote>
347 * The result of looking up getter (respectively setter) <i>m</i> in class
348 * <i>C</i> with respect to library <i>L</i> is: If <i>C</i> declares an
349 * instance getter (respectively setter) named <i>m</i> that is accessible to
350 * <i>L</i>, then that getter (respectively setter) is the result of the
351 * lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the result
352 * of the lookup is the result of looking up getter (respectively setter)
353 * <i>m</i> in <i>S</i> with respect to <i>L</i>. Otherwise, we say that the
354 * lookup has failed.
355 * </blockquote>
356 */
357 PropertyAccessorElement lookUpGetter(
358 String getterName, LibraryElement library);
359
360 /**
361 * Return the element representing the getter that results from looking up the
362 * given [getterName] in the superclass of this class with respect to the
363 * given [library], ignoring abstract getters, or `null` if the look up fails.
364 * The behavior of this method is defined by the Dart Language Specification
365 * in section 16.15.2:
366 * <blockquote>
367 * The result of looking up getter (respectively setter) <i>m</i> in class
368 * <i>C</i> with respect to library <i>L</i> is: If <i>C</i> declares an
369 * instance getter (respectively setter) named <i>m</i> that is accessible to
370 * <i>L</i>, then that getter (respectively setter) is the result of the
371 * lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the result
372 * of the lookup is the result of looking up getter (respectively setter)
373 * <i>m</i> in <i>S</i> with respect to <i>L</i>. Otherwise, we say that the
374 * lookup has failed.
375 * </blockquote>
376 */
377 PropertyAccessorElement lookUpInheritedConcreteGetter(
378 String getterName, LibraryElement library);
379
380 /**
381 * Return the element representing the method that results from looking up the
382 * given [methodName] in the superclass of this class with respect to the
383 * given [library], ignoring abstract methods, or `null` if the look up fails.
384 * The behavior of this method is defined by the Dart Language Specification
385 * in section 16.15.1:
386 * <blockquote>
387 * The result of looking up method <i>m</i> in class <i>C</i> with respect to
388 * library <i>L</i> is: If <i>C</i> declares an instance method named
389 * <i>m</i> that is accessible to <i>L</i>, then that method is the result of
390 * the lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the
391 * result of the lookup is the result of looking up method <i>m</i> in
392 * <i>S</i> with respect to <i>L</i>. Otherwise, we say that the lookup has
393 * failed.
394 * </blockquote>
395 */
396 MethodElement lookUpInheritedConcreteMethod(
397 String methodName, LibraryElement library);
398
399 /**
400 * Return the element representing the setter that results from looking up the
401 * given [setterName] in the superclass of this class with respect to the
402 * given [library], ignoring abstract setters, or `null` if the look up fails.
403 * The behavior of this method is defined by the Dart Language Specification
404 * in section 16.15.2:
405 * <blockquote>
406 * The result of looking up getter (respectively setter) <i>m</i> in class
407 * <i>C</i> with respect to library <i>L</i> is: If <i>C</i> declares an
408 * instance getter (respectively setter) named <i>m</i> that is accessible to
409 * <i>L</i>, then that getter (respectively setter) is the result of the
410 * lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the result
411 * of the lookup is the result of looking up getter (respectively setter)
412 * <i>m</i> in <i>S</i> with respect to <i>L</i>. Otherwise, we say that the
413 * lookup has failed.
414 * </blockquote>
415 */
416 PropertyAccessorElement lookUpInheritedConcreteSetter(
417 String setterName, LibraryElement library);
418
419 /**
420 * Return the element representing the method that results from looking up the
421 * given [methodName] in the superclass of this class with respect to the
422 * given [library], or `null` if the look up fails. The behavior of this
423 * method is defined by the Dart Language Specification in section 16.15.1:
424 * <blockquote>
425 * The result of looking up method <i>m</i> in class <i>C</i> with respect to
426 * library <i>L</i> is: If <i>C</i> declares an instance method named
427 * <i>m</i> that is accessible to <i>L</i>, then that method is the result of
428 * the lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the
429 * result of the lookup is the result of looking up method <i>m</i> in
430 * <i>S</i> with respect to <i>L</i>. Otherwise, we say that the lookup has
431 * failed.
432 * </blockquote>
433 */
434 MethodElement lookUpInheritedMethod(
435 String methodName, LibraryElement library);
436
437 /**
438 * Return the element representing the method that results from looking up the
439 * given [methodName] in this class with respect to the given [library], or
440 * `null` if the look up fails. The behavior of this method is defined by the
441 * Dart Language Specification in section 16.15.1:
442 * <blockquote>
443 * The result of looking up method <i>m</i> in class <i>C</i> with respect to
444 * library <i>L</i> is: If <i>C</i> declares an instance method named
445 * <i>m</i> that is accessible to <i>L</i>, then that method is the result of
446 * the lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the
447 * result of the lookup is the result of looking up method <i>m</i> in
448 * <i>S</i> with respect to <i>L</i>. Otherwise, we say that the lookup has
449 * failed.
450 * </blockquote>
451 */
452 MethodElement lookUpMethod(String methodName, LibraryElement library);
453
454 /**
455 * Return the element representing the setter that results from looking up the
456 * given [setterName] in this class with respect to the given [library], or
457 * `null` if the look up fails. The behavior of this method is defined by the
458 * Dart Language Specification in section 16.15.2:
459 * <blockquote>
460 * The result of looking up getter (respectively setter) <i>m</i> in class
461 * <i>C</i> with respect to library <i>L</i> is: If <i>C</i> declares an
462 * instance getter (respectively setter) named <i>m</i> that is accessible to
463 * <i>L</i>, then that getter (respectively setter) is the result of the
464 * lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the result
465 * of the lookup is the result of looking up getter (respectively setter)
466 * <i>m</i> in <i>S</i> with respect to <i>L</i>. Otherwise, we say that the
467 * lookup has failed.
468 * </blockquote>
469 */
470 PropertyAccessorElement lookUpSetter(
471 String setterName, LibraryElement library);
472 }
473
474 /**
475 * A concrete implementation of a [ClassElement]. 133 * A concrete implementation of a [ClassElement].
476 */ 134 */
477 class ClassElementImpl extends ElementImpl implements ClassElement { 135 class ClassElementImpl extends ElementImpl implements ClassElement {
478 /** 136 /**
479 * A list containing all of the accessors (getters and setters) contained in 137 * A list containing all of the accessors (getters and setters) contained in
480 * this class. 138 * this class.
481 */ 139 */
482 List<PropertyAccessorElement> _accessors = PropertyAccessorElement.EMPTY_LIST; 140 List<PropertyAccessorElement> _accessors = PropertyAccessorElement.EMPTY_LIST;
483 141
484 /** 142 /**
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after
1306 for (int i = 0; i < supertypes.length; i++) { 964 for (int i = 0; i < supertypes.length; i++) {
1307 if (_safeIsOrInheritsProxy(supertypes[i].element, visitedClassElts)) { 965 if (_safeIsOrInheritsProxy(supertypes[i].element, visitedClassElts)) {
1308 return true; 966 return true;
1309 } 967 }
1310 } 968 }
1311 return false; 969 return false;
1312 } 970 }
1313 } 971 }
1314 972
1315 /** 973 /**
1316 * An element that is contained within a [ClassElement].
1317 */
1318 abstract class ClassMemberElement implements Element {
1319 /**
1320 * Return the type in which this member is defined.
1321 */
1322 @override
1323 ClassElement get enclosingElement;
1324
1325 /**
1326 * Return `true` if this element is a static element. A static element is an
1327 * element that is not associated with a particular instance, but rather with
1328 * an entire library or class.
1329 */
1330 bool get isStatic;
1331 }
1332
1333 /**
1334 * An element representing a compilation unit.
1335 */
1336 abstract class CompilationUnitElement implements Element, UriReferencedElement {
1337 /**
1338 * An empty list of compilation unit elements.
1339 */
1340 static const List<CompilationUnitElement> EMPTY_LIST =
1341 const <CompilationUnitElement>[];
1342
1343 /**
1344 * Return a list containing all of the top-level accessors (getters and
1345 * setters) contained in this compilation unit.
1346 */
1347 List<PropertyAccessorElement> get accessors;
1348
1349 /**
1350 * Return the library in which this compilation unit is defined.
1351 */
1352 @override
1353 LibraryElement get enclosingElement;
1354
1355 /**
1356 * Return a list containing all of the enums contained in this compilation
1357 * unit.
1358 */
1359 List<ClassElement> get enums;
1360
1361 /**
1362 * Return a list containing all of the top-level functions contained in this
1363 * compilation unit.
1364 */
1365 List<FunctionElement> get functions;
1366
1367 /**
1368 * Return a list containing all of the function type aliases contained in this
1369 * compilation unit.
1370 */
1371 List<FunctionTypeAliasElement> get functionTypeAliases;
1372
1373 /**
1374 * Return `true` if this compilation unit defines a top-level function named
1375 * `loadLibrary`.
1376 */
1377 bool get hasLoadLibraryFunction;
1378
1379 /**
1380 * Return a list containing all of the top-level variables contained in this
1381 * compilation unit.
1382 */
1383 List<TopLevelVariableElement> get topLevelVariables;
1384
1385 /**
1386 * Return a list containing all of the classes contained in this compilation
1387 * unit.
1388 */
1389 List<ClassElement> get types;
1390
1391 /**
1392 * Return the resolved [CompilationUnit] node that declares this element.
1393 *
1394 * This method is expensive, because resolved AST might be evicted from cache,
1395 * so parsing and resolving will be performed.
1396 */
1397 @override
1398 CompilationUnit computeNode();
1399
1400 /**
1401 * Return the element at the given [offset], maybe `null` if no such element.
1402 */
1403 Element getElementAt(int offset);
1404
1405 /**
1406 * Return the enum defined in this compilation unit that has the given [name],
1407 * or `null` if this compilation unit does not define an enum with the given
1408 * name.
1409 */
1410 ClassElement getEnum(String name);
1411
1412 /**
1413 * Return the class defined in this compilation unit that has the given
1414 * [name], or `null` if this compilation unit does not define a class with the
1415 * given name.
1416 */
1417 ClassElement getType(String name);
1418 }
1419
1420 /**
1421 * A concrete implementation of a [CompilationUnitElement]. 974 * A concrete implementation of a [CompilationUnitElement].
1422 */ 975 */
1423 class CompilationUnitElementImpl extends UriReferencedElementImpl 976 class CompilationUnitElementImpl extends UriReferencedElementImpl
1424 implements CompilationUnitElement { 977 implements CompilationUnitElement {
1425 /** 978 /**
1426 * The source that corresponds to this compilation unit. 979 * The source that corresponds to this compilation unit.
1427 */ 980 */
1428 Source source; 981 Source source;
1429 982
1430 /** 983 /**
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1769 @override 1322 @override
1770 EvaluationResultImpl get evaluationResult => _result; 1323 EvaluationResultImpl get evaluationResult => _result;
1771 1324
1772 @override 1325 @override
1773 void set evaluationResult(EvaluationResultImpl result) { 1326 void set evaluationResult(EvaluationResultImpl result) {
1774 this._result = result; 1327 this._result = result;
1775 } 1328 }
1776 } 1329 }
1777 1330
1778 /** 1331 /**
1779 * An element representing a constructor or a factory method defined within a
1780 * class.
1781 */
1782 abstract class ConstructorElement
1783 implements ClassMemberElement, ExecutableElement, ConstantEvaluationTarget {
1784 /**
1785 * An empty list of constructor elements.
1786 */
1787 static const List<ConstructorElement> EMPTY_LIST =
1788 const <ConstructorElement>[];
1789
1790 /**
1791 * Return `true` if this constructor is a const constructor.
1792 */
1793 bool get isConst;
1794
1795 /**
1796 * Return `true` if this constructor can be used as a default constructor -
1797 * unnamed and has no required parameters.
1798 */
1799 bool get isDefaultConstructor;
1800
1801 /**
1802 * Return `true` if this constructor represents a factory constructor.
1803 */
1804 bool get isFactory;
1805
1806 /**
1807 * Return the offset of the character immediately following the last character
1808 * of this constructor's name, or `null` if not named.
1809 */
1810 int get nameEnd;
1811
1812 /**
1813 * Return the offset of the `.` before this constructor name, or `null` if
1814 * not named.
1815 */
1816 int get periodOffset;
1817
1818 /**
1819 * Return the constructor to which this constructor is redirecting, or `null`
1820 * if this constructor does not redirect to another constructor or if the
1821 * library containing this constructor has not yet been resolved.
1822 */
1823 ConstructorElement get redirectedConstructor;
1824
1825 /**
1826 * Return the resolved [ConstructorDeclaration] node that declares this
1827 * [ConstructorElement] .
1828 *
1829 * This method is expensive, because resolved AST might be evicted from cache,
1830 * so parsing and resolving will be performed.
1831 */
1832 @override
1833 ConstructorDeclaration computeNode();
1834 }
1835
1836 /**
1837 * A concrete implementation of a [ConstructorElement]. 1332 * A concrete implementation of a [ConstructorElement].
1838 */ 1333 */
1839 class ConstructorElementImpl extends ExecutableElementImpl 1334 class ConstructorElementImpl extends ExecutableElementImpl
1840 implements ConstructorElement { 1335 implements ConstructorElement {
1841 /** 1336 /**
1842 * The constructor to which this constructor is redirecting. 1337 * The constructor to which this constructor is redirecting.
1843 */ 1338 */
1844 ConstructorElement redirectedConstructor; 1339 ConstructorElement redirectedConstructor;
1845 1340
1846 /** 1341 /**
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
2019 buffer.write("("); 1514 buffer.write("(");
2020 int parameterCount = parameters.length; 1515 int parameterCount = parameters.length;
2021 for (int i = 0; i < parameterCount; i++) { 1516 for (int i = 0; i < parameterCount; i++) {
2022 if (i > 0) { 1517 if (i > 0) {
2023 buffer.write(", "); 1518 buffer.write(", ");
2024 } 1519 }
2025 buffer.write(parameters[i]); 1520 buffer.write(parameters[i]);
2026 } 1521 }
2027 buffer.write(")"); 1522 buffer.write(")");
2028 if (type != null) { 1523 if (type != null) {
2029 buffer.write(Element.RIGHT_ARROW); 1524 buffer.write(ElementImpl.RIGHT_ARROW);
2030 buffer.write(type.returnType); 1525 buffer.write(type.returnType);
2031 } 1526 }
2032 return buffer.toString(); 1527 return buffer.toString();
2033 } 1528 }
2034 1529
2035 /** 1530 /**
2036 * If the given [constructor]'s type is different when any type parameters 1531 * If the given [constructor]'s type is different when any type parameters
2037 * from the defining type's declaration are replaced with the actual type 1532 * from the defining type's declaration are replaced with the actual type
2038 * arguments from the [definingType], create a constructor member representing 1533 * arguments from the [definingType], create a constructor member representing
2039 * the given constructor. Return the member that was created, or the original 1534 * the given constructor. Return the member that was created, or the original
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
2107 * 1602 *
2108 * Note that in correct Dart code, all constant variables must have 1603 * Note that in correct Dart code, all constant variables must have
2109 * initializers. However, analyzer also needs to handle incorrect Dart code, 1604 * initializers. However, analyzer also needs to handle incorrect Dart code,
2110 * in which case there might be some constant variables that lack 1605 * in which case there might be some constant variables that lack
2111 * initializers. 1606 * initializers.
2112 */ 1607 */
2113 Expression constantInitializer; 1608 Expression constantInitializer;
2114 } 1609 }
2115 1610
2116 /** 1611 /**
2117 * The type associated with elements in the element model.
2118 */
2119 abstract class DartType {
2120 /**
2121 * An empty list of types.
2122 */
2123 static const List<DartType> EMPTY_LIST = const <DartType>[];
2124
2125 /**
2126 * Return the name of this type as it should appear when presented to users in
2127 * contexts such as error messages.
2128 */
2129 String get displayName;
2130
2131 /**
2132 * Return the element representing the declaration of this type, or `null` if
2133 * the type has not, or cannot, be associated with an element. The former case
2134 * will occur if the element model is not yet complete; the latter case will
2135 * occur if this object represents an undefined type.
2136 */
2137 Element get element;
2138
2139 /**
2140 * Return `true` if this type represents the bottom type.
2141 */
2142 bool get isBottom;
2143
2144 /**
2145 * Return `true` if this type represents the type 'Function' defined in the
2146 * dart:core library.
2147 */
2148 bool get isDartCoreFunction;
2149
2150 /**
2151 * Return `true` if this type represents the type 'dynamic'.
2152 */
2153 bool get isDynamic;
2154
2155 /**
2156 * Return `true` if this type represents the type 'Object'.
2157 */
2158 bool get isObject;
2159
2160 /**
2161 * Return `true` if this type represents a typename that couldn't be resolved.
2162 */
2163 bool get isUndefined;
2164
2165 /**
2166 * Return `true` if this type represents the type 'void'.
2167 */
2168 bool get isVoid;
2169
2170 /**
2171 * Return the name of this type, or `null` if the type does not have a name,
2172 * such as when the type represents the type of an unnamed function.
2173 */
2174 String get name;
2175
2176 /**
2177 * Return `true` if this type is assignable to the given [type]. A type
2178 * <i>T</i> may be assigned to a type <i>S</i>, written <i>T</i> &hArr;
2179 * <i>S</i>, iff either <i>T</i> <: <i>S</i> or <i>S</i> <: <i>T</i>.
2180 */
2181 bool isAssignableTo(DartType type);
2182
2183 /**
2184 * Return `true` if this type is more specific than the given [type].
2185 */
2186 bool isMoreSpecificThan(DartType type);
2187
2188 /**
2189 * Return `true` if this type is a subtype of the given [type].
2190 */
2191 bool isSubtypeOf(DartType type);
2192
2193 /**
2194 * Return `true` if this type is a supertype of the given [type]. A type
2195 * <i>S</i> is a supertype of <i>T</i>, written <i>S</i> :> <i>T</i>, iff
2196 * <i>T</i> is a subtype of <i>S</i>.
2197 */
2198 bool isSupertypeOf(DartType type);
2199
2200 /**
2201 * Return the type resulting from substituting the given [argumentTypes] for
2202 * the given [parameterTypes] in this type. The specification defines this
2203 * operation in section 2:
2204 * <blockquote>
2205 * The notation <i>[x<sub>1</sub>, ..., x<sub>n</sub>/y<sub>1</sub>, ...,
2206 * y<sub>n</sub>]E</i> denotes a copy of <i>E</i> in which all occurrences of
2207 * <i>y<sub>i</sub>, 1 <= i <= n</i> have been replaced with
2208 * <i>x<sub>i</sub></i>.
2209 * </blockquote>
2210 * Note that, contrary to the specification, this method will not create a
2211 * copy of this type if no substitutions were required, but will return this
2212 * type directly.
2213 *
2214 * Note too that the current implementation of this method is only guaranteed
2215 * to work when the parameter types are type variables.
2216 */
2217 DartType substitute2(
2218 List<DartType> argumentTypes, List<DartType> parameterTypes);
2219 }
2220
2221 /**
2222 * A [FieldFormalParameterElementImpl] for parameters that have an initializer. 1612 * A [FieldFormalParameterElementImpl] for parameters that have an initializer.
2223 */ 1613 */
2224 class DefaultFieldFormalParameterElementImpl 1614 class DefaultFieldFormalParameterElementImpl
2225 extends FieldFormalParameterElementImpl with ConstVariableElement { 1615 extends FieldFormalParameterElementImpl with ConstVariableElement {
2226 /** 1616 /**
2227 * The result of evaluating this variable's initializer. 1617 * The result of evaluating this variable's initializer.
2228 */ 1618 */
2229 EvaluationResultImpl _result; 1619 EvaluationResultImpl _result;
2230 1620
2231 /** 1621 /**
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
2371 for (int i = 0; i < length; i++) { 1761 for (int i = 0; i < length; i++) {
2372 if (parameterTypes[i] == this) { 1762 if (parameterTypes[i] == this) {
2373 return argumentTypes[i]; 1763 return argumentTypes[i];
2374 } 1764 }
2375 } 1765 }
2376 return this; 1766 return this;
2377 } 1767 }
2378 } 1768 }
2379 1769
2380 /** 1770 /**
2381 * The base class for all of the elements in the element model. Generally
2382 * speaking, the element model is a semantic model of the program that
2383 * represents things that are declared with a name and hence can be referenced
2384 * elsewhere in the code.
2385 *
2386 * There are two exceptions to the general case. First, there are elements in
2387 * the element model that are created for the convenience of various kinds of
2388 * analysis but that do not have any corresponding declaration within the source
2389 * code. Such elements are marked as being <i>synthetic</i>. Examples of
2390 * synthetic elements include
2391 * * default constructors in classes that do not define any explicit
2392 * constructors,
2393 * * getters and setters that are induced by explicit field declarations,
2394 * * fields that are induced by explicit declarations of getters and setters,
2395 * and
2396 * * functions representing the initialization expression for a variable.
2397 *
2398 * Second, there are elements in the element model that do not have a name.
2399 * These correspond to unnamed functions and exist in order to more accurately
2400 * represent the semantic structure of the program.
2401 */
2402 abstract class Element implements AnalysisTarget {
2403 /**
2404 * An Unicode right arrow.
2405 */
2406 static final String RIGHT_ARROW = " \u2192 ";
2407
2408 /**
2409 * A comparator that can be used to sort elements by their name offset.
2410 * Elements with a smaller offset will be sorted to be before elements with a
2411 * larger name offset.
2412 */
2413 static final Comparator<Element> SORT_BY_OFFSET =
2414 (Element firstElement, Element secondElement) =>
2415 firstElement.nameOffset - secondElement.nameOffset;
2416
2417 /**
2418 * Return the analysis context in which this element is defined.
2419 */
2420 AnalysisContext get context;
2421
2422 /**
2423 * Return the display name of this element, or `null` if this element does not
2424 * have a name.
2425 *
2426 * In most cases the name and the display name are the same. Differences
2427 * though are cases such as setters where the name of some setter `set f(x)`
2428 * is `f=`, instead of `f`.
2429 */
2430 String get displayName;
2431
2432 /**
2433 * Return the source range of the documentation comment for this element,
2434 * or `null` if this element does not or cannot have a documentation.
2435 */
2436 SourceRange get docRange;
2437
2438 /**
2439 * Return the element that either physically or logically encloses this
2440 * element. This will be `null` if this element is a library because libraries
2441 * are the top-level elements in the model.
2442 */
2443 Element get enclosingElement;
2444
2445 /**
2446 * The unique integer identifier of this element.
2447 */
2448 int get id;
2449
2450 /**
2451 * Return `true` if this element has an annotation of the form '@deprecated'
2452 * or '@Deprecated('..')'.
2453 */
2454 bool get isDeprecated;
2455
2456 /**
2457 * Return `true` if this element has an annotation of the form '@override'.
2458 */
2459 bool get isOverride;
2460
2461 /**
2462 * Return `true` if this element is private. Private elements are visible only
2463 * within the library in which they are declared.
2464 */
2465 bool get isPrivate;
2466
2467 /**
2468 * Return `true` if this element is public. Public elements are visible within
2469 * any library that imports the library in which they are declared.
2470 */
2471 bool get isPublic;
2472
2473 /**
2474 * Return `true` if this element is synthetic. A synthetic element is an
2475 * element that is not represented in the source code explicitly, but is
2476 * implied by the source code, such as the default constructor for a class
2477 * that does not explicitly define any constructors.
2478 */
2479 bool get isSynthetic;
2480
2481 /**
2482 * Return the kind of element that this is.
2483 */
2484 ElementKind get kind;
2485
2486 /**
2487 * Return the library that contains this element. This will be the element
2488 * itself if it is a library element. This will be `null` if this element is
2489 * an HTML file because HTML files are not contained in libraries.
2490 */
2491 LibraryElement get library;
2492
2493 /**
2494 * Return an object representing the location of this element in the element
2495 * model. The object can be used to locate this element at a later time.
2496 */
2497 ElementLocation get location;
2498
2499 /**
2500 * Return a list containing all of the metadata associated with this element.
2501 * The array will be empty if the element does not have any metadata or if the
2502 * library containing this element has not yet been resolved.
2503 */
2504 List<ElementAnnotation> get metadata;
2505
2506 /**
2507 * Return the name of this element, or `null` if this element does not have a
2508 * name.
2509 */
2510 String get name;
2511
2512 /**
2513 * Return the length of the name of this element in the file that contains the
2514 * declaration of this element, or `0` if this element does not have a name.
2515 */
2516 int get nameLength;
2517
2518 /**
2519 * Return the offset of the name of this element in the file that contains the
2520 * declaration of this element, or `-1` if this element is synthetic, does not
2521 * have a name, or otherwise does not have an offset.
2522 */
2523 int get nameOffset;
2524
2525 /**
2526 * Return the source that contains this element, or `null` if this element is
2527 * not contained in a source.
2528 */
2529 Source get source;
2530
2531 /**
2532 * Return the resolved [CompilationUnit] that declares this element, or `null`
2533 * if this element is synthetic.
2534 *
2535 * This method is expensive, because resolved AST might have been already
2536 * evicted from cache, so parsing and resolving will be performed.
2537 */
2538 CompilationUnit get unit;
2539
2540 /**
2541 * Use the given [visitor] to visit this element. Return the value returned by
2542 * the visitor as a result of visiting this element.
2543 */
2544 accept(ElementVisitor visitor);
2545
2546 /**
2547 * Return the documentation comment for this element as it appears in the
2548 * original source (complete with the beginning and ending delimiters), or
2549 * `null` if this element does not have a documentation comment associated
2550 * with it. This can be a long-running operation if the information needed to
2551 * access the comment is not cached.
2552 *
2553 * Throws [AnalysisException] if the documentation comment could not be
2554 * determined because the analysis could not be performed
2555 */
2556 String computeDocumentationComment();
2557
2558 /**
2559 * Return the resolved [AstNode] node that declares this element, or `null` if
2560 * this element is synthetic or isn't contained in a compilation unit, such as
2561 * a [LibraryElement].
2562 *
2563 * This method is expensive, because resolved AST might be evicted from cache,
2564 * so parsing and resolving will be performed.
2565 *
2566 * <b>Note:</b> This method cannot be used in an async environment.
2567 */
2568 AstNode computeNode();
2569
2570 /**
2571 * Return the most immediate ancestor of this element for which the
2572 * [predicate] returns `true`, or `null` if there is no such ancestor. Note
2573 * that this element will never be returned.
2574 */
2575 Element getAncestor(Predicate<Element> predicate);
2576
2577 /**
2578 * Return a display name for the given element that includes the path to the
2579 * compilation unit in which the type is defined. If [shortName] is `null`
2580 * then [getDisplayName] will be used as the name of this element. Otherwise
2581 * the provided name will be used.
2582 */
2583 // TODO(brianwilkerson) Make the parameter optional.
2584 String getExtendedDisplayName(String shortName);
2585
2586 /**
2587 * Return `true` if this element, assuming that it is within scope, is
2588 * accessible to code in the given [library]. This is defined by the Dart
2589 * Language Specification in section 3.2:
2590 * <blockquote>
2591 * A declaration <i>m</i> is accessible to library <i>L</i> if <i>m</i> is
2592 * declared in <i>L</i> or if <i>m</i> is public.
2593 * </blockquote>
2594 */
2595 bool isAccessibleIn(LibraryElement library);
2596
2597 /**
2598 * Use the given [visitor] to visit all of the children of this element. There
2599 * is no guarantee of the order in which the children will be visited.
2600 */
2601 void visitChildren(ElementVisitor visitor);
2602 }
2603
2604 /**
2605 * A single annotation associated with an element.
2606 */
2607 abstract class ElementAnnotation {
2608 /**
2609 * An empty list of annotations.
2610 */
2611 static const List<ElementAnnotation> EMPTY_LIST = const <ElementAnnotation>[];
2612
2613 /**
2614 * Return a representation of the value of this annotation.
2615 *
2616 * Return `null` if the value of this annotation could not be computed because
2617 * of errors.
2618 */
2619 DartObject get constantValue;
2620
2621 /**
2622 * Return the element representing the field, variable, or const constructor
2623 * being used as an annotation.
2624 */
2625 Element get element;
2626
2627 /**
2628 * Return `true` if this annotation marks the associated element as being
2629 * deprecated.
2630 */
2631 bool get isDeprecated;
2632
2633 /**
2634 * Return `true` if this annotation marks the associated method as being
2635 * expected to override an inherited method.
2636 */
2637 bool get isOverride;
2638
2639 /**
2640 * Return `true` if this annotation marks the associated class as implementing
2641 * a proxy object.
2642 */
2643 bool get isProxy;
2644 }
2645
2646 /**
2647 * A concrete implementation of an [ElementAnnotation]. 1771 * A concrete implementation of an [ElementAnnotation].
2648 */ 1772 */
2649 class ElementAnnotationImpl implements ElementAnnotation { 1773 class ElementAnnotationImpl implements ElementAnnotation {
2650 /** 1774 /**
2651 * The name of the class used to mark an element as being deprecated. 1775 * The name of the class used to mark an element as being deprecated.
2652 */ 1776 */
2653 static String _DEPRECATED_CLASS_NAME = "Deprecated"; 1777 static String _DEPRECATED_CLASS_NAME = "Deprecated";
2654 1778
2655 /** 1779 /**
2656 * The name of the top-level variable used to mark an element as being 1780 * The name of the top-level variable used to mark an element as being
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
2742 } 1866 }
2743 1867
2744 @override 1868 @override
2745 String toString() => '@$element'; 1869 String toString() => '@$element';
2746 } 1870 }
2747 1871
2748 /** 1872 /**
2749 * A base class for concrete implementations of an [Element]. 1873 * A base class for concrete implementations of an [Element].
2750 */ 1874 */
2751 abstract class ElementImpl implements Element { 1875 abstract class ElementImpl implements Element {
1876 /**
1877 * An Unicode right arrow.
1878 */
1879 static final String RIGHT_ARROW = " \u2192 ";
1880
2752 static int _NEXT_ID = 0; 1881 static int _NEXT_ID = 0;
2753 1882
2754 final int id = _NEXT_ID++; 1883 final int id = _NEXT_ID++;
2755 1884
2756 /** 1885 /**
2757 * The enclosing element of this element, or `null` if this element is at the 1886 * The enclosing element of this element, or `null` if this element is at the
2758 * root of the element structure. 1887 * root of the element structure.
2759 */ 1888 */
2760 ElementImpl _enclosingElement; 1889 ElementImpl _enclosingElement;
2761 1890
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
3102 return buffer.toString(); 2231 return buffer.toString();
3103 } 2232 }
3104 2233
3105 @override 2234 @override
3106 void visitChildren(ElementVisitor visitor) { 2235 void visitChildren(ElementVisitor visitor) {
3107 // There are no children to visit 2236 // There are no children to visit
3108 } 2237 }
3109 } 2238 }
3110 2239
3111 /** 2240 /**
3112 * The enumeration `ElementKind` defines the various kinds of elements in the
3113 * element model.
3114 */
3115 class ElementKind extends Enum<ElementKind> {
3116 static const ElementKind CLASS = const ElementKind('CLASS', 0, "class");
3117
3118 static const ElementKind COMPILATION_UNIT =
3119 const ElementKind('COMPILATION_UNIT', 1, "compilation unit");
3120
3121 static const ElementKind CONSTRUCTOR =
3122 const ElementKind('CONSTRUCTOR', 2, "constructor");
3123
3124 static const ElementKind DYNAMIC =
3125 const ElementKind('DYNAMIC', 3, "<dynamic>");
3126
3127 static const ElementKind EMBEDDED_HTML_SCRIPT =
3128 const ElementKind('EMBEDDED_HTML_SCRIPT', 4, "embedded html script");
3129
3130 static const ElementKind ERROR = const ElementKind('ERROR', 5, "<error>");
3131
3132 static const ElementKind EXPORT =
3133 const ElementKind('EXPORT', 6, "export directive");
3134
3135 static const ElementKind EXTERNAL_HTML_SCRIPT =
3136 const ElementKind('EXTERNAL_HTML_SCRIPT', 7, "external html script");
3137
3138 static const ElementKind FIELD = const ElementKind('FIELD', 8, "field");
3139
3140 static const ElementKind FUNCTION =
3141 const ElementKind('FUNCTION', 9, "function");
3142
3143 static const ElementKind GETTER = const ElementKind('GETTER', 10, "getter");
3144
3145 static const ElementKind HTML = const ElementKind('HTML', 11, "html");
3146
3147 static const ElementKind IMPORT =
3148 const ElementKind('IMPORT', 12, "import directive");
3149
3150 static const ElementKind LABEL = const ElementKind('LABEL', 13, "label");
3151
3152 static const ElementKind LIBRARY =
3153 const ElementKind('LIBRARY', 14, "library");
3154
3155 static const ElementKind LOCAL_VARIABLE =
3156 const ElementKind('LOCAL_VARIABLE', 15, "local variable");
3157
3158 static const ElementKind METHOD = const ElementKind('METHOD', 16, "method");
3159
3160 static const ElementKind NAME = const ElementKind('NAME', 17, "<name>");
3161
3162 static const ElementKind PARAMETER =
3163 const ElementKind('PARAMETER', 18, "parameter");
3164
3165 static const ElementKind PREFIX =
3166 const ElementKind('PREFIX', 19, "import prefix");
3167
3168 static const ElementKind SETTER = const ElementKind('SETTER', 20, "setter");
3169
3170 static const ElementKind TOP_LEVEL_VARIABLE =
3171 const ElementKind('TOP_LEVEL_VARIABLE', 21, "top level variable");
3172
3173 static const ElementKind FUNCTION_TYPE_ALIAS =
3174 const ElementKind('FUNCTION_TYPE_ALIAS', 22, "function type alias");
3175
3176 static const ElementKind TYPE_PARAMETER =
3177 const ElementKind('TYPE_PARAMETER', 23, "type parameter");
3178
3179 static const ElementKind UNIVERSE =
3180 const ElementKind('UNIVERSE', 24, "<universe>");
3181
3182 static const List<ElementKind> values = const [
3183 CLASS,
3184 COMPILATION_UNIT,
3185 CONSTRUCTOR,
3186 DYNAMIC,
3187 EMBEDDED_HTML_SCRIPT,
3188 ERROR,
3189 EXPORT,
3190 EXTERNAL_HTML_SCRIPT,
3191 FIELD,
3192 FUNCTION,
3193 GETTER,
3194 HTML,
3195 IMPORT,
3196 LABEL,
3197 LIBRARY,
3198 LOCAL_VARIABLE,
3199 METHOD,
3200 NAME,
3201 PARAMETER,
3202 PREFIX,
3203 SETTER,
3204 TOP_LEVEL_VARIABLE,
3205 FUNCTION_TYPE_ALIAS,
3206 TYPE_PARAMETER,
3207 UNIVERSE
3208 ];
3209
3210 /**
3211 * The name displayed in the UI for this kind of element.
3212 */
3213 final String displayName;
3214
3215 /**
3216 * Initialize a newly created element kind to have the given [displayName].
3217 */
3218 const ElementKind(String name, int ordinal, this.displayName)
3219 : super(name, ordinal);
3220
3221 /**
3222 * Return the kind of the given [element], or [ERROR] if the element is
3223 * `null`. This is a utility method that can reduce the need for null checks
3224 * in other places.
3225 */
3226 static ElementKind of(Element element) {
3227 if (element == null) {
3228 return ERROR;
3229 }
3230 return element.kind;
3231 }
3232 }
3233
3234 /**
3235 * The location of an element within the element model.
3236 */
3237 abstract class ElementLocation {
3238 /**
3239 * Return the path to the element whose location is represented by this
3240 * object. Clients must not modify the returned array.
3241 */
3242 List<String> get components;
3243
3244 /**
3245 * Return an encoded representation of this location that can be used to
3246 * create a location that is equal to this location.
3247 */
3248 String get encoding;
3249 }
3250
3251 /**
3252 * A concrete implementation of an [ElementLocation]. 2241 * A concrete implementation of an [ElementLocation].
3253 */ 2242 */
3254 class ElementLocationImpl implements ElementLocation { 2243 class ElementLocationImpl implements ElementLocation {
3255 /** 2244 /**
3256 * The character used to separate components in the encoded form. 2245 * The character used to separate components in the encoded form.
3257 */ 2246 */
3258 static int _SEPARATOR_CHAR = 0x3B; 2247 static int _SEPARATOR_CHAR = 0x3B;
3259 2248
3260 /** 2249 /**
3261 * The path to the element whose location is represented by this object. 2250 * The path to the element whose location is represented by this object.
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
3394 int currentChar = component.codeUnitAt(i); 2383 int currentChar = component.codeUnitAt(i);
3395 if (currentChar == _SEPARATOR_CHAR) { 2384 if (currentChar == _SEPARATOR_CHAR) {
3396 buffer.writeCharCode(_SEPARATOR_CHAR); 2385 buffer.writeCharCode(_SEPARATOR_CHAR);
3397 } 2386 }
3398 buffer.writeCharCode(currentChar); 2387 buffer.writeCharCode(currentChar);
3399 } 2388 }
3400 } 2389 }
3401 } 2390 }
3402 2391
3403 /** 2392 /**
3404 * An object that can be used to visit an element structure.
3405 */
3406 abstract class ElementVisitor<R> {
3407 R visitClassElement(ClassElement element);
3408
3409 R visitCompilationUnitElement(CompilationUnitElement element);
3410
3411 R visitConstructorElement(ConstructorElement element);
3412
3413 R visitExportElement(ExportElement element);
3414
3415 R visitFieldElement(FieldElement element);
3416
3417 R visitFieldFormalParameterElement(FieldFormalParameterElement element);
3418
3419 R visitFunctionElement(FunctionElement element);
3420
3421 R visitFunctionTypeAliasElement(FunctionTypeAliasElement element);
3422
3423 R visitImportElement(ImportElement element);
3424
3425 R visitLabelElement(LabelElement element);
3426
3427 R visitLibraryElement(LibraryElement element);
3428
3429 R visitLocalVariableElement(LocalVariableElement element);
3430
3431 R visitMethodElement(MethodElement element);
3432
3433 R visitMultiplyDefinedElement(MultiplyDefinedElement element);
3434
3435 R visitParameterElement(ParameterElement element);
3436
3437 R visitPrefixElement(PrefixElement element);
3438
3439 R visitPropertyAccessorElement(PropertyAccessorElement element);
3440
3441 R visitTopLevelVariableElement(TopLevelVariableElement element);
3442
3443 R visitTypeParameterElement(TypeParameterElement element);
3444 }
3445
3446 /**
3447 * An element representing an executable object, including functions, methods,
3448 * constructors, getters, and setters.
3449 */
3450 abstract class ExecutableElement implements FunctionTypedElement {
3451 /**
3452 * An empty list of executable elements.
3453 */
3454 static const List<ExecutableElement> EMPTY_LIST = const <ExecutableElement>[];
3455
3456 /**
3457 * Return a list containing all of the functions defined within this
3458 * executable element.
3459 */
3460 List<FunctionElement> get functions;
3461
3462 /**
3463 * Return `true` if this executable element did not have an explicit return
3464 * type specified for it in the original source. Note that if there was no
3465 * explicit return type, and if the element model is fully populated, then
3466 * the [returnType] will not be `null`.
3467 */
3468 bool get hasImplicitReturnType;
3469
3470 /**
3471 * Return `true` if this executable element is abstract. Executable elements
3472 * are abstract if they are not external and have no body.
3473 */
3474 bool get isAbstract;
3475
3476 /**
3477 * Return `true` if this executable element has body marked as being
3478 * asynchronous.
3479 */
3480 bool get isAsynchronous;
3481
3482 /**
3483 * Return `true` if this executable element is external. Executable elements
3484 * are external if they are explicitly marked as such using the 'external'
3485 * keyword.
3486 */
3487 bool get isExternal;
3488
3489 /**
3490 * Return `true` if this executable element has a body marked as being a
3491 * generator.
3492 */
3493 bool get isGenerator;
3494
3495 /**
3496 * Return `true` if this executable element is an operator. The test may be
3497 * based on the name of the executable element, in which case the result will
3498 * be correct when the name is legal.
3499 */
3500 bool get isOperator;
3501
3502 /**
3503 * Return `true` if this element is a static element. A static element is an
3504 * element that is not associated with a particular instance, but rather with
3505 * an entire library or class.
3506 */
3507 bool get isStatic;
3508
3509 /**
3510 * Return `true` if this executable element has a body marked as being
3511 * synchronous.
3512 */
3513 bool get isSynchronous;
3514
3515 /**
3516 * Return a list containing all of the labels defined within this executable
3517 * element.
3518 */
3519 List<LabelElement> get labels;
3520
3521 /**
3522 * Return a list containing all of the local variables defined within this
3523 * executable element.
3524 */
3525 List<LocalVariableElement> get localVariables;
3526 }
3527
3528 /**
3529 * A base class for concrete implementations of an [ExecutableElement]. 2393 * A base class for concrete implementations of an [ExecutableElement].
3530 */ 2394 */
3531 abstract class ExecutableElementImpl extends ElementImpl 2395 abstract class ExecutableElementImpl extends ElementImpl
3532 implements ExecutableElement { 2396 implements ExecutableElement {
3533 /** 2397 /**
3534 * A list containing all of the functions defined within this executable 2398 * A list containing all of the functions defined within this executable
3535 * element. 2399 * element.
3536 */ 2400 */
3537 List<FunctionElement> _functions = FunctionElement.EMPTY_LIST; 2401 List<FunctionElement> _functions = FunctionElement.EMPTY_LIST;
3538 2402
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
3738 } 2602 }
3739 kind = parameterKind; 2603 kind = parameterKind;
3740 parameter.appendToWithoutDelimiters(buffer); 2604 parameter.appendToWithoutDelimiters(buffer);
3741 } 2605 }
3742 if (closing != null) { 2606 if (closing != null) {
3743 buffer.write(closing); 2607 buffer.write(closing);
3744 } 2608 }
3745 buffer.write(")"); 2609 buffer.write(")");
3746 } 2610 }
3747 if (type != null) { 2611 if (type != null) {
3748 buffer.write(Element.RIGHT_ARROW); 2612 buffer.write(ElementImpl.RIGHT_ARROW);
3749 buffer.write(type.returnType); 2613 buffer.write(type.returnType);
3750 } 2614 }
3751 } 2615 }
3752 2616
3753 @override 2617 @override
3754 ElementImpl getChild(String identifier) { 2618 ElementImpl getChild(String identifier) {
3755 for (ExecutableElement function in _functions) { 2619 for (ExecutableElement function in _functions) {
3756 if ((function as ExecutableElementImpl).identifier == identifier) { 2620 if ((function as ExecutableElementImpl).identifier == identifier) {
3757 return function as ExecutableElementImpl; 2621 return function as ExecutableElementImpl;
3758 } 2622 }
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
3871 // below so that we can safely invoke them. 2735 // below so that we can safely invoke them.
3872 super.visitChildren(visitor); 2736 super.visitChildren(visitor);
3873 safelyVisitChildren(baseElement.functions, visitor); 2737 safelyVisitChildren(baseElement.functions, visitor);
3874 safelyVisitChildren(labels, visitor); 2738 safelyVisitChildren(labels, visitor);
3875 safelyVisitChildren(baseElement.localVariables, visitor); 2739 safelyVisitChildren(baseElement.localVariables, visitor);
3876 safelyVisitChildren(parameters, visitor); 2740 safelyVisitChildren(parameters, visitor);
3877 } 2741 }
3878 } 2742 }
3879 2743
3880 /** 2744 /**
3881 * An export directive within a library.
3882 */
3883 abstract class ExportElement implements Element, UriReferencedElement {
3884 /**
3885 * An empty list of export elements.
3886 */
3887 static const List<ExportElement> EMPTY_LIST = const <ExportElement>[];
3888
3889 /**
3890 * Return a list containing the combinators that were specified as part of the
3891 * export directive in the order in which they were specified.
3892 */
3893 List<NamespaceCombinator> get combinators;
3894
3895 /**
3896 * Return the library that is exported from this library by this export
3897 * directive.
3898 */
3899 LibraryElement get exportedLibrary;
3900 }
3901
3902 /**
3903 * A concrete implementation of an [ExportElement]. 2745 * A concrete implementation of an [ExportElement].
3904 */ 2746 */
3905 class ExportElementImpl extends UriReferencedElementImpl 2747 class ExportElementImpl extends UriReferencedElementImpl
3906 implements ExportElement { 2748 implements ExportElement {
3907 /** 2749 /**
3908 * The library that is exported from this library by this export directive. 2750 * The library that is exported from this library by this export directive.
3909 */ 2751 */
3910 LibraryElement exportedLibrary; 2752 LibraryElement exportedLibrary;
3911 2753
3912 /** 2754 /**
(...skipping 17 matching lines...) Expand all
3930 accept(ElementVisitor visitor) => visitor.visitExportElement(this); 2772 accept(ElementVisitor visitor) => visitor.visitExportElement(this);
3931 2773
3932 @override 2774 @override
3933 void appendTo(StringBuffer buffer) { 2775 void appendTo(StringBuffer buffer) {
3934 buffer.write("export "); 2776 buffer.write("export ");
3935 (exportedLibrary as LibraryElementImpl).appendTo(buffer); 2777 (exportedLibrary as LibraryElementImpl).appendTo(buffer);
3936 } 2778 }
3937 } 2779 }
3938 2780
3939 /** 2781 /**
3940 * A field defined within a type.
3941 */
3942 abstract class FieldElement
3943 implements ClassMemberElement, PropertyInducingElement {
3944 /**
3945 * An empty list of field elements.
3946 */
3947 static const List<FieldElement> EMPTY_LIST = const <FieldElement>[];
3948
3949 /**
3950 * Return {@code true} if this element is an enum constant.
3951 */
3952 bool get isEnumConstant;
3953
3954 /**
3955 * Return the resolved [VariableDeclaration] or [EnumConstantDeclaration]
3956 * node that declares this [FieldElement].
3957 *
3958 * This method is expensive, because resolved AST might be evicted from cache,
3959 * so parsing and resolving will be performed.
3960 */
3961 @override
3962 AstNode computeNode();
3963 }
3964
3965 /**
3966 * A concrete implementation of a [FieldElement]. 2782 * A concrete implementation of a [FieldElement].
3967 */ 2783 */
3968 class FieldElementImpl extends PropertyInducingElementImpl 2784 class FieldElementImpl extends PropertyInducingElementImpl
3969 implements FieldElement { 2785 implements FieldElement {
3970 /** 2786 /**
3971 * Initialize a newly created synthetic field element to have the given [name] 2787 * Initialize a newly created synthetic field element to have the given [name]
3972 * at the given [offset]. 2788 * at the given [offset].
3973 */ 2789 */
3974 FieldElementImpl(String name, int offset) : super(name, offset); 2790 FieldElementImpl(String name, int offset) : super(name, offset);
3975 2791
(...skipping 26 matching lines...) Expand all
4002 AstNode computeNode() { 2818 AstNode computeNode() {
4003 if (isEnumConstant) { 2819 if (isEnumConstant) {
4004 return getNodeMatching((node) => node is EnumConstantDeclaration); 2820 return getNodeMatching((node) => node is EnumConstantDeclaration);
4005 } else { 2821 } else {
4006 return getNodeMatching((node) => node is VariableDeclaration); 2822 return getNodeMatching((node) => node is VariableDeclaration);
4007 } 2823 }
4008 } 2824 }
4009 } 2825 }
4010 2826
4011 /** 2827 /**
4012 * A field formal parameter defined within a constructor element.
4013 */
4014 abstract class FieldFormalParameterElement implements ParameterElement {
4015 /**
4016 * Return the field element associated with this field formal parameter, or
4017 * `null` if the parameter references a field that doesn't exist.
4018 */
4019 FieldElement get field;
4020 }
4021
4022 /**
4023 * A [ParameterElementImpl] that has the additional information of the 2828 * A [ParameterElementImpl] that has the additional information of the
4024 * [FieldElement] associated with the parameter. 2829 * [FieldElement] associated with the parameter.
4025 */ 2830 */
4026 class FieldFormalParameterElementImpl extends ParameterElementImpl 2831 class FieldFormalParameterElementImpl extends ParameterElementImpl
4027 implements FieldFormalParameterElement { 2832 implements FieldFormalParameterElement {
4028 /** 2833 /**
4029 * The field associated with this field formal parameter. 2834 * The field associated with this field formal parameter.
4030 */ 2835 */
4031 FieldElement field; 2836 FieldElement field;
4032 2837
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
4160 if (basePropagatedType != substitutedPropagatedType) { 2965 if (basePropagatedType != substitutedPropagatedType) {
4161 return true; 2966 return true;
4162 } 2967 }
4163 } 2968 }
4164 } 2969 }
4165 return false; 2970 return false;
4166 } 2971 }
4167 } 2972 }
4168 2973
4169 /** 2974 /**
4170 * A (non-method) function. This can be either a top-level function, a local
4171 * function, a closure, or the initialization expression for a field or
4172 * variable.
4173 */
4174 abstract class FunctionElement implements ExecutableElement, LocalElement {
4175 /**
4176 * An empty list of function elements.
4177 */
4178 static const List<FunctionElement> EMPTY_LIST = const <FunctionElement>[];
4179
4180 /**
4181 * The name of the method that can be implemented by a class to allow its
4182 * instances to be invoked as if they were a function.
4183 */
4184 static final String CALL_METHOD_NAME = "call";
4185
4186 /**
4187 * The name of the synthetic function defined for libraries that are deferred.
4188 */
4189 static final String LOAD_LIBRARY_NAME = "loadLibrary";
4190
4191 /**
4192 * The name of the function used as an entry point.
4193 */
4194 static const String MAIN_FUNCTION_NAME = "main";
4195
4196 /**
4197 * The name of the method that will be invoked if an attempt is made to invoke
4198 * an undefined method on an object.
4199 */
4200 static final String NO_SUCH_METHOD_METHOD_NAME = "noSuchMethod";
4201
4202 /**
4203 * Return `true` if the function is an entry point, i.e. a top-level function
4204 * and has the name `main`.
4205 */
4206 bool get isEntryPoint;
4207
4208 /**
4209 * Return the resolved function declaration node that declares this element.
4210 *
4211 * This method is expensive, because resolved AST might be evicted from cache,
4212 * so parsing and resolving will be performed.
4213 */
4214 @override
4215 FunctionDeclaration computeNode();
4216 }
4217
4218 /**
4219 * A concrete implementation of a [FunctionElement]. 2975 * A concrete implementation of a [FunctionElement].
4220 */ 2976 */
4221 class FunctionElementImpl extends ExecutableElementImpl 2977 class FunctionElementImpl extends ExecutableElementImpl
4222 implements FunctionElement { 2978 implements FunctionElement {
4223 /** 2979 /**
4224 * The offset to the beginning of the visible range for this element. 2980 * The offset to the beginning of the visible range for this element.
4225 */ 2981 */
4226 int _visibleRangeOffset = 0; 2982 int _visibleRangeOffset = 0;
4227 2983
4228 /** 2984 /**
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
4369 FunctionType substitutedType = 3125 FunctionType substitutedType =
4370 baseType.substitute2(argumentTypes, parameterTypes); 3126 baseType.substitute2(argumentTypes, parameterTypes);
4371 if (baseType == substitutedType) { 3127 if (baseType == substitutedType) {
4372 return method; 3128 return method;
4373 } 3129 }
4374 return new MethodMember(method, definingType, substitutedType); 3130 return new MethodMember(method, definingType, substitutedType);
4375 } 3131 }
4376 } 3132 }
4377 3133
4378 /** 3134 /**
4379 * The type of a function, method, constructor, getter, or setter. Function
4380 * types come in three variations:
4381 *
4382 * * The types of functions that only have required parameters. These have the
4383 * general form <i>(T<sub>1</sub>, &hellip;, T<sub>n</sub>) &rarr; T</i>.
4384 * * The types of functions with optional positional parameters. These have the
4385 * general form <i>(T<sub>1</sub>, &hellip;, T<sub>n</sub>, [T<sub>n+1</sub>
4386 * &hellip;, T<sub>n+k</sub>]) &rarr; T</i>.
4387 * * The types of functions with named parameters. These have the general form
4388 * <i>(T<sub>1</sub>, &hellip;, T<sub>n</sub>, {T<sub>x1</sub> x1, &hellip;,
4389 * T<sub>xk</sub> xk}) &rarr; T</i>.
4390 */
4391 abstract class FunctionType implements ParameterizedType {
4392 /**
4393 * The type parameters of this generic function. For example `<T> T -> T`.
4394 *
4395 * These are distinct from the [typeParameters] list, which contains type
4396 * parameters from surrounding contexts, and thus are free type variables from
4397 * the perspective of this function type.
4398 */
4399 List<TypeParameterElement> get boundTypeParameters;
4400
4401 /**
4402 * Return a map from the names of named parameters to the types of the named
4403 * parameters of this type of function. The entries in the map will be
4404 * iterated in the same order as the order in which the named parameters were
4405 * defined. If there were no named parameters declared then the map will be
4406 * empty.
4407 */
4408 Map<String, DartType> get namedParameterTypes;
4409
4410 /**
4411 * Return a list containing the types of the normal parameters of this type of
4412 * function. The parameter types are in the same order as they appear in the
4413 * declaration of the function.
4414 */
4415 List<DartType> get normalParameterTypes;
4416
4417 /**
4418 * Return a map from the names of optional (positional) parameters to the
4419 * types of the optional parameters of this type of function. The entries in
4420 * the map will be iterated in the same order as the order in which the
4421 * optional parameters were defined. If there were no optional parameters
4422 * declared then the map will be empty.
4423 */
4424 List<DartType> get optionalParameterTypes;
4425
4426 /**
4427 * Return a list containing the parameters elements of this type of function.
4428 * The parameter types are in the same order as they appear in the declaration
4429 * of the function.
4430 */
4431 List<ParameterElement> get parameters;
4432
4433 /**
4434 * Return the type of object returned by this type of function.
4435 */
4436 DartType get returnType;
4437
4438 /**
4439 * Return the type resulting from instantiating (replacing) the given
4440 * [argumentTypes] for this function's bound type parameters.
4441 */
4442 FunctionType instantiate(List<DartType> argumentTypes);
4443
4444 /**
4445 * Return `true` if this type is a subtype of the given [type].
4446 *
4447 * A function type <i>(T<sub>1</sub>, &hellip;, T<sub>n</sub>) &rarr; T</i> is
4448 * a subtype of the function type <i>(S<sub>1</sub>, &hellip;, S<sub>n</sub>)
4449 * &rarr; S</i>, if all of the following conditions are met:
4450 *
4451 * * Either
4452 * * <i>S</i> is void, or
4453 * * <i>T &hArr; S</i>.
4454 *
4455 * * For all <i>i</i>, 1 <= <i>i</i> <= <i>n</i>, <i>T<sub>i</sub> &hArr;
4456 * S<sub>i</sub></i>.
4457 *
4458 * A function type <i>(T<sub>1</sub>, &hellip;, T<sub>n</sub>,
4459 * [T<sub>n+1</sub>, &hellip;, T<sub>n+k</sub>]) &rarr; T</i> is a subtype of
4460 * the function type <i>(S<sub>1</sub>, &hellip;, S<sub>n</sub>,
4461 * [S<sub>n+1</sub>, &hellip;, S<sub>n+m</sub>]) &rarr; S</i>, if all of the
4462 * following conditions are met:
4463 *
4464 * * Either
4465 * * <i>S</i> is void, or
4466 * * <i>T &hArr; S</i>.
4467 *
4468 * * <i>k</i> >= <i>m</i> and for all <i>i</i>, 1 <= <i>i</i> <= <i>n+m</i>,
4469 * <i>T<sub>i</sub> &hArr; S<sub>i</sub></i>.
4470 *
4471 * A function type <i>(T<sub>1</sub>, &hellip;, T<sub>n</sub>,
4472 * {T<sub>x1</sub> x1, &hellip;, T<sub>xk</sub> xk}) &rarr; T</i> is a subtype
4473 * of the function type <i>(S<sub>1</sub>, &hellip;, S<sub>n</sub>,
4474 * {S<sub>y1</sub> y1, &hellip;, S<sub>ym</sub> ym}) &rarr; S</i>, if all of
4475 * the following conditions are met:
4476 * * Either
4477 * * <i>S</i> is void,
4478 * * or <i>T &hArr; S</i>.
4479 *
4480 * * For all <i>i</i>, 1 <= <i>i</i> <= <i>n</i>, <i>T<sub>i</sub> &hArr;
4481 * S<sub>i</sub></i>.
4482 * * <i>k</i> >= <i>m</i> and <i>y<sub>i</sub></i> in <i>{x<sub>1</sub>,
4483 * &hellip;, x<sub>k</sub>}</i>, 1 <= <i>i</i> <= <i>m</i>.
4484 * * For all <i>y<sub>i</sub></i> in <i>{y<sub>1</sub>, &hellip;,
4485 * y<sub>m</sub>}</i>, <i>y<sub>i</sub> = x<sub>j</sub> => Tj &hArr; Si</i>.
4486 *
4487 * In addition, the following subtype rules apply:
4488 *
4489 * <i>(T<sub>1</sub>, &hellip;, T<sub>n</sub>, []) &rarr; T <: (T<sub>1</sub>,
4490 * &hellip;, T<sub>n</sub>) &rarr; T.</i><br>
4491 * <i>(T<sub>1</sub>, &hellip;, T<sub>n</sub>) &rarr; T <: (T<sub>1</sub>,
4492 * &hellip;, T<sub>n</sub>, {}) &rarr; T.</i><br>
4493 * <i>(T<sub>1</sub>, &hellip;, T<sub>n</sub>, {}) &rarr; T <: (T<sub>1</sub>,
4494 * &hellip;, T<sub>n</sub>) &rarr; T.</i><br>
4495 * <i>(T<sub>1</sub>, &hellip;, T<sub>n</sub>) &rarr; T <: (T<sub>1</sub>,
4496 * &hellip;, T<sub>n</sub>, []) &rarr; T.</i>
4497 *
4498 * All functions implement the class `Function`. However not all function
4499 * types are a subtype of `Function`. If an interface type <i>I</i> includes a
4500 * method named `call()`, and the type of `call()` is the function type
4501 * <i>F</i>, then <i>I</i> is considered to be a subtype of <i>F</i>.
4502 */
4503 @override
4504 bool isSubtypeOf(DartType type);
4505
4506 @override
4507 FunctionType substitute2(
4508 List<DartType> argumentTypes, List<DartType> parameterTypes);
4509
4510 /**
4511 * Return the type resulting from substituting the given [argumentTypes] for
4512 * this type's parameters. This is fully equivalent to
4513 * `substitute(argumentTypes, getTypeArguments())`.
4514 */
4515 @deprecated // use instantiate
4516 FunctionType substitute3(List<DartType> argumentTypes);
4517 }
4518
4519 /**
4520 * A function type alias (`typedef`).
4521 */
4522 abstract class FunctionTypeAliasElement
4523 implements TypeDefiningElement, FunctionTypedElement {
4524 /**
4525 * An empty array of type alias elements.
4526 */
4527 static List<FunctionTypeAliasElement> EMPTY_LIST =
4528 new List<FunctionTypeAliasElement>(0);
4529
4530 /**
4531 * Return the compilation unit in which this type alias is defined.
4532 */
4533 @override
4534 CompilationUnitElement get enclosingElement;
4535
4536 /**
4537 * Return the resolved function type alias node that declares this element.
4538 *
4539 * This method is expensive, because resolved AST might be evicted from cache,
4540 * so parsing and resolving will be performed.
4541 */
4542 @override
4543 FunctionTypeAlias computeNode();
4544 }
4545
4546 /**
4547 * A concrete implementation of a [FunctionTypeAliasElement]. 3135 * A concrete implementation of a [FunctionTypeAliasElement].
4548 */ 3136 */
4549 class FunctionTypeAliasElementImpl extends ElementImpl 3137 class FunctionTypeAliasElementImpl extends ElementImpl
4550 implements FunctionTypeAliasElement { 3138 implements FunctionTypeAliasElement {
4551 /** 3139 /**
4552 * A list containing all of the parameters defined by this type alias. 3140 * A list containing all of the parameters defined by this type alias.
4553 */ 3141 */
4554 List<ParameterElement> _parameters = ParameterElement.EMPTY_LIST; 3142 List<ParameterElement> _parameters = ParameterElement.EMPTY_LIST;
4555 3143
4556 /** 3144 /**
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
4640 buffer.write("("); 3228 buffer.write("(");
4641 int parameterCount = _parameters.length; 3229 int parameterCount = _parameters.length;
4642 for (int i = 0; i < parameterCount; i++) { 3230 for (int i = 0; i < parameterCount; i++) {
4643 if (i > 0) { 3231 if (i > 0) {
4644 buffer.write(", "); 3232 buffer.write(", ");
4645 } 3233 }
4646 (_parameters[i] as ParameterElementImpl).appendTo(buffer); 3234 (_parameters[i] as ParameterElementImpl).appendTo(buffer);
4647 } 3235 }
4648 buffer.write(")"); 3236 buffer.write(")");
4649 if (type != null) { 3237 if (type != null) {
4650 buffer.write(Element.RIGHT_ARROW); 3238 buffer.write(ElementImpl.RIGHT_ARROW);
4651 buffer.write(type.returnType); 3239 buffer.write(type.returnType);
4652 } else if (returnType != null) { 3240 } else if (returnType != null) {
4653 buffer.write(Element.RIGHT_ARROW); 3241 buffer.write(ElementImpl.RIGHT_ARROW);
4654 buffer.write(returnType); 3242 buffer.write(returnType);
4655 } 3243 }
4656 } 3244 }
4657 3245
4658 @override 3246 @override
4659 FunctionTypeAlias computeNode() => 3247 FunctionTypeAlias computeNode() =>
4660 getNodeMatching((node) => node is FunctionTypeAlias); 3248 getNodeMatching((node) => node is FunctionTypeAlias);
4661 3249
4662 @override 3250 @override
4663 ElementImpl getChild(String identifier) { 3251 ElementImpl getChild(String identifier) {
(...skipping 13 matching lines...) Expand all
4677 3265
4678 @override 3266 @override
4679 void visitChildren(ElementVisitor visitor) { 3267 void visitChildren(ElementVisitor visitor) {
4680 super.visitChildren(visitor); 3268 super.visitChildren(visitor);
4681 safelyVisitChildren(_parameters, visitor); 3269 safelyVisitChildren(_parameters, visitor);
4682 safelyVisitChildren(_typeParameters, visitor); 3270 safelyVisitChildren(_typeParameters, visitor);
4683 } 3271 }
4684 } 3272 }
4685 3273
4686 /** 3274 /**
4687 * An element that has a [FunctionType] as its [type].
4688 *
4689 * This also provides convenient access to the parameters and return type.
4690 */
4691 abstract class FunctionTypedElement implements TypeParameterizedElement {
4692 /**
4693 * Return a list containing all of the parameters defined by this executable
4694 * element.
4695 */
4696 List<ParameterElement> get parameters;
4697
4698 /**
4699 * Return the return type defined by this element. If the element model is
4700 * fully populated, then the [returnType] will not be `null`, even
4701 * if no return type was explicitly specified.
4702 */
4703 DartType get returnType;
4704
4705 /**
4706 * Return the type of function defined by this element.
4707 */
4708 FunctionType get type;
4709 }
4710
4711 /**
4712 * The type of a function, method, constructor, getter, or setter. 3275 * The type of a function, method, constructor, getter, or setter.
4713 */ 3276 */
4714 class FunctionTypeImpl extends TypeImpl implements FunctionType { 3277 class FunctionTypeImpl extends TypeImpl implements FunctionType {
4715 /** 3278 /**
4716 * The list of [typeArguments]. 3279 * The list of [typeArguments].
4717 */ 3280 */
4718 List<DartType> _typeArguments; 3281 List<DartType> _typeArguments;
4719 3282
4720 /** 3283 /**
4721 * The list of [typeParameters]. 3284 * The list of [typeParameters].
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
4861 needsComma = true; 3424 needsComma = true;
4862 } 3425 }
4863 buffer.write(name); 3426 buffer.write(name);
4864 buffer.write(": "); 3427 buffer.write(": ");
4865 buffer.write(type.displayName); 3428 buffer.write(type.displayName);
4866 }); 3429 });
4867 buffer.write("}"); 3430 buffer.write("}");
4868 needsComma = true; 3431 needsComma = true;
4869 } 3432 }
4870 buffer.write(")"); 3433 buffer.write(")");
4871 buffer.write(Element.RIGHT_ARROW); 3434 buffer.write(ElementImpl.RIGHT_ARROW);
4872 if (returnType == null) { 3435 if (returnType == null) {
4873 buffer.write("null"); 3436 buffer.write("null");
4874 } else { 3437 } else {
4875 buffer.write(returnType.displayName); 3438 buffer.write(returnType.displayName);
4876 } 3439 }
4877 name = buffer.toString(); 3440 name = buffer.toString();
4878 } 3441 }
4879 return name; 3442 return name;
4880 } 3443 }
4881 3444
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
5223 needsComma = true; 3786 needsComma = true;
5224 } 3787 }
5225 buffer.write(name); 3788 buffer.write(name);
5226 buffer.write(": "); 3789 buffer.write(": ");
5227 (type as TypeImpl).appendTo(buffer); 3790 (type as TypeImpl).appendTo(buffer);
5228 }); 3791 });
5229 buffer.write("}"); 3792 buffer.write("}");
5230 needsComma = true; 3793 needsComma = true;
5231 } 3794 }
5232 buffer.write(")"); 3795 buffer.write(")");
5233 buffer.write(Element.RIGHT_ARROW); 3796 buffer.write(ElementImpl.RIGHT_ARROW);
5234 if (returnType == null) { 3797 if (returnType == null) {
5235 buffer.write("null"); 3798 buffer.write("null");
5236 } else { 3799 } else {
5237 (returnType as TypeImpl).appendTo(buffer); 3800 (returnType as TypeImpl).appendTo(buffer);
5238 } 3801 }
5239 } 3802 }
5240 3803
5241 @override 3804 @override
5242 FunctionTypeImpl instantiate(List<DartType> argumentTypes) { 3805 FunctionTypeImpl instantiate(List<DartType> argumentTypes) {
5243 if (argumentTypes.length != boundTypeParameters.length) { 3806 if (argumentTypes.length != boundTypeParameters.length) {
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
5619 TypeImpl secondType = secondTypes[secondKey]; 4182 TypeImpl secondType = secondTypes[secondKey];
5620 if (firstKey != secondKey || firstType != secondType) { 4183 if (firstKey != secondKey || firstType != secondType) {
5621 return false; 4184 return false;
5622 } 4185 }
5623 } 4186 }
5624 return true; 4187 return true;
5625 } 4188 }
5626 } 4189 }
5627 4190
5628 /** 4191 /**
5629 * An element visitor that will recursively visit all of the elements in an
5630 * element model (like instances of the class [RecursiveElementVisitor]). In
5631 * addition, when an element of a specific type is visited not only will the
5632 * visit method for that specific type of element be invoked, but additional
5633 * methods for the supertypes of that element will also be invoked. For example,
5634 * using an instance of this class to visit a [MethodElement] will cause the
5635 * method [visitMethodElement] to be invoked but will also cause the methods
5636 * [visitExecutableElement] and [visitElement] to be subsequently invoked. This
5637 * allows visitors to be written that visit all executable elements without
5638 * needing to override the visit method for each of the specific subclasses of
5639 * [ExecutableElement].
5640 *
5641 * Note, however, that unlike many visitors, element visitors visit objects
5642 * based on the interfaces implemented by those elements. Because interfaces
5643 * form a graph structure rather than a tree structure the way classes do, and
5644 * because it is generally undesirable for an object to be visited more than
5645 * once, this class flattens the interface graph into a pseudo-tree. In
5646 * particular, this class treats elements as if the element types were
5647 * structured in the following way:
5648 *
5649 * <pre>
5650 * Element
5651 * ClassElement
5652 * CompilationUnitElement
5653 * ExecutableElement
5654 * ConstructorElement
5655 * LocalElement
5656 * FunctionElement
5657 * MethodElement
5658 * PropertyAccessorElement
5659 * ExportElement
5660 * HtmlElement
5661 * ImportElement
5662 * LabelElement
5663 * LibraryElement
5664 * MultiplyDefinedElement
5665 * PrefixElement
5666 * TypeAliasElement
5667 * TypeParameterElement
5668 * UndefinedElement
5669 * VariableElement
5670 * PropertyInducingElement
5671 * FieldElement
5672 * TopLevelVariableElement
5673 * LocalElement
5674 * LocalVariableElement
5675 * ParameterElement
5676 * FieldFormalParameterElement
5677 * </pre>
5678 *
5679 * Subclasses that override a visit method must either invoke the overridden
5680 * visit method or explicitly invoke the more general visit method. Failure to
5681 * do so will cause the visit methods for superclasses of the element to not be
5682 * invoked and will cause the children of the visited node to not be visited.
5683 */
5684 class GeneralizingElementVisitor<R> implements ElementVisitor<R> {
5685 @override
5686 R visitClassElement(ClassElement element) => visitElement(element);
5687
5688 @override
5689 R visitCompilationUnitElement(CompilationUnitElement element) =>
5690 visitElement(element);
5691
5692 @override
5693 R visitConstructorElement(ConstructorElement element) =>
5694 visitExecutableElement(element);
5695
5696 R visitElement(Element element) {
5697 element.visitChildren(this);
5698 return null;
5699 }
5700
5701 R visitExecutableElement(ExecutableElement element) => visitElement(element);
5702
5703 @override
5704 R visitExportElement(ExportElement element) => visitElement(element);
5705
5706 @override
5707 R visitFieldElement(FieldElement element) =>
5708 visitPropertyInducingElement(element);
5709
5710 @override
5711 R visitFieldFormalParameterElement(FieldFormalParameterElement element) =>
5712 visitParameterElement(element);
5713
5714 @override
5715 R visitFunctionElement(FunctionElement element) => visitLocalElement(element);
5716
5717 @override
5718 R visitFunctionTypeAliasElement(FunctionTypeAliasElement element) =>
5719 visitElement(element);
5720
5721 @override
5722 R visitImportElement(ImportElement element) => visitElement(element);
5723
5724 @override
5725 R visitLabelElement(LabelElement element) => visitElement(element);
5726
5727 @override
5728 R visitLibraryElement(LibraryElement element) => visitElement(element);
5729
5730 R visitLocalElement(LocalElement element) {
5731 if (element is LocalVariableElement) {
5732 return visitVariableElement(element);
5733 } else if (element is ParameterElement) {
5734 return visitVariableElement(element);
5735 } else if (element is FunctionElement) {
5736 return visitExecutableElement(element);
5737 }
5738 return null;
5739 }
5740
5741 @override
5742 R visitLocalVariableElement(LocalVariableElement element) =>
5743 visitLocalElement(element);
5744
5745 @override
5746 R visitMethodElement(MethodElement element) =>
5747 visitExecutableElement(element);
5748
5749 @override
5750 R visitMultiplyDefinedElement(MultiplyDefinedElement element) =>
5751 visitElement(element);
5752
5753 @override
5754 R visitParameterElement(ParameterElement element) =>
5755 visitLocalElement(element);
5756
5757 @override
5758 R visitPrefixElement(PrefixElement element) => visitElement(element);
5759
5760 @override
5761 R visitPropertyAccessorElement(PropertyAccessorElement element) =>
5762 visitExecutableElement(element);
5763
5764 R visitPropertyInducingElement(PropertyInducingElement element) =>
5765 visitVariableElement(element);
5766
5767 @override
5768 R visitTopLevelVariableElement(TopLevelVariableElement element) =>
5769 visitPropertyInducingElement(element);
5770
5771 @override
5772 R visitTypeParameterElement(TypeParameterElement element) =>
5773 visitElement(element);
5774
5775 R visitVariableElement(VariableElement element) => visitElement(element);
5776 }
5777
5778 /**
5779 * A combinator that causes some of the names in a namespace to be hidden when
5780 * being imported.
5781 */
5782 abstract class HideElementCombinator implements NamespaceCombinator {
5783 /**
5784 * Return a list containing the names that are not to be made visible in the
5785 * importing library even if they are defined in the imported library.
5786 */
5787 List<String> get hiddenNames;
5788 }
5789
5790 /**
5791 * A concrete implementation of a [HideElementCombinator]. 4192 * A concrete implementation of a [HideElementCombinator].
5792 */ 4193 */
5793 class HideElementCombinatorImpl implements HideElementCombinator { 4194 class HideElementCombinatorImpl implements HideElementCombinator {
5794 /** 4195 /**
5795 * The names that are not to be made visible in the importing library even if 4196 * The names that are not to be made visible in the importing library even if
5796 * they are defined in the imported library. 4197 * they are defined in the imported library.
5797 */ 4198 */
5798 List<String> hiddenNames = StringUtilities.EMPTY_ARRAY; 4199 List<String> hiddenNames = StringUtilities.EMPTY_ARRAY;
5799 4200
5800 @override 4201 @override
5801 String toString() { 4202 String toString() {
5802 StringBuffer buffer = new StringBuffer(); 4203 StringBuffer buffer = new StringBuffer();
5803 buffer.write("show "); 4204 buffer.write("show ");
5804 int count = hiddenNames.length; 4205 int count = hiddenNames.length;
5805 for (int i = 0; i < count; i++) { 4206 for (int i = 0; i < count; i++) {
5806 if (i > 0) { 4207 if (i > 0) {
5807 buffer.write(", "); 4208 buffer.write(", ");
5808 } 4209 }
5809 buffer.write(hiddenNames[i]); 4210 buffer.write(hiddenNames[i]);
5810 } 4211 }
5811 return buffer.toString(); 4212 return buffer.toString();
5812 } 4213 }
5813 } 4214 }
5814 4215
5815 /** 4216 /**
5816 * A single import directive within a library.
5817 */
5818 abstract class ImportElement implements Element, UriReferencedElement {
5819 /**
5820 * An empty list of import elements.
5821 */
5822 static const List<ImportElement> EMPTY_LIST = const <ImportElement>[];
5823
5824 /**
5825 * Return a list containing the combinators that were specified as part of the
5826 * import directive in the order in which they were specified.
5827 */
5828 List<NamespaceCombinator> get combinators;
5829
5830 /**
5831 * Return the library that is imported into this library by this import
5832 * directive.
5833 */
5834 LibraryElement get importedLibrary;
5835
5836 /**
5837 * Return `true` if this import is for a deferred library.
5838 */
5839 bool get isDeferred;
5840
5841 /**
5842 * Return the prefix that was specified as part of the import directive, or
5843 * `null` if there was no prefix specified.
5844 */
5845 PrefixElement get prefix;
5846
5847 /**
5848 * Return the offset of the prefix of this import in the file that contains
5849 * this import directive, or `-1` if this import is synthetic, does not have a
5850 * prefix, or otherwise does not have an offset.
5851 */
5852 int get prefixOffset;
5853 }
5854
5855 /**
5856 * A concrete implementation of an [ImportElement]. 4217 * A concrete implementation of an [ImportElement].
5857 */ 4218 */
5858 class ImportElementImpl extends UriReferencedElementImpl 4219 class ImportElementImpl extends UriReferencedElementImpl
5859 implements ImportElement { 4220 implements ImportElement {
5860 /** 4221 /**
5861 * The offset of the prefix of this import in the file that contains the this 4222 * The offset of the prefix of this import in the file that contains the this
5862 * import directive, or `-1` if this import is synthetic. 4223 * import directive, or `-1` if this import is synthetic.
5863 */ 4224 */
5864 int prefixOffset = 0; 4225 int prefixOffset = 0;
5865 4226
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
5913 } 4274 }
5914 4275
5915 @override 4276 @override
5916 void visitChildren(ElementVisitor visitor) { 4277 void visitChildren(ElementVisitor visitor) {
5917 super.visitChildren(visitor); 4278 super.visitChildren(visitor);
5918 safelyVisitChild(prefix, visitor); 4279 safelyVisitChild(prefix, visitor);
5919 } 4280 }
5920 } 4281 }
5921 4282
5922 /** 4283 /**
5923 * The type introduced by either a class or an interface, or a reference to such
5924 * a type.
5925 */
5926 abstract class InterfaceType implements ParameterizedType {
5927 /**
5928 * An empty list of types.
5929 */
5930 static const List<InterfaceType> EMPTY_LIST = const <InterfaceType>[];
5931
5932 /**
5933 * Return a list containing all of the accessors (getters and setters)
5934 * declared in this type.
5935 */
5936 List<PropertyAccessorElement> get accessors;
5937
5938 /**
5939 * Return a list containing all of the constructors declared in this type.
5940 */
5941 List<ConstructorElement> get constructors;
5942
5943 @override
5944 ClassElement get element;
5945
5946 /**
5947 * Return a list containing all of the interfaces that are implemented by this
5948 * interface. Note that this is <b>not</b>, in general, equivalent to getting
5949 * the interfaces from this type's element because the types returned by this
5950 * method will have had their type parameters replaced.
5951 */
5952 List<InterfaceType> get interfaces;
5953
5954 /**
5955 * Return a list containing all of the methods declared in this type.
5956 */
5957 List<MethodElement> get methods;
5958
5959 /**
5960 * Return a list containing all of the mixins that are applied to the class
5961 * being extended in order to derive the superclass of this class. Note that
5962 * this is <b>not</b>, in general, equivalent to getting the mixins from this
5963 * type's element because the types returned by this method will have had
5964 * their type parameters replaced.
5965 */
5966 List<InterfaceType> get mixins;
5967
5968 /**
5969 * Return the type representing the superclass of this type, or null if this
5970 * type represents the class 'Object'. Note that this is <b>not</b>, in
5971 * general, equivalent to getting the superclass from this type's element
5972 * because the type returned by this method will have had it's type parameters
5973 * replaced.
5974 */
5975 InterfaceType get superclass;
5976
5977 /**
5978 * Return the element representing the getter with the given [name] that is
5979 * declared in this class, or `null` if this class does not declare a getter
5980 * with the given name.
5981 */
5982 PropertyAccessorElement getGetter(String name);
5983
5984 /**
5985 * Return the element representing the method with the given [name] that is
5986 * declared in this class, or `null` if this class does not declare a method
5987 * with the given name.
5988 */
5989 MethodElement getMethod(String name);
5990
5991 /**
5992 * Return the element representing the setter with the given [name] that is
5993 * declared in this class, or `null` if this class does not declare a setter
5994 * with the given name.
5995 */
5996 PropertyAccessorElement getSetter(String name);
5997
5998 /**
5999 * Return `true` if this type is a direct supertype of the given [type]. The
6000 * implicit interface of class <i>I</i> is a direct supertype of the implicit
6001 * interface of class <i>J</i> iff:
6002 *
6003 * * <i>I</i> is Object, and <i>J</i> has no extends clause.
6004 * * <i>I</i> is listed in the extends clause of <i>J</i>.
6005 * * <i>I</i> is listed in the implements clause of <i>J</i>.
6006 * * <i>I</i> is listed in the with clause of <i>J</i>.
6007 * * <i>J</i> is a mixin application of the mixin of <i>I</i>.
6008 */
6009 bool isDirectSupertypeOf(InterfaceType type);
6010
6011 /**
6012 * Return `true` if this type is more specific than the given [type]. An
6013 * interface type <i>T</i> is more specific than an interface type <i>S</i>,
6014 * written <i>T &laquo; S</i>, if one of the following conditions is met:
6015 *
6016 * * Reflexivity: <i>T</i> is <i>S</i>.
6017 * * <i>T</i> is bottom.
6018 * * <i>S</i> is dynamic.
6019 * * Direct supertype: <i>S</i> is a direct supertype of <i>T</i>.
6020 * * <i>T</i> is a type parameter and <i>S</i> is the upper bound of <i>T</i>.
6021 * * Covariance: <i>T</i> is of the form <i>I&lt;T<sub>1</sub>, &hellip;,
6022 * T<sub>n</sub>&gt;</i> and S</i> is of the form <i>I&lt;S<sub>1</sub>,
6023 * &hellip;, S<sub>n</sub>&gt;</i> and <i>T<sub>i</sub> &laquo;
6024 * S<sub>i</sub></i>, <i>1 <= i <= n</i>.
6025 * * Transitivity: <i>T &laquo; U</i> and <i>U &laquo; S</i>.
6026 */
6027 @override
6028 bool isMoreSpecificThan(DartType type);
6029
6030 /**
6031 * Return `true` if this type is a subtype of the given [type]. An interface
6032 * type <i>T</i> is a subtype of an interface type <i>S</i>, written <i>T</i>
6033 * <: <i>S</i>, iff <i>[bottom/dynamic]T</i> &laquo; <i>S</i> (<i>T</i> is
6034 * more specific than <i>S</i>). If an interface type <i>I</i> includes a
6035 * method named <i>call()</i>, and the type of <i>call()</i> is the function
6036 * type <i>F</i>, then <i>I</i> is considered to be a subtype of <i>F</i>.
6037 */
6038 @override
6039 bool isSubtypeOf(DartType type);
6040
6041 /**
6042 * Return the element representing the constructor that results from looking
6043 * up the constructor with the given [name] in this class with respect to the
6044 * given [library], or `null` if the look up fails. The behavior of this
6045 * method is defined by the Dart Language Specification in section 12.11.1:
6046 * <blockquote>
6047 * If <i>e</i> is of the form <b>new</b> <i>T.id()</i> then let <i>q<i> be the
6048 * constructor <i>T.id</i>, otherwise let <i>q<i> be the constructor <i>T<i>.
6049 * Otherwise, if <i>q</i> is not defined or not accessible, a
6050 * NoSuchMethodException is thrown.
6051 * </blockquote>
6052 */
6053 ConstructorElement lookUpConstructor(String name, LibraryElement library);
6054
6055 /**
6056 * Return the element representing the getter that results from looking up the
6057 * getter with the given [name] in this class with respect to the given
6058 * [library], or `null` if the look up fails. The behavior of this method is
6059 * defined by the Dart Language Specification in section 12.15.1:
6060 * <blockquote>
6061 * The result of looking up getter (respectively setter) <i>m</i> in class
6062 * <i>C</i> with respect to library <i>L</i> is:
6063 * * If <i>C</i> declares an instance getter (respectively setter) named
6064 * <i>m</i> that is accessible to <i>L</i>, then that getter (respectively
6065 * setter) is the result of the lookup. Otherwise, if <i>C</i> has a
6066 * superclass <i>S</i>, then the result of the lookup is the result of
6067 * looking up getter (respectively setter) <i>m</i> in <i>S</i> with respect
6068 * to <i>L</i>. Otherwise, we say that the lookup has failed.
6069 * </blockquote>
6070 */
6071 PropertyAccessorElement lookUpGetter(String name, LibraryElement library);
6072
6073 /**
6074 * Return the element representing the getter that results from looking up the
6075 * getter with the given [name] in the superclass of this class with respect
6076 * to the given [library], or `null` if the look up fails. The behavior of
6077 * this method is defined by the Dart Language Specification in section
6078 * 12.15.1:
6079 * <blockquote>
6080 * The result of looking up getter (respectively setter) <i>m</i> in class
6081 * <i>C</i> with respect to library <i>L</i> is:
6082 * * If <i>C</i> declares an instance getter (respectively setter) named
6083 * <i>m</i> that is accessible to <i>L</i>, then that getter (respectively
6084 * setter) is the result of the lookup. Otherwise, if <i>C</i> has a
6085 * superclass <i>S</i>, then the result of the lookup is the result of
6086 * looking up getter (respectively setter) <i>m</i> in <i>S</i> with respect
6087 * to <i>L</i>. Otherwise, we say that the lookup has failed.
6088 * </blockquote>
6089 */
6090 PropertyAccessorElement lookUpGetterInSuperclass(
6091 String name, LibraryElement library);
6092
6093 /**
6094 * Look up the member with the given [name] in this type and all extended
6095 * and mixed in classes, and by default including [thisType]. If the search
6096 * fails, this will then search interfaces.
6097 *
6098 * Return the element representing the member that was found, or `null` if
6099 * there is no getter with the given name.
6100 *
6101 * The [library] determines if a private member name is visible, and does not
6102 * need to be supplied for public names.
6103 */
6104 PropertyAccessorElement lookUpInheritedGetter(String name,
6105 {LibraryElement library, bool thisType: true});
6106
6107 /**
6108 * Look up the member with the given [name] in this type and all extended
6109 * and mixed in classes, starting from this type. If the search fails,
6110 * search interfaces.
6111 *
6112 * Return the element representing the member that was found, or `null` if
6113 * there is no getter with the given name.
6114 *
6115 * The [library] determines if a private member name is visible, and does not
6116 * need to be supplied for public names.
6117 */
6118 ExecutableElement lookUpInheritedGetterOrMethod(String name,
6119 {LibraryElement library});
6120
6121 /**
6122 * Look up the member with the given [name] in this type and all extended
6123 * and mixed in classes, and by default including [thisType]. If the search
6124 * fails, this will then search interfaces.
6125 *
6126 * Return the element representing the member that was found, or `null` if
6127 * there is no getter with the given name.
6128 *
6129 * The [library] determines if a private member name is visible, and does not
6130 * need to be supplied for public names.
6131 */
6132 MethodElement lookUpInheritedMethod(String name,
6133 {LibraryElement library, bool thisType: true});
6134
6135 /**
6136 * Look up the member with the given [name] in this type and all extended
6137 * and mixed in classes, and by default including [thisType]. If the search
6138 * fails, this will then search interfaces.
6139 *
6140 * Return the element representing the member that was found, or `null` if
6141 * there is no getter with the given name.
6142 *
6143 * The [library] determines if a private member name is visible, and does not
6144 * need to be supplied for public names.
6145 */
6146 PropertyAccessorElement lookUpInheritedSetter(String name,
6147 {LibraryElement library, bool thisType: true});
6148
6149 /**
6150 * Return the element representing the method that results from looking up the
6151 * method with the given [name] in this class with respect to the given
6152 * [library], or `null` if the look up fails. The behavior of this method is
6153 * defined by the Dart Language Specification in section 12.15.1:
6154 * <blockquote>
6155 * The result of looking up method <i>m</i> in class <i>C</i> with respect to
6156 * library <i>L</i> is:
6157 * * If <i>C</i> declares an instance method named <i>m</i> that is accessible
6158 * to <i>L</i>, then that method is the result of the lookup. Otherwise, if
6159 * <i>C</i> has a superclass <i>S</i>, then the result of the lookup is the
6160 * result of looking up method <i>m</i> in <i>S</i> with respect to <i>L</i>
6161 * Otherwise, we say that the lookup has failed.
6162 * </blockquote>
6163 */
6164 MethodElement lookUpMethod(String name, LibraryElement library);
6165
6166 /**
6167 * Return the element representing the method that results from looking up the
6168 * method with the given [name] in the superclass of this class with respect
6169 * to the given [library], or `null` if the look up fails. The behavior of
6170 * this method is defined by the Dart Language Specification in section
6171 * 12.15.1:
6172 * <blockquote>
6173 * The result of looking up method <i>m</i> in class <i>C</i> with respect to
6174 * library <i>L</i> is:
6175 * * If <i>C</i> declares an instance method named <i>m</i> that is accessible
6176 * to <i>L</i>, then that method is the result of the lookup. Otherwise, if
6177 * <i>C</i> has a superclass <i>S</i>, then the result of the lookup is the
6178 * result of looking up method <i>m</i> in <i>S</i> with respect to <i>L</i>.
6179 * Otherwise, we say that the lookup has failed.
6180 * </blockquote>
6181 */
6182 MethodElement lookUpMethodInSuperclass(String name, LibraryElement library);
6183
6184 /**
6185 * Return the element representing the setter that results from looking up the
6186 * setter with the given [name] in this class with respect to the given
6187 * [library], or `null` if the look up fails. The behavior of this method is
6188 * defined by the Dart Language Specification in section 12.16:
6189 * <blockquote>
6190 * The result of looking up getter (respectively setter) <i>m</i> in class
6191 * <i>C</i> with respect to library <i>L</i> is:
6192 * * If <i>C</i> declares an instance getter (respectively setter) named
6193 * <i>m</i> that is accessible to <i>L</i>, then that getter (respectively
6194 * setter) is the result of the lookup. Otherwise, if <i>C</i> has a
6195 * superclass <i>S</i>, then the result of the lookup is the result of
6196 * looking up getter (respectively setter) <i>m</i> in <i>S</i> with respect
6197 * to <i>L</i>. Otherwise, we say that the lookup has failed.
6198 * </blockquote>
6199 */
6200 PropertyAccessorElement lookUpSetter(String name, LibraryElement library);
6201
6202 /**
6203 * Return the element representing the setter that results from looking up the
6204 * setter with the given [name] in the superclass of this class with respect
6205 * to the given [library], or `null` if the look up fails. The behavior of
6206 * this method is defined by the Dart Language Specification in section 12.16:
6207 * <blockquote>
6208 * The result of looking up getter (respectively setter) <i>m</i> in class
6209 * <i>C</i> with respect to library <i>L</i> is:
6210 * * If <i>C</i> declares an instance getter (respectively setter) named
6211 * <i>m</i> that is accessible to <i>L</i>, then that getter (respectively
6212 * setter) is the result of the lookup. Otherwise, if <i>C</i> has a
6213 * superclass <i>S</i>, then the result of the lookup is the result of
6214 * looking up getter (respectively setter) <i>m</i> in <i>S</i> with respect
6215 * to <i>L</i>. Otherwise, we say that the lookup has failed.
6216 * </blockquote>
6217 */
6218 PropertyAccessorElement lookUpSetterInSuperclass(
6219 String name, LibraryElement library);
6220
6221 @override
6222 InterfaceType substitute2(
6223 List<DartType> argumentTypes, List<DartType> parameterTypes);
6224
6225 // TODO(jmesserly): introduce a new "instantiate" and deprecate this.
6226 // The new "instantiate" should work similar to FunctionType.instantiate,
6227 // which uses [boundTypeParameters] to model type parameters that haven't been
6228 // filled in yet. Those are kept separate from already-substituted type
6229 // parameters or free variables from the enclosing scopes, which allows nested
6230 // generics to work, such as a generic method in a generic class.
6231 /**
6232 * Return the type resulting from substituting the given arguments for this
6233 * type's parameters. This is fully equivalent to `substitute2(argumentTypes,
6234 * getTypeArguments())`.
6235 */
6236 InterfaceType substitute4(List<DartType> argumentTypes);
6237
6238 /**
6239 * Returns a "smart" version of the "least upper bound" of the given types.
6240 *
6241 * If these types have the same element and differ only in terms of the type
6242 * arguments, attempts to find a compatible set of type arguments.
6243 *
6244 * Otherwise, calls [DartType.getLeastUpperBound].
6245 */
6246 static InterfaceType getSmartLeastUpperBound(
6247 InterfaceType first, InterfaceType second) {
6248 // TODO(paulberry): this needs to be deprecated and replaced with a method
6249 // in [TypeSystem], since it relies on the deprecated functionality of
6250 // [DartType.getLeastUpperBound].
6251 if (first.element == second.element) {
6252 return _leastUpperBound(first, second);
6253 }
6254 AnalysisContext context = first.element.context;
6255 return context.typeSystem
6256 .getLeastUpperBound(context.typeProvider, first, second);
6257 }
6258
6259 /**
6260 * Return the "least upper bound" of the given types under the assumption that
6261 * the types have the same element and differ only in terms of the type
6262 * arguments.
6263 *
6264 * The resulting type is composed by comparing the corresponding type
6265 * arguments, keeping those that are the same, and using 'dynamic' for those
6266 * that are different.
6267 */
6268 static InterfaceType _leastUpperBound(
6269 InterfaceType firstType, InterfaceType secondType) {
6270 ClassElement firstElement = firstType.element;
6271 ClassElement secondElement = secondType.element;
6272 if (firstElement != secondElement) {
6273 throw new IllegalArgumentException('The same elements expected, but '
6274 '$firstElement and $secondElement are given.');
6275 }
6276 if (firstType == secondType) {
6277 return firstType;
6278 }
6279 List<DartType> firstArguments = firstType.typeArguments;
6280 List<DartType> secondArguments = secondType.typeArguments;
6281 int argumentCount = firstArguments.length;
6282 if (argumentCount == 0) {
6283 return firstType;
6284 }
6285 List<DartType> lubArguments = new List<DartType>(argumentCount);
6286 for (int i = 0; i < argumentCount; i++) {
6287 //
6288 // Ideally we would take the least upper bound of the two argument types,
6289 // but this can cause an infinite recursion (such as when finding the
6290 // least upper bound of String and num).
6291 //
6292 if (firstArguments[i] == secondArguments[i]) {
6293 lubArguments[i] = firstArguments[i];
6294 }
6295 if (lubArguments[i] == null) {
6296 lubArguments[i] = DynamicTypeImpl.instance;
6297 }
6298 }
6299 InterfaceTypeImpl lub = new InterfaceTypeImpl(firstElement);
6300 lub.typeArguments = lubArguments;
6301 return lub;
6302 }
6303 }
6304
6305 /**
6306 * A concrete implementation of an [InterfaceType]. 4284 * A concrete implementation of an [InterfaceType].
6307 */ 4285 */
6308 class InterfaceTypeImpl extends TypeImpl implements InterfaceType { 4286 class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
6309 /** 4287 /**
6310 * A list containing the actual types of the type arguments. 4288 * A list containing the actual types of the type arguments.
6311 */ 4289 */
6312 List<DartType> typeArguments = DartType.EMPTY_LIST; 4290 List<DartType> typeArguments = DartType.EMPTY_LIST;
6313 4291
6314 /** 4292 /**
6315 * The set of typedefs which should not be expanded when exploring this type, 4293 * The set of typedefs which should not be expanded when exploring this type,
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
6971 4949
6972 /** 4950 /**
6973 * Returns the set of all superinterfaces of the given [type]. 4951 * Returns the set of all superinterfaces of the given [type].
6974 * 4952 *
6975 * See [computeLeastUpperBound]. 4953 * See [computeLeastUpperBound].
6976 */ 4954 */
6977 static Set<InterfaceType> computeSuperinterfaceSet(InterfaceType type) => 4955 static Set<InterfaceType> computeSuperinterfaceSet(InterfaceType type) =>
6978 _computeSuperinterfaceSet(type, new HashSet<InterfaceType>()); 4956 _computeSuperinterfaceSet(type, new HashSet<InterfaceType>());
6979 4957
6980 /** 4958 /**
4959 * Returns a "smart" version of the "least upper bound" of the given types.
4960 *
4961 * If these types have the same element and differ only in terms of the type
4962 * arguments, attempts to find a compatible set of type arguments.
4963 *
4964 * Otherwise, calls [DartType.getLeastUpperBound].
4965 */
4966 static InterfaceType getSmartLeastUpperBound(
4967 InterfaceType first, InterfaceType second) {
4968 // TODO(paulberry): this needs to be deprecated and replaced with a method
4969 // in [TypeSystem], since it relies on the deprecated functionality of
4970 // [DartType.getLeastUpperBound].
4971 if (first.element == second.element) {
4972 return _leastUpperBound(first, second);
4973 }
4974 AnalysisContext context = first.element.context;
4975 return context.typeSystem
4976 .getLeastUpperBound(context.typeProvider, first, second);
4977 }
4978
4979 /**
6981 * Return the length of the longest inheritance path from a subtype of the 4980 * Return the length of the longest inheritance path from a subtype of the
6982 * given [type] to Object, where the given [depth] is the length of the 4981 * given [type] to Object, where the given [depth] is the length of the
6983 * longest path from the subtype to this type. The set of [visitedTypes] is 4982 * longest path from the subtype to this type. The set of [visitedTypes] is
6984 * used to prevent infinite recursion in the case of a cyclic type structure. 4983 * used to prevent infinite recursion in the case of a cyclic type structure.
6985 * 4984 *
6986 * See [computeLongestInheritancePathToObject], and [computeLeastUpperBound]. 4985 * See [computeLongestInheritancePathToObject], and [computeLeastUpperBound].
6987 */ 4986 */
6988 static int _computeLongestInheritancePathToObject( 4987 static int _computeLongestInheritancePathToObject(
6989 InterfaceType type, int depth, HashSet<ClassElement> visitedTypes) { 4988 InterfaceType type, int depth, HashSet<ClassElement> visitedTypes) {
6990 ClassElement classElement = type.element; 4989 ClassElement classElement = type.element;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
7054 * intersection is based on the equality of the types themselves. 5053 * intersection is based on the equality of the types themselves.
7055 */ 5054 */
7056 static List<InterfaceType> _intersection( 5055 static List<InterfaceType> _intersection(
7057 Set<InterfaceType> first, Set<InterfaceType> second) { 5056 Set<InterfaceType> first, Set<InterfaceType> second) {
7058 Set<InterfaceType> result = new HashSet<InterfaceType>.from(first); 5057 Set<InterfaceType> result = new HashSet<InterfaceType>.from(first);
7059 result.retainAll(second); 5058 result.retainAll(second);
7060 return new List.from(result); 5059 return new List.from(result);
7061 } 5060 }
7062 5061
7063 /** 5062 /**
5063 * Return the "least upper bound" of the given types under the assumption that
5064 * the types have the same element and differ only in terms of the type
5065 * arguments.
5066 *
5067 * The resulting type is composed by comparing the corresponding type
5068 * arguments, keeping those that are the same, and using 'dynamic' for those
5069 * that are different.
5070 */
5071 static InterfaceType _leastUpperBound(
5072 InterfaceType firstType, InterfaceType secondType) {
5073 ClassElement firstElement = firstType.element;
5074 ClassElement secondElement = secondType.element;
5075 if (firstElement != secondElement) {
5076 throw new IllegalArgumentException('The same elements expected, but '
5077 '$firstElement and $secondElement are given.');
5078 }
5079 if (firstType == secondType) {
5080 return firstType;
5081 }
5082 List<DartType> firstArguments = firstType.typeArguments;
5083 List<DartType> secondArguments = secondType.typeArguments;
5084 int argumentCount = firstArguments.length;
5085 if (argumentCount == 0) {
5086 return firstType;
5087 }
5088 List<DartType> lubArguments = new List<DartType>(argumentCount);
5089 for (int i = 0; i < argumentCount; i++) {
5090 //
5091 // Ideally we would take the least upper bound of the two argument types,
5092 // but this can cause an infinite recursion (such as when finding the
5093 // least upper bound of String and num).
5094 //
5095 if (firstArguments[i] == secondArguments[i]) {
5096 lubArguments[i] = firstArguments[i];
5097 }
5098 if (lubArguments[i] == null) {
5099 lubArguments[i] = DynamicTypeImpl.instance;
5100 }
5101 }
5102 InterfaceTypeImpl lub = new InterfaceTypeImpl(firstElement);
5103 lub.typeArguments = lubArguments;
5104 return lub;
5105 }
5106
5107 /**
7064 * Look up the getter with the given [name] in the interfaces 5108 * Look up the getter with the given [name] in the interfaces
7065 * implemented by the given [targetType], either directly or indirectly. 5109 * implemented by the given [targetType], either directly or indirectly.
7066 * Return the element representing the getter that was found, or `null` if 5110 * Return the element representing the getter that was found, or `null` if
7067 * there is no getter with the given name. The flag [includeTargetType] should 5111 * there is no getter with the given name. The flag [includeTargetType] should
7068 * be `true` if the search should include the target type. The 5112 * be `true` if the search should include the target type. The
7069 * [visitedInterfaces] is a set containing all of the interfaces that have 5113 * [visitedInterfaces] is a set containing all of the interfaces that have
7070 * been examined, used to prevent infinite recursion and to optimize the 5114 * been examined, used to prevent infinite recursion and to optimize the
7071 * search. 5115 * search.
7072 */ 5116 */
7073 static ExecutableElement _lookUpMemberInInterfaces( 5117 static ExecutableElement _lookUpMemberInInterfaces(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
7107 InterfaceType superclass = targetType.superclass; 5151 InterfaceType superclass = targetType.superclass;
7108 if (superclass == null) { 5152 if (superclass == null) {
7109 return null; 5153 return null;
7110 } 5154 }
7111 return _lookUpMemberInInterfaces( 5155 return _lookUpMemberInInterfaces(
7112 superclass, true, library, visitedInterfaces, getMember); 5156 superclass, true, library, visitedInterfaces, getMember);
7113 } 5157 }
7114 } 5158 }
7115 5159
7116 /** 5160 /**
7117 * A label associated with a statement.
7118 */
7119 abstract class LabelElement implements Element {
7120 /**
7121 * An empty list of label elements.
7122 */
7123 static const List<LabelElement> EMPTY_LIST = const <LabelElement>[];
7124
7125 /**
7126 * Return the executable element in which this label is defined.
7127 */
7128 @override
7129 ExecutableElement get enclosingElement;
7130 }
7131
7132 /**
7133 * A concrete implementation of a [LabelElement]. 5161 * A concrete implementation of a [LabelElement].
7134 */ 5162 */
7135 class LabelElementImpl extends ElementImpl implements LabelElement { 5163 class LabelElementImpl extends ElementImpl implements LabelElement {
7136 /** 5164 /**
7137 * A flag indicating whether this label is associated with a `switch` 5165 * A flag indicating whether this label is associated with a `switch`
7138 * statement. 5166 * statement.
7139 */ 5167 */
7140 // TODO(brianwilkerson) Make this a modifier. 5168 // TODO(brianwilkerson) Make this a modifier.
7141 final bool _onSwitchStatement; 5169 final bool _onSwitchStatement;
7142 5170
(...skipping 30 matching lines...) Expand all
7173 bool get isOnSwitchStatement => _onSwitchStatement; 5201 bool get isOnSwitchStatement => _onSwitchStatement;
7174 5202
7175 @override 5203 @override
7176 ElementKind get kind => ElementKind.LABEL; 5204 ElementKind get kind => ElementKind.LABEL;
7177 5205
7178 @override 5206 @override
7179 accept(ElementVisitor visitor) => visitor.visitLabelElement(this); 5207 accept(ElementVisitor visitor) => visitor.visitLabelElement(this);
7180 } 5208 }
7181 5209
7182 /** 5210 /**
7183 * A library.
7184 */
7185 abstract class LibraryElement implements Element {
7186 /**
7187 * An empty list of library elements.
7188 */
7189 static const List<LibraryElement> EMPTY_LIST = const <LibraryElement>[];
7190
7191 /**
7192 * Return the compilation unit that defines this library.
7193 */
7194 CompilationUnitElement get definingCompilationUnit;
7195
7196 /**
7197 * Return the entry point for this library, or `null` if this library does not
7198 * have an entry point. The entry point is defined to be a zero argument
7199 * top-level function whose name is `main`.
7200 */
7201 FunctionElement get entryPoint;
7202
7203 /**
7204 * Return a list containing all of the libraries that are exported from this
7205 * library.
7206 */
7207 List<LibraryElement> get exportedLibraries;
7208
7209 /**
7210 * The export [Namespace] of this library, `null` if it has not been
7211 * computed yet.
7212 */
7213 Namespace get exportNamespace;
7214
7215 /**
7216 * Return a list containing all of the exports defined in this library.
7217 */
7218 List<ExportElement> get exports;
7219
7220 /**
7221 * Return `true` if the defining compilation unit of this library contains at
7222 * least one import directive whose URI uses the "dart-ext" scheme.
7223 */
7224 bool get hasExtUri;
7225
7226 /**
7227 * Return `true` if this library defines a top-level function named
7228 * `loadLibrary`.
7229 */
7230 bool get hasLoadLibraryFunction;
7231
7232 /**
7233 * Return a list containing all of the libraries that are imported into this
7234 * library. This includes all of the libraries that are imported using a
7235 * prefix (also available through the prefixes returned by [getPrefixes]) and
7236 * those that are imported without a prefix.
7237 */
7238 List<LibraryElement> get importedLibraries;
7239
7240 /**
7241 * Return a list containing all of the imports defined in this library.
7242 */
7243 List<ImportElement> get imports;
7244
7245 /**
7246 * Return `true` if this library is an application that can be run in the
7247 * browser.
7248 */
7249 bool get isBrowserApplication;
7250
7251 /**
7252 * Return `true` if this library is the dart:core library.
7253 */
7254 bool get isDartCore;
7255
7256 /**
7257 * Return `true` if this library is part of the SDK.
7258 */
7259 bool get isInSdk;
7260
7261 /**
7262 * Return the element representing the synthetic function `loadLibrary` that
7263 * is implicitly defined for this library if the library is imported using a
7264 * deferred import.
7265 */
7266 FunctionElement get loadLibraryFunction;
7267
7268 /**
7269 * Return a list containing all of the compilation units that are included in
7270 * this library using a `part` directive. This does not include the defining
7271 * compilation unit that contains the `part` directives.
7272 */
7273 List<CompilationUnitElement> get parts;
7274
7275 /**
7276 * Return a list containing elements for each of the prefixes used to `import`
7277 * libraries into this library. Each prefix can be used in more than one
7278 * `import` directive.
7279 */
7280 List<PrefixElement> get prefixes;
7281
7282 /**
7283 * The public [Namespace] of this library, `null` if it has not been
7284 * computed yet.
7285 */
7286 Namespace get publicNamespace;
7287
7288 /**
7289 * Return a list containing all of the compilation units this library consists
7290 * of. This includes the defining compilation unit and units included using
7291 * the `part` directive.
7292 */
7293 List<CompilationUnitElement> get units;
7294
7295 /**
7296 * Return a list containing all directly and indirectly imported libraries.
7297 */
7298 List<LibraryElement> get visibleLibraries;
7299
7300 /**
7301 * Return a list containing all of the imports that share the given [prefix],
7302 * or an empty array if there are no such imports.
7303 */
7304 List<ImportElement> getImportsWithPrefix(PrefixElement prefix);
7305
7306 /**
7307 * Return the class defined in this library that has the given [name], or
7308 * `null` if this library does not define a class with the given name.
7309 */
7310 ClassElement getType(String className);
7311
7312 /**
7313 * Return `true` if this library is up to date with respect to the given
7314 * [timeStamp]. If any transitively referenced Source is newer than the time
7315 * stamp, this method returns false.
7316 */
7317 bool isUpToDate(int timeStamp);
7318 }
7319
7320 /**
7321 * A concrete implementation of a [LibraryElement]. 5211 * A concrete implementation of a [LibraryElement].
7322 */ 5212 */
7323 class LibraryElementImpl extends ElementImpl implements LibraryElement { 5213 class LibraryElementImpl extends ElementImpl implements LibraryElement {
7324 /** 5214 /**
7325 * The analysis context in which this library is defined. 5215 * The analysis context in which this library is defined.
7326 */ 5216 */
7327 final AnalysisContext context; 5217 final AnalysisContext context;
7328 5218
7329 /** 5219 /**
7330 * The compilation unit that defines this library. 5220 * The compilation unit that defines this library.
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
7831 (exportedLibrary as LibraryElementImpl) 5721 (exportedLibrary as LibraryElementImpl)
7832 ._addVisibleLibraries(visibleLibraries, true); 5722 ._addVisibleLibraries(visibleLibraries, true);
7833 } 5723 }
7834 } 5724 }
7835 } 5725 }
7836 } 5726 }
7837 5727
7838 /** 5728 /**
7839 * Return `true` if the given [library] is up to date with respect to the 5729 * Return `true` if the given [library] is up to date with respect to the
7840 * given [timeStamp]. The set of [visitedLibraries] is used to prevent 5730 * given [timeStamp]. The set of [visitedLibraries] is used to prevent
7841 * infinite recusion in the case of mutually dependent libraries. 5731 * infinite recursion in the case of mutually dependent libraries.
7842 */ 5732 */
7843 static bool _safeIsUpToDate(LibraryElement library, int timeStamp, 5733 static bool _safeIsUpToDate(LibraryElement library, int timeStamp,
7844 Set<LibraryElement> visitedLibraries) { 5734 Set<LibraryElement> visitedLibraries) {
7845 if (!visitedLibraries.contains(library)) { 5735 if (!visitedLibraries.contains(library)) {
7846 visitedLibraries.add(library); 5736 visitedLibraries.add(library);
7847 AnalysisContext context = library.context; 5737 AnalysisContext context = library.context;
7848 // Check the defining compilation unit. 5738 // Check the defining compilation unit.
7849 if (timeStamp < 5739 if (timeStamp <
7850 context 5740 context
7851 .getModificationStamp(library.definingCompilationUnit.source)) { 5741 .getModificationStamp(library.definingCompilationUnit.source)) {
(...skipping 16 matching lines...) Expand all
7868 if (!_safeIsUpToDate(exportedLibrary, timeStamp, visitedLibraries)) { 5758 if (!_safeIsUpToDate(exportedLibrary, timeStamp, visitedLibraries)) {
7869 return false; 5759 return false;
7870 } 5760 }
7871 } 5761 }
7872 } 5762 }
7873 return true; 5763 return true;
7874 } 5764 }
7875 } 5765 }
7876 5766
7877 /** 5767 /**
7878 * An element that can be (but are not required to be) defined within a method
7879 * or function (an [ExecutableElement]).
7880 */
7881 abstract class LocalElement implements Element {
7882 /**
7883 * Return a source range that covers the approximate portion of the source in
7884 * which the name of this element is visible, or `null` if there is no single
7885 * range of characters within which the element name is visible.
7886 *
7887 * * For a local variable, this includes everything from the end of the
7888 * variable's initializer to the end of the block that encloses the variable
7889 * declaration.
7890 * * For a parameter, this includes the body of the method or function that
7891 * declares the parameter.
7892 * * For a local function, this includes everything from the beginning of the
7893 * function's body to the end of the block that encloses the function
7894 * declaration.
7895 * * For top-level functions, `null` will be returned because they are
7896 * potentially visible in multiple sources.
7897 */
7898 SourceRange get visibleRange;
7899 }
7900
7901 /**
7902 * A local variable.
7903 */
7904 abstract class LocalVariableElement implements LocalElement, VariableElement {
7905 /**
7906 * An empty list of field elements.
7907 */
7908 static const List<LocalVariableElement> EMPTY_LIST =
7909 const <LocalVariableElement>[];
7910 }
7911
7912 /**
7913 * A concrete implementation of a [LocalVariableElement]. 5768 * A concrete implementation of a [LocalVariableElement].
7914 */ 5769 */
7915 class LocalVariableElementImpl extends VariableElementImpl 5770 class LocalVariableElementImpl extends VariableElementImpl
7916 implements LocalVariableElement { 5771 implements LocalVariableElement {
7917 /** 5772 /**
7918 * The offset to the beginning of the visible range for this element. 5773 * The offset to the beginning of the visible range for this element.
7919 */ 5774 */
7920 int _visibleRangeOffset = 0; 5775 int _visibleRangeOffset = 0;
7921 5776
7922 /** 5777 /**
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
8140 return type.substitute2(argumentTypes, parameterTypes); 5995 return type.substitute2(argumentTypes, parameterTypes);
8141 } 5996 }
8142 5997
8143 @override 5998 @override
8144 void visitChildren(ElementVisitor visitor) { 5999 void visitChildren(ElementVisitor visitor) {
8145 // There are no children to visit 6000 // There are no children to visit
8146 } 6001 }
8147 } 6002 }
8148 6003
8149 /** 6004 /**
8150 * An element that represents a method defined within a type.
8151 */
8152 abstract class MethodElement implements ClassMemberElement, ExecutableElement {
8153 /**
8154 * An empty list of method elements.
8155 */
8156 static const List<MethodElement> EMPTY_LIST = const <MethodElement>[];
8157
8158 /**
8159 * Return the resolved [MethodDeclaration] node that declares this
8160 * [MethodElement].
8161 *
8162 * This method is expensive, because resolved AST might be evicted from cache,
8163 * so parsing and resolving will be performed.
8164 */
8165 @override
8166 MethodDeclaration computeNode();
8167 }
8168
8169 /**
8170 * A concrete implementation of a [MethodElement]. 6005 * A concrete implementation of a [MethodElement].
8171 */ 6006 */
8172 class MethodElementImpl extends ExecutableElementImpl implements MethodElement { 6007 class MethodElementImpl extends ExecutableElementImpl implements MethodElement {
8173 /** 6008 /**
8174 * Initialize a newly created method element to have the given [name] at the 6009 * Initialize a newly created method element to have the given [name] at the
8175 * given [offset]. 6010 * given [offset].
8176 */ 6011 */
8177 MethodElementImpl(String name, int offset) : super(name, offset); 6012 MethodElementImpl(String name, int offset) : super(name, offset);
8178 6013
8179 /** 6014 /**
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
8290 buffer.write("("); 6125 buffer.write("(");
8291 int parameterCount = parameters.length; 6126 int parameterCount = parameters.length;
8292 for (int i = 0; i < parameterCount; i++) { 6127 for (int i = 0; i < parameterCount; i++) {
8293 if (i > 0) { 6128 if (i > 0) {
8294 buffer.write(", "); 6129 buffer.write(", ");
8295 } 6130 }
8296 buffer.write(parameters[i]); 6131 buffer.write(parameters[i]);
8297 } 6132 }
8298 buffer.write(")"); 6133 buffer.write(")");
8299 if (type != null) { 6134 if (type != null) {
8300 buffer.write(Element.RIGHT_ARROW); 6135 buffer.write(ElementImpl.RIGHT_ARROW);
8301 buffer.write(type.returnType); 6136 buffer.write(type.returnType);
8302 } 6137 }
8303 return buffer.toString(); 6138 return buffer.toString();
8304 } 6139 }
8305 6140
8306 /** 6141 /**
8307 * If the given [method]'s type is different when any type parameters from the 6142 * If the given [method]'s type is different when any type parameters from the
8308 * defining type's declaration are replaced with the actual type arguments 6143 * defining type's declaration are replaced with the actual type arguments
8309 * from the [definingType], create a method member representing the given 6144 * from the [definingType], create a method member representing the given
8310 * method. Return the member that was created, or the base method if no member 6145 * method. Return the member that was created, or the base method if no member
8311 * was created. 6146 * was created.
8312 */ 6147 */
8313 static MethodElement from(MethodElement method, InterfaceType definingType) { 6148 static MethodElement from(MethodElement method, InterfaceType definingType) {
8314 if (method == null || definingType.typeArguments.length == 0) { 6149 if (method == null || definingType.typeArguments.length == 0) {
8315 return method; 6150 return method;
8316 } 6151 }
8317 FunctionType baseType = method.type; 6152 FunctionType baseType = method.type;
8318 List<DartType> argumentTypes = definingType.typeArguments; 6153 List<DartType> argumentTypes = definingType.typeArguments;
8319 List<DartType> parameterTypes = definingType.element.type.typeArguments; 6154 List<DartType> parameterTypes = definingType.element.type.typeArguments;
8320 FunctionType substitutedType = 6155 FunctionType substitutedType =
8321 baseType.substitute2(argumentTypes, parameterTypes); 6156 baseType.substitute2(argumentTypes, parameterTypes);
8322 if (baseType == substitutedType) { 6157 if (baseType == substitutedType) {
8323 return method; 6158 return method;
8324 } 6159 }
8325 return new MethodMember(method, definingType, substitutedType); 6160 return new MethodMember(method, definingType, substitutedType);
8326 } 6161 }
8327 } 6162 }
8328 6163
8329 /** 6164 /**
8330 * The enumeration `Modifier` defines constants for all of the modifiers defined
8331 * by the Dart language and for a few additional flags that are useful.
8332 */
8333 class Modifier extends Enum<Modifier> {
8334 /**
8335 * Indicates that the modifier 'abstract' was applied to the element.
8336 */
8337 static const Modifier ABSTRACT = const Modifier('ABSTRACT', 0);
8338
8339 /**
8340 * Indicates that an executable element has a body marked as being
8341 * asynchronous.
8342 */
8343 static const Modifier ASYNCHRONOUS = const Modifier('ASYNCHRONOUS', 1);
8344
8345 /**
8346 * Indicates that the modifier 'const' was applied to the element.
8347 */
8348 static const Modifier CONST = const Modifier('CONST', 2);
8349
8350 /**
8351 * Indicates that the import element represents a deferred library.
8352 */
8353 static const Modifier DEFERRED = const Modifier('DEFERRED', 3);
8354
8355 /**
8356 * Indicates that a class element was defined by an enum declaration.
8357 */
8358 static const Modifier ENUM = const Modifier('ENUM', 4);
8359
8360 /**
8361 * Indicates that a class element was defined by an enum declaration.
8362 */
8363 static const Modifier EXTERNAL = const Modifier('EXTERNAL', 5);
8364
8365 /**
8366 * Indicates that the modifier 'factory' was applied to the element.
8367 */
8368 static const Modifier FACTORY = const Modifier('FACTORY', 6);
8369
8370 /**
8371 * Indicates that the modifier 'final' was applied to the element.
8372 */
8373 static const Modifier FINAL = const Modifier('FINAL', 7);
8374
8375 /**
8376 * Indicates that an executable element has a body marked as being a
8377 * generator.
8378 */
8379 static const Modifier GENERATOR = const Modifier('GENERATOR', 8);
8380
8381 /**
8382 * Indicates that the pseudo-modifier 'get' was applied to the element.
8383 */
8384 static const Modifier GETTER = const Modifier('GETTER', 9);
8385
8386 /**
8387 * A flag used for libraries indicating that the defining compilation unit
8388 * contains at least one import directive whose URI uses the "dart-ext"
8389 * scheme.
8390 */
8391 static const Modifier HAS_EXT_URI = const Modifier('HAS_EXT_URI', 10);
8392
8393 /**
8394 * Indicates that the associated element did not have an explicit type
8395 * associated with it. If the element is an [ExecutableElement], then the
8396 * type being referred to is the return type.
8397 */
8398 static const Modifier IMPLICIT_TYPE = const Modifier('IMPLICIT_TYPE', 11);
8399
8400 /**
8401 * Indicates that a class can validly be used as a mixin.
8402 */
8403 static const Modifier MIXIN = const Modifier('MIXIN', 12);
8404
8405 /**
8406 * Indicates that a class is a mixin application.
8407 */
8408 static const Modifier MIXIN_APPLICATION =
8409 const Modifier('MIXIN_APPLICATION', 13);
8410
8411 /**
8412 * Indicates that the value of a parameter or local variable might be mutated
8413 * within the context.
8414 */
8415 static const Modifier POTENTIALLY_MUTATED_IN_CONTEXT =
8416 const Modifier('POTENTIALLY_MUTATED_IN_CONTEXT', 14);
8417
8418 /**
8419 * Indicates that the value of a parameter or local variable might be mutated
8420 * within the scope.
8421 */
8422 static const Modifier POTENTIALLY_MUTATED_IN_SCOPE =
8423 const Modifier('POTENTIALLY_MUTATED_IN_SCOPE', 15);
8424
8425 /**
8426 * Indicates that a class contains an explicit reference to 'super'.
8427 */
8428 static const Modifier REFERENCES_SUPER =
8429 const Modifier('REFERENCES_SUPER', 16);
8430
8431 /**
8432 * Indicates that the pseudo-modifier 'set' was applied to the element.
8433 */
8434 static const Modifier SETTER = const Modifier('SETTER', 17);
8435
8436 /**
8437 * Indicates that the modifier 'static' was applied to the element.
8438 */
8439 static const Modifier STATIC = const Modifier('STATIC', 18);
8440
8441 /**
8442 * Indicates that the element does not appear in the source code but was
8443 * implicitly created. For example, if a class does not define any
8444 * constructors, an implicit zero-argument constructor will be created and it
8445 * will be marked as being synthetic.
8446 */
8447 static const Modifier SYNTHETIC = const Modifier('SYNTHETIC', 19);
8448
8449 static const List<Modifier> values = const [
8450 ABSTRACT,
8451 ASYNCHRONOUS,
8452 CONST,
8453 DEFERRED,
8454 ENUM,
8455 EXTERNAL,
8456 FACTORY,
8457 FINAL,
8458 GENERATOR,
8459 GETTER,
8460 HAS_EXT_URI,
8461 IMPLICIT_TYPE,
8462 MIXIN,
8463 MIXIN_APPLICATION,
8464 POTENTIALLY_MUTATED_IN_CONTEXT,
8465 POTENTIALLY_MUTATED_IN_SCOPE,
8466 REFERENCES_SUPER,
8467 SETTER,
8468 STATIC,
8469 SYNTHETIC
8470 ];
8471
8472 const Modifier(String name, int ordinal) : super(name, ordinal);
8473 }
8474
8475 /**
8476 * A pseudo-element that represents multiple elements defined within a single
8477 * scope that have the same name. This situation is not allowed by the language,
8478 * so objects implementing this interface always represent an error. As a
8479 * result, most of the normal operations on elements do not make sense and will
8480 * return useless results.
8481 */
8482 abstract class MultiplyDefinedElement implements Element {
8483 /**
8484 * Return a list containing all of the elements that were defined within the
8485 * scope to have the same name.
8486 */
8487 List<Element> get conflictingElements;
8488
8489 /**
8490 * Return the type of this element as the dynamic type.
8491 */
8492 DartType get type;
8493 }
8494
8495 /**
8496 * A concrete implementation of a [MultiplyDefinedElement]. 6165 * A concrete implementation of a [MultiplyDefinedElement].
8497 */ 6166 */
8498 class MultiplyDefinedElementImpl implements MultiplyDefinedElement { 6167 class MultiplyDefinedElementImpl implements MultiplyDefinedElement {
8499 /** 6168 /**
8500 * The unique integer identifier of this element. 6169 * The unique integer identifier of this element.
8501 */ 6170 */
8502 final int id = ElementImpl._NEXT_ID++; 6171 final int id = ElementImpl._NEXT_ID++;
8503 6172
8504 /** 6173 /**
8505 * The analysis context in which the multiply defined elements are defined. 6174 * The analysis context in which the multiply defined elements are defined.
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
8676 static List<Element> _computeConflictingElements( 6345 static List<Element> _computeConflictingElements(
8677 Element firstElement, Element secondElement) { 6346 Element firstElement, Element secondElement) {
8678 HashSet<Element> elements = new HashSet<Element>(); 6347 HashSet<Element> elements = new HashSet<Element>();
8679 _add(elements, firstElement); 6348 _add(elements, firstElement);
8680 _add(elements, secondElement); 6349 _add(elements, secondElement);
8681 return new List.from(elements); 6350 return new List.from(elements);
8682 } 6351 }
8683 } 6352 }
8684 6353
8685 /** 6354 /**
8686 * An [ExecutableElement], with the additional information of a list of
8687 * [ExecutableElement]s from which this element was composed.
8688 */
8689 abstract class MultiplyInheritedExecutableElement implements ExecutableElement {
8690 /**
8691 * Return a list containing all of the executable elements defined within this
8692 * executable element.
8693 */
8694 List<ExecutableElement> get inheritedElements;
8695 }
8696
8697 /**
8698 * A [MethodElementImpl], with the additional information of a list of 6355 * A [MethodElementImpl], with the additional information of a list of
8699 * [ExecutableElement]s from which this element was composed. 6356 * [ExecutableElement]s from which this element was composed.
8700 */ 6357 */
8701 class MultiplyInheritedMethodElementImpl extends MethodElementImpl 6358 class MultiplyInheritedMethodElementImpl extends MethodElementImpl
8702 implements MultiplyInheritedExecutableElement { 6359 implements MultiplyInheritedExecutableElement {
8703 /** 6360 /**
8704 * A list the array of executable elements that were used to compose this 6361 * A list the array of executable elements that were used to compose this
8705 * element. 6362 * element.
8706 */ 6363 */
8707 List<ExecutableElement> _elements = MethodElement.EMPTY_LIST; 6364 List<ExecutableElement> _elements = MethodElement.EMPTY_LIST;
(...skipping 30 matching lines...) Expand all
8738 6395
8739 @override 6396 @override
8740 List<ExecutableElement> get inheritedElements => _elements; 6397 List<ExecutableElement> get inheritedElements => _elements;
8741 6398
8742 void set inheritedElements(List<ExecutableElement> elements) { 6399 void set inheritedElements(List<ExecutableElement> elements) {
8743 this._elements = elements; 6400 this._elements = elements;
8744 } 6401 }
8745 } 6402 }
8746 6403
8747 /** 6404 /**
8748 * An object that controls how namespaces are combined.
8749 */
8750 abstract class NamespaceCombinator {
8751 /**
8752 * An empty list of namespace combinators.
8753 */
8754 static const List<NamespaceCombinator> EMPTY_LIST =
8755 const <NamespaceCombinator>[];
8756 }
8757
8758 /**
8759 * A parameter defined within an executable element.
8760 */
8761 abstract class ParameterElement
8762 implements LocalElement, VariableElement, ConstantEvaluationTarget {
8763 /**
8764 * An empty list of parameter elements.
8765 */
8766 static const List<ParameterElement> EMPTY_LIST = const <ParameterElement>[];
8767
8768 /**
8769 * Return the Dart code of the default value, or `null` if no default value.
8770 */
8771 String get defaultValueCode;
8772
8773 /**
8774 * Return `true` if this parameter is an initializing formal parameter.
8775 */
8776 bool get isInitializingFormal;
8777
8778 /**
8779 * Return the kind of this parameter.
8780 */
8781 ParameterKind get parameterKind;
8782
8783 /**
8784 * Return a list containing all of the parameters defined by this parameter.
8785 * A parameter will only define other parameters if it is a function typed
8786 * parameter.
8787 */
8788 List<ParameterElement> get parameters;
8789
8790 /**
8791 * Return a list containing all of the type parameters defined by this
8792 * parameter. A parameter will only define other parameters if it is a
8793 * function typed parameter.
8794 */
8795 List<TypeParameterElement> get typeParameters;
8796
8797 /**
8798 * Append the type, name and possibly the default value of this parameter to
8799 * the given [buffer].
8800 */
8801 void appendToWithoutDelimiters(StringBuffer buffer);
8802
8803 @override
8804 FormalParameter computeNode();
8805 }
8806
8807 /**
8808 * A concrete implementation of a [ParameterElement]. 6405 * A concrete implementation of a [ParameterElement].
8809 */ 6406 */
8810 class ParameterElementImpl extends VariableElementImpl 6407 class ParameterElementImpl extends VariableElementImpl
8811 with ParameterElementMixin 6408 with ParameterElementMixin
8812 implements ParameterElement { 6409 implements ParameterElement {
8813 /** 6410 /**
8814 * A list containing all of the parameters defined by this parameter element. 6411 * A list containing all of the parameters defined by this parameter element.
8815 * There will only be parameters if this parameter is a function typed 6412 * There will only be parameters if this parameter is a function typed
8816 * parameter. 6413 * parameter.
8817 */ 6414 */
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
8998 } 6595 }
8999 if (parameterKind == ParameterKind.POSITIONAL) { 6596 if (parameterKind == ParameterKind.POSITIONAL) {
9000 buffer.write(" = "); 6597 buffer.write(" = ");
9001 } 6598 }
9002 buffer.write(defaultValueCode); 6599 buffer.write(defaultValueCode);
9003 } 6600 }
9004 } 6601 }
9005 } 6602 }
9006 6603
9007 /** 6604 /**
9008 * A type with type parameters, such as a class or function type alias.
9009 */
9010 abstract class ParameterizedType implements DartType {
9011 /**
9012 * Return a list containing the actual types of the type arguments. If this
9013 * type's element does not have type parameters, then the array should be
9014 * empty (although it is possible for type arguments to be erroneously
9015 * declared). If the element has type parameters and the actual type does not
9016 * explicitly include argument values, then the type "dynamic" will be
9017 * automatically provided.
9018 */
9019 List<DartType> get typeArguments;
9020
9021 /**
9022 * Return a list containing all of the type parameters declared for this type.
9023 */
9024 List<TypeParameterElement> get typeParameters;
9025 }
9026
9027 /**
9028 * A parameter element defined in a parameterized type where the values of the 6605 * A parameter element defined in a parameterized type where the values of the
9029 * type parameters are known. 6606 * type parameters are known.
9030 */ 6607 */
9031 class ParameterMember extends VariableMember 6608 class ParameterMember extends VariableMember
9032 with ParameterElementMixin 6609 with ParameterElementMixin
9033 implements ParameterElement { 6610 implements ParameterElement {
9034 /** 6611 /**
9035 * Initialize a newly created element to represent a parameter, based on the 6612 * Initialize a newly created element to represent a parameter, based on the
9036 * [baseElement], defined by the [definingType]. If [type] is passed it will 6613 * [baseElement], defined by the [definingType]. If [type] is passed it will
9037 * represent the already substituted type. 6614 * represent the already substituted type.
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
9152 baseType.substitute2(argumentTypes, parameterTypes); 6729 baseType.substitute2(argumentTypes, parameterTypes);
9153 if (baseType == substitutedType) { 6730 if (baseType == substitutedType) {
9154 return parameter; 6731 return parameter;
9155 } 6732 }
9156 return new ParameterMember(parameter, definingType, substitutedType); 6733 return new ParameterMember(parameter, definingType, substitutedType);
9157 } 6734 }
9158 } 6735 }
9159 } 6736 }
9160 6737
9161 /** 6738 /**
9162 * A prefix used to import one or more libraries into another library.
9163 */
9164 abstract class PrefixElement implements Element {
9165 /**
9166 * An empty list of prefix elements.
9167 */
9168 static const List<PrefixElement> EMPTY_LIST = const <PrefixElement>[];
9169
9170 /**
9171 * Return the library into which other libraries are imported using this
9172 * prefix.
9173 */
9174 @override
9175 LibraryElement get enclosingElement;
9176
9177 /**
9178 * Return a list containing all of the libraries that are imported using this
9179 * prefix.
9180 */
9181 List<LibraryElement> get importedLibraries;
9182 }
9183
9184 /**
9185 * A concrete implementation of a [PrefixElement]. 6739 * A concrete implementation of a [PrefixElement].
9186 */ 6740 */
9187 class PrefixElementImpl extends ElementImpl implements PrefixElement { 6741 class PrefixElementImpl extends ElementImpl implements PrefixElement {
9188 /** 6742 /**
9189 * A list containing all of the libraries that are imported using this prefix. 6743 * A list containing all of the libraries that are imported using this prefix.
9190 */ 6744 */
9191 List<LibraryElement> _importedLibraries = LibraryElement.EMPTY_LIST; 6745 List<LibraryElement> _importedLibraries = LibraryElement.EMPTY_LIST;
9192 6746
9193 /** 6747 /**
9194 * Initialize a newly created method element to have the given [name] and 6748 * Initialize a newly created method element to have the given [name] and
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
9229 accept(ElementVisitor visitor) => visitor.visitPrefixElement(this); 6783 accept(ElementVisitor visitor) => visitor.visitPrefixElement(this);
9230 6784
9231 @override 6785 @override
9232 void appendTo(StringBuffer buffer) { 6786 void appendTo(StringBuffer buffer) {
9233 buffer.write("as "); 6787 buffer.write("as ");
9234 super.appendTo(buffer); 6788 super.appendTo(buffer);
9235 } 6789 }
9236 } 6790 }
9237 6791
9238 /** 6792 /**
9239 * A getter or a setter. Note that explicitly defined property accessors
9240 * implicitly define a synthetic field. Symmetrically, synthetic accessors are
9241 * implicitly created for explicitly defined fields. The following rules apply:
9242 *
9243 * * Every explicit field is represented by a non-synthetic [FieldElement].
9244 * * Every explicit field induces a getter and possibly a setter, both of which
9245 * are represented by synthetic [PropertyAccessorElement]s.
9246 * * Every explicit getter or setter is represented by a non-synthetic
9247 * [PropertyAccessorElement].
9248 * * Every explicit getter or setter (or pair thereof if they have the same
9249 * name) induces a field that is represented by a synthetic [FieldElement].
9250 */
9251 abstract class PropertyAccessorElement implements ExecutableElement {
9252 /**
9253 * An empty list of property accessor elements.
9254 */
9255 static const List<PropertyAccessorElement> EMPTY_LIST =
9256 const <PropertyAccessorElement>[];
9257
9258 /**
9259 * Return the accessor representing the getter that corresponds to (has the
9260 * same name as) this setter, or `null` if this accessor is not a setter or if
9261 * there is no corresponding getter.
9262 */
9263 PropertyAccessorElement get correspondingGetter;
9264
9265 /**
9266 * Return the accessor representing the setter that corresponds to (has the
9267 * same name as) this getter, or `null` if this accessor is not a getter or if
9268 * there is no corresponding setter.
9269 */
9270 PropertyAccessorElement get correspondingSetter;
9271
9272 /**
9273 * Return `true` if this accessor represents a getter.
9274 */
9275 bool get isGetter;
9276
9277 /**
9278 * Return `true` if this accessor represents a setter.
9279 */
9280 bool get isSetter;
9281
9282 /**
9283 * Return the field or top-level variable associated with this accessor. If
9284 * this accessor was explicitly defined (is not synthetic) then the variable
9285 * associated with it will be synthetic.
9286 */
9287 PropertyInducingElement get variable;
9288 }
9289
9290 /**
9291 * A concrete implementation of a [PropertyAccessorElement]. 6793 * A concrete implementation of a [PropertyAccessorElement].
9292 */ 6794 */
9293 class PropertyAccessorElementImpl extends ExecutableElementImpl 6795 class PropertyAccessorElementImpl extends ExecutableElementImpl
9294 implements PropertyAccessorElement { 6796 implements PropertyAccessorElement {
9295 /** 6797 /**
9296 * The variable associated with this accessor. 6798 * The variable associated with this accessor.
9297 */ 6799 */
9298 PropertyInducingElement variable; 6800 PropertyInducingElement variable;
9299 6801
9300 /** 6802 /**
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
9490 builder.write("("); 6992 builder.write("(");
9491 int parameterCount = parameters.length; 6993 int parameterCount = parameters.length;
9492 for (int i = 0; i < parameterCount; i++) { 6994 for (int i = 0; i < parameterCount; i++) {
9493 if (i > 0) { 6995 if (i > 0) {
9494 builder.write(", "); 6996 builder.write(", ");
9495 } 6997 }
9496 builder.write(parameters[i]); 6998 builder.write(parameters[i]);
9497 } 6999 }
9498 builder.write(")"); 7000 builder.write(")");
9499 if (type != null) { 7001 if (type != null) {
9500 builder.write(Element.RIGHT_ARROW); 7002 builder.write(ElementImpl.RIGHT_ARROW);
9501 builder.write(type.returnType); 7003 builder.write(type.returnType);
9502 } 7004 }
9503 return builder.toString(); 7005 return builder.toString();
9504 } 7006 }
9505 7007
9506 /** 7008 /**
9507 * If the given [accessor]'s type is different when any type parameters from 7009 * If the given [accessor]'s type is different when any type parameters from
9508 * the defining type's declaration are replaced with the actual type 7010 * the defining type's declaration are replaced with the actual type
9509 * arguments from the [definingType], create an accessor member representing 7011 * arguments from the [definingType], create an accessor member representing
9510 * the given accessor. Return the member that was created, or the base 7012 * the given accessor. Return the member that was created, or the base
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
9555 return true; 7057 return true;
9556 } 7058 }
9557 } 7059 }
9558 } 7060 }
9559 } 7061 }
9560 return false; 7062 return false;
9561 } 7063 }
9562 } 7064 }
9563 7065
9564 /** 7066 /**
9565 * A variable that has an associated getter and possibly a setter. Note that
9566 * explicitly defined variables implicitly define a synthetic getter and that
9567 * non-`final` explicitly defined variables implicitly define a synthetic
9568 * setter. Symmetrically, synthetic fields are implicitly created for explicitly
9569 * defined getters and setters. The following rules apply:
9570 *
9571 * * Every explicit variable is represented by a non-synthetic
9572 * [PropertyInducingElement].
9573 * * Every explicit variable induces a getter and possibly a setter, both of
9574 * which are represented by synthetic [PropertyAccessorElement]s.
9575 * * Every explicit getter or setter is represented by a non-synthetic
9576 * [PropertyAccessorElement].
9577 * * Every explicit getter or setter (or pair thereof if they have the same
9578 * name) induces a variable that is represented by a synthetic
9579 * [PropertyInducingElement].
9580 */
9581 abstract class PropertyInducingElement implements VariableElement {
9582 /**
9583 * An empty list of elements.
9584 */
9585 static const List<PropertyInducingElement> EMPTY_LIST =
9586 const <PropertyInducingElement>[];
9587
9588 /**
9589 * Return the getter associated with this variable. If this variable was
9590 * explicitly defined (is not synthetic) then the getter associated with it
9591 * will be synthetic.
9592 */
9593 PropertyAccessorElement get getter;
9594
9595 /**
9596 * Return the propagated type of this variable, or `null` if type propagation
9597 * has not been performed, for example because the variable is not final.
9598 */
9599 DartType get propagatedType;
9600
9601 /**
9602 * Return the setter associated with this variable, or `null` if the variable
9603 * is effectively `final` and therefore does not have a setter associated with
9604 * it. (This can happen either because the variable is explicitly defined as
9605 * being `final` or because the variable is induced by an explicit getter that
9606 * does not have a corresponding setter.) If this variable was explicitly
9607 * defined (is not synthetic) then the setter associated with it will be
9608 * synthetic.
9609 */
9610 PropertyAccessorElement get setter;
9611 }
9612
9613 /**
9614 * A concrete implementation of a [PropertyInducingElement]. 7067 * A concrete implementation of a [PropertyInducingElement].
9615 */ 7068 */
9616 abstract class PropertyInducingElementImpl extends VariableElementImpl 7069 abstract class PropertyInducingElementImpl extends VariableElementImpl
9617 implements PropertyInducingElement { 7070 implements PropertyInducingElement {
9618 /** 7071 /**
9619 * The getter associated with this element. 7072 * The getter associated with this element.
9620 */ 7073 */
9621 PropertyAccessorElement getter; 7074 PropertyAccessorElement getter;
9622 7075
9623 /** 7076 /**
(...skipping 15 matching lines...) Expand all
9639 */ 7092 */
9640 PropertyInducingElementImpl(String name, int offset) : super(name, offset); 7093 PropertyInducingElementImpl(String name, int offset) : super(name, offset);
9641 7094
9642 /** 7095 /**
9643 * Initialize a newly created element to have the given [name]. 7096 * Initialize a newly created element to have the given [name].
9644 */ 7097 */
9645 PropertyInducingElementImpl.forNode(Identifier name) : super.forNode(name); 7098 PropertyInducingElementImpl.forNode(Identifier name) : super.forNode(name);
9646 } 7099 }
9647 7100
9648 /** 7101 /**
9649 * A visitor that will recursively visit all of the element in an element model.
9650 * For example, using an instance of this class to visit a
9651 * [CompilationUnitElement] will also cause all of the types in the compilation
9652 * unit to be visited.
9653 *
9654 * Subclasses that override a visit method must either invoke the overridden
9655 * visit method or must explicitly ask the visited element to visit its
9656 * children. Failure to do so will cause the children of the visited element to
9657 * not be visited.
9658 */
9659 class RecursiveElementVisitor<R> implements ElementVisitor<R> {
9660 @override
9661 R visitClassElement(ClassElement element) {
9662 element.visitChildren(this);
9663 return null;
9664 }
9665
9666 @override
9667 R visitCompilationUnitElement(CompilationUnitElement element) {
9668 element.visitChildren(this);
9669 return null;
9670 }
9671
9672 @override
9673 R visitConstructorElement(ConstructorElement element) {
9674 element.visitChildren(this);
9675 return null;
9676 }
9677
9678 @override
9679 R visitExportElement(ExportElement element) {
9680 element.visitChildren(this);
9681 return null;
9682 }
9683
9684 @override
9685 R visitFieldElement(FieldElement element) {
9686 element.visitChildren(this);
9687 return null;
9688 }
9689
9690 @override
9691 R visitFieldFormalParameterElement(FieldFormalParameterElement element) {
9692 element.visitChildren(this);
9693 return null;
9694 }
9695
9696 @override
9697 R visitFunctionElement(FunctionElement element) {
9698 element.visitChildren(this);
9699 return null;
9700 }
9701
9702 @override
9703 R visitFunctionTypeAliasElement(FunctionTypeAliasElement element) {
9704 element.visitChildren(this);
9705 return null;
9706 }
9707
9708 @override
9709 R visitImportElement(ImportElement element) {
9710 element.visitChildren(this);
9711 return null;
9712 }
9713
9714 @override
9715 R visitLabelElement(LabelElement element) {
9716 element.visitChildren(this);
9717 return null;
9718 }
9719
9720 @override
9721 R visitLibraryElement(LibraryElement element) {
9722 element.visitChildren(this);
9723 return null;
9724 }
9725
9726 @override
9727 R visitLocalVariableElement(LocalVariableElement element) {
9728 element.visitChildren(this);
9729 return null;
9730 }
9731
9732 @override
9733 R visitMethodElement(MethodElement element) {
9734 element.visitChildren(this);
9735 return null;
9736 }
9737
9738 @override
9739 R visitMultiplyDefinedElement(MultiplyDefinedElement element) {
9740 element.visitChildren(this);
9741 return null;
9742 }
9743
9744 @override
9745 R visitParameterElement(ParameterElement element) {
9746 element.visitChildren(this);
9747 return null;
9748 }
9749
9750 @override
9751 R visitPrefixElement(PrefixElement element) {
9752 element.visitChildren(this);
9753 return null;
9754 }
9755
9756 @override
9757 R visitPropertyAccessorElement(PropertyAccessorElement element) {
9758 element.visitChildren(this);
9759 return null;
9760 }
9761
9762 @override
9763 R visitTopLevelVariableElement(TopLevelVariableElement element) {
9764 element.visitChildren(this);
9765 return null;
9766 }
9767
9768 @override
9769 R visitTypeParameterElement(TypeParameterElement element) {
9770 element.visitChildren(this);
9771 return null;
9772 }
9773 }
9774
9775 /**
9776 * A combinator that cause some of the names in a namespace to be visible (and
9777 * the rest hidden) when being imported.
9778 */
9779 abstract class ShowElementCombinator implements NamespaceCombinator {
9780 /**
9781 * Return the offset of the character immediately following the last character
9782 * of this node.
9783 */
9784 int get end;
9785
9786 /**
9787 * Return the offset of the 'show' keyword of this element.
9788 */
9789 int get offset;
9790
9791 /**
9792 * Return a list containing the names that are to be made visible in the
9793 * importing library if they are defined in the imported library.
9794 */
9795 List<String> get shownNames;
9796 }
9797
9798 /**
9799 * A concrete implementation of a [ShowElementCombinator]. 7102 * A concrete implementation of a [ShowElementCombinator].
9800 */ 7103 */
9801 class ShowElementCombinatorImpl implements ShowElementCombinator { 7104 class ShowElementCombinatorImpl implements ShowElementCombinator {
9802 /** 7105 /**
9803 * The names that are to be made visible in the importing library if they are 7106 * The names that are to be made visible in the importing library if they are
9804 * defined in the imported library. 7107 * defined in the imported library.
9805 */ 7108 */
9806 List<String> shownNames = StringUtilities.EMPTY_ARRAY; 7109 List<String> shownNames = StringUtilities.EMPTY_ARRAY;
9807 7110
9808 /** 7111 /**
(...skipping 16 matching lines...) Expand all
9825 if (i > 0) { 7128 if (i > 0) {
9826 buffer.write(", "); 7129 buffer.write(", ");
9827 } 7130 }
9828 buffer.write(shownNames[i]); 7131 buffer.write(shownNames[i]);
9829 } 7132 }
9830 return buffer.toString(); 7133 return buffer.toString();
9831 } 7134 }
9832 } 7135 }
9833 7136
9834 /** 7137 /**
9835 * A visitor that will do nothing when visiting an element. It is intended to be
9836 * a superclass for classes that use the visitor pattern primarily as a dispatch
9837 * mechanism (and hence don't need to recursively visit a whole structure) and
9838 * that only need to visit a small number of element types.
9839 */
9840 class SimpleElementVisitor<R> implements ElementVisitor<R> {
9841 @override
9842 R visitClassElement(ClassElement element) => null;
9843
9844 @override
9845 R visitCompilationUnitElement(CompilationUnitElement element) => null;
9846
9847 @override
9848 R visitConstructorElement(ConstructorElement element) => null;
9849
9850 @override
9851 R visitExportElement(ExportElement element) => null;
9852
9853 @override
9854 R visitFieldElement(FieldElement element) => null;
9855
9856 @override
9857 R visitFieldFormalParameterElement(FieldFormalParameterElement element) =>
9858 null;
9859
9860 @override
9861 R visitFunctionElement(FunctionElement element) => null;
9862
9863 @override
9864 R visitFunctionTypeAliasElement(FunctionTypeAliasElement element) => null;
9865
9866 @override
9867 R visitImportElement(ImportElement element) => null;
9868
9869 @override
9870 R visitLabelElement(LabelElement element) => null;
9871
9872 @override
9873 R visitLibraryElement(LibraryElement element) => null;
9874
9875 @override
9876 R visitLocalVariableElement(LocalVariableElement element) => null;
9877
9878 @override
9879 R visitMethodElement(MethodElement element) => null;
9880
9881 @override
9882 R visitMultiplyDefinedElement(MultiplyDefinedElement element) => null;
9883
9884 @override
9885 R visitParameterElement(ParameterElement element) => null;
9886
9887 @override
9888 R visitPrefixElement(PrefixElement element) => null;
9889
9890 @override
9891 R visitPropertyAccessorElement(PropertyAccessorElement element) => null;
9892
9893 @override
9894 R visitTopLevelVariableElement(TopLevelVariableElement element) => null;
9895
9896 @override
9897 R visitTypeParameterElement(TypeParameterElement element) => null;
9898 }
9899
9900 /**
9901 * A top-level variable.
9902 */
9903 abstract class TopLevelVariableElement implements PropertyInducingElement {
9904 /**
9905 * An empty list of top-level variable elements.
9906 */
9907 static const List<TopLevelVariableElement> EMPTY_LIST =
9908 const <TopLevelVariableElement>[];
9909
9910 @override
9911 VariableDeclaration computeNode();
9912 }
9913
9914 /**
9915 * A concrete implementation of a [TopLevelVariableElement]. 7138 * A concrete implementation of a [TopLevelVariableElement].
9916 */ 7139 */
9917 class TopLevelVariableElementImpl extends PropertyInducingElementImpl 7140 class TopLevelVariableElementImpl extends PropertyInducingElementImpl
9918 implements TopLevelVariableElement { 7141 implements TopLevelVariableElement {
9919 /** 7142 /**
9920 * Initialize a newly created synthetic top-level variable element to have the 7143 * Initialize a newly created synthetic top-level variable element to have the
9921 * given [name] and [offset]. 7144 * given [name] and [offset].
9922 */ 7145 */
9923 TopLevelVariableElementImpl(String name, int offset) : super(name, offset); 7146 TopLevelVariableElementImpl(String name, int offset) : super(name, offset);
9924 7147
(...skipping 11 matching lines...) Expand all
9936 7159
9937 @override 7160 @override
9938 accept(ElementVisitor visitor) => visitor.visitTopLevelVariableElement(this); 7161 accept(ElementVisitor visitor) => visitor.visitTopLevelVariableElement(this);
9939 7162
9940 @override 7163 @override
9941 VariableDeclaration computeNode() => 7164 VariableDeclaration computeNode() =>
9942 getNodeMatching((node) => node is VariableDeclaration); 7165 getNodeMatching((node) => node is VariableDeclaration);
9943 } 7166 }
9944 7167
9945 /** 7168 /**
9946 * An element that defines a type.
9947 */
9948 abstract class TypeDefiningElement implements Element {
9949 /**
9950 * Return the type defined by this element.
9951 */
9952 DartType get type;
9953 }
9954
9955 /**
9956 * The abstract class `TypeImpl` implements the behavior common to objects 7169 * The abstract class `TypeImpl` implements the behavior common to objects
9957 * representing the declared type of elements in the element model. 7170 * representing the declared type of elements in the element model.
9958 */ 7171 */
9959 abstract class TypeImpl implements DartType { 7172 abstract class TypeImpl implements DartType {
9960 /** 7173 /**
9961 * The element representing the declaration of this type, or `null` if the 7174 * The element representing the declaration of this type, or `null` if the
9962 * type has not, or cannot, be associated with an element. 7175 * type has not, or cannot, be associated with an element.
9963 */ 7176 */
9964 final Element _element; 7177 final Element _element;
9965 7178
(...skipping 27 matching lines...) Expand all
9993 bool get isObject => false; 7206 bool get isObject => false;
9994 7207
9995 @override 7208 @override
9996 bool get isUndefined => false; 7209 bool get isUndefined => false;
9997 7210
9998 @override 7211 @override
9999 bool get isVoid => false; 7212 bool get isVoid => false;
10000 7213
10001 /** 7214 /**
10002 * Append a textual representation of this type to the given [buffer]. The set 7215 * Append a textual representation of this type to the given [buffer]. The set
10003 * of [visitedTypes] is used to prevent infinite recusion. 7216 * of [visitedTypes] is used to prevent infinite recursion.
10004 */ 7217 */
10005 void appendTo(StringBuffer buffer) { 7218 void appendTo(StringBuffer buffer) {
10006 if (name == null) { 7219 if (name == null) {
10007 buffer.write("<unnamed type>"); 7220 buffer.write("<unnamed type>");
10008 } else { 7221 } else {
10009 buffer.write(name); 7222 buffer.write(name);
10010 } 7223 }
10011 } 7224 }
10012 7225
10013 /** 7226 /**
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
10143 List<DartType> newTypes = new List<DartType>(length); 7356 List<DartType> newTypes = new List<DartType>(length);
10144 for (int i = 0; i < length; i++) { 7357 for (int i = 0; i < length; i++) {
10145 newTypes[i] = (types[i] as TypeImpl) 7358 newTypes[i] = (types[i] as TypeImpl)
10146 .substitute2(argumentTypes, parameterTypes, prune); 7359 .substitute2(argumentTypes, parameterTypes, prune);
10147 } 7360 }
10148 return newTypes; 7361 return newTypes;
10149 } 7362 }
10150 } 7363 }
10151 7364
10152 /** 7365 /**
10153 * A type parameter.
10154 */
10155 abstract class TypeParameterElement implements TypeDefiningElement {
10156 /**
10157 * An empty list of type parameter elements.
10158 */
10159 static const List<TypeParameterElement> EMPTY_LIST =
10160 const <TypeParameterElement>[];
10161
10162 /**
10163 * Return the type representing the bound associated with this parameter, or
10164 * `null` if this parameter does not have an explicit bound.
10165 */
10166 DartType get bound;
10167
10168 /**
10169 * Return the type defined by this type parameter.
10170 */
10171 TypeParameterType get type;
10172 }
10173
10174 /**
10175 * A concrete implementation of a [TypeParameterElement]. 7366 * A concrete implementation of a [TypeParameterElement].
10176 */ 7367 */
10177 class TypeParameterElementImpl extends ElementImpl 7368 class TypeParameterElementImpl extends ElementImpl
10178 implements TypeParameterElement { 7369 implements TypeParameterElement {
10179 /** 7370 /**
10180 * The type defined by this type parameter. 7371 * The type defined by this type parameter.
10181 */ 7372 */
10182 TypeParameterType type; 7373 TypeParameterType type;
10183 7374
10184 /** 7375 /**
(...skipping 23 matching lines...) Expand all
10208 void appendTo(StringBuffer buffer) { 7399 void appendTo(StringBuffer buffer) {
10209 buffer.write(displayName); 7400 buffer.write(displayName);
10210 if (bound != null) { 7401 if (bound != null) {
10211 buffer.write(" extends "); 7402 buffer.write(" extends ");
10212 buffer.write(bound); 7403 buffer.write(bound);
10213 } 7404 }
10214 } 7405 }
10215 } 7406 }
10216 7407
10217 /** 7408 /**
10218 * An element that has type parameters.
10219 *
10220 * For example, a class or a typedef. This also includes functions and methods
10221 * if support for generic methods is enabled.
10222 */
10223 abstract class TypeParameterizedElement implements Element {
10224 /**
10225 * Return a list containing all of the type parameters declared for this
10226 * class.
10227 */
10228 List<TypeParameterElement> get typeParameters;
10229 }
10230
10231 /**
10232 * The type introduced by a type parameter.
10233 */
10234 abstract class TypeParameterType implements DartType {
10235 /**
10236 * An empty list of type parameter types.
10237 */
10238 static const List<TypeParameterType> EMPTY_LIST = const <TypeParameterType>[];
10239
10240 @override
10241 TypeParameterElement get element;
10242 }
10243
10244 /**
10245 * A concrete implementation of a [TypeParameterType]. 7409 * A concrete implementation of a [TypeParameterType].
10246 */ 7410 */
10247 class TypeParameterTypeImpl extends TypeImpl implements TypeParameterType { 7411 class TypeParameterTypeImpl extends TypeImpl implements TypeParameterType {
10248 /** 7412 /**
10249 * Initialize a newly created type parameter type to be declared by the given 7413 * Initialize a newly created type parameter type to be declared by the given
10250 * [element] and to have the given name. 7414 * [element] and to have the given name.
10251 */ 7415 */
10252 TypeParameterTypeImpl(TypeParameterElement element) 7416 TypeParameterTypeImpl(TypeParameterElement element)
10253 : super(element, element.name); 7417 : super(element, element.name);
10254 7418
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
10347 } 7511 }
10348 List<TypeParameterType> types = new List<TypeParameterType>(count); 7512 List<TypeParameterType> types = new List<TypeParameterType>(count);
10349 for (int i = 0; i < count; i++) { 7513 for (int i = 0; i < count; i++) {
10350 types[i] = typeParameters[i].type; 7514 types[i] = typeParameters[i].type;
10351 } 7515 }
10352 return types; 7516 return types;
10353 } 7517 }
10354 } 7518 }
10355 7519
10356 /** 7520 /**
10357 * A pseudo-elements that represents names that are undefined. This situation is
10358 * not allowed by the language, so objects implementing this interface always
10359 * represent an error. As a result, most of the normal operations on elements do
10360 * not make sense and will return useless results.
10361 */
10362 abstract class UndefinedElement implements Element {}
10363
10364 /**
10365 * The unique instance of the class `UndefinedTypeImpl` implements the type of 7521 * The unique instance of the class `UndefinedTypeImpl` implements the type of
10366 * typenames that couldn't be resolved. 7522 * type names that couldn't be resolved.
10367 * 7523 *
10368 * This class behaves like DynamicTypeImpl in almost every respect, to reduce 7524 * This class behaves like DynamicTypeImpl in almost every respect, to reduce
10369 * cascading errors. 7525 * cascading errors.
10370 */ 7526 */
10371 class UndefinedTypeImpl extends TypeImpl { 7527 class UndefinedTypeImpl extends TypeImpl {
10372 /** 7528 /**
10373 * The unique instance of this class. 7529 * The unique instance of this class.
10374 */ 7530 */
10375 static UndefinedTypeImpl _INSTANCE = new UndefinedTypeImpl._(); 7531 static UndefinedTypeImpl _INSTANCE = new UndefinedTypeImpl._();
10376 7532
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
10425 for (int i = 0; i < length; i++) { 7581 for (int i = 0; i < length; i++) {
10426 if (parameterTypes[i] == this) { 7582 if (parameterTypes[i] == this) {
10427 return argumentTypes[i]; 7583 return argumentTypes[i];
10428 } 7584 }
10429 } 7585 }
10430 return this; 7586 return this;
10431 } 7587 }
10432 } 7588 }
10433 7589
10434 /** 7590 /**
10435 * An element included into a library using some URI.
10436 */
10437 abstract class UriReferencedElement implements Element {
10438 /**
10439 * Return the URI that is used to include this element into the enclosing
10440 * library, or `null` if this is the defining compilation unit of a library.
10441 */
10442 String get uri;
10443
10444 /**
10445 * Return the offset of the character immediately following the last character
10446 * of this node's URI, or `-1` for synthetic import.
10447 */
10448 int get uriEnd;
10449
10450 /**
10451 * Return the offset of the URI in the file, or `-1` if this element is
10452 * synthetic.
10453 */
10454 int get uriOffset;
10455 }
10456
10457 /**
10458 * A concrete implementation of a [UriReferencedElement]. 7591 * A concrete implementation of a [UriReferencedElement].
10459 */ 7592 */
10460 abstract class UriReferencedElementImpl extends ElementImpl 7593 abstract class UriReferencedElementImpl extends ElementImpl
10461 implements UriReferencedElement { 7594 implements UriReferencedElement {
10462 /** 7595 /**
10463 * The offset of the URI in the file, may be `-1` if synthetic. 7596 * The offset of the URI in the file, may be `-1` if synthetic.
10464 */ 7597 */
10465 int uriOffset = -1; 7598 int uriOffset = -1;
10466 7599
10467 /** 7600 /**
10468 * The offset of the character immediately following the last character of 7601 * The offset of the character immediately following the last character of
10469 * this node's URI, may be `-1` if synthetic. 7602 * this node's URI, may be `-1` if synthetic.
10470 */ 7603 */
10471 int uriEnd = -1; 7604 int uriEnd = -1;
10472 7605
10473 /** 7606 /**
10474 * The URI that is specified by this directive. 7607 * The URI that is specified by this directive.
10475 */ 7608 */
10476 String uri; 7609 String uri;
10477 7610
10478 /** 7611 /**
10479 * Initialize a newly created import element to heve the given [name] and 7612 * Initialize a newly created import element to have the given [name] and
10480 * [offset]. The offset may be `-1` if the element is synthetic. 7613 * [offset]. The offset may be `-1` if the element is synthetic.
10481 */ 7614 */
10482 UriReferencedElementImpl(String name, int offset) : super(name, offset); 7615 UriReferencedElementImpl(String name, int offset) : super(name, offset);
10483 } 7616 }
10484 7617
10485 /** 7618 /**
10486 * A variable. There are concrete subclasses for different kinds of variables.
10487 */
10488 abstract class VariableElement implements Element, ConstantEvaluationTarget {
10489 /**
10490 * An empty list of variable elements.
10491 */
10492 static const List<VariableElement> EMPTY_LIST = const <VariableElement>[];
10493
10494 /**
10495 * Return a representation of the value of this variable.
10496 *
10497 * Return `null` if either this variable was not declared with the 'const'
10498 * modifier or if the value of this variable could not be computed because of
10499 * errors.
10500 */
10501 DartObject get constantValue;
10502
10503 /**
10504 * Return `true` if this variable element did not have an explicit type
10505 * specified for it.
10506 */
10507 bool get hasImplicitType;
10508
10509 /**
10510 * Return a synthetic function representing this variable's initializer, or
10511 * `null` if this variable does not have an initializer. The function will
10512 * have no parameters. The return type of the function will be the
10513 * compile-time type of the initialization expression.
10514 */
10515 FunctionElement get initializer;
10516
10517 /**
10518 * Return `true` if this variable was declared with the 'const' modifier.
10519 */
10520 bool get isConst;
10521
10522 /**
10523 * Return `true` if this variable was declared with the 'final' modifier.
10524 * Variables that are declared with the 'const' modifier will return `false`
10525 * even though they are implicitly final.
10526 */
10527 bool get isFinal;
10528
10529 /**
10530 * Return `true` if this variable is potentially mutated somewhere in a
10531 * closure. This information is only available for local variables (including
10532 * parameters) and only after the compilation unit containing the variable has
10533 * been resolved.
10534 */
10535 bool get isPotentiallyMutatedInClosure;
10536
10537 /**
10538 * Return `true` if this variable is potentially mutated somewhere in its
10539 * scope. This information is only available for local variables (including
10540 * parameters) and only after the compilation unit containing the variable has
10541 * been resolved.
10542 */
10543 bool get isPotentiallyMutatedInScope;
10544
10545 /**
10546 * Return `true` if this element is a static variable, as per section 8 of the
10547 * Dart Language Specification:
10548 *
10549 * > A static variable is a variable that is not associated with a particular
10550 * > instance, but rather with an entire library or class. Static variables
10551 * > include library variables and class variables. Class variables are
10552 * > variables whose declaration is immediately nested inside a class
10553 * > declaration and includes the modifier static. A library variable is
10554 * > implicitly static.
10555 */
10556 bool get isStatic;
10557
10558 /**
10559 * Return the declared type of this variable, or `null` if the variable did
10560 * not have a declared type (such as if it was declared using the keyword
10561 * 'var').
10562 */
10563 DartType get type;
10564 }
10565
10566 /**
10567 * A concrete implementation of a [VariableElement]. 7619 * A concrete implementation of a [VariableElement].
10568 */ 7620 */
10569 abstract class VariableElementImpl extends ElementImpl 7621 abstract class VariableElementImpl extends ElementImpl
10570 implements VariableElement { 7622 implements VariableElement {
10571 /** 7623 /**
10572 * The declared type of this variable. 7624 * The declared type of this variable.
10573 */ 7625 */
10574 DartType type; 7626 DartType type;
10575 7627
10576 /** 7628 /**
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
10829 7881
10830 @override 7882 @override
10831 void visitElement(Element element) { 7883 void visitElement(Element element) {
10832 int offset = element.nameOffset; 7884 int offset = element.nameOffset;
10833 if (offset != -1) { 7885 if (offset != -1) {
10834 map[offset] = element; 7886 map[offset] = element;
10835 } 7887 }
10836 super.visitElement(element); 7888 super.visitElement(element);
10837 } 7889 }
10838 } 7890 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/dart/element/visitor.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698