| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * Defines the element model. The element model describes the semantic (as |
| 7 * opposed to syntactic) structure of Dart code. The syntactic structure of the |
| 8 * code is modeled by the [AST structure](../ast/ast.dart). |
| 9 * |
| 10 * The element model consists of two closely related kinds of objects: elements |
| 11 * (instances of a subclass of [Element]) and types. This library defines the |
| 12 * elements, the types are defined in [type.dart](type.dart). |
| 13 * |
| 14 * Generally speaking, an element represents something that is declared in the |
| 15 * code, such as a class, method, or variable. Elements are organized in a tree |
| 16 * structure in which the children of an element are the elements that are |
| 17 * logically (and often syntactically) part of the declaration of the parent. |
| 18 * For example, the elements representing the methods and fields in a class are |
| 19 * children of the element representing the class. |
| 20 * |
| 21 * Every complete element structure is rooted by an instance of the class |
| 22 * [LibraryElement]. A library element represents a single Dart library. Every |
| 23 * library is defined by one or more compilation units (the library and all of |
| 24 * its parts). The compilation units are represented by the class |
| 25 * [CompilationUnitElement] and are children of the library that is defined by |
| 26 * them. Each compilation unit can contain zero or more top-level declarations, |
| 27 * such as classes, functions, and variables. Each of these is in turn |
| 28 * represented as an element that is a child of the compilation unit. Classes |
| 29 * contain methods and fields, methods can contain local variables, etc. |
| 30 * |
| 31 * The element model does not contain everything in the code, only those things |
| 32 * that are declared by the code. For example, it does not include any |
| 33 * representation of the statements in a method body, but if one of those |
| 34 * statements declares a local variable then the local variable will be |
| 35 * represented by an element. |
| 36 */ |
| 37 library analyzer.dart.element.element; |
| 38 |
| 39 import 'package:analyzer/dart/ast/ast.dart'; |
| 40 import 'package:analyzer/dart/constant/value.dart'; |
| 41 import 'package:analyzer/dart/element/type.dart'; |
| 42 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; |
| 43 import 'package:analyzer/src/generated/java_engine.dart'; |
| 44 import 'package:analyzer/src/generated/resolver.dart'; |
| 45 import 'package:analyzer/src/generated/source.dart'; |
| 46 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 47 import 'package:analyzer/src/task/dart.dart'; |
| 48 import 'package:analyzer/task/model.dart' show AnalysisTarget; |
| 49 |
| 50 /** |
| 51 * An element that represents a class. |
| 52 * |
| 53 * Clients may not extend, implement or mix-in this class. |
| 54 */ |
| 55 abstract class ClassElement |
| 56 implements TypeDefiningElement, TypeParameterizedElement { |
| 57 /** |
| 58 * An empty list of class elements. |
| 59 */ |
| 60 static const List<ClassElement> EMPTY_LIST = const <ClassElement>[]; |
| 61 |
| 62 /** |
| 63 * Return a list containing all of the accessors (getters and setters) |
| 64 * declared in this class. |
| 65 */ |
| 66 List<PropertyAccessorElement> get accessors; |
| 67 |
| 68 /** |
| 69 * Return a list containing all the supertypes defined for this class and its |
| 70 * supertypes. This includes superclasses, mixins and interfaces. |
| 71 */ |
| 72 List<InterfaceType> get allSupertypes; |
| 73 |
| 74 /** |
| 75 * Return a list containing all of the constructors declared in this class. |
| 76 */ |
| 77 List<ConstructorElement> get constructors; |
| 78 |
| 79 /** |
| 80 * Return a list containing all of the fields declared in this class. |
| 81 */ |
| 82 List<FieldElement> get fields; |
| 83 |
| 84 /** |
| 85 * Return `true` if this class or its superclass declares a non-final instance |
| 86 * field. |
| 87 */ |
| 88 bool get hasNonFinalField; |
| 89 |
| 90 /** |
| 91 * Return `true` if this class has reference to super (so, for example, cannot |
| 92 * be used as a mixin). |
| 93 */ |
| 94 bool get hasReferenceToSuper; |
| 95 |
| 96 /** |
| 97 * Return `true` if this class declares a static member. |
| 98 */ |
| 99 bool get hasStaticMember; |
| 100 |
| 101 /** |
| 102 * Return a list containing all of the interfaces that are implemented by this |
| 103 * class. |
| 104 * |
| 105 * <b>Note:</b> Because the element model represents the state of the code, it |
| 106 * is possible for it to be semantically invalid. In particular, it is not |
| 107 * safe to assume that the inheritance structure of a class does not contain a |
| 108 * cycle. Clients that traverse the inheritance structure must explicitly |
| 109 * guard against infinite loops. |
| 110 */ |
| 111 List<InterfaceType> get interfaces; |
| 112 |
| 113 /** |
| 114 * Return `true` if this class is abstract. A class is abstract if it has an |
| 115 * explicit `abstract` modifier. Note, that this definition of <i>abstract</i> |
| 116 * is different from <i>has unimplemented members</i>. |
| 117 */ |
| 118 bool get isAbstract; |
| 119 |
| 120 /** |
| 121 * Return `true` if this class is defined by an enum declaration. |
| 122 */ |
| 123 bool get isEnum; |
| 124 |
| 125 /** |
| 126 * Return `true` if this class is a mixin application. A class is a mixin |
| 127 * application if it was declared using the syntax "class A = B with C;". |
| 128 */ |
| 129 bool get isMixinApplication; |
| 130 |
| 131 /** |
| 132 * Return `true` if this class [isProxy], or if it inherits the proxy |
| 133 * annotation from a supertype. |
| 134 */ |
| 135 bool get isOrInheritsProxy; |
| 136 |
| 137 /** |
| 138 * Return `true` if this element has an annotation of the form '@proxy'. |
| 139 */ |
| 140 bool get isProxy; |
| 141 |
| 142 /** |
| 143 * Return `true` if this class can validly be used as a mixin when defining |
| 144 * another class. The behavior of this method is defined by the Dart Language |
| 145 * Specification in section 9: |
| 146 * <blockquote> |
| 147 * It is a compile-time error if a declared or derived mixin refers to super. |
| 148 * It is a compile-time error if a declared or derived mixin explicitly |
| 149 * declares a constructor. It is a compile-time error if a mixin is derived |
| 150 * from a class whose superclass is not Object. |
| 151 * </blockquote> |
| 152 */ |
| 153 bool get isValidMixin; |
| 154 |
| 155 /** |
| 156 * Return a list containing all of the methods declared in this class. |
| 157 */ |
| 158 List<MethodElement> get methods; |
| 159 |
| 160 /** |
| 161 * Return a list containing all of the mixins that are applied to the class |
| 162 * being extended in order to derive the superclass of this class. |
| 163 * |
| 164 * <b>Note:</b> Because the element model represents the state of the code, it |
| 165 * is possible for it to be semantically invalid. In particular, it is not |
| 166 * safe to assume that the inheritance structure of a class does not contain a |
| 167 * cycle. Clients that traverse the inheritance structure must explicitly |
| 168 * guard against infinite loops. |
| 169 */ |
| 170 List<InterfaceType> get mixins; |
| 171 |
| 172 /** |
| 173 * Return the superclass of this class, or `null` if the class represents the |
| 174 * class 'Object'. All other classes will have a non-`null` superclass. If the |
| 175 * superclass was not explicitly declared then the implicit superclass |
| 176 * 'Object' will be returned. |
| 177 * |
| 178 * <b>Note:</b> Because the element model represents the state of the code, it |
| 179 * is possible for it to be semantically invalid. In particular, it is not |
| 180 * safe to assume that the inheritance structure of a class does not contain a |
| 181 * cycle. Clients that traverse the inheritance structure must explicitly |
| 182 * guard against infinite loops. |
| 183 */ |
| 184 InterfaceType get supertype; |
| 185 |
| 186 @override |
| 187 InterfaceType get type; |
| 188 |
| 189 /** |
| 190 * Return the unnamed constructor declared in this class, or `null` if this |
| 191 * class does not declare an unnamed constructor but does declare named |
| 192 * constructors. The returned constructor will be synthetic if this class does |
| 193 * not declare any constructors, in which case it will represent the default |
| 194 * constructor for the class. |
| 195 */ |
| 196 ConstructorElement get unnamedConstructor; |
| 197 |
| 198 @override |
| 199 NamedCompilationUnitMember computeNode(); |
| 200 |
| 201 /** |
| 202 * Return the field (synthetic or explicit) defined in this class that has the |
| 203 * given [name], or `null` if this class does not define a field with the |
| 204 * given name. |
| 205 */ |
| 206 FieldElement getField(String name); |
| 207 |
| 208 /** |
| 209 * Return the element representing the getter with the given [name] that is |
| 210 * declared in this class, or `null` if this class does not declare a getter |
| 211 * with the given name. |
| 212 */ |
| 213 PropertyAccessorElement getGetter(String name); |
| 214 |
| 215 /** |
| 216 * Return the element representing the method with the given [name] that is |
| 217 * declared in this class, or `null` if this class does not declare a method |
| 218 * with the given name. |
| 219 */ |
| 220 MethodElement getMethod(String name); |
| 221 |
| 222 /** |
| 223 * Return the named constructor declared in this class with the given [name], |
| 224 * or `null` if this class does not declare a named constructor with the given |
| 225 * name. |
| 226 */ |
| 227 ConstructorElement getNamedConstructor(String name); |
| 228 |
| 229 /** |
| 230 * Return the element representing the setter with the given [name] that is |
| 231 * declared in this class, or `null` if this class does not declare a setter |
| 232 * with the given name. |
| 233 */ |
| 234 PropertyAccessorElement getSetter(String name); |
| 235 |
| 236 /** |
| 237 * Determine whether the given [constructor], which exists in the superclass |
| 238 * of this class, is accessible to constructors in this class. |
| 239 */ |
| 240 bool isSuperConstructorAccessible(ConstructorElement constructor); |
| 241 |
| 242 /** |
| 243 * Return the element representing the method that results from looking up the |
| 244 * given [methodName] in this class with respect to the given [library], |
| 245 * ignoring abstract methods, or `null` if the look up fails. The behavior of |
| 246 * this method is defined by the Dart Language Specification in section |
| 247 * 16.15.1: |
| 248 * <blockquote> |
| 249 * The result of looking up method <i>m</i> in class <i>C</i> with respect to |
| 250 * library <i>L</i> is: If <i>C</i> declares an instance method named <i>m</i> |
| 251 * that is accessible to <i>L</i>, then that method is the result of the |
| 252 * lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the result |
| 253 * of the lookup is the result of looking up method <i>m</i> in <i>S</i> with |
| 254 * respect to <i>L</i>. Otherwise, we say that the lookup has failed. |
| 255 * </blockquote> |
| 256 */ |
| 257 MethodElement lookUpConcreteMethod(String methodName, LibraryElement library); |
| 258 |
| 259 /** |
| 260 * Return the element representing the getter that results from looking up the |
| 261 * given [getterName] in this class with respect to the given [library], or |
| 262 * `null` if the look up fails. The behavior of this method is defined by the |
| 263 * Dart Language Specification in section 16.15.2: |
| 264 * <blockquote> |
| 265 * The result of looking up getter (respectively setter) <i>m</i> in class |
| 266 * <i>C</i> with respect to library <i>L</i> is: If <i>C</i> declares an |
| 267 * instance getter (respectively setter) named <i>m</i> that is accessible to |
| 268 * <i>L</i>, then that getter (respectively setter) is the result of the |
| 269 * lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the result |
| 270 * of the lookup is the result of looking up getter (respectively setter) |
| 271 * <i>m</i> in <i>S</i> with respect to <i>L</i>. Otherwise, we say that the |
| 272 * lookup has failed. |
| 273 * </blockquote> |
| 274 */ |
| 275 PropertyAccessorElement lookUpGetter( |
| 276 String getterName, LibraryElement library); |
| 277 |
| 278 /** |
| 279 * Return the element representing the getter that results from looking up the |
| 280 * given [getterName] in the superclass of this class with respect to the |
| 281 * given [library], ignoring abstract getters, or `null` if the look up fails. |
| 282 * The behavior of this method is defined by the Dart Language Specification |
| 283 * in section 16.15.2: |
| 284 * <blockquote> |
| 285 * The result of looking up getter (respectively setter) <i>m</i> in class |
| 286 * <i>C</i> with respect to library <i>L</i> is: If <i>C</i> declares an |
| 287 * instance getter (respectively setter) named <i>m</i> that is accessible to |
| 288 * <i>L</i>, then that getter (respectively setter) is the result of the |
| 289 * lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the result |
| 290 * of the lookup is the result of looking up getter (respectively setter) |
| 291 * <i>m</i> in <i>S</i> with respect to <i>L</i>. Otherwise, we say that the |
| 292 * lookup has failed. |
| 293 * </blockquote> |
| 294 */ |
| 295 PropertyAccessorElement lookUpInheritedConcreteGetter( |
| 296 String getterName, LibraryElement library); |
| 297 |
| 298 /** |
| 299 * Return the element representing the method that results from looking up the |
| 300 * given [methodName] in the superclass of this class with respect to the |
| 301 * given [library], ignoring abstract methods, or `null` if the look up fails. |
| 302 * The behavior of this method is defined by the Dart Language Specification |
| 303 * in section 16.15.1: |
| 304 * <blockquote> |
| 305 * The result of looking up method <i>m</i> in class <i>C</i> with respect to |
| 306 * library <i>L</i> is: If <i>C</i> declares an instance method named |
| 307 * <i>m</i> that is accessible to <i>L</i>, then that method is the result of |
| 308 * the lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the |
| 309 * result of the lookup is the result of looking up method <i>m</i> in |
| 310 * <i>S</i> with respect to <i>L</i>. Otherwise, we say that the lookup has |
| 311 * failed. |
| 312 * </blockquote> |
| 313 */ |
| 314 MethodElement lookUpInheritedConcreteMethod( |
| 315 String methodName, LibraryElement library); |
| 316 |
| 317 /** |
| 318 * Return the element representing the setter that results from looking up the |
| 319 * given [setterName] in the superclass of this class with respect to the |
| 320 * given [library], ignoring abstract setters, or `null` if the look up fails. |
| 321 * The behavior of this method is defined by the Dart Language Specification |
| 322 * in section 16.15.2: |
| 323 * <blockquote> |
| 324 * The result of looking up getter (respectively setter) <i>m</i> in class |
| 325 * <i>C</i> with respect to library <i>L</i> is: If <i>C</i> declares an |
| 326 * instance getter (respectively setter) named <i>m</i> that is accessible to |
| 327 * <i>L</i>, then that getter (respectively setter) is the result of the |
| 328 * lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the result |
| 329 * of the lookup is the result of looking up getter (respectively setter) |
| 330 * <i>m</i> in <i>S</i> with respect to <i>L</i>. Otherwise, we say that the |
| 331 * lookup has failed. |
| 332 * </blockquote> |
| 333 */ |
| 334 PropertyAccessorElement lookUpInheritedConcreteSetter( |
| 335 String setterName, LibraryElement library); |
| 336 |
| 337 /** |
| 338 * Return the element representing the method that results from looking up the |
| 339 * given [methodName] in the superclass of this class with respect to the |
| 340 * given [library], or `null` if the look up fails. The behavior of this |
| 341 * method is defined by the Dart Language Specification in section 16.15.1: |
| 342 * <blockquote> |
| 343 * The result of looking up method <i>m</i> in class <i>C</i> with respect to |
| 344 * library <i>L</i> is: If <i>C</i> declares an instance method named |
| 345 * <i>m</i> that is accessible to <i>L</i>, then that method is the result of |
| 346 * the lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the |
| 347 * result of the lookup is the result of looking up method <i>m</i> in |
| 348 * <i>S</i> with respect to <i>L</i>. Otherwise, we say that the lookup has |
| 349 * failed. |
| 350 * </blockquote> |
| 351 */ |
| 352 MethodElement lookUpInheritedMethod( |
| 353 String methodName, LibraryElement library); |
| 354 |
| 355 /** |
| 356 * Return the element representing the method that results from looking up the |
| 357 * given [methodName] in this class with respect to the given [library], or |
| 358 * `null` if the look up fails. The behavior of this method is defined by the |
| 359 * Dart Language Specification in section 16.15.1: |
| 360 * <blockquote> |
| 361 * The result of looking up method <i>m</i> in class <i>C</i> with respect to |
| 362 * library <i>L</i> is: If <i>C</i> declares an instance method named |
| 363 * <i>m</i> that is accessible to <i>L</i>, then that method is the result of |
| 364 * the lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the |
| 365 * result of the lookup is the result of looking up method <i>m</i> in |
| 366 * <i>S</i> with respect to <i>L</i>. Otherwise, we say that the lookup has |
| 367 * failed. |
| 368 * </blockquote> |
| 369 */ |
| 370 MethodElement lookUpMethod(String methodName, LibraryElement library); |
| 371 |
| 372 /** |
| 373 * Return the element representing the setter that results from looking up the |
| 374 * given [setterName] in this class with respect to the given [library], or |
| 375 * `null` if the look up fails. The behavior of this method is defined by the |
| 376 * Dart Language Specification in section 16.15.2: |
| 377 * <blockquote> |
| 378 * The result of looking up getter (respectively setter) <i>m</i> in class |
| 379 * <i>C</i> with respect to library <i>L</i> is: If <i>C</i> declares an |
| 380 * instance getter (respectively setter) named <i>m</i> that is accessible to |
| 381 * <i>L</i>, then that getter (respectively setter) is the result of the |
| 382 * lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the result |
| 383 * of the lookup is the result of looking up getter (respectively setter) |
| 384 * <i>m</i> in <i>S</i> with respect to <i>L</i>. Otherwise, we say that the |
| 385 * lookup has failed. |
| 386 * </blockquote> |
| 387 */ |
| 388 PropertyAccessorElement lookUpSetter( |
| 389 String setterName, LibraryElement library); |
| 390 } |
| 391 |
| 392 /** |
| 393 * An element that is contained within a [ClassElement]. |
| 394 * |
| 395 * Clients may not extend, implement or mix-in this class. |
| 396 */ |
| 397 abstract class ClassMemberElement implements Element { |
| 398 @override |
| 399 ClassElement get enclosingElement; |
| 400 |
| 401 /** |
| 402 * Return `true` if this element is a static element. A static element is an |
| 403 * element that is not associated with a particular instance, but rather with |
| 404 * an entire library or class. |
| 405 */ |
| 406 bool get isStatic; |
| 407 } |
| 408 |
| 409 /** |
| 410 * An element representing a compilation unit. |
| 411 * |
| 412 * Clients may not extend, implement or mix-in this class. |
| 413 */ |
| 414 abstract class CompilationUnitElement implements Element, UriReferencedElement { |
| 415 /** |
| 416 * An empty list of compilation unit elements. |
| 417 */ |
| 418 static const List<CompilationUnitElement> EMPTY_LIST = |
| 419 const <CompilationUnitElement>[]; |
| 420 |
| 421 /** |
| 422 * Return a list containing all of the top-level accessors (getters and |
| 423 * setters) contained in this compilation unit. |
| 424 */ |
| 425 List<PropertyAccessorElement> get accessors; |
| 426 |
| 427 @override |
| 428 LibraryElement get enclosingElement; |
| 429 |
| 430 /** |
| 431 * Return a list containing all of the enums contained in this compilation |
| 432 * unit. |
| 433 */ |
| 434 List<ClassElement> get enums; |
| 435 |
| 436 /** |
| 437 * Return a list containing all of the top-level functions contained in this |
| 438 * compilation unit. |
| 439 */ |
| 440 List<FunctionElement> get functions; |
| 441 |
| 442 /** |
| 443 * Return a list containing all of the function type aliases contained in this |
| 444 * compilation unit. |
| 445 */ |
| 446 List<FunctionTypeAliasElement> get functionTypeAliases; |
| 447 |
| 448 /** |
| 449 * Return `true` if this compilation unit defines a top-level function named |
| 450 * `loadLibrary`. |
| 451 */ |
| 452 bool get hasLoadLibraryFunction; |
| 453 |
| 454 /** |
| 455 * Return a list containing all of the top-level variables contained in this |
| 456 * compilation unit. |
| 457 */ |
| 458 List<TopLevelVariableElement> get topLevelVariables; |
| 459 |
| 460 /** |
| 461 * Return a list containing all of the classes contained in this compilation |
| 462 * unit. |
| 463 */ |
| 464 List<ClassElement> get types; |
| 465 |
| 466 @override |
| 467 CompilationUnit computeNode(); |
| 468 |
| 469 /** |
| 470 * Return the element at the given [offset], maybe `null` if no such element. |
| 471 */ |
| 472 Element getElementAt(int offset); |
| 473 |
| 474 /** |
| 475 * Return the enum defined in this compilation unit that has the given [name], |
| 476 * or `null` if this compilation unit does not define an enum with the given |
| 477 * name. |
| 478 */ |
| 479 ClassElement getEnum(String name); |
| 480 |
| 481 /** |
| 482 * Return the class defined in this compilation unit that has the given |
| 483 * [name], or `null` if this compilation unit does not define a class with the |
| 484 * given name. |
| 485 */ |
| 486 ClassElement getType(String name); |
| 487 } |
| 488 |
| 489 /** |
| 490 * An element representing a constructor or a factory method defined within a |
| 491 * class. |
| 492 * |
| 493 * Clients may not extend, implement or mix-in this class. |
| 494 */ |
| 495 abstract class ConstructorElement |
| 496 implements ClassMemberElement, ExecutableElement, ConstantEvaluationTarget { |
| 497 /** |
| 498 * An empty list of constructor elements. |
| 499 */ |
| 500 static const List<ConstructorElement> EMPTY_LIST = |
| 501 const <ConstructorElement>[]; |
| 502 |
| 503 /** |
| 504 * Return `true` if this constructor is a const constructor. |
| 505 */ |
| 506 bool get isConst; |
| 507 |
| 508 /** |
| 509 * Return `true` if this constructor can be used as a default constructor - |
| 510 * unnamed and has no required parameters. |
| 511 */ |
| 512 bool get isDefaultConstructor; |
| 513 |
| 514 /** |
| 515 * Return `true` if this constructor represents a factory constructor. |
| 516 */ |
| 517 bool get isFactory; |
| 518 |
| 519 /** |
| 520 * Return the offset of the character immediately following the last character |
| 521 * of this constructor's name, or `null` if not named. |
| 522 */ |
| 523 int get nameEnd; |
| 524 |
| 525 /** |
| 526 * Return the offset of the `.` before this constructor name, or `null` if |
| 527 * not named. |
| 528 */ |
| 529 int get periodOffset; |
| 530 |
| 531 /** |
| 532 * Return the constructor to which this constructor is redirecting, or `null` |
| 533 * if this constructor does not redirect to another constructor or if the |
| 534 * library containing this constructor has not yet been resolved. |
| 535 */ |
| 536 ConstructorElement get redirectedConstructor; |
| 537 |
| 538 @override |
| 539 ConstructorDeclaration computeNode(); |
| 540 } |
| 541 |
| 542 /** |
| 543 * The base class for all of the elements in the element model. Generally |
| 544 * speaking, the element model is a semantic model of the program that |
| 545 * represents things that are declared with a name and hence can be referenced |
| 546 * elsewhere in the code. |
| 547 * |
| 548 * There are two exceptions to the general case. First, there are elements in |
| 549 * the element model that are created for the convenience of various kinds of |
| 550 * analysis but that do not have any corresponding declaration within the source |
| 551 * code. Such elements are marked as being <i>synthetic</i>. Examples of |
| 552 * synthetic elements include |
| 553 * * default constructors in classes that do not define any explicit |
| 554 * constructors, |
| 555 * * getters and setters that are induced by explicit field declarations, |
| 556 * * fields that are induced by explicit declarations of getters and setters, |
| 557 * and |
| 558 * * functions representing the initialization expression for a variable. |
| 559 * |
| 560 * Second, there are elements in the element model that do not have a name. |
| 561 * These correspond to unnamed functions and exist in order to more accurately |
| 562 * represent the semantic structure of the program. |
| 563 * |
| 564 * Clients may not extend, implement or mix-in this class. |
| 565 */ |
| 566 abstract class Element implements AnalysisTarget { |
| 567 /** |
| 568 * A comparator that can be used to sort elements by their name offset. |
| 569 * Elements with a smaller offset will be sorted to be before elements with a |
| 570 * larger name offset. |
| 571 */ |
| 572 static final Comparator<Element> SORT_BY_OFFSET = |
| 573 (Element firstElement, Element secondElement) => |
| 574 firstElement.nameOffset - secondElement.nameOffset; |
| 575 |
| 576 /** |
| 577 * Return the analysis context in which this element is defined. |
| 578 */ |
| 579 AnalysisContext get context; |
| 580 |
| 581 /** |
| 582 * Return the display name of this element, or `null` if this element does not |
| 583 * have a name. |
| 584 * |
| 585 * In most cases the name and the display name are the same. Differences |
| 586 * though are cases such as setters where the name of some setter `set f(x)` |
| 587 * is `f=`, instead of `f`. |
| 588 */ |
| 589 String get displayName; |
| 590 |
| 591 /** |
| 592 * Return the content of the documentation comment (including delimiters) for |
| 593 * this element, or `null` if this element does not or cannot have |
| 594 * documentation. |
| 595 */ |
| 596 String get documentationComment; |
| 597 |
| 598 /** |
| 599 * Return the element that either physically or logically encloses this |
| 600 * element. This will be `null` if this element is a library because libraries |
| 601 * are the top-level elements in the model. |
| 602 */ |
| 603 Element get enclosingElement; |
| 604 |
| 605 /** |
| 606 * The unique integer identifier of this element. |
| 607 */ |
| 608 int get id; |
| 609 |
| 610 /** |
| 611 * Return `true` if this element has an annotation of the form '@deprecated' |
| 612 * or '@Deprecated('..')'. |
| 613 */ |
| 614 bool get isDeprecated; |
| 615 |
| 616 /** |
| 617 * Return `true` if this element has an annotation of the form '@factory'. |
| 618 */ |
| 619 bool get isFactory; |
| 620 |
| 621 /** |
| 622 * Return `true` if this element has an annotation of the form '@JS(..)'. |
| 623 */ |
| 624 bool get isJS; |
| 625 |
| 626 /** |
| 627 * Return `true` if this element has an annotation of the form '@override'. |
| 628 */ |
| 629 bool get isOverride; |
| 630 |
| 631 /** |
| 632 * Return `true` if this element is private. Private elements are visible only |
| 633 * within the library in which they are declared. |
| 634 */ |
| 635 bool get isPrivate; |
| 636 |
| 637 /** |
| 638 * Return `true` if this element has an annotation of the form '@protected'. |
| 639 */ |
| 640 bool get isProtected; |
| 641 |
| 642 /** |
| 643 * Return `true` if this element is public. Public elements are visible within |
| 644 * any library that imports the library in which they are declared. |
| 645 */ |
| 646 bool get isPublic; |
| 647 |
| 648 /** |
| 649 * Return `true` if this element has an annotation of the form '@required'. |
| 650 */ |
| 651 bool get isRequired; |
| 652 |
| 653 /** |
| 654 * Return `true` if this element is synthetic. A synthetic element is an |
| 655 * element that is not represented in the source code explicitly, but is |
| 656 * implied by the source code, such as the default constructor for a class |
| 657 * that does not explicitly define any constructors. |
| 658 */ |
| 659 bool get isSynthetic; |
| 660 |
| 661 /** |
| 662 * Return the kind of element that this is. |
| 663 */ |
| 664 ElementKind get kind; |
| 665 |
| 666 /** |
| 667 * Return the library that contains this element. This will be the element |
| 668 * itself if it is a library element. This will be `null` if this element is |
| 669 * an HTML file because HTML files are not contained in libraries. |
| 670 */ |
| 671 LibraryElement get library; |
| 672 |
| 673 /** |
| 674 * Return an object representing the location of this element in the element |
| 675 * model. The object can be used to locate this element at a later time. |
| 676 */ |
| 677 ElementLocation get location; |
| 678 |
| 679 /** |
| 680 * Return a list containing all of the metadata associated with this element. |
| 681 * The array will be empty if the element does not have any metadata or if the |
| 682 * library containing this element has not yet been resolved. |
| 683 */ |
| 684 List<ElementAnnotation> get metadata; |
| 685 |
| 686 /** |
| 687 * Return the name of this element, or `null` if this element does not have a |
| 688 * name. |
| 689 */ |
| 690 String get name; |
| 691 |
| 692 /** |
| 693 * Return the length of the name of this element in the file that contains the |
| 694 * declaration of this element, or `0` if this element does not have a name. |
| 695 */ |
| 696 int get nameLength; |
| 697 |
| 698 /** |
| 699 * Return the offset of the name of this element in the file that contains the |
| 700 * declaration of this element, or `-1` if this element is synthetic, does not |
| 701 * have a name, or otherwise does not have an offset. |
| 702 */ |
| 703 int get nameOffset; |
| 704 |
| 705 @override |
| 706 Source get source; |
| 707 |
| 708 /** |
| 709 * Return the resolved [CompilationUnit] that declares this element, or `null` |
| 710 * if this element is synthetic. |
| 711 * |
| 712 * This method is expensive, because resolved AST might have been already |
| 713 * evicted from cache, so parsing and resolving will be performed. |
| 714 */ |
| 715 CompilationUnit get unit; |
| 716 |
| 717 /** |
| 718 * Use the given [visitor] to visit this element. Return the value returned by |
| 719 * the visitor as a result of visiting this element. |
| 720 */ |
| 721 accept(ElementVisitor visitor); |
| 722 |
| 723 /** |
| 724 * Return the documentation comment for this element as it appears in the |
| 725 * original source (complete with the beginning and ending delimiters), or |
| 726 * `null` if this element does not have a documentation comment associated |
| 727 * with it. This can be a long-running operation if the information needed to |
| 728 * access the comment is not cached. |
| 729 * |
| 730 * Throws [AnalysisException] if the documentation comment could not be |
| 731 * determined because the analysis could not be performed |
| 732 * |
| 733 * Deprecated. Use [documentationComment] instead. |
| 734 */ |
| 735 @deprecated |
| 736 String computeDocumentationComment(); |
| 737 |
| 738 /** |
| 739 * Return the resolved [AstNode] node that declares this element, or `null` if |
| 740 * this element is synthetic or isn't contained in a compilation unit, such as |
| 741 * a [LibraryElement]. |
| 742 * |
| 743 * This method is expensive, because resolved AST might be evicted from cache, |
| 744 * so parsing and resolving will be performed. |
| 745 * |
| 746 * <b>Note:</b> This method cannot be used in an async environment. |
| 747 */ |
| 748 AstNode computeNode(); |
| 749 |
| 750 /** |
| 751 * Return the most immediate ancestor of this element for which the |
| 752 * [predicate] returns `true`, or `null` if there is no such ancestor. Note |
| 753 * that this element will never be returned. |
| 754 */ |
| 755 Element/*=E*/ getAncestor/*<E extends Element >*/( |
| 756 Predicate<Element> predicate); |
| 757 |
| 758 /** |
| 759 * Return a display name for the given element that includes the path to the |
| 760 * compilation unit in which the type is defined. If [shortName] is `null` |
| 761 * then [displayName] will be used as the name of this element. Otherwise |
| 762 * the provided name will be used. |
| 763 */ |
| 764 // TODO(brianwilkerson) Make the parameter optional. |
| 765 String getExtendedDisplayName(String shortName); |
| 766 |
| 767 /** |
| 768 * Return `true` if this element, assuming that it is within scope, is |
| 769 * accessible to code in the given [library]. This is defined by the Dart |
| 770 * Language Specification in section 3.2: |
| 771 * <blockquote> |
| 772 * A declaration <i>m</i> is accessible to library <i>L</i> if <i>m</i> is |
| 773 * declared in <i>L</i> or if <i>m</i> is public. |
| 774 * </blockquote> |
| 775 */ |
| 776 bool isAccessibleIn(LibraryElement library); |
| 777 |
| 778 /** |
| 779 * Use the given [visitor] to visit all of the children of this element. There |
| 780 * is no guarantee of the order in which the children will be visited. |
| 781 */ |
| 782 void visitChildren(ElementVisitor visitor); |
| 783 } |
| 784 |
| 785 /** |
| 786 * A single annotation associated with an element. |
| 787 * |
| 788 * Clients may not extend, implement or mix-in this class. |
| 789 */ |
| 790 abstract class ElementAnnotation implements ConstantEvaluationTarget { |
| 791 /** |
| 792 * An empty list of annotations. |
| 793 */ |
| 794 static const List<ElementAnnotation> EMPTY_LIST = const <ElementAnnotation>[]; |
| 795 |
| 796 /** |
| 797 * Return a representation of the value of this annotation. |
| 798 * |
| 799 * Return `null` if the value of this annotation could not be computed because |
| 800 * of errors. |
| 801 */ |
| 802 DartObject get constantValue; |
| 803 |
| 804 /** |
| 805 * Return the element representing the field, variable, or const constructor |
| 806 * being used as an annotation. |
| 807 */ |
| 808 Element get element; |
| 809 |
| 810 /** |
| 811 * Return `true` if this annotation marks the associated element as being |
| 812 * deprecated. |
| 813 */ |
| 814 bool get isDeprecated; |
| 815 |
| 816 /** |
| 817 * Return `true` if this annotation marks the associated member as a factory. |
| 818 */ |
| 819 bool get isFactory; |
| 820 |
| 821 /** |
| 822 * Return `true` if this annotation marks the associated element with the `JS` |
| 823 * annotation. |
| 824 */ |
| 825 bool get isJS; |
| 826 |
| 827 /** |
| 828 * Return `true` if this annotation marks the associated member as requiring |
| 829 * overriding methods to call super. |
| 830 */ |
| 831 bool get isMustCallSuper; |
| 832 |
| 833 /** |
| 834 * Return `true` if this annotation marks the associated method as being |
| 835 * expected to override an inherited method. |
| 836 */ |
| 837 bool get isOverride; |
| 838 |
| 839 /** |
| 840 * Return `true` if this annotation marks the associated member as being |
| 841 * protected. |
| 842 */ |
| 843 bool get isProtected; |
| 844 |
| 845 /** |
| 846 * Return `true` if this annotation marks the associated class as implementing |
| 847 * a proxy object. |
| 848 */ |
| 849 bool get isProxy; |
| 850 |
| 851 /** |
| 852 * Return `true` if this annotation marks the associated member as being |
| 853 * required. |
| 854 */ |
| 855 bool get isRequired; |
| 856 |
| 857 /** |
| 858 * Return a representation of the value of this annotation, forcing the value |
| 859 * to be computed if it had not previously been computed, or `null` if the |
| 860 * value of this annotation could not be computed because of errors. |
| 861 */ |
| 862 DartObject computeConstantValue(); |
| 863 } |
| 864 |
| 865 /** |
| 866 * The kind of elements in the element model. |
| 867 * |
| 868 * Clients may not extend, implement or mix-in this class. |
| 869 */ |
| 870 class ElementKind implements Comparable<ElementKind> { |
| 871 static const ElementKind CLASS = const ElementKind('CLASS', 0, "class"); |
| 872 |
| 873 static const ElementKind COMPILATION_UNIT = |
| 874 const ElementKind('COMPILATION_UNIT', 1, "compilation unit"); |
| 875 |
| 876 static const ElementKind CONSTRUCTOR = |
| 877 const ElementKind('CONSTRUCTOR', 2, "constructor"); |
| 878 |
| 879 static const ElementKind DYNAMIC = |
| 880 const ElementKind('DYNAMIC', 3, "<dynamic>"); |
| 881 |
| 882 static const ElementKind ERROR = const ElementKind('ERROR', 4, "<error>"); |
| 883 |
| 884 static const ElementKind EXPORT = |
| 885 const ElementKind('EXPORT', 5, "export directive"); |
| 886 |
| 887 static const ElementKind FIELD = const ElementKind('FIELD', 6, "field"); |
| 888 |
| 889 static const ElementKind FUNCTION = |
| 890 const ElementKind('FUNCTION', 7, "function"); |
| 891 |
| 892 static const ElementKind GETTER = const ElementKind('GETTER', 8, "getter"); |
| 893 |
| 894 static const ElementKind IMPORT = |
| 895 const ElementKind('IMPORT', 9, "import directive"); |
| 896 |
| 897 static const ElementKind LABEL = const ElementKind('LABEL', 10, "label"); |
| 898 |
| 899 static const ElementKind LIBRARY = |
| 900 const ElementKind('LIBRARY', 11, "library"); |
| 901 |
| 902 static const ElementKind LOCAL_VARIABLE = |
| 903 const ElementKind('LOCAL_VARIABLE', 12, "local variable"); |
| 904 |
| 905 static const ElementKind METHOD = const ElementKind('METHOD', 13, "method"); |
| 906 |
| 907 static const ElementKind NAME = const ElementKind('NAME', 14, "<name>"); |
| 908 |
| 909 static const ElementKind PARAMETER = |
| 910 const ElementKind('PARAMETER', 15, "parameter"); |
| 911 |
| 912 static const ElementKind PREFIX = |
| 913 const ElementKind('PREFIX', 16, "import prefix"); |
| 914 |
| 915 static const ElementKind SETTER = const ElementKind('SETTER', 17, "setter"); |
| 916 |
| 917 static const ElementKind TOP_LEVEL_VARIABLE = |
| 918 const ElementKind('TOP_LEVEL_VARIABLE', 18, "top level variable"); |
| 919 |
| 920 static const ElementKind FUNCTION_TYPE_ALIAS = |
| 921 const ElementKind('FUNCTION_TYPE_ALIAS', 19, "function type alias"); |
| 922 |
| 923 static const ElementKind TYPE_PARAMETER = |
| 924 const ElementKind('TYPE_PARAMETER', 20, "type parameter"); |
| 925 |
| 926 static const ElementKind UNIVERSE = |
| 927 const ElementKind('UNIVERSE', 21, "<universe>"); |
| 928 |
| 929 static const List<ElementKind> values = const [ |
| 930 CLASS, |
| 931 COMPILATION_UNIT, |
| 932 CONSTRUCTOR, |
| 933 DYNAMIC, |
| 934 ERROR, |
| 935 EXPORT, |
| 936 FIELD, |
| 937 FUNCTION, |
| 938 GETTER, |
| 939 IMPORT, |
| 940 LABEL, |
| 941 LIBRARY, |
| 942 LOCAL_VARIABLE, |
| 943 METHOD, |
| 944 NAME, |
| 945 PARAMETER, |
| 946 PREFIX, |
| 947 SETTER, |
| 948 TOP_LEVEL_VARIABLE, |
| 949 FUNCTION_TYPE_ALIAS, |
| 950 TYPE_PARAMETER, |
| 951 UNIVERSE |
| 952 ]; |
| 953 |
| 954 /** |
| 955 * The name of this element kind. |
| 956 */ |
| 957 final String name; |
| 958 |
| 959 /** |
| 960 * The ordinal value of the element kind. |
| 961 */ |
| 962 final int ordinal; |
| 963 |
| 964 /** |
| 965 * The name displayed in the UI for this kind of element. |
| 966 */ |
| 967 final String displayName; |
| 968 |
| 969 /** |
| 970 * Initialize a newly created element kind to have the given [displayName]. |
| 971 */ |
| 972 const ElementKind(this.name, this.ordinal, this.displayName); |
| 973 |
| 974 @override |
| 975 int get hashCode => ordinal; |
| 976 |
| 977 @override |
| 978 int compareTo(ElementKind other) => ordinal - other.ordinal; |
| 979 |
| 980 @override |
| 981 String toString() => name; |
| 982 |
| 983 /** |
| 984 * Return the kind of the given [element], or [ERROR] if the element is |
| 985 * `null`. This is a utility method that can reduce the need for null checks |
| 986 * in other places. |
| 987 */ |
| 988 static ElementKind of(Element element) { |
| 989 if (element == null) { |
| 990 return ERROR; |
| 991 } |
| 992 return element.kind; |
| 993 } |
| 994 } |
| 995 |
| 996 /** |
| 997 * The location of an element within the element model. |
| 998 * |
| 999 * Clients may not extend, implement or mix-in this class. |
| 1000 */ |
| 1001 abstract class ElementLocation { |
| 1002 /** |
| 1003 * Return the path to the element whose location is represented by this |
| 1004 * object. Clients must not modify the returned array. |
| 1005 */ |
| 1006 List<String> get components; |
| 1007 |
| 1008 /** |
| 1009 * Return an encoded representation of this location that can be used to |
| 1010 * create a location that is equal to this location. |
| 1011 */ |
| 1012 String get encoding; |
| 1013 } |
| 1014 |
| 1015 /** |
| 1016 * An object that can be used to visit an element structure. |
| 1017 * |
| 1018 * Clients may not extend, implement or mix-in this class. There are classes |
| 1019 * that implement this interface that provide useful default behaviors in |
| 1020 * `package:analyzer/dart/ast/visitor.dart`. A couple of the most useful include |
| 1021 * * SimpleElementVisitor which implements every visit method by doing nothing, |
| 1022 * * RecursiveElementVisitor which will cause every node in a structure to be |
| 1023 * visited, and |
| 1024 * * ThrowingElementVisitor which implements every visit method by throwing an |
| 1025 * exception. |
| 1026 */ |
| 1027 abstract class ElementVisitor<R> { |
| 1028 R visitClassElement(ClassElement element); |
| 1029 |
| 1030 R visitCompilationUnitElement(CompilationUnitElement element); |
| 1031 |
| 1032 R visitConstructorElement(ConstructorElement element); |
| 1033 |
| 1034 R visitExportElement(ExportElement element); |
| 1035 |
| 1036 R visitFieldElement(FieldElement element); |
| 1037 |
| 1038 R visitFieldFormalParameterElement(FieldFormalParameterElement element); |
| 1039 |
| 1040 R visitFunctionElement(FunctionElement element); |
| 1041 |
| 1042 R visitFunctionTypeAliasElement(FunctionTypeAliasElement element); |
| 1043 |
| 1044 R visitImportElement(ImportElement element); |
| 1045 |
| 1046 R visitLabelElement(LabelElement element); |
| 1047 |
| 1048 R visitLibraryElement(LibraryElement element); |
| 1049 |
| 1050 R visitLocalVariableElement(LocalVariableElement element); |
| 1051 |
| 1052 R visitMethodElement(MethodElement element); |
| 1053 |
| 1054 R visitMultiplyDefinedElement(MultiplyDefinedElement element); |
| 1055 |
| 1056 R visitParameterElement(ParameterElement element); |
| 1057 |
| 1058 R visitPrefixElement(PrefixElement element); |
| 1059 |
| 1060 R visitPropertyAccessorElement(PropertyAccessorElement element); |
| 1061 |
| 1062 R visitTopLevelVariableElement(TopLevelVariableElement element); |
| 1063 |
| 1064 R visitTypeParameterElement(TypeParameterElement element); |
| 1065 } |
| 1066 |
| 1067 /** |
| 1068 * An element representing an executable object, including functions, methods, |
| 1069 * constructors, getters, and setters. |
| 1070 * |
| 1071 * Clients may not extend, implement or mix-in this class. |
| 1072 */ |
| 1073 abstract class ExecutableElement implements FunctionTypedElement { |
| 1074 /** |
| 1075 * An empty list of executable elements. |
| 1076 */ |
| 1077 static const List<ExecutableElement> EMPTY_LIST = const <ExecutableElement>[]; |
| 1078 |
| 1079 /** |
| 1080 * Return a list containing all of the functions defined within this |
| 1081 * executable element. |
| 1082 */ |
| 1083 List<FunctionElement> get functions; |
| 1084 |
| 1085 /** |
| 1086 * Return `true` if this executable element did not have an explicit return |
| 1087 * type specified for it in the original source. Note that if there was no |
| 1088 * explicit return type, and if the element model is fully populated, then |
| 1089 * the [returnType] will not be `null`. |
| 1090 */ |
| 1091 bool get hasImplicitReturnType; |
| 1092 |
| 1093 /** |
| 1094 * Return `true` if this executable element is abstract. Executable elements |
| 1095 * are abstract if they are not external and have no body. |
| 1096 */ |
| 1097 bool get isAbstract; |
| 1098 |
| 1099 /** |
| 1100 * Return `true` if this executable element has body marked as being |
| 1101 * asynchronous. |
| 1102 */ |
| 1103 bool get isAsynchronous; |
| 1104 |
| 1105 /** |
| 1106 * Return `true` if this executable element is external. Executable elements |
| 1107 * are external if they are explicitly marked as such using the 'external' |
| 1108 * keyword. |
| 1109 */ |
| 1110 bool get isExternal; |
| 1111 |
| 1112 /** |
| 1113 * Return `true` if this executable element has a body marked as being a |
| 1114 * generator. |
| 1115 */ |
| 1116 bool get isGenerator; |
| 1117 |
| 1118 /** |
| 1119 * Return `true` if this executable element is an operator. The test may be |
| 1120 * based on the name of the executable element, in which case the result will |
| 1121 * be correct when the name is legal. |
| 1122 */ |
| 1123 bool get isOperator; |
| 1124 |
| 1125 /** |
| 1126 * Return `true` if this element is a static element. A static element is an |
| 1127 * element that is not associated with a particular instance, but rather with |
| 1128 * an entire library or class. |
| 1129 */ |
| 1130 bool get isStatic; |
| 1131 |
| 1132 /** |
| 1133 * Return `true` if this executable element has a body marked as being |
| 1134 * synchronous. |
| 1135 */ |
| 1136 bool get isSynchronous; |
| 1137 |
| 1138 /** |
| 1139 * Return a list containing all of the labels defined within this executable |
| 1140 * element. |
| 1141 */ |
| 1142 List<LabelElement> get labels; |
| 1143 |
| 1144 /** |
| 1145 * Return a list containing all of the local variables defined within this |
| 1146 * executable element. |
| 1147 */ |
| 1148 List<LocalVariableElement> get localVariables; |
| 1149 } |
| 1150 |
| 1151 /** |
| 1152 * An export directive within a library. |
| 1153 * |
| 1154 * Clients may not extend, implement or mix-in this class. |
| 1155 */ |
| 1156 abstract class ExportElement implements Element, UriReferencedElement { |
| 1157 /** |
| 1158 * An empty list of export elements. |
| 1159 */ |
| 1160 static const List<ExportElement> EMPTY_LIST = const <ExportElement>[]; |
| 1161 |
| 1162 /** |
| 1163 * Return a list containing the combinators that were specified as part of the |
| 1164 * export directive in the order in which they were specified. |
| 1165 */ |
| 1166 List<NamespaceCombinator> get combinators; |
| 1167 |
| 1168 /** |
| 1169 * Return the library that is exported from this library by this export |
| 1170 * directive. |
| 1171 */ |
| 1172 LibraryElement get exportedLibrary; |
| 1173 } |
| 1174 |
| 1175 /** |
| 1176 * A field defined within a type. |
| 1177 * |
| 1178 * Clients may not extend, implement or mix-in this class. |
| 1179 */ |
| 1180 abstract class FieldElement |
| 1181 implements ClassMemberElement, PropertyInducingElement { |
| 1182 /** |
| 1183 * An empty list of field elements. |
| 1184 */ |
| 1185 static const List<FieldElement> EMPTY_LIST = const <FieldElement>[]; |
| 1186 |
| 1187 /** |
| 1188 * Return {@code true} if this element is an enum constant. |
| 1189 */ |
| 1190 bool get isEnumConstant; |
| 1191 |
| 1192 /** |
| 1193 * Returns `true` if this field can be overridden in strong mode. |
| 1194 */ |
| 1195 bool get isVirtual; |
| 1196 |
| 1197 @override |
| 1198 AstNode computeNode(); |
| 1199 } |
| 1200 |
| 1201 /** |
| 1202 * A field formal parameter defined within a constructor element. |
| 1203 * |
| 1204 * Clients may not extend, implement or mix-in this class. |
| 1205 */ |
| 1206 abstract class FieldFormalParameterElement implements ParameterElement { |
| 1207 /** |
| 1208 * Return the field element associated with this field formal parameter, or |
| 1209 * `null` if the parameter references a field that doesn't exist. |
| 1210 */ |
| 1211 FieldElement get field; |
| 1212 } |
| 1213 |
| 1214 /** |
| 1215 * A (non-method) function. This can be either a top-level function, a local |
| 1216 * function, a closure, or the initialization expression for a field or |
| 1217 * variable. |
| 1218 * |
| 1219 * Clients may not extend, implement or mix-in this class. |
| 1220 */ |
| 1221 abstract class FunctionElement implements ExecutableElement, LocalElement { |
| 1222 /** |
| 1223 * An empty list of function elements. |
| 1224 */ |
| 1225 static const List<FunctionElement> EMPTY_LIST = const <FunctionElement>[]; |
| 1226 |
| 1227 /** |
| 1228 * The name of the method that can be implemented by a class to allow its |
| 1229 * instances to be invoked as if they were a function. |
| 1230 */ |
| 1231 static final String CALL_METHOD_NAME = "call"; |
| 1232 |
| 1233 /** |
| 1234 * The name of the synthetic function defined for libraries that are deferred. |
| 1235 */ |
| 1236 static final String LOAD_LIBRARY_NAME = "loadLibrary"; |
| 1237 |
| 1238 /** |
| 1239 * The name of the function used as an entry point. |
| 1240 */ |
| 1241 static const String MAIN_FUNCTION_NAME = "main"; |
| 1242 |
| 1243 /** |
| 1244 * The name of the method that will be invoked if an attempt is made to invoke |
| 1245 * an undefined method on an object. |
| 1246 */ |
| 1247 static final String NO_SUCH_METHOD_METHOD_NAME = "noSuchMethod"; |
| 1248 |
| 1249 /** |
| 1250 * Return `true` if the function is an entry point, i.e. a top-level function |
| 1251 * and has the name `main`. |
| 1252 */ |
| 1253 bool get isEntryPoint; |
| 1254 |
| 1255 @override |
| 1256 FunctionDeclaration computeNode(); |
| 1257 } |
| 1258 |
| 1259 /** |
| 1260 * A function type alias (`typedef`). |
| 1261 * |
| 1262 * Clients may not extend, implement or mix-in this class. |
| 1263 */ |
| 1264 abstract class FunctionTypeAliasElement |
| 1265 implements FunctionTypedElement, TypeDefiningElement { |
| 1266 /** |
| 1267 * An empty array of type alias elements. |
| 1268 */ |
| 1269 static List<FunctionTypeAliasElement> EMPTY_LIST = |
| 1270 new List<FunctionTypeAliasElement>(0); |
| 1271 |
| 1272 /** |
| 1273 * Return the compilation unit in which this type alias is defined. |
| 1274 */ |
| 1275 @override |
| 1276 CompilationUnitElement get enclosingElement; |
| 1277 |
| 1278 @override |
| 1279 FunctionTypeAlias computeNode(); |
| 1280 } |
| 1281 |
| 1282 /** |
| 1283 * An element that has a [FunctionType] as its [type]. |
| 1284 * |
| 1285 * This also provides convenient access to the parameters and return type. |
| 1286 * |
| 1287 * Clients may not extend, implement or mix-in this class. |
| 1288 */ |
| 1289 abstract class FunctionTypedElement implements TypeParameterizedElement { |
| 1290 /** |
| 1291 * Return a list containing all of the parameters defined by this executable |
| 1292 * element. |
| 1293 */ |
| 1294 List<ParameterElement> get parameters; |
| 1295 |
| 1296 /** |
| 1297 * Return the return type defined by this element. If the element model is |
| 1298 * fully populated, then the [returnType] will not be `null`, even if no |
| 1299 * return type was explicitly specified. |
| 1300 */ |
| 1301 DartType get returnType; |
| 1302 |
| 1303 /** |
| 1304 * The type of this element, which will be a function type. |
| 1305 */ |
| 1306 FunctionType get type; |
| 1307 } |
| 1308 |
| 1309 /** |
| 1310 * A combinator that causes some of the names in a namespace to be hidden when |
| 1311 * being imported. |
| 1312 * |
| 1313 * Clients may not extend, implement or mix-in this class. |
| 1314 */ |
| 1315 abstract class HideElementCombinator implements NamespaceCombinator { |
| 1316 /** |
| 1317 * Return a list containing the names that are not to be made visible in the |
| 1318 * importing library even if they are defined in the imported library. |
| 1319 */ |
| 1320 List<String> get hiddenNames; |
| 1321 } |
| 1322 |
| 1323 /** |
| 1324 * A single import directive within a library. |
| 1325 * |
| 1326 * Clients may not extend, implement or mix-in this class. |
| 1327 */ |
| 1328 abstract class ImportElement implements Element, UriReferencedElement { |
| 1329 /** |
| 1330 * An empty list of import elements. |
| 1331 */ |
| 1332 static const List<ImportElement> EMPTY_LIST = const <ImportElement>[]; |
| 1333 |
| 1334 /** |
| 1335 * Return a list containing the combinators that were specified as part of the |
| 1336 * import directive in the order in which they were specified. |
| 1337 */ |
| 1338 List<NamespaceCombinator> get combinators; |
| 1339 |
| 1340 /** |
| 1341 * Return the library that is imported into this library by this import |
| 1342 * directive. |
| 1343 */ |
| 1344 LibraryElement get importedLibrary; |
| 1345 |
| 1346 /** |
| 1347 * Return `true` if this import is for a deferred library. |
| 1348 */ |
| 1349 bool get isDeferred; |
| 1350 |
| 1351 /** |
| 1352 * Return the prefix that was specified as part of the import directive, or |
| 1353 * `null` if there was no prefix specified. |
| 1354 */ |
| 1355 PrefixElement get prefix; |
| 1356 |
| 1357 /** |
| 1358 * Return the offset of the prefix of this import in the file that contains |
| 1359 * this import directive, or `-1` if this import is synthetic, does not have a |
| 1360 * prefix, or otherwise does not have an offset. |
| 1361 */ |
| 1362 int get prefixOffset; |
| 1363 } |
| 1364 |
| 1365 /** |
| 1366 * A label associated with a statement. |
| 1367 * |
| 1368 * Clients may not extend, implement or mix-in this class. |
| 1369 */ |
| 1370 abstract class LabelElement implements Element { |
| 1371 /** |
| 1372 * An empty list of label elements. |
| 1373 */ |
| 1374 static const List<LabelElement> EMPTY_LIST = const <LabelElement>[]; |
| 1375 |
| 1376 @override |
| 1377 ExecutableElement get enclosingElement; |
| 1378 } |
| 1379 |
| 1380 /** |
| 1381 * A library. |
| 1382 * |
| 1383 * Clients may not extend, implement or mix-in this class. |
| 1384 */ |
| 1385 abstract class LibraryElement implements Element { |
| 1386 /** |
| 1387 * An empty list of library elements. |
| 1388 */ |
| 1389 static const List<LibraryElement> EMPTY_LIST = const <LibraryElement>[]; |
| 1390 |
| 1391 /** |
| 1392 * Return the compilation unit that defines this library. |
| 1393 */ |
| 1394 CompilationUnitElement get definingCompilationUnit; |
| 1395 |
| 1396 /** |
| 1397 * Return the entry point for this library, or `null` if this library does not |
| 1398 * have an entry point. The entry point is defined to be a zero argument |
| 1399 * top-level function whose name is `main`. |
| 1400 */ |
| 1401 FunctionElement get entryPoint; |
| 1402 |
| 1403 /** |
| 1404 * Return a list containing all of the libraries that are exported from this |
| 1405 * library. |
| 1406 */ |
| 1407 List<LibraryElement> get exportedLibraries; |
| 1408 |
| 1409 /** |
| 1410 * The export [Namespace] of this library, `null` if it has not been |
| 1411 * computed yet. |
| 1412 */ |
| 1413 Namespace get exportNamespace; |
| 1414 |
| 1415 /** |
| 1416 * Return a list containing all of the exports defined in this library. |
| 1417 */ |
| 1418 List<ExportElement> get exports; |
| 1419 |
| 1420 /** |
| 1421 * Return `true` if the defining compilation unit of this library contains at |
| 1422 * least one import directive whose URI uses the "dart-ext" scheme. |
| 1423 */ |
| 1424 bool get hasExtUri; |
| 1425 |
| 1426 /** |
| 1427 * Return `true` if this library defines a top-level function named |
| 1428 * `loadLibrary`. |
| 1429 */ |
| 1430 bool get hasLoadLibraryFunction; |
| 1431 |
| 1432 /** |
| 1433 * Return an identifier that uniquely identifies this element among the |
| 1434 * children of this element's parent. |
| 1435 */ |
| 1436 String get identifier; |
| 1437 |
| 1438 /** |
| 1439 * Return a list containing all of the libraries that are imported into this |
| 1440 * library. This includes all of the libraries that are imported using a |
| 1441 * prefix (also available through the prefixes returned by [getPrefixes]) and |
| 1442 * those that are imported without a prefix. |
| 1443 */ |
| 1444 List<LibraryElement> get importedLibraries; |
| 1445 |
| 1446 /** |
| 1447 * Return a list containing all of the imports defined in this library. |
| 1448 */ |
| 1449 List<ImportElement> get imports; |
| 1450 |
| 1451 /** |
| 1452 * Return `true` if this library is an application that can be run in the |
| 1453 * browser. |
| 1454 */ |
| 1455 bool get isBrowserApplication; |
| 1456 |
| 1457 /** |
| 1458 * Return `true` if this library is the dart:async library. |
| 1459 */ |
| 1460 bool get isDartAsync; |
| 1461 |
| 1462 /** |
| 1463 * Return `true` if this library is the dart:core library. |
| 1464 */ |
| 1465 bool get isDartCore; |
| 1466 |
| 1467 /** |
| 1468 * Return `true` if this library is part of the SDK. |
| 1469 */ |
| 1470 bool get isInSdk; |
| 1471 |
| 1472 /** |
| 1473 * Return a list containing the strongly connected component in the |
| 1474 * import/export graph in which the current library resides. |
| 1475 */ |
| 1476 List<LibraryElement> get libraryCycle; |
| 1477 |
| 1478 /** |
| 1479 * Return the element representing the synthetic function `loadLibrary` that |
| 1480 * is implicitly defined for this library if the library is imported using a |
| 1481 * deferred import. |
| 1482 */ |
| 1483 FunctionElement get loadLibraryFunction; |
| 1484 |
| 1485 /** |
| 1486 * Return a list containing all of the compilation units that are included in |
| 1487 * this library using a `part` directive. This does not include the defining |
| 1488 * compilation unit that contains the `part` directives. |
| 1489 */ |
| 1490 List<CompilationUnitElement> get parts; |
| 1491 |
| 1492 /** |
| 1493 * Return a list containing elements for each of the prefixes used to `import` |
| 1494 * libraries into this library. Each prefix can be used in more than one |
| 1495 * `import` directive. |
| 1496 */ |
| 1497 List<PrefixElement> get prefixes; |
| 1498 |
| 1499 /** |
| 1500 * The public [Namespace] of this library, `null` if it has not been |
| 1501 * computed yet. |
| 1502 */ |
| 1503 Namespace get publicNamespace; |
| 1504 |
| 1505 /** |
| 1506 * Return a list containing all of the compilation units this library consists |
| 1507 * of. This includes the defining compilation unit and units included using |
| 1508 * the `part` directive. |
| 1509 */ |
| 1510 List<CompilationUnitElement> get units; |
| 1511 |
| 1512 /** |
| 1513 * Return a list containing all of the imports that share the given [prefix], |
| 1514 * or an empty array if there are no such imports. |
| 1515 */ |
| 1516 List<ImportElement> getImportsWithPrefix(PrefixElement prefix); |
| 1517 |
| 1518 /** |
| 1519 * Return the class defined in this library that has the given [name], or |
| 1520 * `null` if this library does not define a class with the given name. |
| 1521 */ |
| 1522 ClassElement getType(String className); |
| 1523 } |
| 1524 |
| 1525 /** |
| 1526 * An element that can be (but is not required to be) defined within a method |
| 1527 * or function (an [ExecutableElement]). |
| 1528 * |
| 1529 * Clients may not extend, implement or mix-in this class. |
| 1530 */ |
| 1531 abstract class LocalElement implements Element { |
| 1532 /** |
| 1533 * Return a source range that covers the approximate portion of the source in |
| 1534 * which the name of this element is visible, or `null` if there is no single |
| 1535 * range of characters within which the element name is visible. |
| 1536 * |
| 1537 * * For a local variable, this is the source range of the block that |
| 1538 * encloses the variable declaration. |
| 1539 * * For a parameter, this includes the body of the method or function that |
| 1540 * declares the parameter. |
| 1541 * * For a local function, this is the source range of the block that |
| 1542 * encloses the variable declaration. |
| 1543 * * For top-level functions, `null` will be returned because they are |
| 1544 * potentially visible in multiple sources. |
| 1545 */ |
| 1546 SourceRange get visibleRange; |
| 1547 } |
| 1548 |
| 1549 /** |
| 1550 * A local variable. |
| 1551 * |
| 1552 * Clients may not extend, implement or mix-in this class. |
| 1553 */ |
| 1554 abstract class LocalVariableElement implements LocalElement, VariableElement { |
| 1555 /** |
| 1556 * An empty list of field elements. |
| 1557 */ |
| 1558 static const List<LocalVariableElement> EMPTY_LIST = |
| 1559 const <LocalVariableElement>[]; |
| 1560 } |
| 1561 |
| 1562 /** |
| 1563 * An element that represents a method defined within a type. |
| 1564 * |
| 1565 * Clients may not extend, implement or mix-in this class. |
| 1566 */ |
| 1567 abstract class MethodElement implements ClassMemberElement, ExecutableElement { |
| 1568 /** |
| 1569 * An empty list of method elements. |
| 1570 */ |
| 1571 static const List<MethodElement> EMPTY_LIST = const <MethodElement>[]; |
| 1572 |
| 1573 @override |
| 1574 MethodDeclaration computeNode(); |
| 1575 } |
| 1576 |
| 1577 /** |
| 1578 * A pseudo-element that represents multiple elements defined within a single |
| 1579 * scope that have the same name. This situation is not allowed by the language, |
| 1580 * so objects implementing this interface always represent an error. As a |
| 1581 * result, most of the normal operations on elements do not make sense and will |
| 1582 * return useless results. |
| 1583 * |
| 1584 * Clients may not extend, implement or mix-in this class. |
| 1585 */ |
| 1586 abstract class MultiplyDefinedElement implements Element { |
| 1587 /** |
| 1588 * Return a list containing all of the elements that were defined within the |
| 1589 * scope to have the same name. |
| 1590 */ |
| 1591 List<Element> get conflictingElements; |
| 1592 |
| 1593 /** |
| 1594 * Return the type of this element as the dynamic type. |
| 1595 */ |
| 1596 DartType get type; |
| 1597 } |
| 1598 |
| 1599 /** |
| 1600 * An [ExecutableElement], with the additional information of a list of |
| 1601 * [ExecutableElement]s from which this element was composed. |
| 1602 * |
| 1603 * Clients may not extend, implement or mix-in this class. |
| 1604 */ |
| 1605 abstract class MultiplyInheritedExecutableElement implements ExecutableElement { |
| 1606 /** |
| 1607 * Return a list containing all of the executable elements defined within this |
| 1608 * executable element. |
| 1609 */ |
| 1610 List<ExecutableElement> get inheritedElements; |
| 1611 } |
| 1612 |
| 1613 /** |
| 1614 * An object that controls how namespaces are combined. |
| 1615 * |
| 1616 * Clients may not extend, implement or mix-in this class. |
| 1617 */ |
| 1618 abstract class NamespaceCombinator { |
| 1619 /** |
| 1620 * An empty list of namespace combinators. |
| 1621 */ |
| 1622 static const List<NamespaceCombinator> EMPTY_LIST = |
| 1623 const <NamespaceCombinator>[]; |
| 1624 } |
| 1625 |
| 1626 /** |
| 1627 * A parameter defined within an executable element. |
| 1628 * |
| 1629 * Clients may not extend, implement or mix-in this class. |
| 1630 */ |
| 1631 abstract class ParameterElement |
| 1632 implements LocalElement, VariableElement, ConstantEvaluationTarget { |
| 1633 /** |
| 1634 * An empty list of parameter elements. |
| 1635 */ |
| 1636 static const List<ParameterElement> EMPTY_LIST = const <ParameterElement>[]; |
| 1637 |
| 1638 /** |
| 1639 * Return the Dart code of the default value, or `null` if no default value. |
| 1640 */ |
| 1641 String get defaultValueCode; |
| 1642 |
| 1643 /** |
| 1644 * Return `true` if this parameter is covariant, meaning it is allowed to have |
| 1645 * a narrower type in an override. |
| 1646 */ |
| 1647 bool get isCovariant; |
| 1648 |
| 1649 /** |
| 1650 * Return `true` if this parameter is an initializing formal parameter. |
| 1651 */ |
| 1652 bool get isInitializingFormal; |
| 1653 |
| 1654 /** |
| 1655 * Return the kind of this parameter. |
| 1656 */ |
| 1657 ParameterKind get parameterKind; |
| 1658 |
| 1659 /** |
| 1660 * Return a list containing all of the parameters defined by this parameter. |
| 1661 * A parameter will only define other parameters if it is a function typed |
| 1662 * parameter. |
| 1663 */ |
| 1664 List<ParameterElement> get parameters; |
| 1665 |
| 1666 /** |
| 1667 * Return a list containing all of the type parameters defined by this |
| 1668 * parameter. A parameter will only define other parameters if it is a |
| 1669 * function typed parameter. |
| 1670 */ |
| 1671 List<TypeParameterElement> get typeParameters; |
| 1672 |
| 1673 /** |
| 1674 * Append the type, name and possibly the default value of this parameter to |
| 1675 * the given [buffer]. |
| 1676 */ |
| 1677 void appendToWithoutDelimiters(StringBuffer buffer); |
| 1678 |
| 1679 @override |
| 1680 FormalParameter computeNode(); |
| 1681 } |
| 1682 |
| 1683 /** |
| 1684 * A prefix used to import one or more libraries into another library. |
| 1685 * |
| 1686 * Clients may not extend, implement or mix-in this class. |
| 1687 */ |
| 1688 abstract class PrefixElement implements Element { |
| 1689 /** |
| 1690 * An empty list of prefix elements. |
| 1691 */ |
| 1692 static const List<PrefixElement> EMPTY_LIST = const <PrefixElement>[]; |
| 1693 |
| 1694 @override |
| 1695 LibraryElement get enclosingElement; |
| 1696 |
| 1697 /** |
| 1698 * Return the empty list. |
| 1699 * |
| 1700 * Deprecated: this getter was intended to return a list containing all of |
| 1701 * the libraries that are imported using this prefix, but it was never |
| 1702 * implemented. Due to lack of demand, it is being removed. |
| 1703 */ |
| 1704 @deprecated |
| 1705 List<LibraryElement> get importedLibraries; |
| 1706 } |
| 1707 |
| 1708 /** |
| 1709 * A getter or a setter. Note that explicitly defined property accessors |
| 1710 * implicitly define a synthetic field. Symmetrically, synthetic accessors are |
| 1711 * implicitly created for explicitly defined fields. The following rules apply: |
| 1712 * |
| 1713 * * Every explicit field is represented by a non-synthetic [FieldElement]. |
| 1714 * * Every explicit field induces a getter and possibly a setter, both of which |
| 1715 * are represented by synthetic [PropertyAccessorElement]s. |
| 1716 * * Every explicit getter or setter is represented by a non-synthetic |
| 1717 * [PropertyAccessorElement]. |
| 1718 * * Every explicit getter or setter (or pair thereof if they have the same |
| 1719 * name) induces a field that is represented by a synthetic [FieldElement]. |
| 1720 * |
| 1721 * Clients may not extend, implement or mix-in this class. |
| 1722 */ |
| 1723 abstract class PropertyAccessorElement implements ExecutableElement { |
| 1724 /** |
| 1725 * An empty list of property accessor elements. |
| 1726 */ |
| 1727 static const List<PropertyAccessorElement> EMPTY_LIST = |
| 1728 const <PropertyAccessorElement>[]; |
| 1729 |
| 1730 /** |
| 1731 * Return the accessor representing the getter that corresponds to (has the |
| 1732 * same name as) this setter, or `null` if this accessor is not a setter or if |
| 1733 * there is no corresponding getter. |
| 1734 */ |
| 1735 PropertyAccessorElement get correspondingGetter; |
| 1736 |
| 1737 /** |
| 1738 * Return the accessor representing the setter that corresponds to (has the |
| 1739 * same name as) this getter, or `null` if this accessor is not a getter or if |
| 1740 * there is no corresponding setter. |
| 1741 */ |
| 1742 PropertyAccessorElement get correspondingSetter; |
| 1743 |
| 1744 /** |
| 1745 * Return `true` if this accessor represents a getter. |
| 1746 */ |
| 1747 bool get isGetter; |
| 1748 |
| 1749 /** |
| 1750 * Return `true` if this accessor represents a setter. |
| 1751 */ |
| 1752 bool get isSetter; |
| 1753 |
| 1754 /** |
| 1755 * Return the field or top-level variable associated with this accessor. If |
| 1756 * this accessor was explicitly defined (is not synthetic) then the variable |
| 1757 * associated with it will be synthetic. |
| 1758 */ |
| 1759 PropertyInducingElement get variable; |
| 1760 } |
| 1761 |
| 1762 /** |
| 1763 * A variable that has an associated getter and possibly a setter. Note that |
| 1764 * explicitly defined variables implicitly define a synthetic getter and that |
| 1765 * non-`final` explicitly defined variables implicitly define a synthetic |
| 1766 * setter. Symmetrically, synthetic fields are implicitly created for explicitly |
| 1767 * defined getters and setters. The following rules apply: |
| 1768 * |
| 1769 * * Every explicit variable is represented by a non-synthetic |
| 1770 * [PropertyInducingElement]. |
| 1771 * * Every explicit variable induces a getter and possibly a setter, both of |
| 1772 * which are represented by synthetic [PropertyAccessorElement]s. |
| 1773 * * Every explicit getter or setter is represented by a non-synthetic |
| 1774 * [PropertyAccessorElement]. |
| 1775 * * Every explicit getter or setter (or pair thereof if they have the same |
| 1776 * name) induces a variable that is represented by a synthetic |
| 1777 * [PropertyInducingElement]. |
| 1778 * |
| 1779 * Clients may not extend, implement or mix-in this class. |
| 1780 */ |
| 1781 abstract class PropertyInducingElement implements VariableElement { |
| 1782 /** |
| 1783 * An empty list of elements. |
| 1784 */ |
| 1785 static const List<PropertyInducingElement> EMPTY_LIST = |
| 1786 const <PropertyInducingElement>[]; |
| 1787 |
| 1788 /** |
| 1789 * Return the getter associated with this variable. If this variable was |
| 1790 * explicitly defined (is not synthetic) then the getter associated with it |
| 1791 * will be synthetic. |
| 1792 */ |
| 1793 PropertyAccessorElement get getter; |
| 1794 |
| 1795 /** |
| 1796 * Return the propagated type of this variable, or `null` if type propagation |
| 1797 * has not been performed, for example because the variable is not final. |
| 1798 */ |
| 1799 DartType get propagatedType; |
| 1800 |
| 1801 /** |
| 1802 * Return the setter associated with this variable, or `null` if the variable |
| 1803 * is effectively `final` and therefore does not have a setter associated with |
| 1804 * it. (This can happen either because the variable is explicitly defined as |
| 1805 * being `final` or because the variable is induced by an explicit getter that |
| 1806 * does not have a corresponding setter.) If this variable was explicitly |
| 1807 * defined (is not synthetic) then the setter associated with it will be |
| 1808 * synthetic. |
| 1809 */ |
| 1810 PropertyAccessorElement get setter; |
| 1811 } |
| 1812 |
| 1813 /** |
| 1814 * A combinator that cause some of the names in a namespace to be visible (and |
| 1815 * the rest hidden) when being imported. |
| 1816 * |
| 1817 * Clients may not extend, implement or mix-in this class. |
| 1818 */ |
| 1819 abstract class ShowElementCombinator implements NamespaceCombinator { |
| 1820 /** |
| 1821 * Return the offset of the character immediately following the last character |
| 1822 * of this node. |
| 1823 */ |
| 1824 int get end; |
| 1825 |
| 1826 /** |
| 1827 * Return the offset of the 'show' keyword of this element. |
| 1828 */ |
| 1829 int get offset; |
| 1830 |
| 1831 /** |
| 1832 * Return a list containing the names that are to be made visible in the |
| 1833 * importing library if they are defined in the imported library. |
| 1834 */ |
| 1835 List<String> get shownNames; |
| 1836 } |
| 1837 |
| 1838 /** |
| 1839 * A top-level variable. |
| 1840 * |
| 1841 * Clients may not extend, implement or mix-in this class. |
| 1842 */ |
| 1843 abstract class TopLevelVariableElement implements PropertyInducingElement { |
| 1844 /** |
| 1845 * An empty list of top-level variable elements. |
| 1846 */ |
| 1847 static const List<TopLevelVariableElement> EMPTY_LIST = |
| 1848 const <TopLevelVariableElement>[]; |
| 1849 |
| 1850 @override |
| 1851 VariableDeclaration computeNode(); |
| 1852 } |
| 1853 |
| 1854 /** |
| 1855 * An element that defines a type. |
| 1856 * |
| 1857 * Clients may not extend, implement or mix-in this class. |
| 1858 */ |
| 1859 abstract class TypeDefiningElement implements Element { |
| 1860 /** |
| 1861 * Return the type defined by this element. |
| 1862 */ |
| 1863 DartType get type; |
| 1864 } |
| 1865 |
| 1866 /** |
| 1867 * A type parameter. |
| 1868 * |
| 1869 * Clients may not extend, implement or mix-in this class. |
| 1870 */ |
| 1871 abstract class TypeParameterElement implements TypeDefiningElement { |
| 1872 /** |
| 1873 * An empty list of type parameter elements. |
| 1874 */ |
| 1875 static const List<TypeParameterElement> EMPTY_LIST = |
| 1876 const <TypeParameterElement>[]; |
| 1877 |
| 1878 /** |
| 1879 * Return the type representing the bound associated with this parameter, or |
| 1880 * `null` if this parameter does not have an explicit bound. |
| 1881 */ |
| 1882 DartType get bound; |
| 1883 |
| 1884 @override |
| 1885 TypeParameterType get type; |
| 1886 } |
| 1887 |
| 1888 /** |
| 1889 * An element that has type parameters, such as a class or a typedef. This also |
| 1890 * includes functions and methods if support for generic methods is enabled. |
| 1891 * |
| 1892 * Clients may not extend, implement or mix-in this class. |
| 1893 */ |
| 1894 abstract class TypeParameterizedElement implements Element { |
| 1895 /** |
| 1896 * The type of this element, which will be a parameterized type. |
| 1897 */ |
| 1898 ParameterizedType get type; |
| 1899 |
| 1900 /** |
| 1901 * Return a list containing all of the type parameters declared by this |
| 1902 * element directly. This does not include type parameters that are declared |
| 1903 * by any enclosing elements. |
| 1904 */ |
| 1905 List<TypeParameterElement> get typeParameters; |
| 1906 } |
| 1907 |
| 1908 /** |
| 1909 * A pseudo-elements that represents names that are undefined. This situation is |
| 1910 * not allowed by the language, so objects implementing this interface always |
| 1911 * represent an error. As a result, most of the normal operations on elements do |
| 1912 * not make sense and will return useless results. |
| 1913 * |
| 1914 * Clients may not extend, implement or mix-in this class. |
| 1915 */ |
| 1916 abstract class UndefinedElement implements Element {} |
| 1917 |
| 1918 /** |
| 1919 * An element included into a library using some URI. |
| 1920 * |
| 1921 * Clients may not extend, implement or mix-in this class. |
| 1922 */ |
| 1923 abstract class UriReferencedElement implements Element { |
| 1924 /** |
| 1925 * Return the URI that is used to include this element into the enclosing |
| 1926 * library, or `null` if this is the defining compilation unit of a library. |
| 1927 */ |
| 1928 String get uri; |
| 1929 |
| 1930 /** |
| 1931 * Return the offset of the character immediately following the last character |
| 1932 * of this node's URI, or `-1` for synthetic import. |
| 1933 */ |
| 1934 int get uriEnd; |
| 1935 |
| 1936 /** |
| 1937 * Return the offset of the URI in the file, or `-1` if this element is |
| 1938 * synthetic. |
| 1939 */ |
| 1940 int get uriOffset; |
| 1941 } |
| 1942 |
| 1943 /** |
| 1944 * A variable. There are more specific subclasses for more specific kinds of |
| 1945 * variables. |
| 1946 * |
| 1947 * Clients may not extend, implement or mix-in this class. |
| 1948 */ |
| 1949 abstract class VariableElement implements Element, ConstantEvaluationTarget { |
| 1950 /** |
| 1951 * An empty list of variable elements. |
| 1952 */ |
| 1953 static const List<VariableElement> EMPTY_LIST = const <VariableElement>[]; |
| 1954 |
| 1955 /** |
| 1956 * Return a representation of the value of this variable. |
| 1957 * |
| 1958 * Return `null` if either this variable was not declared with the 'const' |
| 1959 * modifier or if the value of this variable could not be computed because of |
| 1960 * errors. |
| 1961 */ |
| 1962 DartObject get constantValue; |
| 1963 |
| 1964 /** |
| 1965 * Return `true` if this variable element did not have an explicit type |
| 1966 * specified for it. |
| 1967 */ |
| 1968 bool get hasImplicitType; |
| 1969 |
| 1970 /** |
| 1971 * Return a synthetic function representing this variable's initializer, or |
| 1972 * `null` if this variable does not have an initializer. The function will |
| 1973 * have no parameters. The return type of the function will be the |
| 1974 * compile-time type of the initialization expression. |
| 1975 */ |
| 1976 FunctionElement get initializer; |
| 1977 |
| 1978 /** |
| 1979 * Return `true` if this variable was declared with the 'const' modifier. |
| 1980 */ |
| 1981 bool get isConst; |
| 1982 |
| 1983 /** |
| 1984 * Return `true` if this variable was declared with the 'final' modifier. |
| 1985 * Variables that are declared with the 'const' modifier will return `false` |
| 1986 * even though they are implicitly final. |
| 1987 */ |
| 1988 bool get isFinal; |
| 1989 |
| 1990 /** |
| 1991 * Return `true` if this variable is potentially mutated somewhere in a |
| 1992 * closure. This information is only available for local variables (including |
| 1993 * parameters) and only after the compilation unit containing the variable has |
| 1994 * been resolved. |
| 1995 * |
| 1996 * This getter is deprecated--it now returns `true` for all local variables |
| 1997 * and parameters. Please use [FunctionBody.isPotentiallyMutatedInClosure] |
| 1998 * instead. |
| 1999 */ |
| 2000 @deprecated |
| 2001 bool get isPotentiallyMutatedInClosure; |
| 2002 |
| 2003 /** |
| 2004 * Return `true` if this variable is potentially mutated somewhere in its |
| 2005 * scope. This information is only available for local variables (including |
| 2006 * parameters) and only after the compilation unit containing the variable has |
| 2007 * been resolved. |
| 2008 * |
| 2009 * This getter is deprecated--it now returns `true` for all local variables |
| 2010 * and parameters. Please use [FunctionBody.isPotentiallyMutatedInClosure] |
| 2011 * instead. |
| 2012 */ |
| 2013 @deprecated |
| 2014 bool get isPotentiallyMutatedInScope; |
| 2015 |
| 2016 /** |
| 2017 * Return `true` if this element is a static variable, as per section 8 of the |
| 2018 * Dart Language Specification: |
| 2019 * |
| 2020 * > A static variable is a variable that is not associated with a particular |
| 2021 * > instance, but rather with an entire library or class. Static variables |
| 2022 * > include library variables and class variables. Class variables are |
| 2023 * > variables whose declaration is immediately nested inside a class |
| 2024 * > declaration and includes the modifier static. A library variable is |
| 2025 * > implicitly static. |
| 2026 */ |
| 2027 bool get isStatic; |
| 2028 |
| 2029 /** |
| 2030 * Return the declared type of this variable, or `null` if the variable did |
| 2031 * not have a declared type (such as if it was declared using the keyword |
| 2032 * 'var'). |
| 2033 */ |
| 2034 DartType get type; |
| 2035 |
| 2036 /** |
| 2037 * Return a representation of the value of this variable, forcing the value |
| 2038 * to be computed if it had not previously been computed, or `null` if either |
| 2039 * this variable was not declared with the 'const' modifier or if the value of |
| 2040 * this variable could not be computed because of errors. |
| 2041 */ |
| 2042 DartObject computeConstantValue(); |
| 2043 } |
| OLD | NEW |