| OLD | NEW |
| (Empty) |
| 1 // This code was auto-generated, is not intended to be edited, and is subject to | |
| 2 // significant change. Please see the README file for more information. | |
| 3 library engine.element; | |
| 4 import 'dart:collection'; | |
| 5 import 'java_core.dart'; | |
| 6 import 'java_engine.dart'; | |
| 7 import 'utilities_collection.dart'; | |
| 8 import 'source.dart'; | |
| 9 import 'scanner.dart' show Keyword; | |
| 10 import 'ast.dart' show Identifier, LibraryIdentifier; | |
| 11 import 'sdk.dart' show DartSdk; | |
| 12 import 'html.dart' show XmlTagNode; | |
| 13 import 'engine.dart' show AnalysisContext; | |
| 14 import 'constant.dart' show EvaluationResultImpl; | |
| 15 import 'utilities_dart.dart'; | |
| 16 /** | |
| 17 * The interface `ClassElement` defines the behavior of elements that represent
a class. | |
| 18 * | |
| 19 * @coverage dart.engine.element | |
| 20 */ | |
| 21 abstract class ClassElement implements Element { | |
| 22 | |
| 23 /** | |
| 24 * Return an array containing all of the accessors (getters and setters) decla
red in this class. | |
| 25 * | |
| 26 * @return the accessors declared in this class | |
| 27 */ | |
| 28 List<PropertyAccessorElement> get accessors; | |
| 29 | |
| 30 /** | |
| 31 * Return an array containing all the supertypes defined for this class and it
s supertypes. This | |
| 32 * includes superclasses, mixins and interfaces. | |
| 33 * | |
| 34 * @return all the supertypes of this class, including mixins | |
| 35 */ | |
| 36 List<InterfaceType> get allSupertypes; | |
| 37 | |
| 38 /** | |
| 39 * Return an array containing all of the constructors declared in this class. | |
| 40 * | |
| 41 * @return the constructors declared in this class | |
| 42 */ | |
| 43 List<ConstructorElement> get constructors; | |
| 44 | |
| 45 /** | |
| 46 * Return an array containing all of the fields declared in this class. | |
| 47 * | |
| 48 * @return the fields declared in this class | |
| 49 */ | |
| 50 List<FieldElement> get fields; | |
| 51 | |
| 52 /** | |
| 53 * Return the element representing the getter with the given name that is decl
ared in this class, | |
| 54 * or `null` if this class does not declare a getter with the given name. | |
| 55 * | |
| 56 * @param getterName the name of the getter to be returned | |
| 57 * @return the getter declared in this class with the given name | |
| 58 */ | |
| 59 PropertyAccessorElement getGetter(String getterName); | |
| 60 | |
| 61 /** | |
| 62 * Return an array containing all of the interfaces that are implemented by th
is class. | |
| 63 * | |
| 64 * <b>Note:</b> Because the element model represents the state of the code, it
is possible for it | |
| 65 * to be semantically invalid. In particular, it is not safe to assume that th
e inheritance | |
| 66 * structure of a class does not contain a cycle. Clients that traverse the in
heritance structure | |
| 67 * must explicitly guard against infinite loops. | |
| 68 * | |
| 69 * @return the interfaces that are implemented by this class | |
| 70 */ | |
| 71 List<InterfaceType> get interfaces; | |
| 72 | |
| 73 /** | |
| 74 * Return the element representing the method with the given name that is decl
ared in this class, | |
| 75 * or `null` if this class does not declare a method with the given name. | |
| 76 * | |
| 77 * @param methodName the name of the method to be returned | |
| 78 * @return the method declared in this class with the given name | |
| 79 */ | |
| 80 MethodElement getMethod(String methodName); | |
| 81 | |
| 82 /** | |
| 83 * Return an array containing all of the methods declared in this class. | |
| 84 * | |
| 85 * @return the methods declared in this class | |
| 86 */ | |
| 87 List<MethodElement> get methods; | |
| 88 | |
| 89 /** | |
| 90 * Return an array containing all of the mixins that are applied to the class
being extended in | |
| 91 * order to derive the superclass of this class. | |
| 92 * | |
| 93 * <b>Note:</b> Because the element model represents the state of the code, it
is possible for it | |
| 94 * to be semantically invalid. In particular, it is not safe to assume that th
e inheritance | |
| 95 * structure of a class does not contain a cycle. Clients that traverse the in
heritance structure | |
| 96 * must explicitly guard against infinite loops. | |
| 97 * | |
| 98 * @return the mixins that are applied to derive the superclass of this class | |
| 99 */ | |
| 100 List<InterfaceType> get mixins; | |
| 101 | |
| 102 /** | |
| 103 * Return the named constructor declared in this class with the given name, or
`null` if | |
| 104 * this class does not declare a named constructor with the given name. | |
| 105 * | |
| 106 * @param name the name of the constructor to be returned | |
| 107 * @return the element representing the specified constructor | |
| 108 */ | |
| 109 ConstructorElement getNamedConstructor(String name); | |
| 110 | |
| 111 /** | |
| 112 * Return the element representing the setter with the given name that is decl
ared in this class, | |
| 113 * or `null` if this class does not declare a setter with the given name. | |
| 114 * | |
| 115 * @param setterName the name of the getter to be returned | |
| 116 * @return the setter declared in this class with the given name | |
| 117 */ | |
| 118 PropertyAccessorElement getSetter(String setterName); | |
| 119 | |
| 120 /** | |
| 121 * Return the superclass of this class, or `null` if the class represents the
class | |
| 122 * 'Object'. All other classes will have a non-`null` superclass. If the super
class was not | |
| 123 * explicitly declared then the implicit superclass 'Object' will be returned. | |
| 124 * | |
| 125 * <b>Note:</b> Because the element model represents the state of the code, it
is possible for it | |
| 126 * to be semantically invalid. In particular, it is not safe to assume that th
e inheritance | |
| 127 * structure of a class does not contain a cycle. Clients that traverse the in
heritance structure | |
| 128 * must explicitly guard against infinite loops. | |
| 129 * | |
| 130 * @return the superclass of this class | |
| 131 */ | |
| 132 InterfaceType get supertype; | |
| 133 | |
| 134 /** | |
| 135 * Return the type defined by the class. | |
| 136 * | |
| 137 * @return the type defined by the class | |
| 138 */ | |
| 139 InterfaceType get type; | |
| 140 | |
| 141 /** | |
| 142 * Return an array containing all of the type parameters declared for this cla
ss. | |
| 143 * | |
| 144 * @return the type parameters declared for this class | |
| 145 */ | |
| 146 List<TypeParameterElement> get typeParameters; | |
| 147 | |
| 148 /** | |
| 149 * Return the unnamed constructor declared in this class, or `null` if this cl
ass does not | |
| 150 * declare an unnamed constructor but does declare named constructors. The ret
urned constructor | |
| 151 * will be synthetic if this class does not declare any constructors, in which
case it will | |
| 152 * represent the default constructor for the class. | |
| 153 * | |
| 154 * @return the unnamed constructor defined in this class | |
| 155 */ | |
| 156 ConstructorElement get unnamedConstructor; | |
| 157 | |
| 158 /** | |
| 159 * Return `true` if this class or its superclass declares a non-final instance
field. | |
| 160 * | |
| 161 * @return `true` if this class or its superclass declares a non-final instanc
e field | |
| 162 */ | |
| 163 bool hasNonFinalField(); | |
| 164 | |
| 165 /** | |
| 166 * Return `true` if this class has reference to super (so, for example, cannot
be used as a | |
| 167 * mixin). | |
| 168 * | |
| 169 * @return `true` if this class has reference to super | |
| 170 */ | |
| 171 bool hasReferenceToSuper(); | |
| 172 | |
| 173 /** | |
| 174 * Return `true` if this class is abstract. A class is abstract if it has an e
xplicit | |
| 175 * `abstract` modifier. Note, that this definition of <i>abstract</i> is diffe
rent from | |
| 176 * <i>has unimplemented members</i>. | |
| 177 * | |
| 178 * @return `true` if this class is abstract | |
| 179 */ | |
| 180 bool get isAbstract; | |
| 181 | |
| 182 /** | |
| 183 * Return `true` if this class is defined by a typedef construct. | |
| 184 * | |
| 185 * @return `true` if this class is defined by a typedef construct | |
| 186 */ | |
| 187 bool get isTypedef; | |
| 188 | |
| 189 /** | |
| 190 * Return `true` if this class can validly be used as a mixin when defining an
other class. | |
| 191 * The behavior of this method is defined by the Dart Language Specification i
n section 9: | |
| 192 * <blockquote>It is a compile-time error if a declared or derived mixin refer
s to super. It is a | |
| 193 * compile-time error if a declared or derived mixin explicitly declares a con
structor. It is a | |
| 194 * compile-time error if a mixin is derived from a class whose superclass is n
ot | |
| 195 * Object.</blockquote> | |
| 196 * | |
| 197 * @return `true` if this class can validly be used as a mixin | |
| 198 */ | |
| 199 bool get isValidMixin; | |
| 200 | |
| 201 /** | |
| 202 * Return the element representing the getter that results from looking up the
given getter in | |
| 203 * this class with respect to the given library, or `null` if the look up fail
s. The | |
| 204 * behavior of this method is defined by the Dart Language Specification in se
ction 12.15.1: | |
| 205 * <blockquote>The result of looking up getter (respectively setter) <i>m</i>
in class <i>C</i> | |
| 206 * with respect to library <i>L</i> is: | |
| 207 * | |
| 208 * * If <i>C</i> declares an instance getter (respectively setter) named <i>m<
/i> that is | |
| 209 * accessible to <i>L</i>, then that getter (respectively setter) is the resul
t of the lookup. | |
| 210 * Otherwise, if <i>C</i> has a superclass <i>S</i>, then the result of the lo
okup is the result | |
| 211 * of looking up getter (respectively setter) <i>m</i> in <i>S</i> with respec
t to <i>L</i>. | |
| 212 * Otherwise, we say that the lookup has failed. | |
| 213 * | |
| 214 * </blockquote> | |
| 215 * | |
| 216 * @param getterName the name of the getter being looked up | |
| 217 * @param library the library with respect to which the lookup is being perfor
med | |
| 218 * @return the result of looking up the given getter in this class with respec
t to the given | |
| 219 * library | |
| 220 */ | |
| 221 PropertyAccessorElement lookUpGetter(String getterName, LibraryElement library
); | |
| 222 | |
| 223 /** | |
| 224 * Return the element representing the method that results from looking up the
given method in | |
| 225 * this class with respect to the given library, or `null` if the look up fail
s. The | |
| 226 * behavior of this method is defined by the Dart Language Specification in se
ction 12.15.1: | |
| 227 * <blockquote> The result of looking up method <i>m</i> in class <i>C</i> wit
h respect to library | |
| 228 * <i>L</i> is: | |
| 229 * | |
| 230 * * If <i>C</i> declares an instance method named <i>m</i> that is accessible
to <i>L</i>, then | |
| 231 * that method is the result of the lookup. Otherwise, if <i>C</i> has a super
class <i>S</i>, then | |
| 232 * the result of the lookup is the result of looking up method <i>m</i> in <i>
S</i> with respect | |
| 233 * to <i>L</i>. Otherwise, we say that the lookup has failed. | |
| 234 * | |
| 235 * </blockquote> | |
| 236 * | |
| 237 * @param methodName the name of the method being looked up | |
| 238 * @param library the library with respect to which the lookup is being perfor
med | |
| 239 * @return the result of looking up the given method in this class with respec
t to the given | |
| 240 * library | |
| 241 */ | |
| 242 MethodElement lookUpMethod(String methodName, LibraryElement library); | |
| 243 | |
| 244 /** | |
| 245 * Return the element representing the setter that results from looking up the
given setter in | |
| 246 * this class with respect to the given library, or `null` if the look up fail
s. The | |
| 247 * behavior of this method is defined by the Dart Language Specification in se
ction 12.16: | |
| 248 * <blockquote> The result of looking up getter (respectively setter) <i>m</i>
in class <i>C</i> | |
| 249 * with respect to library <i>L</i> is: | |
| 250 * | |
| 251 * * If <i>C</i> declares an instance getter (respectively setter) named <i>m<
/i> that is | |
| 252 * accessible to <i>L</i>, then that getter (respectively setter) is the resul
t of the lookup. | |
| 253 * Otherwise, if <i>C</i> has a superclass <i>S</i>, then the result of the lo
okup is the result | |
| 254 * of looking up getter (respectively setter) <i>m</i> in <i>S</i> with respec
t to <i>L</i>. | |
| 255 * Otherwise, we say that the lookup has failed. | |
| 256 * | |
| 257 * </blockquote> | |
| 258 * | |
| 259 * @param setterName the name of the setter being looked up | |
| 260 * @param library the library with respect to which the lookup is being perfor
med | |
| 261 * @return the result of looking up the given setter in this class with respec
t to the given | |
| 262 * library | |
| 263 */ | |
| 264 PropertyAccessorElement lookUpSetter(String setterName, LibraryElement library
); | |
| 265 } | |
| 266 /** | |
| 267 * The interface `ClassMemberElement` defines the behavior of elements that are
contained | |
| 268 * within a [ClassElement]. | |
| 269 */ | |
| 270 abstract class ClassMemberElement implements Element { | |
| 271 | |
| 272 /** | |
| 273 * Return the type in which this member is defined. | |
| 274 * | |
| 275 * @return the type in which this member is defined | |
| 276 */ | |
| 277 ClassElement get enclosingElement; | |
| 278 | |
| 279 /** | |
| 280 * Return `true` if this element is a static element. A static element is an e
lement that is | |
| 281 * not associated with a particular instance, but rather with an entire librar
y or class. | |
| 282 * | |
| 283 * @return `true` if this executable element is a static element | |
| 284 */ | |
| 285 bool get isStatic; | |
| 286 } | |
| 287 /** | |
| 288 * The interface `CompilationUnitElement` defines the behavior of elements repre
senting a | |
| 289 * compilation unit. | |
| 290 * | |
| 291 * @coverage dart.engine.element | |
| 292 */ | |
| 293 abstract class CompilationUnitElement implements Element, UriReferencedElement { | |
| 294 | |
| 295 /** | |
| 296 * Return an array containing all of the top-level accessors (getters and sett
ers) contained in | |
| 297 * this compilation unit. | |
| 298 * | |
| 299 * @return the top-level accessors contained in this compilation unit | |
| 300 */ | |
| 301 List<PropertyAccessorElement> get accessors; | |
| 302 | |
| 303 /** | |
| 304 * Return the library in which this compilation unit is defined. | |
| 305 * | |
| 306 * @return the library in which this compilation unit is defined | |
| 307 */ | |
| 308 LibraryElement get enclosingElement; | |
| 309 | |
| 310 /** | |
| 311 * Return an array containing all of the top-level functions contained in this
compilation unit. | |
| 312 * | |
| 313 * @return the top-level functions contained in this compilation unit | |
| 314 */ | |
| 315 List<FunctionElement> get functions; | |
| 316 | |
| 317 /** | |
| 318 * Return an array containing all of the function type aliases contained in th
is compilation unit. | |
| 319 * | |
| 320 * @return the function type aliases contained in this compilation unit | |
| 321 */ | |
| 322 List<FunctionTypeAliasElement> get functionTypeAliases; | |
| 323 | |
| 324 /** | |
| 325 * Return an array containing all of the top-level variables contained in this
compilation unit. | |
| 326 * | |
| 327 * @return the top-level variables contained in this compilation unit | |
| 328 */ | |
| 329 List<TopLevelVariableElement> get topLevelVariables; | |
| 330 | |
| 331 /** | |
| 332 * Return the class defined in this compilation unit that has the given name,
or `null` if | |
| 333 * this compilation unit does not define a class with the given name. | |
| 334 * | |
| 335 * @param className the name of the class to be returned | |
| 336 * @return the class with the given name that is defined in this compilation u
nit | |
| 337 */ | |
| 338 ClassElement getType(String className); | |
| 339 | |
| 340 /** | |
| 341 * Return an array containing all of the classes contained in this compilation
unit. | |
| 342 * | |
| 343 * @return the classes contained in this compilation unit | |
| 344 */ | |
| 345 List<ClassElement> get types; | |
| 346 } | |
| 347 /** | |
| 348 * The interface `ConstructorElement` defines the behavior of elements represent
ing a | |
| 349 * constructor or a factory method defined within a type. | |
| 350 * | |
| 351 * @coverage dart.engine.element | |
| 352 */ | |
| 353 abstract class ConstructorElement implements ClassMemberElement, ExecutableEleme
nt { | |
| 354 | |
| 355 /** | |
| 356 * Return the constructor to which this constructor is redirecting. | |
| 357 * | |
| 358 * @return the constructor to which this constructor is redirecting | |
| 359 */ | |
| 360 ConstructorElement get redirectedConstructor; | |
| 361 | |
| 362 /** | |
| 363 * Return `true` if this constructor is a const constructor. | |
| 364 * | |
| 365 * @return `true` if this constructor is a const constructor | |
| 366 */ | |
| 367 bool get isConst; | |
| 368 | |
| 369 /** | |
| 370 * Return `true` if this constructor can be used as a default constructor - un
named and has | |
| 371 * no required parameters. | |
| 372 * | |
| 373 * @return `true` if this constructor can be used as a default constructor. | |
| 374 */ | |
| 375 bool get isDefaultConstructor; | |
| 376 | |
| 377 /** | |
| 378 * Return `true` if this constructor represents a factory constructor. | |
| 379 * | |
| 380 * @return `true` if this constructor represents a factory constructor | |
| 381 */ | |
| 382 bool get isFactory; | |
| 383 } | |
| 384 /** | |
| 385 * The interface `Element` defines the behavior common to all of the elements in
the element | |
| 386 * model. Generally speaking, the element model is a semantic model of the progr
am that represents | |
| 387 * things that are declared with a name and hence can be referenced elsewhere in
the code. | |
| 388 * | |
| 389 * There are two exceptions to the general case. First, there are elements in th
e element model that | |
| 390 * are created for the convenience of various kinds of analysis but that do not
have any | |
| 391 * corresponding declaration within the source code. Such elements are marked as
being | |
| 392 * <i>synthetic</i>. Examples of synthetic elements include | |
| 393 * | |
| 394 * * default constructors in classes that do not define any explicit constructor
s, | |
| 395 * * getters and setters that are induced by explicit field declarations, | |
| 396 * * fields that are induced by explicit declarations of getters and setters, an
d | |
| 397 * * functions representing the initialization expression for a variable. | |
| 398 * | |
| 399 * | |
| 400 * Second, there are elements in the element model that do not have a name. Thes
e correspond to | |
| 401 * unnamed functions and exist in order to more accurately represent the semanti
c structure of the | |
| 402 * program. | |
| 403 * | |
| 404 * @coverage dart.engine.element | |
| 405 */ | |
| 406 abstract class Element { | |
| 407 | |
| 408 /** | |
| 409 * A comparator that can be used to sort elements by their name offset. Elemen
ts with a smaller | |
| 410 * offset will be sorted to be before elements with a larger name offset. | |
| 411 */ | |
| 412 static final Comparator<Element> SORT_BY_OFFSET = (Element firstElement, Eleme
nt secondElement) => firstElement.nameOffset - secondElement.nameOffset; | |
| 413 | |
| 414 /** | |
| 415 * Use the given visitor to visit this element. | |
| 416 * | |
| 417 * @param visitor the visitor that will visit this element | |
| 418 * @return the value returned by the visitor as a result of visiting this elem
ent | |
| 419 */ | |
| 420 accept(ElementVisitor visitor); | |
| 421 | |
| 422 /** | |
| 423 * Return the documentation comment for this element as it appears in the orig
inal source | |
| 424 * (complete with the beginning and ending delimiters), or `null` if this elem
ent does not | |
| 425 * have a documentation comment associated with it. This can be a long-running
operation if the | |
| 426 * information needed to access the comment is not cached. | |
| 427 * | |
| 428 * @return this element's documentation comment | |
| 429 * @throws AnalysisException if the documentation comment could not be determi
ned because the | |
| 430 * analysis could not be performed | |
| 431 */ | |
| 432 String computeDocumentationComment(); | |
| 433 | |
| 434 /** | |
| 435 * Return the element of the given class that most immediately encloses this e
lement, or | |
| 436 * `null` if there is no enclosing element of the given class. | |
| 437 * | |
| 438 * @param elementClass the class of the element to be returned | |
| 439 * @return the element that encloses this element | |
| 440 */ | |
| 441 Element getAncestor(Type elementClass); | |
| 442 | |
| 443 /** | |
| 444 * Return the analysis context in which this element is defined. | |
| 445 * | |
| 446 * @return the analysis context in which this element is defined | |
| 447 */ | |
| 448 AnalysisContext get context; | |
| 449 | |
| 450 /** | |
| 451 * Return the display name of this element, or `null` if this element does not
have a name. | |
| 452 * | |
| 453 * In most cases the name and the display name are the same. Differences thoug
h are cases such as | |
| 454 * setters where the name of some setter `set f(x)` is `f=`, instead of `f`. | |
| 455 * | |
| 456 * @return the display name of this element | |
| 457 */ | |
| 458 String get displayName; | |
| 459 | |
| 460 /** | |
| 461 * Return the element that either physically or logically encloses this elemen
t. This will be | |
| 462 * `null` if this element is a library because libraries are the top-level ele
ments in the | |
| 463 * model. | |
| 464 * | |
| 465 * @return the element that encloses this element | |
| 466 */ | |
| 467 Element get enclosingElement; | |
| 468 | |
| 469 /** | |
| 470 * Return the kind of element that this is. | |
| 471 * | |
| 472 * @return the kind of this element | |
| 473 */ | |
| 474 ElementKind get kind; | |
| 475 | |
| 476 /** | |
| 477 * Return the library that contains this element. This will be the element its
elf if it is a | |
| 478 * library element. This will be `null` if this element is an HTML file becaus
e HTML files | |
| 479 * are not contained in libraries. | |
| 480 * | |
| 481 * @return the library that contains this element | |
| 482 */ | |
| 483 LibraryElement get library; | |
| 484 | |
| 485 /** | |
| 486 * Return an object representing the location of this element in the element m
odel. The object can | |
| 487 * be used to locate this element at a later time. | |
| 488 * | |
| 489 * @return the location of this element in the element model | |
| 490 */ | |
| 491 ElementLocation get location; | |
| 492 | |
| 493 /** | |
| 494 * Return an array containing all of the metadata associated with this element
. | |
| 495 * | |
| 496 * @return the metadata associated with this element | |
| 497 */ | |
| 498 List<ElementAnnotation> get metadata; | |
| 499 | |
| 500 /** | |
| 501 * Return the name of this element, or `null` if this element does not have a
name. | |
| 502 * | |
| 503 * @return the name of this element | |
| 504 */ | |
| 505 String get name; | |
| 506 | |
| 507 /** | |
| 508 * Return the offset of the name of this element in the file that contains the
declaration of this | |
| 509 * element, or `-1` if this element is synthetic, does not have a name, or oth
erwise does | |
| 510 * not have an offset. | |
| 511 * | |
| 512 * @return the offset of the name of this element | |
| 513 */ | |
| 514 int get nameOffset; | |
| 515 | |
| 516 /** | |
| 517 * Return the source that contains this element, or `null` if this element is
not contained | |
| 518 * in a source. | |
| 519 * | |
| 520 * @return the source that contains this element | |
| 521 */ | |
| 522 Source get source; | |
| 523 | |
| 524 /** | |
| 525 * Return `true` if this element, assuming that it is within scope, is accessi
ble to code in | |
| 526 * the given library. This is defined by the Dart Language Specification in se
ction 3.2: | |
| 527 * <blockquote> A declaration <i>m</i> is accessible to library <i>L</i> if <i
>m</i> is declared | |
| 528 * in <i>L</i> or if <i>m</i> is public. </blockquote> | |
| 529 * | |
| 530 * @param library the library in which a possible reference to this element wo
uld occur | |
| 531 * @return `true` if this element is accessible to code in the given library | |
| 532 */ | |
| 533 bool isAccessibleIn(LibraryElement library); | |
| 534 | |
| 535 /** | |
| 536 * Return `true` if this element is synthetic. A synthetic element is an eleme
nt that is not | |
| 537 * represented in the source code explicitly, but is implied by the source cod
e, such as the | |
| 538 * default constructor for a class that does not explicitly define any constru
ctors. | |
| 539 * | |
| 540 * @return `true` if this element is synthetic | |
| 541 */ | |
| 542 bool get isSynthetic; | |
| 543 | |
| 544 /** | |
| 545 * Use the given visitor to visit all of the children of this element. There i
s no guarantee of | |
| 546 * the order in which the children will be visited. | |
| 547 * | |
| 548 * @param visitor the visitor that will be used to visit the children of this
element | |
| 549 */ | |
| 550 void visitChildren(ElementVisitor visitor); | |
| 551 } | |
| 552 /** | |
| 553 * The interface `ElementAnnotation` defines the behavior of objects representin
g a single | |
| 554 * annotation associated with an element. | |
| 555 * | |
| 556 * @coverage dart.engine.element | |
| 557 */ | |
| 558 abstract class ElementAnnotation { | |
| 559 | |
| 560 /** | |
| 561 * Return the element representing the field, variable, or const constructor b
eing used as an | |
| 562 * annotation. | |
| 563 * | |
| 564 * @return the field, variable, or constructor being used as an annotation | |
| 565 */ | |
| 566 Element get element; | |
| 567 } | |
| 568 /** | |
| 569 * The enumeration `ElementKind` defines the various kinds of elements in the el
ement model. | |
| 570 * | |
| 571 * @coverage dart.engine.element | |
| 572 */ | |
| 573 class ElementKind extends Enum<ElementKind> { | |
| 574 static final ElementKind CLASS = new ElementKind('CLASS', 0, "class"); | |
| 575 static final ElementKind COMPILATION_UNIT = new ElementKind('COMPILATION_UNIT'
, 1, "compilation unit"); | |
| 576 static final ElementKind CONSTRUCTOR = new ElementKind('CONSTRUCTOR', 2, "cons
tructor"); | |
| 577 static final ElementKind DYNAMIC = new ElementKind('DYNAMIC', 3, "<dynamic>"); | |
| 578 static final ElementKind EMBEDDED_HTML_SCRIPT = new ElementKind('EMBEDDED_HTML
_SCRIPT', 4, "embedded html script"); | |
| 579 static final ElementKind ERROR = new ElementKind('ERROR', 5, "<error>"); | |
| 580 static final ElementKind EXPORT = new ElementKind('EXPORT', 6, "export directi
ve"); | |
| 581 static final ElementKind EXTERNAL_HTML_SCRIPT = new ElementKind('EXTERNAL_HTML
_SCRIPT', 7, "external html script"); | |
| 582 static final ElementKind FIELD = new ElementKind('FIELD', 8, "field"); | |
| 583 static final ElementKind FUNCTION = new ElementKind('FUNCTION', 9, "function")
; | |
| 584 static final ElementKind GETTER = new ElementKind('GETTER', 10, "getter"); | |
| 585 static final ElementKind HTML = new ElementKind('HTML', 11, "html"); | |
| 586 static final ElementKind IMPORT = new ElementKind('IMPORT', 12, "import direct
ive"); | |
| 587 static final ElementKind LABEL = new ElementKind('LABEL', 13, "label"); | |
| 588 static final ElementKind LIBRARY = new ElementKind('LIBRARY', 14, "library"); | |
| 589 static final ElementKind LOCAL_VARIABLE = new ElementKind('LOCAL_VARIABLE', 15
, "local variable"); | |
| 590 static final ElementKind METHOD = new ElementKind('METHOD', 16, "method"); | |
| 591 static final ElementKind NAME = new ElementKind('NAME', 17, "<name>"); | |
| 592 static final ElementKind PARAMETER = new ElementKind('PARAMETER', 18, "paramet
er"); | |
| 593 static final ElementKind PREFIX = new ElementKind('PREFIX', 19, "import prefix
"); | |
| 594 static final ElementKind SETTER = new ElementKind('SETTER', 20, "setter"); | |
| 595 static final ElementKind TOP_LEVEL_VARIABLE = new ElementKind('TOP_LEVEL_VARIA
BLE', 21, "top level variable"); | |
| 596 static final ElementKind FUNCTION_TYPE_ALIAS = new ElementKind('FUNCTION_TYPE_
ALIAS', 22, "function type alias"); | |
| 597 static final ElementKind TYPE_PARAMETER = new ElementKind('TYPE_PARAMETER', 23
, "type parameter"); | |
| 598 static final ElementKind UNIVERSE = new ElementKind('UNIVERSE', 24, "<universe
>"); | |
| 599 static final List<ElementKind> values = [ | |
| 600 CLASS, | |
| 601 COMPILATION_UNIT, | |
| 602 CONSTRUCTOR, | |
| 603 DYNAMIC, | |
| 604 EMBEDDED_HTML_SCRIPT, | |
| 605 ERROR, | |
| 606 EXPORT, | |
| 607 EXTERNAL_HTML_SCRIPT, | |
| 608 FIELD, | |
| 609 FUNCTION, | |
| 610 GETTER, | |
| 611 HTML, | |
| 612 IMPORT, | |
| 613 LABEL, | |
| 614 LIBRARY, | |
| 615 LOCAL_VARIABLE, | |
| 616 METHOD, | |
| 617 NAME, | |
| 618 PARAMETER, | |
| 619 PREFIX, | |
| 620 SETTER, | |
| 621 TOP_LEVEL_VARIABLE, | |
| 622 FUNCTION_TYPE_ALIAS, | |
| 623 TYPE_PARAMETER, | |
| 624 UNIVERSE]; | |
| 625 | |
| 626 /** | |
| 627 * Return the kind of the given element, or [ERROR] if the element is `null`.
This is | |
| 628 * a utility method that can reduce the need for null checks in other places. | |
| 629 * | |
| 630 * @param element the element whose kind is to be returned | |
| 631 * @return the kind of the given element | |
| 632 */ | |
| 633 static ElementKind of(Element element) { | |
| 634 if (element == null) { | |
| 635 return ERROR; | |
| 636 } | |
| 637 return element.kind; | |
| 638 } | |
| 639 | |
| 640 /** | |
| 641 * The name displayed in the UI for this kind of element. | |
| 642 */ | |
| 643 String displayName; | |
| 644 | |
| 645 /** | |
| 646 * Initialize a newly created element kind to have the given display name. | |
| 647 * | |
| 648 * @param displayName the name displayed in the UI for this kind of element | |
| 649 */ | |
| 650 ElementKind(String name, int ordinal, String displayName) : super(name, ordina
l) { | |
| 651 this.displayName = displayName; | |
| 652 } | |
| 653 } | |
| 654 /** | |
| 655 * The interface `ElementLocation` defines the behavior of objects that represen
t the location | |
| 656 * of an element within the element model. | |
| 657 * | |
| 658 * @coverage dart.engine.element | |
| 659 */ | |
| 660 abstract class ElementLocation { | |
| 661 | |
| 662 /** | |
| 663 * Return an encoded representation of this location that can be used to creat
e a location that is | |
| 664 * equal to this location. | |
| 665 * | |
| 666 * @return an encoded representation of this location | |
| 667 */ | |
| 668 String get encoding; | |
| 669 } | |
| 670 /** | |
| 671 * The interface `ElementVisitor` defines the behavior of objects that can be us
ed to visit an | |
| 672 * element structure. | |
| 673 * | |
| 674 * @coverage dart.engine.element | |
| 675 */ | |
| 676 abstract class ElementVisitor<R> { | |
| 677 R visitClassElement(ClassElement element); | |
| 678 R visitCompilationUnitElement(CompilationUnitElement element); | |
| 679 R visitConstructorElement(ConstructorElement element); | |
| 680 R visitEmbeddedHtmlScriptElement(EmbeddedHtmlScriptElement element); | |
| 681 R visitExportElement(ExportElement element); | |
| 682 R visitExternalHtmlScriptElement(ExternalHtmlScriptElement element); | |
| 683 R visitFieldElement(FieldElement element); | |
| 684 R visitFieldFormalParameterElement(FieldFormalParameterElement element); | |
| 685 R visitFunctionElement(FunctionElement element); | |
| 686 R visitFunctionTypeAliasElement(FunctionTypeAliasElement element); | |
| 687 R visitHtmlElement(HtmlElement element); | |
| 688 R visitImportElement(ImportElement element); | |
| 689 R visitLabelElement(LabelElement element); | |
| 690 R visitLibraryElement(LibraryElement element); | |
| 691 R visitLocalVariableElement(LocalVariableElement element); | |
| 692 R visitMethodElement(MethodElement element); | |
| 693 R visitMultiplyDefinedElement(MultiplyDefinedElement element); | |
| 694 R visitParameterElement(ParameterElement element); | |
| 695 R visitPrefixElement(PrefixElement element); | |
| 696 R visitPropertyAccessorElement(PropertyAccessorElement element); | |
| 697 R visitTopLevelVariableElement(TopLevelVariableElement element); | |
| 698 R visitTypeParameterElement(TypeParameterElement element); | |
| 699 } | |
| 700 /** | |
| 701 * The interface `EmbeddedHtmlScriptElement` defines the behavior of elements re
presenting a | |
| 702 * script tag in an HTML file having content that defines a Dart library. | |
| 703 * | |
| 704 * @coverage dart.engine.element | |
| 705 */ | |
| 706 abstract class EmbeddedHtmlScriptElement implements HtmlScriptElement { | |
| 707 | |
| 708 /** | |
| 709 * Return the library element defined by the content of the script tag. | |
| 710 * | |
| 711 * @return the library element (not `null`) | |
| 712 */ | |
| 713 LibraryElement get scriptLibrary; | |
| 714 } | |
| 715 /** | |
| 716 * The interface `ExecutableElement` defines the behavior of elements representi
ng an | |
| 717 * executable object, including functions, methods, constructors, getters, and s
etters. | |
| 718 * | |
| 719 * @coverage dart.engine.element | |
| 720 */ | |
| 721 abstract class ExecutableElement implements Element { | |
| 722 | |
| 723 /** | |
| 724 * Return an array containing all of the functions defined within this executa
ble element. | |
| 725 * | |
| 726 * @return the functions defined within this executable element | |
| 727 */ | |
| 728 List<FunctionElement> get functions; | |
| 729 | |
| 730 /** | |
| 731 * Return an array containing all of the labels defined within this executable
element. | |
| 732 * | |
| 733 * @return the labels defined within this executable element | |
| 734 */ | |
| 735 List<LabelElement> get labels; | |
| 736 | |
| 737 /** | |
| 738 * Return an array containing all of the local variables defined within this e
xecutable element. | |
| 739 * | |
| 740 * @return the local variables defined within this executable element | |
| 741 */ | |
| 742 List<LocalVariableElement> get localVariables; | |
| 743 | |
| 744 /** | |
| 745 * Return an array containing all of the parameters defined by this executable
element. | |
| 746 * | |
| 747 * @return the parameters defined by this executable element | |
| 748 */ | |
| 749 List<ParameterElement> get parameters; | |
| 750 | |
| 751 /** | |
| 752 * Return the return type defined by this executable element. | |
| 753 * | |
| 754 * @return the return type defined by this executable element | |
| 755 */ | |
| 756 Type2 get returnType; | |
| 757 | |
| 758 /** | |
| 759 * Return the type of function defined by this executable element. | |
| 760 * | |
| 761 * @return the type of function defined by this executable element | |
| 762 */ | |
| 763 FunctionType get type; | |
| 764 | |
| 765 /** | |
| 766 * Return `true` if this executable element is an operator. The test may be ba
sed on the | |
| 767 * name of the executable element, in which case the result will be correct wh
en the name is | |
| 768 * legal. | |
| 769 * | |
| 770 * @return `true` if this executable element is an operator | |
| 771 */ | |
| 772 bool get isOperator; | |
| 773 | |
| 774 /** | |
| 775 * Return `true` if this element is a static element. A static element is an e
lement that is | |
| 776 * not associated with a particular instance, but rather with an entire librar
y or class. | |
| 777 * | |
| 778 * @return `true` if this executable element is a static element | |
| 779 */ | |
| 780 bool get isStatic; | |
| 781 } | |
| 782 /** | |
| 783 * The interface `ExportElement` defines the behavior of objects representing in
formation | |
| 784 * about a single export directive within a library. | |
| 785 * | |
| 786 * @coverage dart.engine.element | |
| 787 */ | |
| 788 abstract class ExportElement implements Element, UriReferencedElement { | |
| 789 | |
| 790 /** | |
| 791 * An empty array of export elements. | |
| 792 */ | |
| 793 static final List<ExportElement> EMPTY_ARRAY = new List<ExportElement>(0); | |
| 794 | |
| 795 /** | |
| 796 * Return an array containing the combinators that were specified as part of t
he export directive | |
| 797 * in the order in which they were specified. | |
| 798 * | |
| 799 * @return the combinators specified in the export directive | |
| 800 */ | |
| 801 List<NamespaceCombinator> get combinators; | |
| 802 | |
| 803 /** | |
| 804 * Return the library that is exported from this library by this export direct
ive. | |
| 805 * | |
| 806 * @return the library that is exported from this library | |
| 807 */ | |
| 808 LibraryElement get exportedLibrary; | |
| 809 } | |
| 810 /** | |
| 811 * The interface `ExternalHtmlScriptElement` defines the behavior of elements re
presenting a | |
| 812 * script tag in an HTML file having a `source` attribute that references a Dart
library | |
| 813 * source file. | |
| 814 * | |
| 815 * @coverage dart.engine.element | |
| 816 */ | |
| 817 abstract class ExternalHtmlScriptElement implements HtmlScriptElement { | |
| 818 | |
| 819 /** | |
| 820 * Return the source referenced by this element, or `null` if this element doe
s not | |
| 821 * reference a Dart library source file. | |
| 822 * | |
| 823 * @return the source for the external Dart library | |
| 824 */ | |
| 825 Source get scriptSource; | |
| 826 } | |
| 827 /** | |
| 828 * The interface `FieldElement` defines the behavior of elements representing a
field defined | |
| 829 * within a type. | |
| 830 * | |
| 831 * @coverage dart.engine.element | |
| 832 */ | |
| 833 abstract class FieldElement implements ClassMemberElement, PropertyInducingEleme
nt { | |
| 834 } | |
| 835 /** | |
| 836 * The interface `FieldFormalParameterElement` defines the behavior of elements
representing a | |
| 837 * field formal parameter defined within a constructor element. | |
| 838 */ | |
| 839 abstract class FieldFormalParameterElement implements ParameterElement { | |
| 840 | |
| 841 /** | |
| 842 * Return the field element associated with this field formal parameter, or `n
ull` if the | |
| 843 * parameter references a field that doesn't exist. | |
| 844 * | |
| 845 * @return the field element associated with this field formal parameter | |
| 846 */ | |
| 847 FieldElement get field; | |
| 848 } | |
| 849 /** | |
| 850 * The interface `FunctionElement` defines the behavior of elements representing
a function. | |
| 851 * | |
| 852 * @coverage dart.engine.element | |
| 853 */ | |
| 854 abstract class FunctionElement implements ExecutableElement, LocalElement { | |
| 855 } | |
| 856 /** | |
| 857 * The interface `FunctionTypeAliasElement` defines the behavior of elements rep
resenting a | |
| 858 * function type alias (`typedef`). | |
| 859 * | |
| 860 * @coverage dart.engine.element | |
| 861 */ | |
| 862 abstract class FunctionTypeAliasElement implements Element { | |
| 863 | |
| 864 /** | |
| 865 * Return the compilation unit in which this type alias is defined. | |
| 866 * | |
| 867 * @return the compilation unit in which this type alias is defined | |
| 868 */ | |
| 869 CompilationUnitElement get enclosingElement; | |
| 870 | |
| 871 /** | |
| 872 * Return an array containing all of the parameters defined by this type alias
. | |
| 873 * | |
| 874 * @return the parameters defined by this type alias | |
| 875 */ | |
| 876 List<ParameterElement> get parameters; | |
| 877 | |
| 878 /** | |
| 879 * Return the return type defined by this type alias. | |
| 880 * | |
| 881 * @return the return type defined by this type alias | |
| 882 */ | |
| 883 Type2 get returnType; | |
| 884 | |
| 885 /** | |
| 886 * Return the type of function defined by this type alias. | |
| 887 * | |
| 888 * @return the type of function defined by this type alias | |
| 889 */ | |
| 890 FunctionType get type; | |
| 891 | |
| 892 /** | |
| 893 * Return an array containing all of the type parameters defined for this type
. | |
| 894 * | |
| 895 * @return the type parameters defined for this type | |
| 896 */ | |
| 897 List<TypeParameterElement> get typeParameters; | |
| 898 } | |
| 899 /** | |
| 900 * The interface `HideElementCombinator` defines the behavior of combinators tha
t cause some | |
| 901 * of the names in a namespace to be hidden when being imported. | |
| 902 * | |
| 903 * @coverage dart.engine.element | |
| 904 */ | |
| 905 abstract class HideElementCombinator implements NamespaceCombinator { | |
| 906 | |
| 907 /** | |
| 908 * Return an array containing the names that are not to be made visible in the
importing library | |
| 909 * even if they are defined in the imported library. | |
| 910 * | |
| 911 * @return the names from the imported library that are hidden from the import
ing library | |
| 912 */ | |
| 913 List<String> get hiddenNames; | |
| 914 } | |
| 915 /** | |
| 916 * The interface `HtmlElement` defines the behavior of elements representing an
HTML file. | |
| 917 * | |
| 918 * @coverage dart.engine.element | |
| 919 */ | |
| 920 abstract class HtmlElement implements Element { | |
| 921 | |
| 922 /** | |
| 923 * Return an array containing all of the script elements contained in the HTML
file. This includes | |
| 924 * scripts with libraries that are defined by the content of a script tag as w
ell as libraries | |
| 925 * that are referenced in the {@core source} attribute of a script tag. | |
| 926 * | |
| 927 * @return the script elements in the HTML file (not `null`, contains no `null
`s) | |
| 928 */ | |
| 929 List<HtmlScriptElement> get scripts; | |
| 930 } | |
| 931 /** | |
| 932 * The interface `HtmlScriptElement` defines the behavior of elements representi
ng a script | |
| 933 * tag in an HTML file. | |
| 934 * | |
| 935 * @see EmbeddedHtmlScriptElement | |
| 936 * @see ExternalHtmlScriptElement | |
| 937 * @coverage dart.engine.element | |
| 938 */ | |
| 939 abstract class HtmlScriptElement implements Element { | |
| 940 } | |
| 941 /** | |
| 942 * The interface `ImportElement` defines the behavior of objects representing in
formation | |
| 943 * about a single import directive within a library. | |
| 944 * | |
| 945 * @coverage dart.engine.element | |
| 946 */ | |
| 947 abstract class ImportElement implements Element, UriReferencedElement { | |
| 948 | |
| 949 /** | |
| 950 * An empty array of import elements. | |
| 951 */ | |
| 952 static final List<ImportElement> EMPTY_ARRAY = new List<ImportElement>(0); | |
| 953 | |
| 954 /** | |
| 955 * Return an array containing the combinators that were specified as part of t
he import directive | |
| 956 * in the order in which they were specified. | |
| 957 * | |
| 958 * @return the combinators specified in the import directive | |
| 959 */ | |
| 960 List<NamespaceCombinator> get combinators; | |
| 961 | |
| 962 /** | |
| 963 * Return the library that is imported into this library by this import direct
ive. | |
| 964 * | |
| 965 * @return the library that is imported into this library | |
| 966 */ | |
| 967 LibraryElement get importedLibrary; | |
| 968 | |
| 969 /** | |
| 970 * Return the prefix that was specified as part of the import directive, or `n
ull` if there | |
| 971 * was no prefix specified. | |
| 972 * | |
| 973 * @return the prefix that was specified as part of the import directive | |
| 974 */ | |
| 975 PrefixElement get prefix; | |
| 976 | |
| 977 /** | |
| 978 * Return the offset of the prefix of this import in the file that contains th
is import directive, | |
| 979 * or `-1` if this import is synthetic, does not have a prefix, or otherwise d
oes not have | |
| 980 * an offset. | |
| 981 * | |
| 982 * @return the offset of the prefix of this import | |
| 983 */ | |
| 984 int get prefixOffset; | |
| 985 | |
| 986 /** | |
| 987 * Return the offset of the character immediately following the last character
of this node's URI, | |
| 988 * or `-1` for synthetic import. | |
| 989 * | |
| 990 * @return the offset of the character just past the node's URI | |
| 991 */ | |
| 992 int get uriEnd; | |
| 993 } | |
| 994 /** | |
| 995 * The interface `LabelElement` defines the behavior of elements representing a
label | |
| 996 * associated with a statement. | |
| 997 * | |
| 998 * @coverage dart.engine.element | |
| 999 */ | |
| 1000 abstract class LabelElement implements Element { | |
| 1001 | |
| 1002 /** | |
| 1003 * Return the executable element in which this label is defined. | |
| 1004 * | |
| 1005 * @return the executable element in which this label is defined | |
| 1006 */ | |
| 1007 ExecutableElement get enclosingElement; | |
| 1008 } | |
| 1009 /** | |
| 1010 * The interface `LibraryElement` defines the behavior of elements representing
a library. | |
| 1011 * | |
| 1012 * @coverage dart.engine.element | |
| 1013 */ | |
| 1014 abstract class LibraryElement implements Element { | |
| 1015 | |
| 1016 /** | |
| 1017 * Return the compilation unit that defines this library. | |
| 1018 * | |
| 1019 * @return the compilation unit that defines this library | |
| 1020 */ | |
| 1021 CompilationUnitElement get definingCompilationUnit; | |
| 1022 | |
| 1023 /** | |
| 1024 * Return the entry point for this library, or `null` if this library does not
have an entry | |
| 1025 * point. The entry point is defined to be a zero argument top-level function
whose name is | |
| 1026 * `main`. | |
| 1027 * | |
| 1028 * @return the entry point for this library | |
| 1029 */ | |
| 1030 FunctionElement get entryPoint; | |
| 1031 | |
| 1032 /** | |
| 1033 * Return an array containing all of the libraries that are exported from this
library. | |
| 1034 * | |
| 1035 * @return an array containing all of the libraries that are exported from thi
s library | |
| 1036 */ | |
| 1037 List<LibraryElement> get exportedLibraries; | |
| 1038 | |
| 1039 /** | |
| 1040 * Return an array containing all of the exports defined in this library. | |
| 1041 * | |
| 1042 * @return the exports defined in this library | |
| 1043 */ | |
| 1044 List<ExportElement> get exports; | |
| 1045 | |
| 1046 /** | |
| 1047 * Return an array containing all of the libraries that are imported into this
library. This | |
| 1048 * includes all of the libraries that are imported using a prefix (also availa
ble through the | |
| 1049 * prefixes returned by [getPrefixes]) and those that are imported without a p
refix. | |
| 1050 * | |
| 1051 * @return an array containing all of the libraries that are imported into thi
s library | |
| 1052 */ | |
| 1053 List<LibraryElement> get importedLibraries; | |
| 1054 | |
| 1055 /** | |
| 1056 * Return an array containing all of the imports defined in this library. | |
| 1057 * | |
| 1058 * @return the imports defined in this library | |
| 1059 */ | |
| 1060 List<ImportElement> get imports; | |
| 1061 | |
| 1062 /** | |
| 1063 * Return an array containing all of the compilation units that are included i
n this library using | |
| 1064 * a `part` directive. This does not include the defining compilation unit tha
t contains the | |
| 1065 * `part` directives. | |
| 1066 * | |
| 1067 * @return the compilation units that are included in this library | |
| 1068 */ | |
| 1069 List<CompilationUnitElement> get parts; | |
| 1070 | |
| 1071 /** | |
| 1072 * Return an array containing elements for each of the prefixes used to `impor
t` libraries | |
| 1073 * into this library. Each prefix can be used in more than one `import` direct
ive. | |
| 1074 * | |
| 1075 * @return the prefixes used to `import` libraries into this library | |
| 1076 */ | |
| 1077 List<PrefixElement> get prefixes; | |
| 1078 | |
| 1079 /** | |
| 1080 * Return the class defined in this library that has the given name, or `null`
if this | |
| 1081 * library does not define a class with the given name. | |
| 1082 * | |
| 1083 * @param className the name of the class to be returned | |
| 1084 * @return the class with the given name that is defined in this library | |
| 1085 */ | |
| 1086 ClassElement getType(String className); | |
| 1087 | |
| 1088 /** | |
| 1089 * Answer `true` if this library is an application that can be run in the brow
ser. | |
| 1090 * | |
| 1091 * @return `true` if this library is an application that can be run in the bro
wser | |
| 1092 */ | |
| 1093 bool get isBrowserApplication; | |
| 1094 | |
| 1095 /** | |
| 1096 * Return `true` if this library is the dart:core library. | |
| 1097 * | |
| 1098 * @return `true` if this library is the dart:core library | |
| 1099 */ | |
| 1100 bool get isDartCore; | |
| 1101 | |
| 1102 /** | |
| 1103 * Return `true` if this library is the dart:core library. | |
| 1104 * | |
| 1105 * @return `true` if this library is the dart:core library | |
| 1106 */ | |
| 1107 bool get isInSdk; | |
| 1108 | |
| 1109 /** | |
| 1110 * Return `true` if this library is up to date with respect to the given time
stamp. If any | |
| 1111 * transitively referenced Source is newer than the time stamp, this method re
turns false. | |
| 1112 * | |
| 1113 * @param timeStamp the time stamp to compare against | |
| 1114 * @return `true` if this library is up to date with respect to the given time
stamp | |
| 1115 */ | |
| 1116 bool isUpToDate2(int timeStamp); | |
| 1117 } | |
| 1118 /** | |
| 1119 * The interface `LocalElement` defines the behavior of elements that can be (bu
t are not | |
| 1120 * required to be) defined within a method or function (an [ExecutableElement]). | |
| 1121 * | |
| 1122 * @coverage dart.engine.element | |
| 1123 */ | |
| 1124 abstract class LocalElement implements Element { | |
| 1125 | |
| 1126 /** | |
| 1127 * Return a source range that covers the approximate portion of the source in
which the name of | |
| 1128 * this element is visible, or `null` if there is no single range of character
s within which | |
| 1129 * the element name is visible. | |
| 1130 * | |
| 1131 * * For a local variable, this includes everything from the end of the variab
le's initializer | |
| 1132 * to the end of the block that encloses the variable declaration. | |
| 1133 * * For a parameter, this includes the body of the method or function that de
clares the | |
| 1134 * parameter. | |
| 1135 * * For a local function, this includes everything from the beginning of the
function's body to | |
| 1136 * the end of the block that encloses the function declaration. | |
| 1137 * * For top-level functions, `null` will be returned because they are potenti
ally visible | |
| 1138 * in multiple sources. | |
| 1139 * | |
| 1140 * | |
| 1141 * @return the range of characters in which the name of this element is visibl
e | |
| 1142 */ | |
| 1143 SourceRange get visibleRange; | |
| 1144 } | |
| 1145 /** | |
| 1146 * The interface `LocalVariableElement` defines the behavior common to elements
that represent | |
| 1147 * a local variable. | |
| 1148 * | |
| 1149 * @coverage dart.engine.element | |
| 1150 */ | |
| 1151 abstract class LocalVariableElement implements LocalElement, VariableElement { | |
| 1152 } | |
| 1153 /** | |
| 1154 * The interface `MethodElement` defines the behavior of elements that represent
a method | |
| 1155 * defined within a type. | |
| 1156 * | |
| 1157 * @coverage dart.engine.element | |
| 1158 */ | |
| 1159 abstract class MethodElement implements ClassMemberElement, ExecutableElement { | |
| 1160 | |
| 1161 /** | |
| 1162 * Return `true` if this method is abstract. Methods are abstract if they are
not external | |
| 1163 * and have no body. | |
| 1164 * | |
| 1165 * @return `true` if this method is abstract | |
| 1166 */ | |
| 1167 bool get isAbstract; | |
| 1168 } | |
| 1169 /** | |
| 1170 * The interface `MultiplyDefinedElement` defines the behavior of pseudo-element
s that | |
| 1171 * represent multiple elements defined within a single scope that have the same
name. This situation | |
| 1172 * is not allowed by the language, so objects implementing this interface always
represent an error. | |
| 1173 * As a result, most of the normal operations on elements do not make sense and
will return useless | |
| 1174 * results. | |
| 1175 * | |
| 1176 * @coverage dart.engine.element | |
| 1177 */ | |
| 1178 abstract class MultiplyDefinedElement implements Element { | |
| 1179 | |
| 1180 /** | |
| 1181 * Return an array containing all of the elements that were defined within the
scope to have the | |
| 1182 * same name. | |
| 1183 * | |
| 1184 * @return the elements that were defined with the same name | |
| 1185 */ | |
| 1186 List<Element> get conflictingElements; | |
| 1187 | |
| 1188 /** | |
| 1189 * Return the type of this element as the dynamic type. | |
| 1190 * | |
| 1191 * @return the type of this element as the dynamic type | |
| 1192 */ | |
| 1193 Type2 get type; | |
| 1194 } | |
| 1195 /** | |
| 1196 * The interface `NamespaceCombinator` defines the behavior common to objects th
at control how | |
| 1197 * namespaces are combined. | |
| 1198 * | |
| 1199 * @coverage dart.engine.element | |
| 1200 */ | |
| 1201 abstract class NamespaceCombinator { | |
| 1202 | |
| 1203 /** | |
| 1204 * An empty array of namespace combinators. | |
| 1205 */ | |
| 1206 static final List<NamespaceCombinator> EMPTY_ARRAY = new List<NamespaceCombina
tor>(0); | |
| 1207 } | |
| 1208 /** | |
| 1209 * The interface `ParameterElement` defines the behavior of elements representin
g a parameter | |
| 1210 * defined within an executable element. | |
| 1211 * | |
| 1212 * @coverage dart.engine.element | |
| 1213 */ | |
| 1214 abstract class ParameterElement implements LocalElement, VariableElement { | |
| 1215 | |
| 1216 /** | |
| 1217 * Return a source range that covers the portion of the source in which the de
fault value for this | |
| 1218 * parameter is specified, or `null` if there is no default value. | |
| 1219 * | |
| 1220 * @return the range of characters in which the default value of this paramete
r is specified | |
| 1221 */ | |
| 1222 SourceRange get defaultValueRange; | |
| 1223 | |
| 1224 /** | |
| 1225 * Return the kind of this parameter. | |
| 1226 * | |
| 1227 * @return the kind of this parameter | |
| 1228 */ | |
| 1229 ParameterKind get parameterKind; | |
| 1230 | |
| 1231 /** | |
| 1232 * Return an array containing all of the parameters defined by this parameter.
A parameter will | |
| 1233 * only define other parameters if it is a function typed parameter. | |
| 1234 * | |
| 1235 * @return the parameters defined by this parameter element | |
| 1236 */ | |
| 1237 List<ParameterElement> get parameters; | |
| 1238 | |
| 1239 /** | |
| 1240 * Return `true` if this parameter is an initializing formal parameter. | |
| 1241 * | |
| 1242 * @return `true` if this parameter is an initializing formal parameter | |
| 1243 */ | |
| 1244 bool get isInitializingFormal; | |
| 1245 } | |
| 1246 /** | |
| 1247 * The interface `PrefixElement` defines the behavior common to elements that re
present a | |
| 1248 * prefix used to import one or more libraries into another library. | |
| 1249 * | |
| 1250 * @coverage dart.engine.element | |
| 1251 */ | |
| 1252 abstract class PrefixElement implements Element { | |
| 1253 | |
| 1254 /** | |
| 1255 * Return the library into which other libraries are imported using this prefi
x. | |
| 1256 * | |
| 1257 * @return the library into which other libraries are imported using this pref
ix | |
| 1258 */ | |
| 1259 LibraryElement get enclosingElement; | |
| 1260 | |
| 1261 /** | |
| 1262 * Return an array containing all of the libraries that are imported using thi
s prefix. | |
| 1263 * | |
| 1264 * @return the libraries that are imported using this prefix | |
| 1265 */ | |
| 1266 List<LibraryElement> get importedLibraries; | |
| 1267 } | |
| 1268 /** | |
| 1269 * The interface `PropertyAccessorElement` defines the behavior of elements repr
esenting a | |
| 1270 * getter or a setter. Note that explicitly defined property accessors implicitl
y define a synthetic | |
| 1271 * field. Symmetrically, synthetic accessors are implicitly created for explicit
ly defined fields. | |
| 1272 * The following rules apply: | |
| 1273 * | |
| 1274 * * Every explicit field is represented by a non-synthetic [FieldElement]. | |
| 1275 * * Every explicit field induces a getter and possibly a setter, both of which
are represented by | |
| 1276 * synthetic [PropertyAccessorElement]s. | |
| 1277 * * Every explicit getter or setter is represented by a non-synthetic | |
| 1278 * [PropertyAccessorElement]. | |
| 1279 * * Every explicit getter or setter (or pair thereof if they have the same name
) induces a field | |
| 1280 * that is represented by a synthetic [FieldElement]. | |
| 1281 * | |
| 1282 * | |
| 1283 * @coverage dart.engine.element | |
| 1284 */ | |
| 1285 abstract class PropertyAccessorElement implements ExecutableElement { | |
| 1286 | |
| 1287 /** | |
| 1288 * Return the accessor representing the getter that corresponds to (has the sa
me name as) this | |
| 1289 * setter, or `null` if this accessor is not a setter or if there is no corres
ponding | |
| 1290 * getter. | |
| 1291 * | |
| 1292 * @return the getter that corresponds to this setter | |
| 1293 */ | |
| 1294 PropertyAccessorElement get correspondingGetter; | |
| 1295 | |
| 1296 /** | |
| 1297 * Return the accessor representing the setter that corresponds to (has the sa
me name as) this | |
| 1298 * getter, or `null` if this accessor is not a getter or if there is no corres
ponding | |
| 1299 * setter. | |
| 1300 * | |
| 1301 * @return the setter that corresponds to this getter | |
| 1302 */ | |
| 1303 PropertyAccessorElement get correspondingSetter; | |
| 1304 | |
| 1305 /** | |
| 1306 * Return the field or top-level variable associated with this accessor. If th
is accessor was | |
| 1307 * explicitly defined (is not synthetic) then the variable associated with it
will be synthetic. | |
| 1308 * | |
| 1309 * @return the variable associated with this accessor | |
| 1310 */ | |
| 1311 PropertyInducingElement get variable; | |
| 1312 | |
| 1313 /** | |
| 1314 * Return `true` if this accessor is abstract. Accessors are abstract if they
are not | |
| 1315 * external and have no body. | |
| 1316 * | |
| 1317 * @return `true` if this accessor is abstract | |
| 1318 */ | |
| 1319 bool get isAbstract; | |
| 1320 | |
| 1321 /** | |
| 1322 * Return `true` if this accessor represents a getter. | |
| 1323 * | |
| 1324 * @return `true` if this accessor represents a getter | |
| 1325 */ | |
| 1326 bool get isGetter; | |
| 1327 | |
| 1328 /** | |
| 1329 * Return `true` if this accessor represents a setter. | |
| 1330 * | |
| 1331 * @return `true` if this accessor represents a setter | |
| 1332 */ | |
| 1333 bool get isSetter; | |
| 1334 } | |
| 1335 /** | |
| 1336 * The interface `PropertyInducingElement` defines the behavior of elements repr
esenting a | |
| 1337 * variable that has an associated getter and possibly a setter. Note that expli
citly defined | |
| 1338 * variables implicitly define a synthetic getter and that non-`final` explicitl
y defined | |
| 1339 * variables implicitly define a synthetic setter. Symmetrically, synthetic fiel
ds are implicitly | |
| 1340 * created for explicitly defined getters and setters. The following rules apply
: | |
| 1341 * | |
| 1342 * * Every explicit variable is represented by a non-synthetic [PropertyInducing
Element]. | |
| 1343 * * Every explicit variable induces a getter and possibly a setter, both of whi
ch are represented | |
| 1344 * by synthetic [PropertyAccessorElement]s. | |
| 1345 * * Every explicit getter or setter is represented by a non-synthetic | |
| 1346 * [PropertyAccessorElement]. | |
| 1347 * * Every explicit getter or setter (or pair thereof if they have the same name
) induces a | |
| 1348 * variable that is represented by a synthetic [PropertyInducingElement]. | |
| 1349 * | |
| 1350 * | |
| 1351 * @coverage dart.engine.element | |
| 1352 */ | |
| 1353 abstract class PropertyInducingElement implements VariableElement { | |
| 1354 | |
| 1355 /** | |
| 1356 * Return the getter associated with this variable. If this variable was expli
citly defined (is | |
| 1357 * not synthetic) then the getter associated with it will be synthetic. | |
| 1358 * | |
| 1359 * @return the getter associated with this variable | |
| 1360 */ | |
| 1361 PropertyAccessorElement get getter; | |
| 1362 | |
| 1363 /** | |
| 1364 * Return the setter associated with this variable, or `null` if the variable
is effectively | |
| 1365 * `final` and therefore does not have a setter associated with it. (This can
happen either | |
| 1366 * because the variable is explicitly defined as being `final` or because the
variable is | |
| 1367 * induced by an explicit getter that does not have a corresponding setter.) I
f this variable was | |
| 1368 * explicitly defined (is not synthetic) then the setter associated with it wi
ll be synthetic. | |
| 1369 * | |
| 1370 * @return the setter associated with this variable | |
| 1371 */ | |
| 1372 PropertyAccessorElement get setter; | |
| 1373 | |
| 1374 /** | |
| 1375 * Return `true` if this element is a static element. A static element is an e
lement that is | |
| 1376 * not associated with a particular instance, but rather with an entire librar
y or class. | |
| 1377 * | |
| 1378 * @return `true` if this executable element is a static element | |
| 1379 */ | |
| 1380 bool get isStatic; | |
| 1381 } | |
| 1382 /** | |
| 1383 * The interface `ShowElementCombinator` defines the behavior of combinators tha
t cause some | |
| 1384 * of the names in a namespace to be visible (and the rest hidden) when being im
ported. | |
| 1385 * | |
| 1386 * @coverage dart.engine.element | |
| 1387 */ | |
| 1388 abstract class ShowElementCombinator implements NamespaceCombinator { | |
| 1389 | |
| 1390 /** | |
| 1391 * Return the offset of the character immediately following the last character
of this node. | |
| 1392 * | |
| 1393 * @return the offset of the character just past this node | |
| 1394 */ | |
| 1395 int get end; | |
| 1396 | |
| 1397 /** | |
| 1398 * Return the offset of the 'show' keyword of this element. | |
| 1399 * | |
| 1400 * @return the offset of the 'show' keyword of this element | |
| 1401 */ | |
| 1402 int get offset; | |
| 1403 | |
| 1404 /** | |
| 1405 * Return an array containing the names that are to be made visible in the imp
orting library if | |
| 1406 * they are defined in the imported library. | |
| 1407 * | |
| 1408 * @return the names from the imported library that are visible in the importi
ng library | |
| 1409 */ | |
| 1410 List<String> get shownNames; | |
| 1411 } | |
| 1412 /** | |
| 1413 * The interface `TopLevelVariableElement` defines the behavior of elements repr
esenting a | |
| 1414 * top-level variable. | |
| 1415 * | |
| 1416 * @coverage dart.engine.element | |
| 1417 */ | |
| 1418 abstract class TopLevelVariableElement implements PropertyInducingElement { | |
| 1419 } | |
| 1420 /** | |
| 1421 * The interface `TypeParameterElement` defines the behavior of elements represe
nting a type | |
| 1422 * parameter. | |
| 1423 * | |
| 1424 * @coverage dart.engine.element | |
| 1425 */ | |
| 1426 abstract class TypeParameterElement implements Element { | |
| 1427 | |
| 1428 /** | |
| 1429 * Return the type representing the bound associated with this parameter, or `
null` if this | |
| 1430 * parameter does not have an explicit bound. | |
| 1431 * | |
| 1432 * @return the type representing the bound associated with this parameter | |
| 1433 */ | |
| 1434 Type2 get bound; | |
| 1435 | |
| 1436 /** | |
| 1437 * Return the type defined by this type parameter. | |
| 1438 * | |
| 1439 * @return the type defined by this type parameter | |
| 1440 */ | |
| 1441 TypeParameterType get type; | |
| 1442 } | |
| 1443 /** | |
| 1444 * The interface `UndefinedElement` defines the behavior of pseudo-elements that
represent | |
| 1445 * names that are undefined. This situation is not allowed by the language, so o
bjects implementing | |
| 1446 * this interface always represent an error. As a result, most of the normal ope
rations on elements | |
| 1447 * do not make sense and will return useless results. | |
| 1448 * | |
| 1449 * @coverage dart.engine.element | |
| 1450 */ | |
| 1451 abstract class UndefinedElement implements Element { | |
| 1452 } | |
| 1453 /** | |
| 1454 * The interface `UriReferencedElement` defines the behavior of objects included
into a | |
| 1455 * library using some URI. | |
| 1456 * | |
| 1457 * @coverage dart.engine.element | |
| 1458 */ | |
| 1459 abstract class UriReferencedElement implements Element { | |
| 1460 | |
| 1461 /** | |
| 1462 * Return the URI that is used to include this element into the enclosing libr
ary, or `null` | |
| 1463 * if this is the defining compilation unit of a library. | |
| 1464 * | |
| 1465 * @return the URI that is used to include this element into the enclosing lib
rary | |
| 1466 */ | |
| 1467 String get uri; | |
| 1468 } | |
| 1469 /** | |
| 1470 * The interface `VariableElement` defines the behavior common to elements that
represent a | |
| 1471 * variable. | |
| 1472 * | |
| 1473 * @coverage dart.engine.element | |
| 1474 */ | |
| 1475 abstract class VariableElement implements Element { | |
| 1476 | |
| 1477 /** | |
| 1478 * Return a synthetic function representing this variable's initializer, or `n
ull` if this | |
| 1479 * variable does not have an initializer. The function will have no parameters
. The return type of | |
| 1480 * the function will be the compile-time type of the initialization expression
. | |
| 1481 * | |
| 1482 * @return a synthetic function representing this variable's initializer | |
| 1483 */ | |
| 1484 FunctionElement get initializer; | |
| 1485 | |
| 1486 /** | |
| 1487 * Return the declared type of this variable, or `null` if the variable did no
t have a | |
| 1488 * declared type (such as if it was declared using the keyword 'var'). | |
| 1489 * | |
| 1490 * @return the declared type of this variable | |
| 1491 */ | |
| 1492 Type2 get type; | |
| 1493 | |
| 1494 /** | |
| 1495 * Return `true` if this variable was declared with the 'const' modifier. | |
| 1496 * | |
| 1497 * @return `true` if this variable was declared with the 'const' modifier | |
| 1498 */ | |
| 1499 bool get isConst; | |
| 1500 | |
| 1501 /** | |
| 1502 * Return `true` if this variable was declared with the 'final' modifier. Vari
ables that are | |
| 1503 * declared with the 'const' modifier will return `false` even though they are
implicitly | |
| 1504 * final. | |
| 1505 * | |
| 1506 * @return `true` if this variable was declared with the 'final' modifier | |
| 1507 */ | |
| 1508 bool get isFinal; | |
| 1509 } | |
| 1510 /** | |
| 1511 * Instances of the class `GeneralizingElementVisitor` implement an element visi
tor that will | |
| 1512 * recursively visit all of the elements in an element model (like instances of
the class | |
| 1513 * [RecursiveElementVisitor]). In addition, when an element of a specific type i
s visited not | |
| 1514 * only will the visit method for that specific type of element be invoked, but
additional methods | |
| 1515 * for the supertypes of that element will also be invoked. For example, using a
n instance of this | |
| 1516 * class to visit a [MethodElement] will cause the method | |
| 1517 * [visitMethodElement] to be invoked but will also cause the methods | |
| 1518 * [visitExecutableElement] and [visitElement] to be | |
| 1519 * subsequently invoked. This allows visitors to be written that visit all execu
table elements | |
| 1520 * without needing to override the visit method for each of the specific subclas
ses of | |
| 1521 * [ExecutableElement]. | |
| 1522 * | |
| 1523 * Note, however, that unlike many visitors, element visitors visit objects base
d on the interfaces | |
| 1524 * implemented by those elements. Because interfaces form a graph structure rath
er than a tree | |
| 1525 * structure the way classes do, and because it is generally undesirable for an
object to be visited | |
| 1526 * more than once, this class flattens the interface graph into a pseudo-tree. I
n particular, this | |
| 1527 * class treats elements as if the element types were structured in the followin
g way: | |
| 1528 * | |
| 1529 * | |
| 1530 * <pre> | |
| 1531 * Element | |
| 1532 * ClassElement | |
| 1533 * CompilationUnitElement | |
| 1534 * ExecutableElement | |
| 1535 * ConstructorElement | |
| 1536 * LocalElement | |
| 1537 * FunctionElement | |
| 1538 * MethodElement | |
| 1539 * PropertyAccessorElement | |
| 1540 * ExportElement | |
| 1541 * HtmlElement | |
| 1542 * ImportElement | |
| 1543 * LabelElement | |
| 1544 * LibraryElement | |
| 1545 * MultiplyDefinedElement | |
| 1546 * PrefixElement | |
| 1547 * TypeAliasElement | |
| 1548 * TypeParameterElement | |
| 1549 * UndefinedElement | |
| 1550 * VariableElement | |
| 1551 * PropertyInducingElement | |
| 1552 * FieldElement | |
| 1553 * TopLevelVariableElement | |
| 1554 * LocalElement | |
| 1555 * LocalVariableElement | |
| 1556 * ParameterElement | |
| 1557 * FieldFormalParameterElement | |
| 1558 * </pre> | |
| 1559 * | |
| 1560 * Subclasses that override a visit method must either invoke the overridden vis
it method or | |
| 1561 * explicitly invoke the more general visit method. Failure to do so will cause
the visit methods | |
| 1562 * for superclasses of the element to not be invoked and will cause the children
of the visited node | |
| 1563 * to not be visited. | |
| 1564 * | |
| 1565 * @coverage dart.engine.element | |
| 1566 */ | |
| 1567 class GeneralizingElementVisitor<R> implements ElementVisitor<R> { | |
| 1568 R visitClassElement(ClassElement element) => visitElement(element); | |
| 1569 R visitCompilationUnitElement(CompilationUnitElement element) => visitElement(
element); | |
| 1570 R visitConstructorElement(ConstructorElement element) => visitExecutableElemen
t(element); | |
| 1571 R visitElement(Element element) { | |
| 1572 element.visitChildren(this); | |
| 1573 return null; | |
| 1574 } | |
| 1575 R visitEmbeddedHtmlScriptElement(EmbeddedHtmlScriptElement element) => visitHt
mlScriptElement(element); | |
| 1576 R visitExecutableElement(ExecutableElement element) => visitElement(element); | |
| 1577 R visitExportElement(ExportElement element) => visitElement(element); | |
| 1578 R visitExternalHtmlScriptElement(ExternalHtmlScriptElement element) => visitHt
mlScriptElement(element); | |
| 1579 R visitFieldElement(FieldElement element) => visitPropertyInducingElement(elem
ent); | |
| 1580 R visitFieldFormalParameterElement(FieldFormalParameterElement element) => vis
itParameterElement(element); | |
| 1581 R visitFunctionElement(FunctionElement element) => visitLocalElement(element); | |
| 1582 R visitFunctionTypeAliasElement(FunctionTypeAliasElement element) => visitElem
ent(element); | |
| 1583 R visitHtmlElement(HtmlElement element) => visitElement(element); | |
| 1584 R visitHtmlScriptElement(HtmlScriptElement element) => visitElement(element); | |
| 1585 R visitImportElement(ImportElement element) => visitElement(element); | |
| 1586 R visitLabelElement(LabelElement element) => visitElement(element); | |
| 1587 R visitLibraryElement(LibraryElement element) => visitElement(element); | |
| 1588 R visitLocalElement(LocalElement element) { | |
| 1589 if (element is LocalVariableElement) { | |
| 1590 return visitVariableElement(element as LocalVariableElement); | |
| 1591 } else if (element is ParameterElement) { | |
| 1592 return visitVariableElement(element as ParameterElement); | |
| 1593 } else if (element is FunctionElement) { | |
| 1594 return visitExecutableElement(element as FunctionElement); | |
| 1595 } | |
| 1596 return null; | |
| 1597 } | |
| 1598 R visitLocalVariableElement(LocalVariableElement element) => visitLocalElement
(element); | |
| 1599 R visitMethodElement(MethodElement element) => visitExecutableElement(element)
; | |
| 1600 R visitMultiplyDefinedElement(MultiplyDefinedElement element) => visitElement(
element); | |
| 1601 R visitParameterElement(ParameterElement element) => visitLocalElement(element
); | |
| 1602 R visitPrefixElement(PrefixElement element) => visitElement(element); | |
| 1603 R visitPropertyAccessorElement(PropertyAccessorElement element) => visitExecut
ableElement(element); | |
| 1604 R visitPropertyInducingElement(PropertyInducingElement element) => visitVariab
leElement(element); | |
| 1605 R visitTopLevelVariableElement(TopLevelVariableElement element) => visitProper
tyInducingElement(element); | |
| 1606 R visitTypeParameterElement(TypeParameterElement element) => visitElement(elem
ent); | |
| 1607 R visitVariableElement(VariableElement element) => visitElement(element); | |
| 1608 } | |
| 1609 /** | |
| 1610 * Instances of the class `RecursiveElementVisitor` implement an element visitor
that will | |
| 1611 * recursively visit all of the element in an element model. For example, using
an instance of this | |
| 1612 * class to visit a [CompilationUnitElement] will also cause all of the types in
the | |
| 1613 * compilation unit to be visited. | |
| 1614 * | |
| 1615 * Subclasses that override a visit method must either invoke the overridden vis
it method or must | |
| 1616 * explicitly ask the visited element to visit its children. Failure to do so wi
ll cause the | |
| 1617 * children of the visited element to not be visited. | |
| 1618 * | |
| 1619 * @coverage dart.engine.element | |
| 1620 */ | |
| 1621 class RecursiveElementVisitor<R> implements ElementVisitor<R> { | |
| 1622 R visitClassElement(ClassElement element) { | |
| 1623 element.visitChildren(this); | |
| 1624 return null; | |
| 1625 } | |
| 1626 R visitCompilationUnitElement(CompilationUnitElement element) { | |
| 1627 element.visitChildren(this); | |
| 1628 return null; | |
| 1629 } | |
| 1630 R visitConstructorElement(ConstructorElement element) { | |
| 1631 element.visitChildren(this); | |
| 1632 return null; | |
| 1633 } | |
| 1634 R visitEmbeddedHtmlScriptElement(EmbeddedHtmlScriptElement element) { | |
| 1635 element.visitChildren(this); | |
| 1636 return null; | |
| 1637 } | |
| 1638 R visitExportElement(ExportElement element) { | |
| 1639 element.visitChildren(this); | |
| 1640 return null; | |
| 1641 } | |
| 1642 R visitExternalHtmlScriptElement(ExternalHtmlScriptElement element) { | |
| 1643 element.visitChildren(this); | |
| 1644 return null; | |
| 1645 } | |
| 1646 R visitFieldElement(FieldElement element) { | |
| 1647 element.visitChildren(this); | |
| 1648 return null; | |
| 1649 } | |
| 1650 R visitFieldFormalParameterElement(FieldFormalParameterElement element) { | |
| 1651 element.visitChildren(this); | |
| 1652 return null; | |
| 1653 } | |
| 1654 R visitFunctionElement(FunctionElement element) { | |
| 1655 element.visitChildren(this); | |
| 1656 return null; | |
| 1657 } | |
| 1658 R visitFunctionTypeAliasElement(FunctionTypeAliasElement element) { | |
| 1659 element.visitChildren(this); | |
| 1660 return null; | |
| 1661 } | |
| 1662 R visitHtmlElement(HtmlElement element) { | |
| 1663 element.visitChildren(this); | |
| 1664 return null; | |
| 1665 } | |
| 1666 R visitImportElement(ImportElement element) { | |
| 1667 element.visitChildren(this); | |
| 1668 return null; | |
| 1669 } | |
| 1670 R visitLabelElement(LabelElement element) { | |
| 1671 element.visitChildren(this); | |
| 1672 return null; | |
| 1673 } | |
| 1674 R visitLibraryElement(LibraryElement element) { | |
| 1675 element.visitChildren(this); | |
| 1676 return null; | |
| 1677 } | |
| 1678 R visitLocalVariableElement(LocalVariableElement element) { | |
| 1679 element.visitChildren(this); | |
| 1680 return null; | |
| 1681 } | |
| 1682 R visitMethodElement(MethodElement element) { | |
| 1683 element.visitChildren(this); | |
| 1684 return null; | |
| 1685 } | |
| 1686 R visitMultiplyDefinedElement(MultiplyDefinedElement element) { | |
| 1687 element.visitChildren(this); | |
| 1688 return null; | |
| 1689 } | |
| 1690 R visitParameterElement(ParameterElement element) { | |
| 1691 element.visitChildren(this); | |
| 1692 return null; | |
| 1693 } | |
| 1694 R visitPrefixElement(PrefixElement element) { | |
| 1695 element.visitChildren(this); | |
| 1696 return null; | |
| 1697 } | |
| 1698 R visitPropertyAccessorElement(PropertyAccessorElement element) { | |
| 1699 element.visitChildren(this); | |
| 1700 return null; | |
| 1701 } | |
| 1702 R visitTopLevelVariableElement(TopLevelVariableElement element) { | |
| 1703 element.visitChildren(this); | |
| 1704 return null; | |
| 1705 } | |
| 1706 R visitTypeParameterElement(TypeParameterElement element) { | |
| 1707 element.visitChildren(this); | |
| 1708 return null; | |
| 1709 } | |
| 1710 } | |
| 1711 /** | |
| 1712 * Instances of the class `SimpleElementVisitor` implement an element visitor th
at will do | |
| 1713 * nothing when visiting an element. It is intended to be a superclass for class
es that use the | |
| 1714 * visitor pattern primarily as a dispatch mechanism (and hence don't need to re
cursively visit a | |
| 1715 * whole structure) and that only need to visit a small number of element types. | |
| 1716 * | |
| 1717 * @coverage dart.engine.element | |
| 1718 */ | |
| 1719 class SimpleElementVisitor<R> implements ElementVisitor<R> { | |
| 1720 R visitClassElement(ClassElement element) => null; | |
| 1721 R visitCompilationUnitElement(CompilationUnitElement element) => null; | |
| 1722 R visitConstructorElement(ConstructorElement element) => null; | |
| 1723 R visitEmbeddedHtmlScriptElement(EmbeddedHtmlScriptElement element) => null; | |
| 1724 R visitExportElement(ExportElement element) => null; | |
| 1725 R visitExternalHtmlScriptElement(ExternalHtmlScriptElement element) => null; | |
| 1726 R visitFieldElement(FieldElement element) => null; | |
| 1727 R visitFieldFormalParameterElement(FieldFormalParameterElement element) => nul
l; | |
| 1728 R visitFunctionElement(FunctionElement element) => null; | |
| 1729 R visitFunctionTypeAliasElement(FunctionTypeAliasElement element) => null; | |
| 1730 R visitHtmlElement(HtmlElement element) => null; | |
| 1731 R visitImportElement(ImportElement element) => null; | |
| 1732 R visitLabelElement(LabelElement element) => null; | |
| 1733 R visitLibraryElement(LibraryElement element) => null; | |
| 1734 R visitLocalVariableElement(LocalVariableElement element) => null; | |
| 1735 R visitMethodElement(MethodElement element) => null; | |
| 1736 R visitMultiplyDefinedElement(MultiplyDefinedElement element) => null; | |
| 1737 R visitParameterElement(ParameterElement element) => null; | |
| 1738 R visitPrefixElement(PrefixElement element) => null; | |
| 1739 R visitPropertyAccessorElement(PropertyAccessorElement element) => null; | |
| 1740 R visitTopLevelVariableElement(TopLevelVariableElement element) => null; | |
| 1741 R visitTypeParameterElement(TypeParameterElement element) => null; | |
| 1742 } | |
| 1743 /** | |
| 1744 * For AST nodes that could be in both the getter and setter contexts ([IndexExp
ression]s and | |
| 1745 * [SimpleIdentifier]s), the additional resolved elements are stored in the AST
node, in an | |
| 1746 * [AuxiliaryElements]. Since resolved elements are either statically resolved o
r resolved | |
| 1747 * using propagated type information, this class is a wrapper for a pair of | |
| 1748 * [ExecutableElement]s, not just a single [ExecutableElement]. | |
| 1749 */ | |
| 1750 class AuxiliaryElements { | |
| 1751 | |
| 1752 /** | |
| 1753 * The element based on propagated type information, or `null` if the AST stru
cture has not | |
| 1754 * been resolved or if this identifier could not be resolved. | |
| 1755 */ | |
| 1756 ExecutableElement propagatedElement; | |
| 1757 | |
| 1758 /** | |
| 1759 * The element associated with this identifier based on static type informatio
n, or `null` | |
| 1760 * if the AST structure has not been resolved or if this identifier could not
be resolved. | |
| 1761 */ | |
| 1762 ExecutableElement staticElement; | |
| 1763 | |
| 1764 /** | |
| 1765 * Create the [AuxiliaryElements] with a static and propagated [ExecutableElem
ent]. | |
| 1766 * | |
| 1767 * @param staticElement the static element | |
| 1768 * @param propagatedElement the propagated element | |
| 1769 */ | |
| 1770 AuxiliaryElements(ExecutableElement staticElement, ExecutableElement propagate
dElement) { | |
| 1771 this.staticElement = staticElement; | |
| 1772 this.propagatedElement = propagatedElement; | |
| 1773 } | |
| 1774 } | |
| 1775 /** | |
| 1776 * Instances of the class `ClassElementImpl` implement a `ClassElement`. | |
| 1777 * | |
| 1778 * @coverage dart.engine.element | |
| 1779 */ | |
| 1780 class ClassElementImpl extends ElementImpl implements ClassElement { | |
| 1781 | |
| 1782 /** | |
| 1783 * An array containing all of the accessors (getters and setters) contained in
this class. | |
| 1784 */ | |
| 1785 List<PropertyAccessorElement> _accessors = PropertyAccessorElementImpl.EMPTY_A
RRAY; | |
| 1786 | |
| 1787 /** | |
| 1788 * An array containing all of the constructors contained in this class. | |
| 1789 */ | |
| 1790 List<ConstructorElement> _constructors = ConstructorElementImpl.EMPTY_ARRAY; | |
| 1791 | |
| 1792 /** | |
| 1793 * An array containing all of the fields contained in this class. | |
| 1794 */ | |
| 1795 List<FieldElement> _fields = FieldElementImpl.EMPTY_ARRAY; | |
| 1796 | |
| 1797 /** | |
| 1798 * An array containing all of the mixins that are applied to the class being e
xtended in order to | |
| 1799 * derive the superclass of this class. | |
| 1800 */ | |
| 1801 List<InterfaceType> _mixins = InterfaceTypeImpl.EMPTY_ARRAY; | |
| 1802 | |
| 1803 /** | |
| 1804 * An array containing all of the interfaces that are implemented by this clas
s. | |
| 1805 */ | |
| 1806 List<InterfaceType> _interfaces = InterfaceTypeImpl.EMPTY_ARRAY; | |
| 1807 | |
| 1808 /** | |
| 1809 * An array containing all of the methods contained in this class. | |
| 1810 */ | |
| 1811 List<MethodElement> _methods = MethodElementImpl.EMPTY_ARRAY; | |
| 1812 | |
| 1813 /** | |
| 1814 * The superclass of the class, or `null` if the class does not have an explic
it superclass. | |
| 1815 */ | |
| 1816 InterfaceType _supertype; | |
| 1817 | |
| 1818 /** | |
| 1819 * The type defined by the class. | |
| 1820 */ | |
| 1821 InterfaceType _type; | |
| 1822 | |
| 1823 /** | |
| 1824 * An array containing all of the type parameters defined for this class. | |
| 1825 */ | |
| 1826 List<TypeParameterElement> _typeParameters = TypeParameterElementImpl.EMPTY_AR
RAY; | |
| 1827 | |
| 1828 /** | |
| 1829 * An empty array of type elements. | |
| 1830 */ | |
| 1831 static List<ClassElement> EMPTY_ARRAY = new List<ClassElement>(0); | |
| 1832 | |
| 1833 /** | |
| 1834 * Initialize a newly created class element to have the given name. | |
| 1835 * | |
| 1836 * @param name the name of this element | |
| 1837 */ | |
| 1838 ClassElementImpl(Identifier name) : super.con1(name); | |
| 1839 accept(ElementVisitor visitor) => visitor.visitClassElement(this); | |
| 1840 List<PropertyAccessorElement> get accessors => _accessors; | |
| 1841 List<InterfaceType> get allSupertypes { | |
| 1842 List<InterfaceType> list = new List<InterfaceType>(); | |
| 1843 collectAllSupertypes(list); | |
| 1844 return new List.from(list); | |
| 1845 } | |
| 1846 ElementImpl getChild(String identifier) { | |
| 1847 for (PropertyAccessorElement accessor in _accessors) { | |
| 1848 if (((accessor as PropertyAccessorElementImpl)).identifier == identifier)
{ | |
| 1849 return accessor as PropertyAccessorElementImpl; | |
| 1850 } | |
| 1851 } | |
| 1852 for (ConstructorElement constructor in _constructors) { | |
| 1853 if (((constructor as ConstructorElementImpl)).identifier == identifier) { | |
| 1854 return constructor as ConstructorElementImpl; | |
| 1855 } | |
| 1856 } | |
| 1857 for (FieldElement field in _fields) { | |
| 1858 if (((field as FieldElementImpl)).identifier == identifier) { | |
| 1859 return field as FieldElementImpl; | |
| 1860 } | |
| 1861 } | |
| 1862 for (MethodElement method in _methods) { | |
| 1863 if (((method as MethodElementImpl)).identifier == identifier) { | |
| 1864 return method as MethodElementImpl; | |
| 1865 } | |
| 1866 } | |
| 1867 for (TypeParameterElement typeParameter in _typeParameters) { | |
| 1868 if (((typeParameter as TypeParameterElementImpl)).identifier == identifier
) { | |
| 1869 return typeParameter as TypeParameterElementImpl; | |
| 1870 } | |
| 1871 } | |
| 1872 return null; | |
| 1873 } | |
| 1874 List<ConstructorElement> get constructors => _constructors; | |
| 1875 | |
| 1876 /** | |
| 1877 * Given some name, this returns the [FieldElement] with the matching name, if
there is no | |
| 1878 * such field, then `null` is returned. | |
| 1879 * | |
| 1880 * @param name some name to lookup a field element with | |
| 1881 * @return the matching field element, or `null` if no such element was found | |
| 1882 */ | |
| 1883 FieldElement getField(String name) { | |
| 1884 for (FieldElement fieldElement in _fields) { | |
| 1885 if (name == fieldElement.name) { | |
| 1886 return fieldElement; | |
| 1887 } | |
| 1888 } | |
| 1889 return null; | |
| 1890 } | |
| 1891 List<FieldElement> get fields => _fields; | |
| 1892 PropertyAccessorElement getGetter(String getterName) { | |
| 1893 for (PropertyAccessorElement accessor in _accessors) { | |
| 1894 if (accessor.isGetter && accessor.name == getterName) { | |
| 1895 return accessor; | |
| 1896 } | |
| 1897 } | |
| 1898 return null; | |
| 1899 } | |
| 1900 List<InterfaceType> get interfaces => _interfaces; | |
| 1901 ElementKind get kind => ElementKind.CLASS; | |
| 1902 MethodElement getMethod(String methodName) { | |
| 1903 for (MethodElement method in _methods) { | |
| 1904 if (method.name == methodName) { | |
| 1905 return method; | |
| 1906 } | |
| 1907 } | |
| 1908 return null; | |
| 1909 } | |
| 1910 List<MethodElement> get methods => _methods; | |
| 1911 List<InterfaceType> get mixins => _mixins; | |
| 1912 ConstructorElement getNamedConstructor(String name) { | |
| 1913 for (ConstructorElement element in constructors) { | |
| 1914 String elementName = element.name; | |
| 1915 if (elementName != null && elementName == name) { | |
| 1916 return element; | |
| 1917 } | |
| 1918 } | |
| 1919 return null; | |
| 1920 } | |
| 1921 PropertyAccessorElement getSetter(String setterName) { | |
| 1922 if (!setterName.endsWith("=")) { | |
| 1923 setterName += '='; | |
| 1924 } | |
| 1925 for (PropertyAccessorElement accessor in _accessors) { | |
| 1926 if (accessor.isSetter && accessor.name == setterName) { | |
| 1927 return accessor; | |
| 1928 } | |
| 1929 } | |
| 1930 return null; | |
| 1931 } | |
| 1932 InterfaceType get supertype => _supertype; | |
| 1933 InterfaceType get type => _type; | |
| 1934 List<TypeParameterElement> get typeParameters => _typeParameters; | |
| 1935 ConstructorElement get unnamedConstructor { | |
| 1936 for (ConstructorElement element in constructors) { | |
| 1937 String name = element.displayName; | |
| 1938 if (name == null || name.isEmpty) { | |
| 1939 return element; | |
| 1940 } | |
| 1941 } | |
| 1942 return null; | |
| 1943 } | |
| 1944 bool hasNonFinalField() { | |
| 1945 List<ClassElement> classesToVisit = new List<ClassElement>(); | |
| 1946 Set<ClassElement> visitedClasses = new Set<ClassElement>(); | |
| 1947 classesToVisit.add(this); | |
| 1948 while (!classesToVisit.isEmpty) { | |
| 1949 ClassElement currentElement = classesToVisit.removeAt(0); | |
| 1950 if (javaSetAdd(visitedClasses, currentElement)) { | |
| 1951 for (FieldElement field in currentElement.fields) { | |
| 1952 if (!field.isFinal && !field.isConst && !field.isStatic && !field.isSy
nthetic) { | |
| 1953 return true; | |
| 1954 } | |
| 1955 } | |
| 1956 for (InterfaceType mixinType in currentElement.mixins) { | |
| 1957 ClassElement mixinElement = mixinType.element; | |
| 1958 classesToVisit.add(mixinElement); | |
| 1959 } | |
| 1960 InterfaceType supertype = currentElement.supertype; | |
| 1961 if (supertype != null) { | |
| 1962 ClassElement superElement = supertype.element; | |
| 1963 if (superElement != null) { | |
| 1964 classesToVisit.add(superElement); | |
| 1965 } | |
| 1966 } | |
| 1967 } | |
| 1968 } | |
| 1969 return false; | |
| 1970 } | |
| 1971 bool hasReferenceToSuper() => hasModifier(Modifier.REFERENCES_SUPER); | |
| 1972 bool get isAbstract => hasModifier(Modifier.ABSTRACT); | |
| 1973 bool get isTypedef => hasModifier(Modifier.TYPEDEF); | |
| 1974 bool get isValidMixin => hasModifier(Modifier.MIXIN); | |
| 1975 PropertyAccessorElement lookUpGetter(String getterName, LibraryElement library
) { | |
| 1976 Set<ClassElement> visitedClasses = new Set<ClassElement>(); | |
| 1977 ClassElement currentElement = this; | |
| 1978 while (currentElement != null && !visitedClasses.contains(currentElement)) { | |
| 1979 javaSetAdd(visitedClasses, currentElement); | |
| 1980 PropertyAccessorElement element = currentElement.getGetter(getterName); | |
| 1981 if (element != null && element.isAccessibleIn(library)) { | |
| 1982 return element; | |
| 1983 } | |
| 1984 for (InterfaceType mixin in currentElement.mixins) { | |
| 1985 ClassElement mixinElement = mixin.element; | |
| 1986 if (mixinElement != null) { | |
| 1987 element = mixinElement.getGetter(getterName); | |
| 1988 if (element != null && element.isAccessibleIn(library)) { | |
| 1989 return element; | |
| 1990 } | |
| 1991 } | |
| 1992 } | |
| 1993 InterfaceType supertype = currentElement.supertype; | |
| 1994 if (supertype == null) { | |
| 1995 return null; | |
| 1996 } | |
| 1997 currentElement = supertype.element; | |
| 1998 } | |
| 1999 return null; | |
| 2000 } | |
| 2001 MethodElement lookUpMethod(String methodName, LibraryElement library) { | |
| 2002 Set<ClassElement> visitedClasses = new Set<ClassElement>(); | |
| 2003 ClassElement currentElement = this; | |
| 2004 while (currentElement != null && !visitedClasses.contains(currentElement)) { | |
| 2005 javaSetAdd(visitedClasses, currentElement); | |
| 2006 MethodElement element = currentElement.getMethod(methodName); | |
| 2007 if (element != null && element.isAccessibleIn(library)) { | |
| 2008 return element; | |
| 2009 } | |
| 2010 for (InterfaceType mixin in currentElement.mixins) { | |
| 2011 ClassElement mixinElement = mixin.element; | |
| 2012 if (mixinElement != null) { | |
| 2013 element = mixinElement.getMethod(methodName); | |
| 2014 if (element != null && element.isAccessibleIn(library)) { | |
| 2015 return element; | |
| 2016 } | |
| 2017 } | |
| 2018 } | |
| 2019 InterfaceType supertype = currentElement.supertype; | |
| 2020 if (supertype == null) { | |
| 2021 return null; | |
| 2022 } | |
| 2023 currentElement = supertype.element; | |
| 2024 } | |
| 2025 return null; | |
| 2026 } | |
| 2027 PropertyAccessorElement lookUpSetter(String setterName, LibraryElement library
) { | |
| 2028 Set<ClassElement> visitedClasses = new Set<ClassElement>(); | |
| 2029 ClassElement currentElement = this; | |
| 2030 while (currentElement != null && !visitedClasses.contains(currentElement)) { | |
| 2031 javaSetAdd(visitedClasses, currentElement); | |
| 2032 PropertyAccessorElement element = currentElement.getSetter(setterName); | |
| 2033 if (element != null && element.isAccessibleIn(library)) { | |
| 2034 return element; | |
| 2035 } | |
| 2036 for (InterfaceType mixin in currentElement.mixins) { | |
| 2037 ClassElement mixinElement = mixin.element; | |
| 2038 if (mixinElement != null) { | |
| 2039 element = mixinElement.getSetter(setterName); | |
| 2040 if (element != null && element.isAccessibleIn(library)) { | |
| 2041 return element; | |
| 2042 } | |
| 2043 } | |
| 2044 } | |
| 2045 InterfaceType supertype = currentElement.supertype; | |
| 2046 if (supertype == null) { | |
| 2047 return null; | |
| 2048 } | |
| 2049 currentElement = supertype.element; | |
| 2050 } | |
| 2051 return null; | |
| 2052 } | |
| 2053 | |
| 2054 /** | |
| 2055 * Set whether this class is abstract to correspond to the given value. | |
| 2056 * | |
| 2057 * @param isAbstract `true` if the class is abstract | |
| 2058 */ | |
| 2059 void set abstract(bool isAbstract) { | |
| 2060 setModifier(Modifier.ABSTRACT, isAbstract); | |
| 2061 } | |
| 2062 | |
| 2063 /** | |
| 2064 * Set the accessors contained in this class to the given accessors. | |
| 2065 * | |
| 2066 * @param accessors the accessors contained in this class | |
| 2067 */ | |
| 2068 void set accessors(List<PropertyAccessorElement> accessors) { | |
| 2069 for (PropertyAccessorElement accessor in accessors) { | |
| 2070 ((accessor as PropertyAccessorElementImpl)).enclosingElement = this; | |
| 2071 } | |
| 2072 this._accessors = accessors; | |
| 2073 } | |
| 2074 | |
| 2075 /** | |
| 2076 * Set the constructors contained in this class to the given constructors. | |
| 2077 * | |
| 2078 * @param constructors the constructors contained in this class | |
| 2079 */ | |
| 2080 void set constructors(List<ConstructorElement> constructors) { | |
| 2081 for (ConstructorElement constructor in constructors) { | |
| 2082 ((constructor as ConstructorElementImpl)).enclosingElement = this; | |
| 2083 } | |
| 2084 this._constructors = constructors; | |
| 2085 } | |
| 2086 | |
| 2087 /** | |
| 2088 * Set the fields contained in this class to the given fields. | |
| 2089 * | |
| 2090 * @param fields the fields contained in this class | |
| 2091 */ | |
| 2092 void set fields(List<FieldElement> fields) { | |
| 2093 for (FieldElement field in fields) { | |
| 2094 ((field as FieldElementImpl)).enclosingElement = this; | |
| 2095 } | |
| 2096 this._fields = fields; | |
| 2097 } | |
| 2098 | |
| 2099 /** | |
| 2100 * Set whether this class references 'super' to the given value. | |
| 2101 * | |
| 2102 * @param isReferencedSuper `true` references 'super' | |
| 2103 */ | |
| 2104 void set hasReferenceToSuper2(bool isReferencedSuper) { | |
| 2105 setModifier(Modifier.REFERENCES_SUPER, isReferencedSuper); | |
| 2106 } | |
| 2107 | |
| 2108 /** | |
| 2109 * Set the interfaces that are implemented by this class to the given types. | |
| 2110 * | |
| 2111 * @param the interfaces that are implemented by this class | |
| 2112 */ | |
| 2113 void set interfaces(List<InterfaceType> interfaces) { | |
| 2114 this._interfaces = interfaces; | |
| 2115 } | |
| 2116 | |
| 2117 /** | |
| 2118 * Set the methods contained in this class to the given methods. | |
| 2119 * | |
| 2120 * @param methods the methods contained in this class | |
| 2121 */ | |
| 2122 void set methods(List<MethodElement> methods) { | |
| 2123 for (MethodElement method in methods) { | |
| 2124 ((method as MethodElementImpl)).enclosingElement = this; | |
| 2125 } | |
| 2126 this._methods = methods; | |
| 2127 } | |
| 2128 | |
| 2129 /** | |
| 2130 * Set the mixins that are applied to the class being extended in order to der
ive the superclass | |
| 2131 * of this class to the given types. | |
| 2132 * | |
| 2133 * @param mixins the mixins that are applied to derive the superclass of this
class | |
| 2134 */ | |
| 2135 void set mixins(List<InterfaceType> mixins) { | |
| 2136 this._mixins = mixins; | |
| 2137 } | |
| 2138 | |
| 2139 /** | |
| 2140 * Set the superclass of the class to the given type. | |
| 2141 * | |
| 2142 * @param supertype the superclass of the class | |
| 2143 */ | |
| 2144 void set supertype(InterfaceType supertype) { | |
| 2145 this._supertype = supertype; | |
| 2146 } | |
| 2147 | |
| 2148 /** | |
| 2149 * Set the type defined by the class to the given type. | |
| 2150 * | |
| 2151 * @param type the type defined by the class | |
| 2152 */ | |
| 2153 void set type(InterfaceType type) { | |
| 2154 this._type = type; | |
| 2155 } | |
| 2156 | |
| 2157 /** | |
| 2158 * Set whether this class is defined by a typedef construct to correspond to t
he given value. | |
| 2159 * | |
| 2160 * @param isTypedef `true` if the class is defined by a typedef construct | |
| 2161 */ | |
| 2162 void set typedef(bool isTypedef) { | |
| 2163 setModifier(Modifier.TYPEDEF, isTypedef); | |
| 2164 } | |
| 2165 | |
| 2166 /** | |
| 2167 * Set the type parameters defined for this class to the given type parameters
. | |
| 2168 * | |
| 2169 * @param typeParameters the type parameters defined for this class | |
| 2170 */ | |
| 2171 void set typeParameters(List<TypeParameterElement> typeParameters) { | |
| 2172 for (TypeParameterElement typeParameter in typeParameters) { | |
| 2173 ((typeParameter as TypeParameterElementImpl)).enclosingElement = this; | |
| 2174 } | |
| 2175 this._typeParameters = typeParameters; | |
| 2176 } | |
| 2177 | |
| 2178 /** | |
| 2179 * Set whether this class is a valid mixin to correspond to the given value. | |
| 2180 * | |
| 2181 * @param isValidMixin `true` if this class can be used as a mixin | |
| 2182 */ | |
| 2183 void set validMixin(bool isValidMixin) { | |
| 2184 setModifier(Modifier.MIXIN, isValidMixin); | |
| 2185 } | |
| 2186 void visitChildren(ElementVisitor visitor) { | |
| 2187 super.visitChildren(visitor); | |
| 2188 safelyVisitChildren(_accessors, visitor); | |
| 2189 safelyVisitChildren(_constructors, visitor); | |
| 2190 safelyVisitChildren(_fields, visitor); | |
| 2191 safelyVisitChildren(_methods, visitor); | |
| 2192 safelyVisitChildren(_typeParameters, visitor); | |
| 2193 } | |
| 2194 void appendTo(JavaStringBuilder builder) { | |
| 2195 String name = displayName; | |
| 2196 if (name == null) { | |
| 2197 builder.append("{unnamed class}"); | |
| 2198 } else { | |
| 2199 builder.append(name); | |
| 2200 } | |
| 2201 int variableCount = _typeParameters.length; | |
| 2202 if (variableCount > 0) { | |
| 2203 builder.append("<"); | |
| 2204 for (int i = 0; i < variableCount; i++) { | |
| 2205 if (i > 0) { | |
| 2206 builder.append(", "); | |
| 2207 } | |
| 2208 ((_typeParameters[i] as TypeParameterElementImpl)).appendTo(builder); | |
| 2209 } | |
| 2210 builder.append(">"); | |
| 2211 } | |
| 2212 } | |
| 2213 void collectAllSupertypes(List<InterfaceType> supertypes) { | |
| 2214 List<InterfaceType> typesToVisit = new List<InterfaceType>(); | |
| 2215 List<ClassElement> visitedClasses = new List<ClassElement>(); | |
| 2216 typesToVisit.add(this.type); | |
| 2217 while (!typesToVisit.isEmpty) { | |
| 2218 InterfaceType currentType = typesToVisit.removeAt(0); | |
| 2219 ClassElement currentElement = currentType.element; | |
| 2220 if (!visitedClasses.contains(currentElement)) { | |
| 2221 visitedClasses.add(currentElement); | |
| 2222 if (currentType != this.type) { | |
| 2223 supertypes.add(currentType); | |
| 2224 } | |
| 2225 InterfaceType supertype = currentType.superclass; | |
| 2226 if (supertype != null) { | |
| 2227 typesToVisit.add(supertype); | |
| 2228 } | |
| 2229 for (InterfaceType type in currentElement.interfaces) { | |
| 2230 typesToVisit.add(type); | |
| 2231 } | |
| 2232 for (InterfaceType type in currentElement.mixins) { | |
| 2233 ClassElement element = type.element; | |
| 2234 if (!visitedClasses.contains(element)) { | |
| 2235 supertypes.add(type); | |
| 2236 } | |
| 2237 } | |
| 2238 } | |
| 2239 } | |
| 2240 } | |
| 2241 } | |
| 2242 /** | |
| 2243 * Instances of the class `CompilationUnitElementImpl` implement a | |
| 2244 * [CompilationUnitElement]. | |
| 2245 * | |
| 2246 * @coverage dart.engine.element | |
| 2247 */ | |
| 2248 class CompilationUnitElementImpl extends ElementImpl implements CompilationUnitE
lement { | |
| 2249 | |
| 2250 /** | |
| 2251 * An empty array of compilation unit elements. | |
| 2252 */ | |
| 2253 static List<CompilationUnitElement> EMPTY_ARRAY = new List<CompilationUnitElem
ent>(0); | |
| 2254 | |
| 2255 /** | |
| 2256 * An array containing all of the top-level accessors (getters and setters) co
ntained in this | |
| 2257 * compilation unit. | |
| 2258 */ | |
| 2259 List<PropertyAccessorElement> _accessors = PropertyAccessorElementImpl.EMPTY_A
RRAY; | |
| 2260 | |
| 2261 /** | |
| 2262 * An array containing all of the top-level functions contained in this compil
ation unit. | |
| 2263 */ | |
| 2264 List<FunctionElement> _functions = FunctionElementImpl.EMPTY_ARRAY; | |
| 2265 | |
| 2266 /** | |
| 2267 * An array containing all of the variables contained in this compilation unit
. | |
| 2268 */ | |
| 2269 List<TopLevelVariableElement> _variables = TopLevelVariableElementImpl.EMPTY_A
RRAY; | |
| 2270 | |
| 2271 /** | |
| 2272 * The source that corresponds to this compilation unit. | |
| 2273 */ | |
| 2274 Source _source; | |
| 2275 | |
| 2276 /** | |
| 2277 * An array containing all of the function type aliases contained in this comp
ilation unit. | |
| 2278 */ | |
| 2279 List<FunctionTypeAliasElement> _typeAliases = FunctionTypeAliasElementImpl.EMP
TY_ARRAY; | |
| 2280 | |
| 2281 /** | |
| 2282 * An array containing all of the types contained in this compilation unit. | |
| 2283 */ | |
| 2284 List<ClassElement> _types = ClassElementImpl.EMPTY_ARRAY; | |
| 2285 | |
| 2286 /** | |
| 2287 * The URI that is specified by the "part" directive in the enclosing library,
or `null` if | |
| 2288 * this is the defining compilation unit of a library. | |
| 2289 */ | |
| 2290 String _uri; | |
| 2291 | |
| 2292 /** | |
| 2293 * Initialize a newly created compilation unit element to have the given name. | |
| 2294 * | |
| 2295 * @param name the name of this element | |
| 2296 */ | |
| 2297 CompilationUnitElementImpl(String name) : super.con2(name, -1); | |
| 2298 accept(ElementVisitor visitor) => visitor.visitCompilationUnitElement(this); | |
| 2299 bool operator ==(Object object) => object != null && runtimeType == object.run
timeType && _source == ((object as CompilationUnitElementImpl)).source; | |
| 2300 List<PropertyAccessorElement> get accessors => _accessors; | |
| 2301 ElementImpl getChild(String identifier) { | |
| 2302 for (PropertyAccessorElement accessor in _accessors) { | |
| 2303 if (((accessor as PropertyAccessorElementImpl)).identifier == identifier)
{ | |
| 2304 return accessor as PropertyAccessorElementImpl; | |
| 2305 } | |
| 2306 } | |
| 2307 for (VariableElement variable in _variables) { | |
| 2308 if (((variable as VariableElementImpl)).identifier == identifier) { | |
| 2309 return variable as VariableElementImpl; | |
| 2310 } | |
| 2311 } | |
| 2312 for (ExecutableElement function in _functions) { | |
| 2313 if (((function as ExecutableElementImpl)).identifier == identifier) { | |
| 2314 return function as ExecutableElementImpl; | |
| 2315 } | |
| 2316 } | |
| 2317 for (FunctionTypeAliasElement typeAlias in _typeAliases) { | |
| 2318 if (((typeAlias as FunctionTypeAliasElementImpl)).identifier == identifier
) { | |
| 2319 return typeAlias as FunctionTypeAliasElementImpl; | |
| 2320 } | |
| 2321 } | |
| 2322 for (ClassElement type in _types) { | |
| 2323 if (((type as ClassElementImpl)).identifier == identifier) { | |
| 2324 return type as ClassElementImpl; | |
| 2325 } | |
| 2326 } | |
| 2327 return null; | |
| 2328 } | |
| 2329 LibraryElement get enclosingElement => super.enclosingElement as LibraryElemen
t; | |
| 2330 List<FunctionElement> get functions => _functions; | |
| 2331 List<FunctionTypeAliasElement> get functionTypeAliases => _typeAliases; | |
| 2332 ElementKind get kind => ElementKind.COMPILATION_UNIT; | |
| 2333 Source get source => _source; | |
| 2334 List<TopLevelVariableElement> get topLevelVariables => _variables; | |
| 2335 ClassElement getType(String className) { | |
| 2336 for (ClassElement type in _types) { | |
| 2337 if (type.name == className) { | |
| 2338 return type; | |
| 2339 } | |
| 2340 } | |
| 2341 return null; | |
| 2342 } | |
| 2343 List<ClassElement> get types => _types; | |
| 2344 String get uri => _uri; | |
| 2345 int get hashCode => _source.hashCode; | |
| 2346 | |
| 2347 /** | |
| 2348 * Set the top-level accessors (getters and setters) contained in this compila
tion unit to the | |
| 2349 * given accessors. | |
| 2350 * | |
| 2351 * @param the top-level accessors (getters and setters) contained in this comp
ilation unit | |
| 2352 */ | |
| 2353 void set accessors(List<PropertyAccessorElement> accessors) { | |
| 2354 for (PropertyAccessorElement accessor in accessors) { | |
| 2355 ((accessor as PropertyAccessorElementImpl)).enclosingElement = this; | |
| 2356 } | |
| 2357 this._accessors = accessors; | |
| 2358 } | |
| 2359 | |
| 2360 /** | |
| 2361 * Set the top-level functions contained in this compilation unit to the given
functions. | |
| 2362 * | |
| 2363 * @param functions the top-level functions contained in this compilation unit | |
| 2364 */ | |
| 2365 void set functions(List<FunctionElement> functions) { | |
| 2366 for (FunctionElement function in functions) { | |
| 2367 ((function as FunctionElementImpl)).enclosingElement = this; | |
| 2368 } | |
| 2369 this._functions = functions; | |
| 2370 } | |
| 2371 | |
| 2372 /** | |
| 2373 * Set the source that corresponds to this compilation unit to the given sourc
e. | |
| 2374 * | |
| 2375 * @param source the source that corresponds to this compilation unit | |
| 2376 */ | |
| 2377 void set source(Source source) { | |
| 2378 this._source = source; | |
| 2379 } | |
| 2380 | |
| 2381 /** | |
| 2382 * Set the top-level variables contained in this compilation unit to the given
variables. | |
| 2383 * | |
| 2384 * @param variables the top-level variables contained in this compilation unit | |
| 2385 */ | |
| 2386 void set topLevelVariables(List<TopLevelVariableElement> variables) { | |
| 2387 for (TopLevelVariableElement field in variables) { | |
| 2388 ((field as TopLevelVariableElementImpl)).enclosingElement = this; | |
| 2389 } | |
| 2390 this._variables = variables; | |
| 2391 } | |
| 2392 | |
| 2393 /** | |
| 2394 * Set the function type aliases contained in this compilation unit to the giv
en type aliases. | |
| 2395 * | |
| 2396 * @param typeAliases the function type aliases contained in this compilation
unit | |
| 2397 */ | |
| 2398 void set typeAliases(List<FunctionTypeAliasElement> typeAliases) { | |
| 2399 for (FunctionTypeAliasElement typeAlias in typeAliases) { | |
| 2400 ((typeAlias as FunctionTypeAliasElementImpl)).enclosingElement = this; | |
| 2401 } | |
| 2402 this._typeAliases = typeAliases; | |
| 2403 } | |
| 2404 | |
| 2405 /** | |
| 2406 * Set the types contained in this compilation unit to the given types. | |
| 2407 * | |
| 2408 * @param types types contained in this compilation unit | |
| 2409 */ | |
| 2410 void set types(List<ClassElement> types) { | |
| 2411 for (ClassElement type in types) { | |
| 2412 ((type as ClassElementImpl)).enclosingElement = this; | |
| 2413 } | |
| 2414 this._types = types; | |
| 2415 } | |
| 2416 | |
| 2417 /** | |
| 2418 * Set the URI that is specified by the "part" directive in the enclosing libr
ary. | |
| 2419 * | |
| 2420 * @param uri the URI that is specified by the "part" directive in the enclosi
ng library. | |
| 2421 */ | |
| 2422 void set uri(String uri) { | |
| 2423 this._uri = uri; | |
| 2424 } | |
| 2425 void visitChildren(ElementVisitor visitor) { | |
| 2426 super.visitChildren(visitor); | |
| 2427 safelyVisitChildren(_accessors, visitor); | |
| 2428 safelyVisitChildren(_functions, visitor); | |
| 2429 safelyVisitChildren(_typeAliases, visitor); | |
| 2430 safelyVisitChildren(_types, visitor); | |
| 2431 safelyVisitChildren(_variables, visitor); | |
| 2432 } | |
| 2433 void appendTo(JavaStringBuilder builder) { | |
| 2434 if (_source == null) { | |
| 2435 builder.append("{compilation unit}"); | |
| 2436 } else { | |
| 2437 builder.append(_source.fullName); | |
| 2438 } | |
| 2439 } | |
| 2440 String get identifier => source.encoding; | |
| 2441 } | |
| 2442 /** | |
| 2443 * Instances of the class `ConstFieldElementImpl` implement a `FieldElement` for
a | |
| 2444 * 'const' field that has an initializer. | |
| 2445 */ | |
| 2446 class ConstFieldElementImpl extends FieldElementImpl { | |
| 2447 | |
| 2448 /** | |
| 2449 * The result of evaluating this variable's initializer. | |
| 2450 */ | |
| 2451 EvaluationResultImpl _result; | |
| 2452 | |
| 2453 /** | |
| 2454 * Initialize a newly created field element to have the given name. | |
| 2455 * | |
| 2456 * @param name the name of this element | |
| 2457 */ | |
| 2458 ConstFieldElementImpl(Identifier name) : super.con1(name); | |
| 2459 EvaluationResultImpl get evaluationResult => _result; | |
| 2460 void set evaluationResult(EvaluationResultImpl result) { | |
| 2461 this._result = result; | |
| 2462 } | |
| 2463 } | |
| 2464 /** | |
| 2465 * Instances of the class `ConstLocalVariableElementImpl` implement a | |
| 2466 * `LocalVariableElement` for a local 'const' variable that has an initializer. | |
| 2467 * | |
| 2468 * @coverage dart.engine.element | |
| 2469 */ | |
| 2470 class ConstLocalVariableElementImpl extends LocalVariableElementImpl { | |
| 2471 | |
| 2472 /** | |
| 2473 * The result of evaluating this variable's initializer. | |
| 2474 */ | |
| 2475 EvaluationResultImpl _result; | |
| 2476 | |
| 2477 /** | |
| 2478 * Initialize a newly created local variable element to have the given name. | |
| 2479 * | |
| 2480 * @param name the name of this element | |
| 2481 */ | |
| 2482 ConstLocalVariableElementImpl(Identifier name) : super(name); | |
| 2483 EvaluationResultImpl get evaluationResult => _result; | |
| 2484 void set evaluationResult(EvaluationResultImpl result) { | |
| 2485 this._result = result; | |
| 2486 } | |
| 2487 } | |
| 2488 /** | |
| 2489 * Instances of the class `ConstTopLevelVariableElementImpl` implement a | |
| 2490 * `TopLevelVariableElement` for a top-level 'const' variable that has an initia
lizer. | |
| 2491 */ | |
| 2492 class ConstTopLevelVariableElementImpl extends TopLevelVariableElementImpl { | |
| 2493 | |
| 2494 /** | |
| 2495 * The result of evaluating this variable's initializer. | |
| 2496 */ | |
| 2497 EvaluationResultImpl _result; | |
| 2498 | |
| 2499 /** | |
| 2500 * Initialize a newly created top-level variable element to have the given nam
e. | |
| 2501 * | |
| 2502 * @param name the name of this element | |
| 2503 */ | |
| 2504 ConstTopLevelVariableElementImpl(Identifier name) : super.con1(name); | |
| 2505 EvaluationResultImpl get evaluationResult => _result; | |
| 2506 void set evaluationResult(EvaluationResultImpl result) { | |
| 2507 this._result = result; | |
| 2508 } | |
| 2509 } | |
| 2510 /** | |
| 2511 * Instances of the class `ConstructorElementImpl` implement a `ConstructorEleme
nt`. | |
| 2512 * | |
| 2513 * @coverage dart.engine.element | |
| 2514 */ | |
| 2515 class ConstructorElementImpl extends ExecutableElementImpl implements Constructo
rElement { | |
| 2516 | |
| 2517 /** | |
| 2518 * An empty array of constructor elements. | |
| 2519 */ | |
| 2520 static List<ConstructorElement> EMPTY_ARRAY = new List<ConstructorElement>(0); | |
| 2521 | |
| 2522 /** | |
| 2523 * The constructor to which this constructor is redirecting. | |
| 2524 */ | |
| 2525 ConstructorElement _redirectedConstructor; | |
| 2526 | |
| 2527 /** | |
| 2528 * Initialize a newly created constructor element to have the given name. | |
| 2529 * | |
| 2530 * @param name the name of this element | |
| 2531 */ | |
| 2532 ConstructorElementImpl(Identifier name) : super.con1(name); | |
| 2533 accept(ElementVisitor visitor) => visitor.visitConstructorElement(this); | |
| 2534 ClassElement get enclosingElement => super.enclosingElement as ClassElement; | |
| 2535 ElementKind get kind => ElementKind.CONSTRUCTOR; | |
| 2536 ConstructorElement get redirectedConstructor => _redirectedConstructor; | |
| 2537 bool get isConst => hasModifier(Modifier.CONST); | |
| 2538 bool get isDefaultConstructor { | |
| 2539 String name = this.name; | |
| 2540 if (name != null && name.length != 0) { | |
| 2541 return false; | |
| 2542 } | |
| 2543 for (ParameterElement parameter in parameters) { | |
| 2544 if (identical(parameter.parameterKind, ParameterKind.REQUIRED)) { | |
| 2545 return false; | |
| 2546 } | |
| 2547 } | |
| 2548 return true; | |
| 2549 } | |
| 2550 bool get isFactory => hasModifier(Modifier.FACTORY); | |
| 2551 bool get isStatic => false; | |
| 2552 | |
| 2553 /** | |
| 2554 * Set whether this constructor represents a 'const' constructor to the given
value. | |
| 2555 * | |
| 2556 * @param isConst `true` if this constructor represents a 'const' constructor | |
| 2557 */ | |
| 2558 void set const2(bool isConst) { | |
| 2559 setModifier(Modifier.CONST, isConst); | |
| 2560 } | |
| 2561 | |
| 2562 /** | |
| 2563 * Set whether this constructor represents a factory method to the given value
. | |
| 2564 * | |
| 2565 * @param isFactory `true` if this constructor represents a factory method | |
| 2566 */ | |
| 2567 void set factory(bool isFactory) { | |
| 2568 setModifier(Modifier.FACTORY, isFactory); | |
| 2569 } | |
| 2570 | |
| 2571 /** | |
| 2572 * Sets the constructor to which this constructor is redirecting. | |
| 2573 * | |
| 2574 * @param redirectedConstructor the constructor to which this constructor is r
edirecting | |
| 2575 */ | |
| 2576 void set redirectedConstructor(ConstructorElement redirectedConstructor) { | |
| 2577 this._redirectedConstructor = redirectedConstructor; | |
| 2578 } | |
| 2579 void appendTo(JavaStringBuilder builder) { | |
| 2580 builder.append(enclosingElement.displayName); | |
| 2581 String name = displayName; | |
| 2582 if (name != null && !name.isEmpty) { | |
| 2583 builder.append("."); | |
| 2584 builder.append(name); | |
| 2585 } | |
| 2586 super.appendTo(builder); | |
| 2587 } | |
| 2588 } | |
| 2589 /** | |
| 2590 * Instances of the class `DefaultFieldFormalParameterElementImpl` implement a | |
| 2591 * `FieldFormalParameterElementImpl` for parameters that have an initializer. | |
| 2592 * | |
| 2593 * @coverage dart.engine.element | |
| 2594 */ | |
| 2595 class DefaultFieldFormalParameterElementImpl extends FieldFormalParameterElement
Impl { | |
| 2596 | |
| 2597 /** | |
| 2598 * The result of evaluating this variable's initializer. | |
| 2599 */ | |
| 2600 EvaluationResultImpl _result; | |
| 2601 | |
| 2602 /** | |
| 2603 * Initialize a newly created parameter element to have the given name. | |
| 2604 * | |
| 2605 * @param name the name of this element | |
| 2606 */ | |
| 2607 DefaultFieldFormalParameterElementImpl(Identifier name) : super(name); | |
| 2608 EvaluationResultImpl get evaluationResult => _result; | |
| 2609 void set evaluationResult(EvaluationResultImpl result) { | |
| 2610 this._result = result; | |
| 2611 } | |
| 2612 } | |
| 2613 /** | |
| 2614 * Instances of the class `DefaultParameterElementImpl` implement a `ParameterEl
ement` | |
| 2615 * for parameters that have an initializer. | |
| 2616 * | |
| 2617 * @coverage dart.engine.element | |
| 2618 */ | |
| 2619 class DefaultParameterElementImpl extends ParameterElementImpl { | |
| 2620 | |
| 2621 /** | |
| 2622 * The result of evaluating this variable's initializer. | |
| 2623 */ | |
| 2624 EvaluationResultImpl _result; | |
| 2625 | |
| 2626 /** | |
| 2627 * Initialize a newly created parameter element to have the given name. | |
| 2628 * | |
| 2629 * @param name the name of this element | |
| 2630 */ | |
| 2631 DefaultParameterElementImpl(Identifier name) : super.con1(name); | |
| 2632 EvaluationResultImpl get evaluationResult => _result; | |
| 2633 void set evaluationResult(EvaluationResultImpl result) { | |
| 2634 this._result = result; | |
| 2635 } | |
| 2636 } | |
| 2637 /** | |
| 2638 * Instances of the class `DynamicElementImpl` represent the synthetic element r
epresenting | |
| 2639 * the declaration of the type `dynamic`. | |
| 2640 * | |
| 2641 * @coverage dart.engine.element | |
| 2642 */ | |
| 2643 class DynamicElementImpl extends ElementImpl { | |
| 2644 | |
| 2645 /** | |
| 2646 * Return the unique instance of this class. | |
| 2647 * | |
| 2648 * @return the unique instance of this class | |
| 2649 */ | |
| 2650 static DynamicElementImpl get instance => DynamicTypeImpl.instance.element as
DynamicElementImpl; | |
| 2651 | |
| 2652 /** | |
| 2653 * The type defined by this element. | |
| 2654 */ | |
| 2655 DynamicTypeImpl type; | |
| 2656 | |
| 2657 /** | |
| 2658 * Initialize a newly created instance of this class. Instances of this class
should <b>not</b> be | |
| 2659 * created except as part of creating the type associated with this element. T
he single instance | |
| 2660 * of this class should be accessed through the method [getInstance]. | |
| 2661 */ | |
| 2662 DynamicElementImpl() : super.con2(Keyword.DYNAMIC.syntax, -1) { | |
| 2663 setModifier(Modifier.SYNTHETIC, true); | |
| 2664 } | |
| 2665 accept(ElementVisitor visitor) => null; | |
| 2666 ElementKind get kind => ElementKind.DYNAMIC; | |
| 2667 } | |
| 2668 /** | |
| 2669 * Instances of the class `ElementAnnotationImpl` implement an [ElementAnnotatio
n]. | |
| 2670 * | |
| 2671 * @coverage dart.engine.element | |
| 2672 */ | |
| 2673 class ElementAnnotationImpl implements ElementAnnotation { | |
| 2674 | |
| 2675 /** | |
| 2676 * The element representing the field, variable, or constructor being used as
an annotation. | |
| 2677 */ | |
| 2678 Element _element; | |
| 2679 | |
| 2680 /** | |
| 2681 * An empty array of annotations. | |
| 2682 */ | |
| 2683 static List<ElementAnnotationImpl> EMPTY_ARRAY = new List<ElementAnnotationImp
l>(0); | |
| 2684 | |
| 2685 /** | |
| 2686 * Initialize a newly created annotation. | |
| 2687 * | |
| 2688 * @param element the element representing the field, variable, or constructor
being used as an | |
| 2689 * annotation | |
| 2690 */ | |
| 2691 ElementAnnotationImpl(Element element) { | |
| 2692 this._element = element; | |
| 2693 } | |
| 2694 Element get element => _element; | |
| 2695 String toString() => "@${_element.toString()}"; | |
| 2696 } | |
| 2697 /** | |
| 2698 * The abstract class `ElementImpl` implements the behavior common to objects th
at implement | |
| 2699 * an [Element]. | |
| 2700 * | |
| 2701 * @coverage dart.engine.element | |
| 2702 */ | |
| 2703 abstract class ElementImpl implements Element { | |
| 2704 | |
| 2705 /** | |
| 2706 * The enclosing element of this element, or `null` if this element is at the
root of the | |
| 2707 * element structure. | |
| 2708 */ | |
| 2709 ElementImpl _enclosingElement; | |
| 2710 | |
| 2711 /** | |
| 2712 * The name of this element. | |
| 2713 */ | |
| 2714 String _name; | |
| 2715 | |
| 2716 /** | |
| 2717 * The offset of the name of this element in the file that contains the declar
ation of this | |
| 2718 * element. | |
| 2719 */ | |
| 2720 int _nameOffset = 0; | |
| 2721 | |
| 2722 /** | |
| 2723 * A bit-encoded form of the modifiers associated with this element. | |
| 2724 */ | |
| 2725 int _modifiers = 0; | |
| 2726 | |
| 2727 /** | |
| 2728 * An array containing all of the metadata associated with this element. | |
| 2729 */ | |
| 2730 List<ElementAnnotation> _metadata = ElementAnnotationImpl.EMPTY_ARRAY; | |
| 2731 | |
| 2732 /** | |
| 2733 * A cached copy of the calculated hashCode for this element. | |
| 2734 */ | |
| 2735 int _cachedHashCode = 0; | |
| 2736 | |
| 2737 /** | |
| 2738 * Initialize a newly created element to have the given name. | |
| 2739 * | |
| 2740 * @param name the name of this element | |
| 2741 */ | |
| 2742 ElementImpl.con1(Identifier name) : this.con2(name == null ? "" : name.name, n
ame == null ? -1 : name.offset); | |
| 2743 | |
| 2744 /** | |
| 2745 * Initialize a newly created element to have the given name. | |
| 2746 * | |
| 2747 * @param name the name of this element | |
| 2748 * @param nameOffset the offset of the name of this element in the file that c
ontains the | |
| 2749 * declaration of this element | |
| 2750 */ | |
| 2751 ElementImpl.con2(String name, int nameOffset) { | |
| 2752 this._name = StringUtilities.intern(name); | |
| 2753 this._nameOffset = nameOffset; | |
| 2754 } | |
| 2755 String computeDocumentationComment() { | |
| 2756 AnalysisContext context = this.context; | |
| 2757 if (context == null) { | |
| 2758 return null; | |
| 2759 } | |
| 2760 return context.computeDocumentationComment(this); | |
| 2761 } | |
| 2762 bool operator ==(Object object) { | |
| 2763 if (identical(this, object)) { | |
| 2764 return true; | |
| 2765 } | |
| 2766 if (object == null || hashCode != object.hashCode) { | |
| 2767 return false; | |
| 2768 } | |
| 2769 return object.runtimeType == runtimeType && ((object as Element)).location =
= location; | |
| 2770 } | |
| 2771 Element getAncestor(Type elementClass) { | |
| 2772 Element ancestor = _enclosingElement; | |
| 2773 while (ancestor != null && !isInstanceOf(ancestor, elementClass)) { | |
| 2774 ancestor = ancestor.enclosingElement; | |
| 2775 } | |
| 2776 return ancestor as Element; | |
| 2777 } | |
| 2778 | |
| 2779 /** | |
| 2780 * Return the child of this element that is uniquely identified by the given i
dentifier, or | |
| 2781 * `null` if there is no such child. | |
| 2782 * | |
| 2783 * @param identifier the identifier used to select a child | |
| 2784 * @return the child of this element with the given identifier | |
| 2785 */ | |
| 2786 ElementImpl getChild(String identifier) => null; | |
| 2787 AnalysisContext get context { | |
| 2788 if (_enclosingElement == null) { | |
| 2789 return null; | |
| 2790 } | |
| 2791 return _enclosingElement.context; | |
| 2792 } | |
| 2793 String get displayName => _name; | |
| 2794 Element get enclosingElement => _enclosingElement; | |
| 2795 LibraryElement get library => getAncestor(LibraryElement); | |
| 2796 ElementLocation get location => new ElementLocationImpl.con1(this); | |
| 2797 List<ElementAnnotation> get metadata => _metadata; | |
| 2798 String get name => _name; | |
| 2799 int get nameOffset => _nameOffset; | |
| 2800 Source get source { | |
| 2801 if (_enclosingElement == null) { | |
| 2802 return null; | |
| 2803 } | |
| 2804 return _enclosingElement.source; | |
| 2805 } | |
| 2806 int get hashCode { | |
| 2807 if (_cachedHashCode == 0) { | |
| 2808 _cachedHashCode = location.hashCode; | |
| 2809 } | |
| 2810 return _cachedHashCode; | |
| 2811 } | |
| 2812 bool isAccessibleIn(LibraryElement library) { | |
| 2813 if (Identifier.isPrivateName(_name)) { | |
| 2814 return library == this.library; | |
| 2815 } | |
| 2816 return true; | |
| 2817 } | |
| 2818 bool get isSynthetic => hasModifier(Modifier.SYNTHETIC); | |
| 2819 | |
| 2820 /** | |
| 2821 * Set the metadata associate with this element to the given array of annotati
ons. | |
| 2822 * | |
| 2823 * @param metadata the metadata to be associated with this element | |
| 2824 */ | |
| 2825 void set metadata(List<ElementAnnotation> metadata) { | |
| 2826 this._metadata = metadata; | |
| 2827 } | |
| 2828 | |
| 2829 /** | |
| 2830 * Set the offset of the name of this element in the file that contains the de
claration of this | |
| 2831 * element to the given value. This is normally done via the constructor, but
this method is | |
| 2832 * provided to support unnamed constructors. | |
| 2833 * | |
| 2834 * @param nameOffset the offset to the beginning of the name | |
| 2835 */ | |
| 2836 void set nameOffset(int nameOffset) { | |
| 2837 this._nameOffset = nameOffset; | |
| 2838 } | |
| 2839 | |
| 2840 /** | |
| 2841 * Set whether this element is synthetic to correspond to the given value. | |
| 2842 * | |
| 2843 * @param isSynthetic `true` if the element is synthetic | |
| 2844 */ | |
| 2845 void set synthetic(bool isSynthetic) { | |
| 2846 setModifier(Modifier.SYNTHETIC, isSynthetic); | |
| 2847 } | |
| 2848 String toString() { | |
| 2849 JavaStringBuilder builder = new JavaStringBuilder(); | |
| 2850 appendTo(builder); | |
| 2851 return builder.toString(); | |
| 2852 } | |
| 2853 void visitChildren(ElementVisitor visitor) { | |
| 2854 } | |
| 2855 | |
| 2856 /** | |
| 2857 * Append a textual representation of this type to the given builder. | |
| 2858 * | |
| 2859 * @param builder the builder to which the text is to be appended | |
| 2860 */ | |
| 2861 void appendTo(JavaStringBuilder builder) { | |
| 2862 if (_name == null) { | |
| 2863 builder.append("<unnamed "); | |
| 2864 builder.append(runtimeType.toString()); | |
| 2865 builder.append(">"); | |
| 2866 } else { | |
| 2867 builder.append(_name); | |
| 2868 } | |
| 2869 } | |
| 2870 | |
| 2871 /** | |
| 2872 * Return an identifier that uniquely identifies this element among the childr
en of this element's | |
| 2873 * parent. | |
| 2874 * | |
| 2875 * @return an identifier that uniquely identifies this element relative to its
parent | |
| 2876 */ | |
| 2877 String get identifier => name; | |
| 2878 | |
| 2879 /** | |
| 2880 * Return `true` if this element has the given modifier associated with it. | |
| 2881 * | |
| 2882 * @param modifier the modifier being tested for | |
| 2883 * @return `true` if this element has the given modifier associated with it | |
| 2884 */ | |
| 2885 bool hasModifier(Modifier modifier) => BooleanArray.get(_modifiers, modifier); | |
| 2886 | |
| 2887 /** | |
| 2888 * If the given child is not `null`, use the given visitor to visit it. | |
| 2889 * | |
| 2890 * @param child the child to be visited | |
| 2891 * @param visitor the visitor to be used to visit the child | |
| 2892 */ | |
| 2893 void safelyVisitChild(Element child, ElementVisitor visitor) { | |
| 2894 if (child != null) { | |
| 2895 child.accept(visitor); | |
| 2896 } | |
| 2897 } | |
| 2898 | |
| 2899 /** | |
| 2900 * Use the given visitor to visit all of the children in the given array. | |
| 2901 * | |
| 2902 * @param children the children to be visited | |
| 2903 * @param visitor the visitor being used to visit the children | |
| 2904 */ | |
| 2905 void safelyVisitChildren(List<Element> children, ElementVisitor visitor) { | |
| 2906 if (children != null) { | |
| 2907 for (Element child in children) { | |
| 2908 child.accept(visitor); | |
| 2909 } | |
| 2910 } | |
| 2911 } | |
| 2912 | |
| 2913 /** | |
| 2914 * Set the enclosing element of this element to the given element. | |
| 2915 * | |
| 2916 * @param element the enclosing element of this element | |
| 2917 */ | |
| 2918 void set enclosingElement(Element element) { | |
| 2919 _enclosingElement = element as ElementImpl; | |
| 2920 } | |
| 2921 | |
| 2922 /** | |
| 2923 * Set whether the given modifier is associated with this element to correspon
d to the given | |
| 2924 * value. | |
| 2925 * | |
| 2926 * @param modifier the modifier to be set | |
| 2927 * @param value `true` if the modifier is to be associated with this element | |
| 2928 */ | |
| 2929 void setModifier(Modifier modifier, bool value) { | |
| 2930 _modifiers = BooleanArray.set(_modifiers, modifier, value); | |
| 2931 } | |
| 2932 } | |
| 2933 /** | |
| 2934 * Instances of the class `ElementLocationImpl` implement an [ElementLocation]. | |
| 2935 * | |
| 2936 * @coverage dart.engine.element | |
| 2937 */ | |
| 2938 class ElementLocationImpl implements ElementLocation { | |
| 2939 | |
| 2940 /** | |
| 2941 * The path to the element whose location is represented by this object. | |
| 2942 */ | |
| 2943 List<String> components; | |
| 2944 | |
| 2945 /** | |
| 2946 * The character used to separate components in the encoded form. | |
| 2947 */ | |
| 2948 static int _SEPARATOR_CHAR = 0x3B; | |
| 2949 | |
| 2950 /** | |
| 2951 * Initialize a newly created location to represent the given element. | |
| 2952 * | |
| 2953 * @param element the element whose location is being represented | |
| 2954 */ | |
| 2955 ElementLocationImpl.con1(Element element) { | |
| 2956 List<String> components = new List<String>(); | |
| 2957 Element ancestor = element; | |
| 2958 while (ancestor != null) { | |
| 2959 components.insert(0, ((ancestor as ElementImpl)).identifier); | |
| 2960 ancestor = ancestor.enclosingElement; | |
| 2961 } | |
| 2962 this.components = new List.from(components); | |
| 2963 } | |
| 2964 | |
| 2965 /** | |
| 2966 * Initialize a newly created location from the given encoded form. | |
| 2967 * | |
| 2968 * @param encoding the encoded form of a location | |
| 2969 */ | |
| 2970 ElementLocationImpl.con2(String encoding) { | |
| 2971 this.components = decode(encoding); | |
| 2972 } | |
| 2973 bool operator ==(Object object) { | |
| 2974 if (identical(this, object)) { | |
| 2975 return true; | |
| 2976 } | |
| 2977 if (object is! ElementLocationImpl) { | |
| 2978 return false; | |
| 2979 } | |
| 2980 ElementLocationImpl location = object as ElementLocationImpl; | |
| 2981 List<String> otherComponents = location.components; | |
| 2982 int length = components.length; | |
| 2983 if (otherComponents.length != length) { | |
| 2984 return false; | |
| 2985 } | |
| 2986 for (int i = length - 1; i >= 2; i--) { | |
| 2987 if (components[i] != otherComponents[i]) { | |
| 2988 return false; | |
| 2989 } | |
| 2990 } | |
| 2991 if (length > 1 && !equalSourceComponents(components[1], otherComponents[1]))
{ | |
| 2992 return false; | |
| 2993 } | |
| 2994 if (length > 0 && !equalSourceComponents(components[0], otherComponents[0]))
{ | |
| 2995 return false; | |
| 2996 } | |
| 2997 return true; | |
| 2998 } | |
| 2999 String get encoding { | |
| 3000 JavaStringBuilder builder = new JavaStringBuilder(); | |
| 3001 int length = components.length; | |
| 3002 for (int i = 0; i < length; i++) { | |
| 3003 if (i > 0) { | |
| 3004 builder.appendChar(_SEPARATOR_CHAR); | |
| 3005 } | |
| 3006 encode(builder, components[i]); | |
| 3007 } | |
| 3008 return builder.toString(); | |
| 3009 } | |
| 3010 int get hashCode { | |
| 3011 int result = 1; | |
| 3012 for (int i = 0; i < components.length; i++) { | |
| 3013 String component = components[i]; | |
| 3014 int componentHash; | |
| 3015 if (i <= 1) { | |
| 3016 componentHash = hashSourceComponent(component); | |
| 3017 } else { | |
| 3018 componentHash = component.hashCode; | |
| 3019 } | |
| 3020 result = 31 * result + componentHash; | |
| 3021 } | |
| 3022 return result; | |
| 3023 } | |
| 3024 String toString() => encoding; | |
| 3025 | |
| 3026 /** | |
| 3027 * Decode the encoded form of a location into an array of components. | |
| 3028 * | |
| 3029 * @param encoding the encoded form of a location | |
| 3030 * @return the components that were encoded | |
| 3031 */ | |
| 3032 List<String> decode(String encoding) { | |
| 3033 List<String> components = new List<String>(); | |
| 3034 JavaStringBuilder builder = new JavaStringBuilder(); | |
| 3035 int index = 0; | |
| 3036 int length = encoding.length; | |
| 3037 while (index < length) { | |
| 3038 int currentChar = encoding.codeUnitAt(index); | |
| 3039 if (currentChar == _SEPARATOR_CHAR) { | |
| 3040 if (index + 1 < length && encoding.codeUnitAt(index + 1) == _SEPARATOR_C
HAR) { | |
| 3041 builder.appendChar(_SEPARATOR_CHAR); | |
| 3042 index += 2; | |
| 3043 } else { | |
| 3044 components.add(builder.toString()); | |
| 3045 builder.length = 0; | |
| 3046 index++; | |
| 3047 } | |
| 3048 } else { | |
| 3049 builder.appendChar(currentChar); | |
| 3050 index++; | |
| 3051 } | |
| 3052 } | |
| 3053 if (builder.length > 0) { | |
| 3054 components.add(builder.toString()); | |
| 3055 } | |
| 3056 return new List.from(components); | |
| 3057 } | |
| 3058 | |
| 3059 /** | |
| 3060 * Append an encoded form of the given component to the given builder. | |
| 3061 * | |
| 3062 * @param builder the builder to which the encoded component is to be appended | |
| 3063 * @param component the component to be appended to the builder | |
| 3064 */ | |
| 3065 void encode(JavaStringBuilder builder, String component) { | |
| 3066 int length = component.length; | |
| 3067 for (int i = 0; i < length; i++) { | |
| 3068 int currentChar = component.codeUnitAt(i); | |
| 3069 if (currentChar == _SEPARATOR_CHAR) { | |
| 3070 builder.appendChar(_SEPARATOR_CHAR); | |
| 3071 } | |
| 3072 builder.appendChar(currentChar); | |
| 3073 } | |
| 3074 } | |
| 3075 | |
| 3076 /** | |
| 3077 * Return `true` if the given components, when interpreted to be encoded sourc
es with a | |
| 3078 * leading source type indicator, are equal when the source type's are ignored
. | |
| 3079 * | |
| 3080 * @param left the left component being compared | |
| 3081 * @param right the right component being compared | |
| 3082 * @return `true` if the given components are equal when the source type's are
ignored | |
| 3083 */ | |
| 3084 bool equalSourceComponents(String left, String right) { | |
| 3085 if (left == null) { | |
| 3086 return right == null; | |
| 3087 } else if (right == null) { | |
| 3088 return false; | |
| 3089 } | |
| 3090 int leftLength = left.length; | |
| 3091 int rightLength = right.length; | |
| 3092 if (leftLength != rightLength) { | |
| 3093 return false; | |
| 3094 } else if (leftLength <= 1 || rightLength <= 1) { | |
| 3095 return left == right; | |
| 3096 } | |
| 3097 return javaStringRegionMatches(left, 1, right, 1, leftLength - 1); | |
| 3098 } | |
| 3099 | |
| 3100 /** | |
| 3101 * Return the hash code of the given encoded source component, ignoring the so
urce type indicator. | |
| 3102 * | |
| 3103 * @param sourceComponent the component to compute a hash code | |
| 3104 * @return the hash code of the given encoded source component | |
| 3105 */ | |
| 3106 int hashSourceComponent(String sourceComponent) { | |
| 3107 if (sourceComponent.length <= 1) { | |
| 3108 return sourceComponent.hashCode; | |
| 3109 } | |
| 3110 return sourceComponent.substring(1).hashCode; | |
| 3111 } | |
| 3112 } | |
| 3113 /** | |
| 3114 * Instances of the class `EmbeddedHtmlScriptElementImpl` implement an | |
| 3115 * [EmbeddedHtmlScriptElement]. | |
| 3116 * | |
| 3117 * @coverage dart.engine.element | |
| 3118 */ | |
| 3119 class EmbeddedHtmlScriptElementImpl extends HtmlScriptElementImpl implements Emb
eddedHtmlScriptElement { | |
| 3120 | |
| 3121 /** | |
| 3122 * The library defined by the script tag's content. | |
| 3123 */ | |
| 3124 LibraryElement _scriptLibrary; | |
| 3125 | |
| 3126 /** | |
| 3127 * Initialize a newly created script element to have the specified tag name an
d offset. | |
| 3128 * | |
| 3129 * @param node the XML node from which this element is derived (not `null`) | |
| 3130 */ | |
| 3131 EmbeddedHtmlScriptElementImpl(XmlTagNode node) : super(node); | |
| 3132 accept(ElementVisitor visitor) => visitor.visitEmbeddedHtmlScriptElement(this)
; | |
| 3133 ElementKind get kind => ElementKind.EMBEDDED_HTML_SCRIPT; | |
| 3134 LibraryElement get scriptLibrary => _scriptLibrary; | |
| 3135 | |
| 3136 /** | |
| 3137 * Set the script library defined by the script tag's content. | |
| 3138 * | |
| 3139 * @param scriptLibrary the library or `null` if none | |
| 3140 */ | |
| 3141 void set scriptLibrary(LibraryElementImpl scriptLibrary) { | |
| 3142 scriptLibrary.enclosingElement = this; | |
| 3143 this._scriptLibrary = scriptLibrary; | |
| 3144 } | |
| 3145 void visitChildren(ElementVisitor visitor) { | |
| 3146 safelyVisitChild(_scriptLibrary, visitor); | |
| 3147 } | |
| 3148 } | |
| 3149 /** | |
| 3150 * The abstract class `ExecutableElementImpl` implements the behavior common to | |
| 3151 * `ExecutableElement`s. | |
| 3152 * | |
| 3153 * @coverage dart.engine.element | |
| 3154 */ | |
| 3155 abstract class ExecutableElementImpl extends ElementImpl implements ExecutableEl
ement { | |
| 3156 | |
| 3157 /** | |
| 3158 * An array containing all of the functions defined within this executable ele
ment. | |
| 3159 */ | |
| 3160 List<FunctionElement> _functions = FunctionElementImpl.EMPTY_ARRAY; | |
| 3161 | |
| 3162 /** | |
| 3163 * An array containing all of the labels defined within this executable elemen
t. | |
| 3164 */ | |
| 3165 List<LabelElement> _labels = LabelElementImpl.EMPTY_ARRAY; | |
| 3166 | |
| 3167 /** | |
| 3168 * An array containing all of the local variables defined within this executab
le element. | |
| 3169 */ | |
| 3170 List<LocalVariableElement> _localVariables = LocalVariableElementImpl.EMPTY_AR
RAY; | |
| 3171 | |
| 3172 /** | |
| 3173 * An array containing all of the parameters defined by this executable elemen
t. | |
| 3174 */ | |
| 3175 List<ParameterElement> _parameters = ParameterElementImpl.EMPTY_ARRAY; | |
| 3176 | |
| 3177 /** | |
| 3178 * The return type defined by this executable element. | |
| 3179 */ | |
| 3180 Type2 _returnType; | |
| 3181 | |
| 3182 /** | |
| 3183 * The type of function defined by this executable element. | |
| 3184 */ | |
| 3185 FunctionType _type; | |
| 3186 | |
| 3187 /** | |
| 3188 * An empty array of executable elements. | |
| 3189 */ | |
| 3190 static List<ExecutableElement> EMPTY_ARRAY = new List<ExecutableElement>(0); | |
| 3191 | |
| 3192 /** | |
| 3193 * Initialize a newly created executable element to have the given name. | |
| 3194 * | |
| 3195 * @param name the name of this element | |
| 3196 */ | |
| 3197 ExecutableElementImpl.con1(Identifier name) : super.con1(name); | |
| 3198 | |
| 3199 /** | |
| 3200 * Initialize a newly created executable element to have the given name. | |
| 3201 * | |
| 3202 * @param name the name of this element | |
| 3203 * @param nameOffset the offset of the name of this element in the file that c
ontains the | |
| 3204 * declaration of this element | |
| 3205 */ | |
| 3206 ExecutableElementImpl.con2(String name, int nameOffset) : super.con2(name, nam
eOffset); | |
| 3207 ElementImpl getChild(String identifier) { | |
| 3208 for (ExecutableElement function in _functions) { | |
| 3209 if (((function as ExecutableElementImpl)).identifier == identifier) { | |
| 3210 return function as ExecutableElementImpl; | |
| 3211 } | |
| 3212 } | |
| 3213 for (LabelElement label in _labels) { | |
| 3214 if (((label as LabelElementImpl)).identifier == identifier) { | |
| 3215 return label as LabelElementImpl; | |
| 3216 } | |
| 3217 } | |
| 3218 for (VariableElement variable in _localVariables) { | |
| 3219 if (((variable as VariableElementImpl)).identifier == identifier) { | |
| 3220 return variable as VariableElementImpl; | |
| 3221 } | |
| 3222 } | |
| 3223 for (ParameterElement parameter in _parameters) { | |
| 3224 if (((parameter as ParameterElementImpl)).identifier == identifier) { | |
| 3225 return parameter as ParameterElementImpl; | |
| 3226 } | |
| 3227 } | |
| 3228 return null; | |
| 3229 } | |
| 3230 List<FunctionElement> get functions => _functions; | |
| 3231 List<LabelElement> get labels => _labels; | |
| 3232 List<LocalVariableElement> get localVariables => _localVariables; | |
| 3233 List<ParameterElement> get parameters => _parameters; | |
| 3234 Type2 get returnType => _returnType; | |
| 3235 FunctionType get type => _type; | |
| 3236 bool get isOperator => false; | |
| 3237 | |
| 3238 /** | |
| 3239 * Set the functions defined within this executable element to the given funct
ions. | |
| 3240 * | |
| 3241 * @param functions the functions defined within this executable element | |
| 3242 */ | |
| 3243 void set functions(List<FunctionElement> functions) { | |
| 3244 for (FunctionElement function in functions) { | |
| 3245 ((function as FunctionElementImpl)).enclosingElement = this; | |
| 3246 } | |
| 3247 this._functions = functions; | |
| 3248 } | |
| 3249 | |
| 3250 /** | |
| 3251 * Set the labels defined within this executable element to the given labels. | |
| 3252 * | |
| 3253 * @param labels the labels defined within this executable element | |
| 3254 */ | |
| 3255 void set labels(List<LabelElement> labels) { | |
| 3256 for (LabelElement label in labels) { | |
| 3257 ((label as LabelElementImpl)).enclosingElement = this; | |
| 3258 } | |
| 3259 this._labels = labels; | |
| 3260 } | |
| 3261 | |
| 3262 /** | |
| 3263 * Set the local variables defined within this executable element to the given
variables. | |
| 3264 * | |
| 3265 * @param localVariables the local variables defined within this executable el
ement | |
| 3266 */ | |
| 3267 void set localVariables(List<LocalVariableElement> localVariables) { | |
| 3268 for (LocalVariableElement variable in localVariables) { | |
| 3269 ((variable as LocalVariableElementImpl)).enclosingElement = this; | |
| 3270 } | |
| 3271 this._localVariables = localVariables; | |
| 3272 } | |
| 3273 | |
| 3274 /** | |
| 3275 * Set the parameters defined by this executable element to the given paramete
rs. | |
| 3276 * | |
| 3277 * @param parameters the parameters defined by this executable element | |
| 3278 */ | |
| 3279 void set parameters(List<ParameterElement> parameters) { | |
| 3280 for (ParameterElement parameter in parameters) { | |
| 3281 ((parameter as ParameterElementImpl)).enclosingElement = this; | |
| 3282 } | |
| 3283 this._parameters = parameters; | |
| 3284 } | |
| 3285 | |
| 3286 /** | |
| 3287 * Set the return type defined by this executable element. | |
| 3288 * | |
| 3289 * @param returnType the return type defined by this executable element | |
| 3290 */ | |
| 3291 void set returnType(Type2 returnType) { | |
| 3292 this._returnType = returnType; | |
| 3293 } | |
| 3294 | |
| 3295 /** | |
| 3296 * Set the type of function defined by this executable element to the given ty
pe. | |
| 3297 * | |
| 3298 * @param type the type of function defined by this executable element | |
| 3299 */ | |
| 3300 void set type(FunctionType type) { | |
| 3301 this._type = type; | |
| 3302 } | |
| 3303 void visitChildren(ElementVisitor visitor) { | |
| 3304 super.visitChildren(visitor); | |
| 3305 safelyVisitChildren(_functions, visitor); | |
| 3306 safelyVisitChildren(_labels, visitor); | |
| 3307 safelyVisitChildren(_localVariables, visitor); | |
| 3308 safelyVisitChildren(_parameters, visitor); | |
| 3309 } | |
| 3310 void appendTo(JavaStringBuilder builder) { | |
| 3311 builder.append("("); | |
| 3312 int parameterCount = _parameters.length; | |
| 3313 for (int i = 0; i < parameterCount; i++) { | |
| 3314 if (i > 0) { | |
| 3315 builder.append(", "); | |
| 3316 } | |
| 3317 ((_parameters[i] as ParameterElementImpl)).appendTo(builder); | |
| 3318 } | |
| 3319 builder.append(")"); | |
| 3320 if (_type != null) { | |
| 3321 builder.append(" -> "); | |
| 3322 builder.append(_type.returnType); | |
| 3323 } | |
| 3324 } | |
| 3325 } | |
| 3326 /** | |
| 3327 * Instances of the class `ExportElementImpl` implement an [ExportElement]. | |
| 3328 * | |
| 3329 * @coverage dart.engine.element | |
| 3330 */ | |
| 3331 class ExportElementImpl extends ElementImpl implements ExportElement { | |
| 3332 | |
| 3333 /** | |
| 3334 * The URI that is specified by this directive. | |
| 3335 */ | |
| 3336 String _uri; | |
| 3337 | |
| 3338 /** | |
| 3339 * The library that is exported from this library by this export directive. | |
| 3340 */ | |
| 3341 LibraryElement _exportedLibrary; | |
| 3342 | |
| 3343 /** | |
| 3344 * The combinators that were specified as part of the export directive in the
order in which they | |
| 3345 * were specified. | |
| 3346 */ | |
| 3347 List<NamespaceCombinator> _combinators = NamespaceCombinator.EMPTY_ARRAY; | |
| 3348 | |
| 3349 /** | |
| 3350 * Initialize a newly created export element. | |
| 3351 */ | |
| 3352 ExportElementImpl() : super.con1(null); | |
| 3353 accept(ElementVisitor visitor) => visitor.visitExportElement(this); | |
| 3354 List<NamespaceCombinator> get combinators => _combinators; | |
| 3355 LibraryElement get exportedLibrary => _exportedLibrary; | |
| 3356 ElementKind get kind => ElementKind.EXPORT; | |
| 3357 String get uri => _uri; | |
| 3358 | |
| 3359 /** | |
| 3360 * Set the combinators that were specified as part of the export directive to
the given array of | |
| 3361 * combinators. | |
| 3362 * | |
| 3363 * @param combinators the combinators that were specified as part of the expor
t directive | |
| 3364 */ | |
| 3365 void set combinators(List<NamespaceCombinator> combinators) { | |
| 3366 this._combinators = combinators; | |
| 3367 } | |
| 3368 | |
| 3369 /** | |
| 3370 * Set the library that is exported from this library by this import directive
to the given | |
| 3371 * library. | |
| 3372 * | |
| 3373 * @param exportedLibrary the library that is exported from this library | |
| 3374 */ | |
| 3375 void set exportedLibrary(LibraryElement exportedLibrary) { | |
| 3376 this._exportedLibrary = exportedLibrary; | |
| 3377 } | |
| 3378 | |
| 3379 /** | |
| 3380 * Set the URI that is specified by this directive. | |
| 3381 * | |
| 3382 * @param uri the URI that is specified by this directive. | |
| 3383 */ | |
| 3384 void set uri(String uri) { | |
| 3385 this._uri = uri; | |
| 3386 } | |
| 3387 void appendTo(JavaStringBuilder builder) { | |
| 3388 builder.append("export "); | |
| 3389 ((_exportedLibrary as LibraryElementImpl)).appendTo(builder); | |
| 3390 } | |
| 3391 String get identifier => _exportedLibrary.name; | |
| 3392 } | |
| 3393 /** | |
| 3394 * Instances of the class `ExternalHtmlScriptElementImpl` implement an | |
| 3395 * [ExternalHtmlScriptElement]. | |
| 3396 * | |
| 3397 * @coverage dart.engine.element | |
| 3398 */ | |
| 3399 class ExternalHtmlScriptElementImpl extends HtmlScriptElementImpl implements Ext
ernalHtmlScriptElement { | |
| 3400 | |
| 3401 /** | |
| 3402 * The source specified in the `source` attribute or `null` if unspecified. | |
| 3403 */ | |
| 3404 Source _scriptSource; | |
| 3405 | |
| 3406 /** | |
| 3407 * Initialize a newly created script element to have the specified tag name an
d offset. | |
| 3408 * | |
| 3409 * @param node the XML node from which this element is derived (not `null`) | |
| 3410 */ | |
| 3411 ExternalHtmlScriptElementImpl(XmlTagNode node) : super(node); | |
| 3412 accept(ElementVisitor visitor) => visitor.visitExternalHtmlScriptElement(this)
; | |
| 3413 ElementKind get kind => ElementKind.EXTERNAL_HTML_SCRIPT; | |
| 3414 Source get scriptSource => _scriptSource; | |
| 3415 | |
| 3416 /** | |
| 3417 * Set the source specified in the `source` attribute. | |
| 3418 * | |
| 3419 * @param scriptSource the script source or `null` if unspecified | |
| 3420 */ | |
| 3421 void set scriptSource(Source scriptSource) { | |
| 3422 this._scriptSource = scriptSource; | |
| 3423 } | |
| 3424 } | |
| 3425 /** | |
| 3426 * Instances of the class `FieldElementImpl` implement a `FieldElement`. | |
| 3427 * | |
| 3428 * @coverage dart.engine.element | |
| 3429 */ | |
| 3430 class FieldElementImpl extends PropertyInducingElementImpl implements FieldEleme
nt { | |
| 3431 | |
| 3432 /** | |
| 3433 * An empty array of field elements. | |
| 3434 */ | |
| 3435 static List<FieldElement> EMPTY_ARRAY = new List<FieldElement>(0); | |
| 3436 | |
| 3437 /** | |
| 3438 * Initialize a newly created field element to have the given name. | |
| 3439 * | |
| 3440 * @param name the name of this element | |
| 3441 */ | |
| 3442 FieldElementImpl.con1(Identifier name) : super.con1(name); | |
| 3443 | |
| 3444 /** | |
| 3445 * Initialize a newly created synthetic field element to have the given name. | |
| 3446 * | |
| 3447 * @param name the name of this element | |
| 3448 */ | |
| 3449 FieldElementImpl.con2(String name) : super.con2(name); | |
| 3450 accept(ElementVisitor visitor) => visitor.visitFieldElement(this); | |
| 3451 ClassElement get enclosingElement => super.enclosingElement as ClassElement; | |
| 3452 ElementKind get kind => ElementKind.FIELD; | |
| 3453 bool get isStatic => hasModifier(Modifier.STATIC); | |
| 3454 | |
| 3455 /** | |
| 3456 * Set whether this field is static to correspond to the given value. | |
| 3457 * | |
| 3458 * @param isStatic `true` if the field is static | |
| 3459 */ | |
| 3460 void set static(bool isStatic) { | |
| 3461 setModifier(Modifier.STATIC, isStatic); | |
| 3462 } | |
| 3463 } | |
| 3464 /** | |
| 3465 * Instances of the class `FieldFormalParameterElementImpl` extend | |
| 3466 * [ParameterElementImpl] to provide the additional information of the [FieldEle
ment] | |
| 3467 * associated with the parameter. | |
| 3468 * | |
| 3469 * @coverage dart.engine.element | |
| 3470 */ | |
| 3471 class FieldFormalParameterElementImpl extends ParameterElementImpl implements Fi
eldFormalParameterElement { | |
| 3472 | |
| 3473 /** | |
| 3474 * The field associated with this field formal parameter. | |
| 3475 */ | |
| 3476 FieldElement _field; | |
| 3477 | |
| 3478 /** | |
| 3479 * Initialize a newly created parameter element to have the given name. | |
| 3480 * | |
| 3481 * @param name the name of this element | |
| 3482 */ | |
| 3483 FieldFormalParameterElementImpl(Identifier name) : super.con1(name); | |
| 3484 accept(ElementVisitor visitor) => visitor.visitFieldFormalParameterElement(thi
s); | |
| 3485 FieldElement get field => _field; | |
| 3486 bool get isInitializingFormal => true; | |
| 3487 | |
| 3488 /** | |
| 3489 * Set the field element associated with this field formal parameter to the gi
ven element. | |
| 3490 * | |
| 3491 * @param field the new field element | |
| 3492 */ | |
| 3493 void set field(FieldElement field) { | |
| 3494 this._field = field; | |
| 3495 } | |
| 3496 } | |
| 3497 /** | |
| 3498 * Instances of the class `FunctionElementImpl` implement a `FunctionElement`. | |
| 3499 * | |
| 3500 * @coverage dart.engine.element | |
| 3501 */ | |
| 3502 class FunctionElementImpl extends ExecutableElementImpl implements FunctionEleme
nt { | |
| 3503 | |
| 3504 /** | |
| 3505 * The offset to the beginning of the visible range for this element. | |
| 3506 */ | |
| 3507 int _visibleRangeOffset = 0; | |
| 3508 | |
| 3509 /** | |
| 3510 * The length of the visible range for this element, or `-1` if this element d
oes not have a | |
| 3511 * visible range. | |
| 3512 */ | |
| 3513 int _visibleRangeLength = -1; | |
| 3514 | |
| 3515 /** | |
| 3516 * An empty array of function elements. | |
| 3517 */ | |
| 3518 static List<FunctionElement> EMPTY_ARRAY = new List<FunctionElement>(0); | |
| 3519 | |
| 3520 /** | |
| 3521 * Initialize a newly created synthetic function element. | |
| 3522 */ | |
| 3523 FunctionElementImpl() : super.con2("", -1) { | |
| 3524 synthetic = true; | |
| 3525 } | |
| 3526 | |
| 3527 /** | |
| 3528 * Initialize a newly created function element to have the given name. | |
| 3529 * | |
| 3530 * @param name the name of this element | |
| 3531 */ | |
| 3532 FunctionElementImpl.con1(Identifier name) : super.con1(name); | |
| 3533 | |
| 3534 /** | |
| 3535 * Initialize a newly created function element to have no name and the given o
ffset. This is used | |
| 3536 * for function expressions, which have no name. | |
| 3537 * | |
| 3538 * @param nameOffset the offset of the name of this element in the file that c
ontains the | |
| 3539 * declaration of this element | |
| 3540 */ | |
| 3541 FunctionElementImpl.con2(int nameOffset) : super.con2("", nameOffset); | |
| 3542 accept(ElementVisitor visitor) => visitor.visitFunctionElement(this); | |
| 3543 ElementKind get kind => ElementKind.FUNCTION; | |
| 3544 SourceRange get visibleRange { | |
| 3545 if (_visibleRangeLength < 0) { | |
| 3546 return null; | |
| 3547 } | |
| 3548 return new SourceRange(_visibleRangeOffset, _visibleRangeLength); | |
| 3549 } | |
| 3550 bool get isStatic => enclosingElement is CompilationUnitElement; | |
| 3551 | |
| 3552 /** | |
| 3553 * Set the visible range for this element to the range starting at the given o
ffset with the given | |
| 3554 * length. | |
| 3555 * | |
| 3556 * @param offset the offset to the beginning of the visible range for this ele
ment | |
| 3557 * @param length the length of the visible range for this element, or `-1` if
this element | |
| 3558 * does not have a visible range | |
| 3559 */ | |
| 3560 void setVisibleRange(int offset, int length) { | |
| 3561 _visibleRangeOffset = offset; | |
| 3562 _visibleRangeLength = length; | |
| 3563 } | |
| 3564 void appendTo(JavaStringBuilder builder) { | |
| 3565 String name = displayName; | |
| 3566 if (name != null) { | |
| 3567 builder.append(name); | |
| 3568 } | |
| 3569 super.appendTo(builder); | |
| 3570 } | |
| 3571 String get identifier => "${name}@${nameOffset}"; | |
| 3572 } | |
| 3573 /** | |
| 3574 * Instances of the class `FunctionTypeAliasElementImpl` implement a | |
| 3575 * `FunctionTypeAliasElement`. | |
| 3576 * | |
| 3577 * @coverage dart.engine.element | |
| 3578 */ | |
| 3579 class FunctionTypeAliasElementImpl extends ElementImpl implements FunctionTypeAl
iasElement { | |
| 3580 | |
| 3581 /** | |
| 3582 * An array containing all of the parameters defined by this type alias. | |
| 3583 */ | |
| 3584 List<ParameterElement> _parameters = ParameterElementImpl.EMPTY_ARRAY; | |
| 3585 | |
| 3586 /** | |
| 3587 * The return type defined by this type alias. | |
| 3588 */ | |
| 3589 Type2 _returnType; | |
| 3590 | |
| 3591 /** | |
| 3592 * The type of function defined by this type alias. | |
| 3593 */ | |
| 3594 FunctionType _type; | |
| 3595 | |
| 3596 /** | |
| 3597 * An array containing all of the type parameters defined for this type. | |
| 3598 */ | |
| 3599 List<TypeParameterElement> _typeParameters = TypeParameterElementImpl.EMPTY_AR
RAY; | |
| 3600 | |
| 3601 /** | |
| 3602 * An empty array of type alias elements. | |
| 3603 */ | |
| 3604 static List<FunctionTypeAliasElement> EMPTY_ARRAY = new List<FunctionTypeAlias
Element>(0); | |
| 3605 | |
| 3606 /** | |
| 3607 * Initialize a newly created type alias element to have the given name. | |
| 3608 * | |
| 3609 * @param name the name of this element | |
| 3610 */ | |
| 3611 FunctionTypeAliasElementImpl(Identifier name) : super.con1(name); | |
| 3612 accept(ElementVisitor visitor) => visitor.visitFunctionTypeAliasElement(this); | |
| 3613 ElementImpl getChild(String identifier) { | |
| 3614 for (VariableElement parameter in _parameters) { | |
| 3615 if (((parameter as VariableElementImpl)).identifier == identifier) { | |
| 3616 return parameter as VariableElementImpl; | |
| 3617 } | |
| 3618 } | |
| 3619 for (TypeParameterElement typeParameter in _typeParameters) { | |
| 3620 if (((typeParameter as TypeParameterElementImpl)).identifier == identifier
) { | |
| 3621 return typeParameter as TypeParameterElementImpl; | |
| 3622 } | |
| 3623 } | |
| 3624 return null; | |
| 3625 } | |
| 3626 CompilationUnitElement get enclosingElement => super.enclosingElement as Compi
lationUnitElement; | |
| 3627 ElementKind get kind => ElementKind.FUNCTION_TYPE_ALIAS; | |
| 3628 List<ParameterElement> get parameters => _parameters; | |
| 3629 Type2 get returnType => _returnType; | |
| 3630 FunctionType get type => _type; | |
| 3631 List<TypeParameterElement> get typeParameters => _typeParameters; | |
| 3632 | |
| 3633 /** | |
| 3634 * Set the parameters defined by this type alias to the given parameters. | |
| 3635 * | |
| 3636 * @param parameters the parameters defined by this type alias | |
| 3637 */ | |
| 3638 void set parameters(List<ParameterElement> parameters) { | |
| 3639 if (parameters != null) { | |
| 3640 for (ParameterElement parameter in parameters) { | |
| 3641 ((parameter as ParameterElementImpl)).enclosingElement = this; | |
| 3642 } | |
| 3643 } | |
| 3644 this._parameters = parameters; | |
| 3645 } | |
| 3646 | |
| 3647 /** | |
| 3648 * Set the return type defined by this type alias. | |
| 3649 * | |
| 3650 * @param returnType the return type defined by this type alias | |
| 3651 */ | |
| 3652 void set returnType(Type2 returnType) { | |
| 3653 this._returnType = returnType; | |
| 3654 } | |
| 3655 | |
| 3656 /** | |
| 3657 * Set the type of function defined by this type alias to the given type. | |
| 3658 * | |
| 3659 * @param type the type of function defined by this type alias | |
| 3660 */ | |
| 3661 void set type(FunctionType type) { | |
| 3662 this._type = type; | |
| 3663 } | |
| 3664 | |
| 3665 /** | |
| 3666 * Set the type parameters defined for this type to the given parameters. | |
| 3667 * | |
| 3668 * @param typeParameters the type parameters defined for this type | |
| 3669 */ | |
| 3670 void set typeParameters(List<TypeParameterElement> typeParameters) { | |
| 3671 for (TypeParameterElement typeParameter in typeParameters) { | |
| 3672 ((typeParameter as TypeParameterElementImpl)).enclosingElement = this; | |
| 3673 } | |
| 3674 this._typeParameters = typeParameters; | |
| 3675 } | |
| 3676 | |
| 3677 /** | |
| 3678 * Set the parameters defined by this type alias to the given parameters witho
ut becoming the | |
| 3679 * parent of the parameters. This should only be used by the [TypeResolverVisi
tor] when | |
| 3680 * creating a synthetic type alias. | |
| 3681 * | |
| 3682 * @param parameters the parameters defined by this type alias | |
| 3683 */ | |
| 3684 void shareParameters(List<ParameterElement> parameters) { | |
| 3685 this._parameters = parameters; | |
| 3686 } | |
| 3687 | |
| 3688 /** | |
| 3689 * Set the type parameters defined for this type to the given parameters witho
ut becoming the | |
| 3690 * parent of the parameters. This should only be used by the [TypeResolverVisi
tor] when | |
| 3691 * creating a synthetic type alias. | |
| 3692 * | |
| 3693 * @param typeParameters the type parameters defined for this type | |
| 3694 */ | |
| 3695 void shareTypeParameters(List<TypeParameterElement> typeParameters) { | |
| 3696 this._typeParameters = typeParameters; | |
| 3697 } | |
| 3698 void visitChildren(ElementVisitor visitor) { | |
| 3699 super.visitChildren(visitor); | |
| 3700 safelyVisitChildren(_parameters, visitor); | |
| 3701 safelyVisitChildren(_typeParameters, visitor); | |
| 3702 } | |
| 3703 void appendTo(JavaStringBuilder builder) { | |
| 3704 builder.append("typedef "); | |
| 3705 builder.append(displayName); | |
| 3706 int typeParameterCount = _typeParameters.length; | |
| 3707 if (typeParameterCount > 0) { | |
| 3708 builder.append("<"); | |
| 3709 for (int i = 0; i < typeParameterCount; i++) { | |
| 3710 if (i > 0) { | |
| 3711 builder.append(", "); | |
| 3712 } | |
| 3713 ((_typeParameters[i] as TypeParameterElementImpl)).appendTo(builder); | |
| 3714 } | |
| 3715 builder.append(">"); | |
| 3716 } | |
| 3717 builder.append("("); | |
| 3718 int parameterCount = _parameters.length; | |
| 3719 for (int i = 0; i < parameterCount; i++) { | |
| 3720 if (i > 0) { | |
| 3721 builder.append(", "); | |
| 3722 } | |
| 3723 ((_parameters[i] as ParameterElementImpl)).appendTo(builder); | |
| 3724 } | |
| 3725 builder.append(")"); | |
| 3726 if (_type != null) { | |
| 3727 builder.append(" -> "); | |
| 3728 builder.append(_type.returnType); | |
| 3729 } | |
| 3730 } | |
| 3731 } | |
| 3732 /** | |
| 3733 * Instances of the class `HideElementCombinatorImpl` implement a | |
| 3734 * [HideElementCombinator]. | |
| 3735 * | |
| 3736 * @coverage dart.engine.element | |
| 3737 */ | |
| 3738 class HideElementCombinatorImpl implements HideElementCombinator { | |
| 3739 | |
| 3740 /** | |
| 3741 * The names that are not to be made visible in the importing library even if
they are defined in | |
| 3742 * the imported library. | |
| 3743 */ | |
| 3744 List<String> _hiddenNames = StringUtilities.EMPTY_ARRAY; | |
| 3745 List<String> get hiddenNames => _hiddenNames; | |
| 3746 | |
| 3747 /** | |
| 3748 * Set the names that are not to be made visible in the importing library even
if they are defined | |
| 3749 * in the imported library to the given names. | |
| 3750 * | |
| 3751 * @param hiddenNames the names that are not to be made visible in the importi
ng library | |
| 3752 */ | |
| 3753 void set hiddenNames(List<String> hiddenNames) { | |
| 3754 this._hiddenNames = hiddenNames; | |
| 3755 } | |
| 3756 String toString() { | |
| 3757 JavaStringBuilder builder = new JavaStringBuilder(); | |
| 3758 builder.append("show "); | |
| 3759 int count = _hiddenNames.length; | |
| 3760 for (int i = 0; i < count; i++) { | |
| 3761 if (i > 0) { | |
| 3762 builder.append(", "); | |
| 3763 } | |
| 3764 builder.append(_hiddenNames[i]); | |
| 3765 } | |
| 3766 return builder.toString(); | |
| 3767 } | |
| 3768 } | |
| 3769 /** | |
| 3770 * Instances of the class `HtmlElementImpl` implement an [HtmlElement]. | |
| 3771 * | |
| 3772 * @coverage dart.engine.element | |
| 3773 */ | |
| 3774 class HtmlElementImpl extends ElementImpl implements HtmlElement { | |
| 3775 | |
| 3776 /** | |
| 3777 * An empty array of HTML file elements. | |
| 3778 */ | |
| 3779 static List<HtmlElement> EMPTY_ARRAY = new List<HtmlElement>(0); | |
| 3780 | |
| 3781 /** | |
| 3782 * The analysis context in which this library is defined. | |
| 3783 */ | |
| 3784 AnalysisContext _context; | |
| 3785 | |
| 3786 /** | |
| 3787 * The scripts contained in or referenced from script tags in the HTML file. | |
| 3788 */ | |
| 3789 List<HtmlScriptElement> _scripts = HtmlScriptElementImpl.EMPTY_ARRAY; | |
| 3790 | |
| 3791 /** | |
| 3792 * The source that corresponds to this HTML file. | |
| 3793 */ | |
| 3794 Source _source; | |
| 3795 | |
| 3796 /** | |
| 3797 * Initialize a newly created HTML element to have the given name. | |
| 3798 * | |
| 3799 * @param context the analysis context in which the HTML file is defined | |
| 3800 * @param name the name of this element | |
| 3801 */ | |
| 3802 HtmlElementImpl(AnalysisContext context, String name) : super.con2(name, -1) { | |
| 3803 this._context = context; | |
| 3804 } | |
| 3805 accept(ElementVisitor visitor) => visitor.visitHtmlElement(this); | |
| 3806 bool operator ==(Object object) => runtimeType == object.runtimeType && _sourc
e == ((object as CompilationUnitElementImpl)).source; | |
| 3807 AnalysisContext get context => _context; | |
| 3808 ElementKind get kind => ElementKind.HTML; | |
| 3809 List<HtmlScriptElement> get scripts => _scripts; | |
| 3810 Source get source => _source; | |
| 3811 int get hashCode => _source.hashCode; | |
| 3812 | |
| 3813 /** | |
| 3814 * Set the scripts contained in the HTML file to the given scripts. | |
| 3815 * | |
| 3816 * @param scripts the scripts | |
| 3817 */ | |
| 3818 void set scripts(List<HtmlScriptElement> scripts) { | |
| 3819 if (scripts.length == 0) { | |
| 3820 scripts = HtmlScriptElementImpl.EMPTY_ARRAY; | |
| 3821 } | |
| 3822 for (HtmlScriptElement script in scripts) { | |
| 3823 ((script as HtmlScriptElementImpl)).enclosingElement = this; | |
| 3824 } | |
| 3825 this._scripts = scripts; | |
| 3826 } | |
| 3827 | |
| 3828 /** | |
| 3829 * Set the source that corresponds to this HTML file to the given source. | |
| 3830 * | |
| 3831 * @param source the source that corresponds to this HTML file | |
| 3832 */ | |
| 3833 void set source(Source source) { | |
| 3834 this._source = source; | |
| 3835 } | |
| 3836 void visitChildren(ElementVisitor visitor) { | |
| 3837 super.visitChildren(visitor); | |
| 3838 safelyVisitChildren(_scripts, visitor); | |
| 3839 } | |
| 3840 void appendTo(JavaStringBuilder builder) { | |
| 3841 if (_source == null) { | |
| 3842 builder.append("{HTML file}"); | |
| 3843 } else { | |
| 3844 builder.append(_source.fullName); | |
| 3845 } | |
| 3846 } | |
| 3847 } | |
| 3848 /** | |
| 3849 * Instances of the class `HtmlScriptElementImpl` implement an [HtmlScriptElemen
t]. | |
| 3850 * | |
| 3851 * @coverage dart.engine.element | |
| 3852 */ | |
| 3853 abstract class HtmlScriptElementImpl extends ElementImpl implements HtmlScriptEl
ement { | |
| 3854 | |
| 3855 /** | |
| 3856 * An empty array of HTML script elements. | |
| 3857 */ | |
| 3858 static List<HtmlScriptElement> EMPTY_ARRAY = new List<HtmlScriptElement>(0); | |
| 3859 | |
| 3860 /** | |
| 3861 * Initialize a newly created script element to have the specified tag name an
d offset. | |
| 3862 * | |
| 3863 * @param node the XML node from which this element is derived (not `null`) | |
| 3864 */ | |
| 3865 HtmlScriptElementImpl(XmlTagNode node) : super.con2(node.tag.lexeme, node.tag.
offset); | |
| 3866 } | |
| 3867 /** | |
| 3868 * Instances of the class `ImportElementImpl` implement an [ImportElement]. | |
| 3869 * | |
| 3870 * @coverage dart.engine.element | |
| 3871 */ | |
| 3872 class ImportElementImpl extends ElementImpl implements ImportElement { | |
| 3873 | |
| 3874 /** | |
| 3875 * The offset of this directive, may be `-1` if synthetic. | |
| 3876 */ | |
| 3877 int _offset = -1; | |
| 3878 | |
| 3879 /** | |
| 3880 * The offset of the character immediately following the last character of thi
s node's URI, may be | |
| 3881 * `-1` if synthetic. | |
| 3882 */ | |
| 3883 int _uriEnd = -1; | |
| 3884 | |
| 3885 /** | |
| 3886 * The offset of the prefix of this import in the file that contains the this
import directive, or | |
| 3887 * `-1` if this import is synthetic. | |
| 3888 */ | |
| 3889 int _prefixOffset = 0; | |
| 3890 | |
| 3891 /** | |
| 3892 * The URI that is specified by this directive. | |
| 3893 */ | |
| 3894 String _uri; | |
| 3895 | |
| 3896 /** | |
| 3897 * The library that is imported into this library by this import directive. | |
| 3898 */ | |
| 3899 LibraryElement _importedLibrary; | |
| 3900 | |
| 3901 /** | |
| 3902 * The combinators that were specified as part of the import directive in the
order in which they | |
| 3903 * were specified. | |
| 3904 */ | |
| 3905 List<NamespaceCombinator> _combinators = NamespaceCombinator.EMPTY_ARRAY; | |
| 3906 | |
| 3907 /** | |
| 3908 * The prefix that was specified as part of the import directive, or `null` if
there was no | |
| 3909 * prefix specified. | |
| 3910 */ | |
| 3911 PrefixElement _prefix; | |
| 3912 | |
| 3913 /** | |
| 3914 * Initialize a newly created import element. | |
| 3915 */ | |
| 3916 ImportElementImpl() : super.con1(null); | |
| 3917 accept(ElementVisitor visitor) => visitor.visitImportElement(this); | |
| 3918 List<NamespaceCombinator> get combinators => _combinators; | |
| 3919 LibraryElement get importedLibrary => _importedLibrary; | |
| 3920 ElementKind get kind => ElementKind.IMPORT; | |
| 3921 PrefixElement get prefix => _prefix; | |
| 3922 int get prefixOffset => _prefixOffset; | |
| 3923 String get uri => _uri; | |
| 3924 int get uriEnd => _uriEnd; | |
| 3925 | |
| 3926 /** | |
| 3927 * Set the combinators that were specified as part of the import directive to
the given array of | |
| 3928 * combinators. | |
| 3929 * | |
| 3930 * @param combinators the combinators that were specified as part of the impor
t directive | |
| 3931 */ | |
| 3932 void set combinators(List<NamespaceCombinator> combinators) { | |
| 3933 this._combinators = combinators; | |
| 3934 } | |
| 3935 | |
| 3936 /** | |
| 3937 * Set the library that is imported into this library by this import directive
to the given | |
| 3938 * library. | |
| 3939 * | |
| 3940 * @param importedLibrary the library that is imported into this library | |
| 3941 */ | |
| 3942 void set importedLibrary(LibraryElement importedLibrary) { | |
| 3943 this._importedLibrary = importedLibrary; | |
| 3944 } | |
| 3945 | |
| 3946 /** | |
| 3947 * Set the offset of this directive. | |
| 3948 */ | |
| 3949 void set offset(int offset) { | |
| 3950 this._offset = offset; | |
| 3951 } | |
| 3952 | |
| 3953 /** | |
| 3954 * Set the prefix that was specified as part of the import directive to the gi
ven prefix. | |
| 3955 * | |
| 3956 * @param prefix the prefix that was specified as part of the import directive | |
| 3957 */ | |
| 3958 void set prefix(PrefixElement prefix) { | |
| 3959 this._prefix = prefix; | |
| 3960 } | |
| 3961 | |
| 3962 /** | |
| 3963 * Set the offset of the prefix of this import in the file that contains the t
his import | |
| 3964 * directive. | |
| 3965 */ | |
| 3966 void set prefixOffset(int prefixOffset) { | |
| 3967 this._prefixOffset = prefixOffset; | |
| 3968 } | |
| 3969 | |
| 3970 /** | |
| 3971 * Set the URI that is specified by this directive. | |
| 3972 * | |
| 3973 * @param uri the URI that is specified by this directive. | |
| 3974 */ | |
| 3975 void set uri(String uri) { | |
| 3976 this._uri = uri; | |
| 3977 } | |
| 3978 | |
| 3979 /** | |
| 3980 * Set the the offset of the character immediately following the last characte
r of this node's | |
| 3981 * URI. `-1` for synthetic import. | |
| 3982 */ | |
| 3983 void set uriEnd(int uriEnd) { | |
| 3984 this._uriEnd = uriEnd; | |
| 3985 } | |
| 3986 void visitChildren(ElementVisitor visitor) { | |
| 3987 super.visitChildren(visitor); | |
| 3988 safelyVisitChild(_prefix, visitor); | |
| 3989 } | |
| 3990 void appendTo(JavaStringBuilder builder) { | |
| 3991 builder.append("import "); | |
| 3992 ((_importedLibrary as LibraryElementImpl)).appendTo(builder); | |
| 3993 } | |
| 3994 String get identifier => "${((_importedLibrary as LibraryElementImpl)).identif
ier}@${_offset}"; | |
| 3995 } | |
| 3996 /** | |
| 3997 * Instances of the class `LabelElementImpl` implement a `LabelElement`. | |
| 3998 * | |
| 3999 * @coverage dart.engine.element | |
| 4000 */ | |
| 4001 class LabelElementImpl extends ElementImpl implements LabelElement { | |
| 4002 | |
| 4003 /** | |
| 4004 * A flag indicating whether this label is associated with a `switch` statemen
t. | |
| 4005 */ | |
| 4006 bool isOnSwitchStatement = false; | |
| 4007 | |
| 4008 /** | |
| 4009 * A flag indicating whether this label is associated with a `switch` member (
`case` | |
| 4010 * or `default`). | |
| 4011 */ | |
| 4012 bool isOnSwitchMember = false; | |
| 4013 | |
| 4014 /** | |
| 4015 * An empty array of label elements. | |
| 4016 */ | |
| 4017 static List<LabelElement> EMPTY_ARRAY = new List<LabelElement>(0); | |
| 4018 | |
| 4019 /** | |
| 4020 * Initialize a newly created label element to have the given name. | |
| 4021 * | |
| 4022 * @param name the name of this element | |
| 4023 * @param onSwitchStatement `true` if this label is associated with a `switch` | |
| 4024 * statement | |
| 4025 * @param onSwitchMember `true` if this label is associated with a `switch` me
mber | |
| 4026 */ | |
| 4027 LabelElementImpl(Identifier name, bool onSwitchStatement, bool onSwitchMember)
: super.con1(name) { | |
| 4028 this.isOnSwitchStatement = onSwitchStatement; | |
| 4029 this.isOnSwitchMember = onSwitchMember; | |
| 4030 } | |
| 4031 accept(ElementVisitor visitor) => visitor.visitLabelElement(this); | |
| 4032 ExecutableElement get enclosingElement => super.enclosingElement as Executable
Element; | |
| 4033 ElementKind get kind => ElementKind.LABEL; | |
| 4034 } | |
| 4035 /** | |
| 4036 * Instances of the class `LibraryElementImpl` implement a `LibraryElement`. | |
| 4037 * | |
| 4038 * @coverage dart.engine.element | |
| 4039 */ | |
| 4040 class LibraryElementImpl extends ElementImpl implements LibraryElement { | |
| 4041 | |
| 4042 /** | |
| 4043 * An empty array of library elements. | |
| 4044 */ | |
| 4045 static List<LibraryElement> EMPTY_ARRAY = new List<LibraryElement>(0); | |
| 4046 | |
| 4047 /** | |
| 4048 * Determine if the given library is up to date with respect to the given time
stamp. | |
| 4049 * | |
| 4050 * @param library the library to process | |
| 4051 * @param timeStamp the time stamp to check against | |
| 4052 * @param visitedLibraries the set of visited libraries | |
| 4053 */ | |
| 4054 static bool isUpToDate(LibraryElement library, int timeStamp, Set<LibraryEleme
nt> visitedLibraries) { | |
| 4055 if (!visitedLibraries.contains(library)) { | |
| 4056 javaSetAdd(visitedLibraries, library); | |
| 4057 if (timeStamp < library.definingCompilationUnit.source.modificationStamp)
{ | |
| 4058 return false; | |
| 4059 } | |
| 4060 for (CompilationUnitElement element in library.parts) { | |
| 4061 if (timeStamp < element.source.modificationStamp) { | |
| 4062 return false; | |
| 4063 } | |
| 4064 } | |
| 4065 for (LibraryElement importedLibrary in library.importedLibraries) { | |
| 4066 if (!isUpToDate(importedLibrary, timeStamp, visitedLibraries)) { | |
| 4067 return false; | |
| 4068 } | |
| 4069 } | |
| 4070 for (LibraryElement exportedLibrary in library.exportedLibraries) { | |
| 4071 if (!isUpToDate(exportedLibrary, timeStamp, visitedLibraries)) { | |
| 4072 return false; | |
| 4073 } | |
| 4074 } | |
| 4075 } | |
| 4076 return true; | |
| 4077 } | |
| 4078 | |
| 4079 /** | |
| 4080 * The analysis context in which this library is defined. | |
| 4081 */ | |
| 4082 AnalysisContext _context; | |
| 4083 | |
| 4084 /** | |
| 4085 * The compilation unit that defines this library. | |
| 4086 */ | |
| 4087 CompilationUnitElement _definingCompilationUnit; | |
| 4088 | |
| 4089 /** | |
| 4090 * The entry point for this library, or `null` if this library does not have a
n entry point. | |
| 4091 */ | |
| 4092 FunctionElement _entryPoint; | |
| 4093 | |
| 4094 /** | |
| 4095 * An array containing specifications of all of the imports defined in this li
brary. | |
| 4096 */ | |
| 4097 List<ImportElement> _imports = ImportElement.EMPTY_ARRAY; | |
| 4098 | |
| 4099 /** | |
| 4100 * An array containing specifications of all of the exports defined in this li
brary. | |
| 4101 */ | |
| 4102 List<ExportElement> _exports = ExportElement.EMPTY_ARRAY; | |
| 4103 | |
| 4104 /** | |
| 4105 * An array containing all of the compilation units that are included in this
library using a | |
| 4106 * `part` directive. | |
| 4107 */ | |
| 4108 List<CompilationUnitElement> _parts = CompilationUnitElementImpl.EMPTY_ARRAY; | |
| 4109 | |
| 4110 /** | |
| 4111 * Initialize a newly created library element to have the given name. | |
| 4112 * | |
| 4113 * @param context the analysis context in which the library is defined | |
| 4114 * @param name the name of this element | |
| 4115 */ | |
| 4116 LibraryElementImpl(AnalysisContext context, LibraryIdentifier name) : super.co
n1(name) { | |
| 4117 this._context = context; | |
| 4118 } | |
| 4119 accept(ElementVisitor visitor) => visitor.visitLibraryElement(this); | |
| 4120 bool operator ==(Object object) => object != null && runtimeType == object.run
timeType && _definingCompilationUnit == ((object as LibraryElementImpl)).definin
gCompilationUnit; | |
| 4121 ElementImpl getChild(String identifier) { | |
| 4122 if (((_definingCompilationUnit as CompilationUnitElementImpl)).identifier ==
identifier) { | |
| 4123 return _definingCompilationUnit as CompilationUnitElementImpl; | |
| 4124 } | |
| 4125 for (CompilationUnitElement part in _parts) { | |
| 4126 if (((part as CompilationUnitElementImpl)).identifier == identifier) { | |
| 4127 return part as CompilationUnitElementImpl; | |
| 4128 } | |
| 4129 } | |
| 4130 for (ImportElement importElement in _imports) { | |
| 4131 if (((importElement as ImportElementImpl)).identifier == identifier) { | |
| 4132 return importElement as ImportElementImpl; | |
| 4133 } | |
| 4134 } | |
| 4135 for (ExportElement exportElement in _exports) { | |
| 4136 if (((exportElement as ExportElementImpl)).identifier == identifier) { | |
| 4137 return exportElement as ExportElementImpl; | |
| 4138 } | |
| 4139 } | |
| 4140 return null; | |
| 4141 } | |
| 4142 AnalysisContext get context => _context; | |
| 4143 CompilationUnitElement get definingCompilationUnit => _definingCompilationUnit
; | |
| 4144 FunctionElement get entryPoint => _entryPoint; | |
| 4145 List<LibraryElement> get exportedLibraries { | |
| 4146 Set<LibraryElement> libraries = new Set<LibraryElement>(); | |
| 4147 for (ExportElement element in _exports) { | |
| 4148 LibraryElement library = element.exportedLibrary; | |
| 4149 if (library != null) { | |
| 4150 javaSetAdd(libraries, library); | |
| 4151 } | |
| 4152 } | |
| 4153 return new List.from(libraries); | |
| 4154 } | |
| 4155 List<ExportElement> get exports => _exports; | |
| 4156 List<LibraryElement> get importedLibraries { | |
| 4157 Set<LibraryElement> libraries = new Set<LibraryElement>(); | |
| 4158 for (ImportElement element in _imports) { | |
| 4159 LibraryElement library = element.importedLibrary; | |
| 4160 if (library != null) { | |
| 4161 javaSetAdd(libraries, library); | |
| 4162 } | |
| 4163 } | |
| 4164 return new List.from(libraries); | |
| 4165 } | |
| 4166 List<ImportElement> get imports => _imports; | |
| 4167 ElementKind get kind => ElementKind.LIBRARY; | |
| 4168 LibraryElement get library => this; | |
| 4169 List<CompilationUnitElement> get parts => _parts; | |
| 4170 List<PrefixElement> get prefixes { | |
| 4171 Set<PrefixElement> prefixes = new Set<PrefixElement>(); | |
| 4172 for (ImportElement element in _imports) { | |
| 4173 PrefixElement prefix = element.prefix; | |
| 4174 if (prefix != null) { | |
| 4175 javaSetAdd(prefixes, prefix); | |
| 4176 } | |
| 4177 } | |
| 4178 return new List.from(prefixes); | |
| 4179 } | |
| 4180 Source get source { | |
| 4181 if (_definingCompilationUnit == null) { | |
| 4182 return null; | |
| 4183 } | |
| 4184 return _definingCompilationUnit.source; | |
| 4185 } | |
| 4186 ClassElement getType(String className) { | |
| 4187 ClassElement type = _definingCompilationUnit.getType(className); | |
| 4188 if (type != null) { | |
| 4189 return type; | |
| 4190 } | |
| 4191 for (CompilationUnitElement part in _parts) { | |
| 4192 type = part.getType(className); | |
| 4193 if (type != null) { | |
| 4194 return type; | |
| 4195 } | |
| 4196 } | |
| 4197 return null; | |
| 4198 } | |
| 4199 int get hashCode => _definingCompilationUnit.hashCode; | |
| 4200 bool get isBrowserApplication => _entryPoint != null && isOrImportsBrowserLibr
ary; | |
| 4201 bool get isDartCore => name == "dart.core"; | |
| 4202 bool get isInSdk => name.startsWith("dart."); | |
| 4203 bool isUpToDate2(int timeStamp) { | |
| 4204 Set<LibraryElement> visitedLibraries = new Set(); | |
| 4205 return isUpToDate(this, timeStamp, visitedLibraries); | |
| 4206 } | |
| 4207 | |
| 4208 /** | |
| 4209 * Set the compilation unit that defines this library to the given compilation
unit. | |
| 4210 * | |
| 4211 * @param definingCompilationUnit the compilation unit that defines this libra
ry | |
| 4212 */ | |
| 4213 void set definingCompilationUnit(CompilationUnitElement definingCompilationUni
t) { | |
| 4214 ((definingCompilationUnit as CompilationUnitElementImpl)).enclosingElement =
this; | |
| 4215 this._definingCompilationUnit = definingCompilationUnit; | |
| 4216 } | |
| 4217 | |
| 4218 /** | |
| 4219 * Set the entry point for this library to the given function. | |
| 4220 * | |
| 4221 * @param entryPoint the entry point for this library | |
| 4222 */ | |
| 4223 void set entryPoint(FunctionElement entryPoint) { | |
| 4224 this._entryPoint = entryPoint; | |
| 4225 } | |
| 4226 | |
| 4227 /** | |
| 4228 * Set the specifications of all of the exports defined in this library to the
given array. | |
| 4229 * | |
| 4230 * @param exports the specifications of all of the exports defined in this lib
rary | |
| 4231 */ | |
| 4232 void set exports(List<ExportElement> exports) { | |
| 4233 for (ExportElement exportElement in exports) { | |
| 4234 ((exportElement as ExportElementImpl)).enclosingElement = this; | |
| 4235 } | |
| 4236 this._exports = exports; | |
| 4237 } | |
| 4238 | |
| 4239 /** | |
| 4240 * Set the specifications of all of the imports defined in this library to the
given array. | |
| 4241 * | |
| 4242 * @param imports the specifications of all of the imports defined in this lib
rary | |
| 4243 */ | |
| 4244 void set imports(List<ImportElement> imports) { | |
| 4245 for (ImportElement importElement in imports) { | |
| 4246 ((importElement as ImportElementImpl)).enclosingElement = this; | |
| 4247 PrefixElementImpl prefix = importElement.prefix as PrefixElementImpl; | |
| 4248 if (prefix != null) { | |
| 4249 prefix.enclosingElement = this; | |
| 4250 } | |
| 4251 } | |
| 4252 this._imports = imports; | |
| 4253 } | |
| 4254 | |
| 4255 /** | |
| 4256 * Set the compilation units that are included in this library using a `part`
directive. | |
| 4257 * | |
| 4258 * @param parts the compilation units that are included in this library using
a `part` | |
| 4259 * directive | |
| 4260 */ | |
| 4261 void set parts(List<CompilationUnitElement> parts) { | |
| 4262 for (CompilationUnitElement compilationUnit in parts) { | |
| 4263 ((compilationUnit as CompilationUnitElementImpl)).enclosingElement = this; | |
| 4264 } | |
| 4265 this._parts = parts; | |
| 4266 } | |
| 4267 void visitChildren(ElementVisitor visitor) { | |
| 4268 super.visitChildren(visitor); | |
| 4269 safelyVisitChild(_definingCompilationUnit, visitor); | |
| 4270 safelyVisitChildren(_exports, visitor); | |
| 4271 safelyVisitChildren(_imports, visitor); | |
| 4272 safelyVisitChildren(_parts, visitor); | |
| 4273 } | |
| 4274 String get identifier => _definingCompilationUnit.source.encoding; | |
| 4275 | |
| 4276 /** | |
| 4277 * Answer `true` if the receiver directly or indirectly imports the dart:html
libraries. | |
| 4278 * | |
| 4279 * @return `true` if the receiver directly or indirectly imports the dart:html
libraries | |
| 4280 */ | |
| 4281 bool get isOrImportsBrowserLibrary { | |
| 4282 List<LibraryElement> visited = new List<LibraryElement>(); | |
| 4283 Source htmlLibSource = _context.sourceFactory.forUri(DartSdk.DART_HTML); | |
| 4284 visited.add(this); | |
| 4285 for (int index = 0; index < visited.length; index++) { | |
| 4286 LibraryElement library = visited[index]; | |
| 4287 Source source = library.definingCompilationUnit.source; | |
| 4288 if (source == htmlLibSource) { | |
| 4289 return true; | |
| 4290 } | |
| 4291 for (LibraryElement importedLibrary in library.importedLibraries) { | |
| 4292 if (!visited.contains(importedLibrary)) { | |
| 4293 visited.add(importedLibrary); | |
| 4294 } | |
| 4295 } | |
| 4296 for (LibraryElement exportedLibrary in library.exportedLibraries) { | |
| 4297 if (!visited.contains(exportedLibrary)) { | |
| 4298 visited.add(exportedLibrary); | |
| 4299 } | |
| 4300 } | |
| 4301 } | |
| 4302 return false; | |
| 4303 } | |
| 4304 } | |
| 4305 /** | |
| 4306 * Instances of the class `LocalVariableElementImpl` implement a `LocalVariableE
lement`. | |
| 4307 * | |
| 4308 * @coverage dart.engine.element | |
| 4309 */ | |
| 4310 class LocalVariableElementImpl extends VariableElementImpl implements LocalVaria
bleElement { | |
| 4311 | |
| 4312 /** | |
| 4313 * Is `true` if this variable is potentially mutated somewhere in its scope. | |
| 4314 */ | |
| 4315 bool _isPotentiallyMutated2 = false; | |
| 4316 | |
| 4317 /** | |
| 4318 * The offset to the beginning of the visible range for this element. | |
| 4319 */ | |
| 4320 int _visibleRangeOffset = 0; | |
| 4321 | |
| 4322 /** | |
| 4323 * The length of the visible range for this element, or `-1` if this element d
oes not have a | |
| 4324 * visible range. | |
| 4325 */ | |
| 4326 int _visibleRangeLength = -1; | |
| 4327 | |
| 4328 /** | |
| 4329 * An empty array of field elements. | |
| 4330 */ | |
| 4331 static List<LocalVariableElement> EMPTY_ARRAY = new List<LocalVariableElement>
(0); | |
| 4332 | |
| 4333 /** | |
| 4334 * Initialize a newly created local variable element to have the given name. | |
| 4335 * | |
| 4336 * @param name the name of this element | |
| 4337 */ | |
| 4338 LocalVariableElementImpl(Identifier name) : super.con1(name); | |
| 4339 accept(ElementVisitor visitor) => visitor.visitLocalVariableElement(this); | |
| 4340 ElementKind get kind => ElementKind.LOCAL_VARIABLE; | |
| 4341 SourceRange get visibleRange { | |
| 4342 if (_visibleRangeLength < 0) { | |
| 4343 return null; | |
| 4344 } | |
| 4345 return new SourceRange(_visibleRangeOffset, _visibleRangeLength); | |
| 4346 } | |
| 4347 bool get isPotentiallyMutated => _isPotentiallyMutated2; | |
| 4348 | |
| 4349 /** | |
| 4350 * Specifies that this variable is potentially mutated somewhere in its scope. | |
| 4351 */ | |
| 4352 void markPotentiallyMutated() { | |
| 4353 _isPotentiallyMutated2 = true; | |
| 4354 } | |
| 4355 | |
| 4356 /** | |
| 4357 * Set the visible range for this element to the range starting at the given o
ffset with the given | |
| 4358 * length. | |
| 4359 * | |
| 4360 * @param offset the offset to the beginning of the visible range for this ele
ment | |
| 4361 * @param length the length of the visible range for this element, or `-1` if
this element | |
| 4362 * does not have a visible range | |
| 4363 */ | |
| 4364 void setVisibleRange(int offset, int length) { | |
| 4365 _visibleRangeOffset = offset; | |
| 4366 _visibleRangeLength = length; | |
| 4367 } | |
| 4368 void appendTo(JavaStringBuilder builder) { | |
| 4369 builder.append(type); | |
| 4370 builder.append(" "); | |
| 4371 builder.append(displayName); | |
| 4372 } | |
| 4373 String get identifier => "${super.identifier}@${nameOffset}"; | |
| 4374 } | |
| 4375 /** | |
| 4376 * Instances of the class `MethodElementImpl` implement a `MethodElement`. | |
| 4377 * | |
| 4378 * @coverage dart.engine.element | |
| 4379 */ | |
| 4380 class MethodElementImpl extends ExecutableElementImpl implements MethodElement { | |
| 4381 | |
| 4382 /** | |
| 4383 * An empty array of method elements. | |
| 4384 */ | |
| 4385 static List<MethodElement> EMPTY_ARRAY = new List<MethodElement>(0); | |
| 4386 | |
| 4387 /** | |
| 4388 * Initialize a newly created method element to have the given name. | |
| 4389 * | |
| 4390 * @param name the name of this element | |
| 4391 */ | |
| 4392 MethodElementImpl.con1(Identifier name) : super.con1(name); | |
| 4393 | |
| 4394 /** | |
| 4395 * Initialize a newly created method element to have the given name. | |
| 4396 * | |
| 4397 * @param name the name of this element | |
| 4398 * @param nameOffset the offset of the name of this element in the file that c
ontains the | |
| 4399 * declaration of this element | |
| 4400 */ | |
| 4401 MethodElementImpl.con2(String name, int nameOffset) : super.con2(name, nameOff
set); | |
| 4402 accept(ElementVisitor visitor) => visitor.visitMethodElement(this); | |
| 4403 ClassElement get enclosingElement => super.enclosingElement as ClassElement; | |
| 4404 ElementKind get kind => ElementKind.METHOD; | |
| 4405 String get name { | |
| 4406 String name = super.name; | |
| 4407 if (isOperator && name == "-") { | |
| 4408 if (parameters.length == 0) { | |
| 4409 return "unary-"; | |
| 4410 } | |
| 4411 } | |
| 4412 return super.name; | |
| 4413 } | |
| 4414 bool get isAbstract => hasModifier(Modifier.ABSTRACT); | |
| 4415 bool get isOperator { | |
| 4416 String name = displayName; | |
| 4417 if (name.isEmpty) { | |
| 4418 return false; | |
| 4419 } | |
| 4420 int first = name.codeUnitAt(0); | |
| 4421 return !((0x61 <= first && first <= 0x7A) || (0x41 <= first && first <= 0x5A
) || first == 0x5F || first == 0x24); | |
| 4422 } | |
| 4423 bool get isStatic => hasModifier(Modifier.STATIC); | |
| 4424 | |
| 4425 /** | |
| 4426 * Set whether this method is abstract to correspond to the given value. | |
| 4427 * | |
| 4428 * @param isAbstract `true` if the method is abstract | |
| 4429 */ | |
| 4430 void set abstract(bool isAbstract) { | |
| 4431 setModifier(Modifier.ABSTRACT, isAbstract); | |
| 4432 } | |
| 4433 | |
| 4434 /** | |
| 4435 * Set whether this method is static to correspond to the given value. | |
| 4436 * | |
| 4437 * @param isStatic `true` if the method is static | |
| 4438 */ | |
| 4439 void set static(bool isStatic) { | |
| 4440 setModifier(Modifier.STATIC, isStatic); | |
| 4441 } | |
| 4442 void appendTo(JavaStringBuilder builder) { | |
| 4443 builder.append(enclosingElement.displayName); | |
| 4444 builder.append("."); | |
| 4445 builder.append(displayName); | |
| 4446 super.appendTo(builder); | |
| 4447 } | |
| 4448 } | |
| 4449 /** | |
| 4450 * The enumeration `Modifier` defines constants for all of the modifiers defined
by the Dart | |
| 4451 * language and for a few additional flags that are useful. | |
| 4452 * | |
| 4453 * @coverage dart.engine.element | |
| 4454 */ | |
| 4455 class Modifier extends Enum<Modifier> { | |
| 4456 static final Modifier ABSTRACT = new Modifier('ABSTRACT', 0); | |
| 4457 static final Modifier CONST = new Modifier('CONST', 1); | |
| 4458 static final Modifier FACTORY = new Modifier('FACTORY', 2); | |
| 4459 static final Modifier FINAL = new Modifier('FINAL', 3); | |
| 4460 static final Modifier GETTER = new Modifier('GETTER', 4); | |
| 4461 static final Modifier MIXIN = new Modifier('MIXIN', 5); | |
| 4462 static final Modifier REFERENCES_SUPER = new Modifier('REFERENCES_SUPER', 6); | |
| 4463 static final Modifier SETTER = new Modifier('SETTER', 7); | |
| 4464 static final Modifier STATIC = new Modifier('STATIC', 8); | |
| 4465 static final Modifier SYNTHETIC = new Modifier('SYNTHETIC', 9); | |
| 4466 static final Modifier TYPEDEF = new Modifier('TYPEDEF', 10); | |
| 4467 static final List<Modifier> values = [ | |
| 4468 ABSTRACT, | |
| 4469 CONST, | |
| 4470 FACTORY, | |
| 4471 FINAL, | |
| 4472 GETTER, | |
| 4473 MIXIN, | |
| 4474 REFERENCES_SUPER, | |
| 4475 SETTER, | |
| 4476 STATIC, | |
| 4477 SYNTHETIC, | |
| 4478 TYPEDEF]; | |
| 4479 Modifier(String name, int ordinal) : super(name, ordinal); | |
| 4480 } | |
| 4481 /** | |
| 4482 * Instances of the class `MultiplyDefinedElementImpl` represent a collection of
elements that | |
| 4483 * have the same name within the same scope. | |
| 4484 * | |
| 4485 * @coverage dart.engine.element | |
| 4486 */ | |
| 4487 class MultiplyDefinedElementImpl implements MultiplyDefinedElement { | |
| 4488 | |
| 4489 /** | |
| 4490 * Return an element that represents the given conflicting elements. | |
| 4491 * | |
| 4492 * @param context the analysis context in which the multiply defined elements
are defined | |
| 4493 * @param firstElement the first element that conflicts | |
| 4494 * @param secondElement the second element that conflicts | |
| 4495 */ | |
| 4496 static Element fromElements(AnalysisContext context, Element firstElement, Ele
ment secondElement) { | |
| 4497 List<Element> conflictingElements = computeConflictingElements(firstElement,
secondElement); | |
| 4498 int length = conflictingElements.length; | |
| 4499 if (length == 0) { | |
| 4500 return null; | |
| 4501 } else if (length == 1) { | |
| 4502 return conflictingElements[0]; | |
| 4503 } | |
| 4504 return new MultiplyDefinedElementImpl(context, conflictingElements); | |
| 4505 } | |
| 4506 | |
| 4507 /** | |
| 4508 * Add the given element to the list of elements. If the element is a multiply
-defined element, | |
| 4509 * add all of the conflicting elements that it represents. | |
| 4510 * | |
| 4511 * @param elements the list to which the element(s) are to be added | |
| 4512 * @param element the element(s) to be added | |
| 4513 */ | |
| 4514 static void add(Set<Element> elements, Element element) { | |
| 4515 if (element is MultiplyDefinedElementImpl) { | |
| 4516 for (Element conflictingElement in ((element as MultiplyDefinedElementImpl
))._conflictingElements) { | |
| 4517 javaSetAdd(elements, conflictingElement); | |
| 4518 } | |
| 4519 } else { | |
| 4520 javaSetAdd(elements, element); | |
| 4521 } | |
| 4522 } | |
| 4523 | |
| 4524 /** | |
| 4525 * Use the given elements to construct an array of conflicting elements. If ei
ther of the given | |
| 4526 * elements are multiply-defined elements then the conflicting elements they r
epresent will be | |
| 4527 * included in the array. Otherwise, the element itself will be included. | |
| 4528 * | |
| 4529 * @param firstElement the first element to be included | |
| 4530 * @param secondElement the second element to be included | |
| 4531 * @return an array containing all of the conflicting elements | |
| 4532 */ | |
| 4533 static List<Element> computeConflictingElements(Element firstElement, Element
secondElement) { | |
| 4534 Set<Element> elements = new Set<Element>(); | |
| 4535 add(elements, firstElement); | |
| 4536 add(elements, secondElement); | |
| 4537 return new List.from(elements); | |
| 4538 } | |
| 4539 | |
| 4540 /** | |
| 4541 * The analysis context in which the multiply defined elements are defined. | |
| 4542 */ | |
| 4543 AnalysisContext _context; | |
| 4544 | |
| 4545 /** | |
| 4546 * The name of the conflicting elements. | |
| 4547 */ | |
| 4548 String _name; | |
| 4549 | |
| 4550 /** | |
| 4551 * A list containing all of the elements that conflict. | |
| 4552 */ | |
| 4553 List<Element> _conflictingElements; | |
| 4554 | |
| 4555 /** | |
| 4556 * Initialize a newly created element to represent a list of conflicting eleme
nts. | |
| 4557 * | |
| 4558 * @param context the analysis context in which the multiply defined elements
are defined | |
| 4559 * @param conflictingElements the elements that conflict | |
| 4560 */ | |
| 4561 MultiplyDefinedElementImpl(AnalysisContext context, List<Element> conflictingE
lements) { | |
| 4562 this._context = context; | |
| 4563 _name = conflictingElements[0].name; | |
| 4564 this._conflictingElements = conflictingElements; | |
| 4565 } | |
| 4566 accept(ElementVisitor visitor) => visitor.visitMultiplyDefinedElement(this); | |
| 4567 String computeDocumentationComment() => null; | |
| 4568 Element getAncestor(Type elementClass) => null; | |
| 4569 List<Element> get conflictingElements => _conflictingElements; | |
| 4570 AnalysisContext get context => _context; | |
| 4571 String get displayName => _name; | |
| 4572 Element get enclosingElement => null; | |
| 4573 ElementKind get kind => ElementKind.ERROR; | |
| 4574 LibraryElement get library => null; | |
| 4575 ElementLocation get location => null; | |
| 4576 List<ElementAnnotation> get metadata => ElementAnnotationImpl.EMPTY_ARRAY; | |
| 4577 String get name => _name; | |
| 4578 int get nameOffset => -1; | |
| 4579 Source get source => null; | |
| 4580 Type2 get type => DynamicTypeImpl.instance; | |
| 4581 bool isAccessibleIn(LibraryElement library) { | |
| 4582 for (Element element in _conflictingElements) { | |
| 4583 if (element.isAccessibleIn(library)) { | |
| 4584 return true; | |
| 4585 } | |
| 4586 } | |
| 4587 return false; | |
| 4588 } | |
| 4589 bool get isSynthetic => true; | |
| 4590 String toString() { | |
| 4591 JavaStringBuilder builder = new JavaStringBuilder(); | |
| 4592 builder.append("["); | |
| 4593 int count = _conflictingElements.length; | |
| 4594 for (int i = 0; i < count; i++) { | |
| 4595 if (i > 0) { | |
| 4596 builder.append(", "); | |
| 4597 } | |
| 4598 ((_conflictingElements[i] as ElementImpl)).appendTo(builder); | |
| 4599 } | |
| 4600 builder.append("]"); | |
| 4601 return builder.toString(); | |
| 4602 } | |
| 4603 void visitChildren(ElementVisitor visitor) { | |
| 4604 } | |
| 4605 } | |
| 4606 /** | |
| 4607 * Instances of the class `ParameterElementImpl` implement a `ParameterElement`. | |
| 4608 * | |
| 4609 * @coverage dart.engine.element | |
| 4610 */ | |
| 4611 class ParameterElementImpl extends VariableElementImpl implements ParameterEleme
nt { | |
| 4612 | |
| 4613 /** | |
| 4614 * Is `true` if this variable is potentially mutated somewhere in its scope. | |
| 4615 */ | |
| 4616 bool _isPotentiallyMutated3 = false; | |
| 4617 | |
| 4618 /** | |
| 4619 * An array containing all of the parameters defined by this parameter element
. There will only be | |
| 4620 * parameters if this parameter is a function typed parameter. | |
| 4621 */ | |
| 4622 List<ParameterElement> _parameters = ParameterElementImpl.EMPTY_ARRAY; | |
| 4623 | |
| 4624 /** | |
| 4625 * The kind of this parameter. | |
| 4626 */ | |
| 4627 ParameterKind _parameterKind; | |
| 4628 | |
| 4629 /** | |
| 4630 * The offset to the beginning of the default value range for this element. | |
| 4631 */ | |
| 4632 int _defaultValueRangeOffset = 0; | |
| 4633 | |
| 4634 /** | |
| 4635 * The length of the default value range for this element, or `-1` if this ele
ment does not | |
| 4636 * have a default value. | |
| 4637 */ | |
| 4638 int _defaultValueRangeLength = -1; | |
| 4639 | |
| 4640 /** | |
| 4641 * The offset to the beginning of the visible range for this element. | |
| 4642 */ | |
| 4643 int _visibleRangeOffset = 0; | |
| 4644 | |
| 4645 /** | |
| 4646 * The length of the visible range for this element, or `-1` if this element d
oes not have a | |
| 4647 * visible range. | |
| 4648 */ | |
| 4649 int _visibleRangeLength = -1; | |
| 4650 | |
| 4651 /** | |
| 4652 * An empty array of field elements. | |
| 4653 */ | |
| 4654 static List<ParameterElement> EMPTY_ARRAY = new List<ParameterElement>(0); | |
| 4655 | |
| 4656 /** | |
| 4657 * Initialize a newly created parameter element to have the given name. | |
| 4658 * | |
| 4659 * @param name the name of this element | |
| 4660 */ | |
| 4661 ParameterElementImpl.con1(Identifier name) : super.con1(name); | |
| 4662 | |
| 4663 /** | |
| 4664 * Initialize a newly created parameter element to have the given name. | |
| 4665 * | |
| 4666 * @param name the name of this element | |
| 4667 * @param nameOffset the offset of the name of this element in the file that c
ontains the | |
| 4668 * declaration of this element | |
| 4669 */ | |
| 4670 ParameterElementImpl.con2(String name, int nameOffset) : super.con2(name, name
Offset); | |
| 4671 accept(ElementVisitor visitor) => visitor.visitParameterElement(this); | |
| 4672 SourceRange get defaultValueRange { | |
| 4673 if (_defaultValueRangeLength < 0) { | |
| 4674 return null; | |
| 4675 } | |
| 4676 return new SourceRange(_defaultValueRangeOffset, _defaultValueRangeLength); | |
| 4677 } | |
| 4678 ElementKind get kind => ElementKind.PARAMETER; | |
| 4679 ParameterKind get parameterKind => _parameterKind; | |
| 4680 List<ParameterElement> get parameters => _parameters; | |
| 4681 SourceRange get visibleRange { | |
| 4682 if (_visibleRangeLength < 0) { | |
| 4683 return null; | |
| 4684 } | |
| 4685 return new SourceRange(_visibleRangeOffset, _visibleRangeLength); | |
| 4686 } | |
| 4687 bool get isInitializingFormal => false; | |
| 4688 bool get isPotentiallyMutated => _isPotentiallyMutated3; | |
| 4689 | |
| 4690 /** | |
| 4691 * Specifies that this variable is potentially mutated somewhere in its scope. | |
| 4692 */ | |
| 4693 void markPotentiallyMutated() { | |
| 4694 _isPotentiallyMutated3 = true; | |
| 4695 } | |
| 4696 | |
| 4697 /** | |
| 4698 * Set the range of the default value for this parameter to the range starting
at the given offset | |
| 4699 * with the given length. | |
| 4700 * | |
| 4701 * @param offset the offset to the beginning of the default value range for th
is element | |
| 4702 * @param length the length of the default value range for this element, or `-
1` if this | |
| 4703 * element does not have a default value | |
| 4704 */ | |
| 4705 void setDefaultValueRange(int offset, int length) { | |
| 4706 _defaultValueRangeOffset = offset; | |
| 4707 _defaultValueRangeLength = length; | |
| 4708 } | |
| 4709 | |
| 4710 /** | |
| 4711 * Set the kind of this parameter to the given kind. | |
| 4712 * | |
| 4713 * @param parameterKind the new kind of this parameter | |
| 4714 */ | |
| 4715 void set parameterKind(ParameterKind parameterKind) { | |
| 4716 this._parameterKind = parameterKind; | |
| 4717 } | |
| 4718 | |
| 4719 /** | |
| 4720 * Set the parameters defined by this executable element to the given paramete
rs. | |
| 4721 * | |
| 4722 * @param parameters the parameters defined by this executable element | |
| 4723 */ | |
| 4724 void set parameters(List<ParameterElement> parameters) { | |
| 4725 for (ParameterElement parameter in parameters) { | |
| 4726 ((parameter as ParameterElementImpl)).enclosingElement = this; | |
| 4727 } | |
| 4728 this._parameters = parameters; | |
| 4729 } | |
| 4730 | |
| 4731 /** | |
| 4732 * Set the visible range for this element to the range starting at the given o
ffset with the given | |
| 4733 * length. | |
| 4734 * | |
| 4735 * @param offset the offset to the beginning of the visible range for this ele
ment | |
| 4736 * @param length the length of the visible range for this element, or `-1` if
this element | |
| 4737 * does not have a visible range | |
| 4738 */ | |
| 4739 void setVisibleRange(int offset, int length) { | |
| 4740 _visibleRangeOffset = offset; | |
| 4741 _visibleRangeLength = length; | |
| 4742 } | |
| 4743 void visitChildren(ElementVisitor visitor) { | |
| 4744 super.visitChildren(visitor); | |
| 4745 safelyVisitChildren(_parameters, visitor); | |
| 4746 } | |
| 4747 void appendTo(JavaStringBuilder builder) { | |
| 4748 String left = ""; | |
| 4749 String right = ""; | |
| 4750 while (true) { | |
| 4751 if (parameterKind == ParameterKind.NAMED) { | |
| 4752 left = "{"; | |
| 4753 right = "}"; | |
| 4754 } else if (parameterKind == ParameterKind.POSITIONAL) { | |
| 4755 left = "["; | |
| 4756 right = "]"; | |
| 4757 } | |
| 4758 break; | |
| 4759 } | |
| 4760 builder.append(left); | |
| 4761 builder.append(type); | |
| 4762 builder.append(" "); | |
| 4763 builder.append(displayName); | |
| 4764 builder.append(right); | |
| 4765 } | |
| 4766 } | |
| 4767 /** | |
| 4768 * Instances of the class `PrefixElementImpl` implement a `PrefixElement`. | |
| 4769 * | |
| 4770 * @coverage dart.engine.element | |
| 4771 */ | |
| 4772 class PrefixElementImpl extends ElementImpl implements PrefixElement { | |
| 4773 | |
| 4774 /** | |
| 4775 * An array containing all of the libraries that are imported using this prefi
x. | |
| 4776 */ | |
| 4777 List<LibraryElement> _importedLibraries = LibraryElementImpl.EMPTY_ARRAY; | |
| 4778 | |
| 4779 /** | |
| 4780 * An empty array of prefix elements. | |
| 4781 */ | |
| 4782 static List<PrefixElement> EMPTY_ARRAY = new List<PrefixElement>(0); | |
| 4783 | |
| 4784 /** | |
| 4785 * Initialize a newly created prefix element to have the given name. | |
| 4786 * | |
| 4787 * @param name the name of this element | |
| 4788 */ | |
| 4789 PrefixElementImpl(Identifier name) : super.con1(name); | |
| 4790 accept(ElementVisitor visitor) => visitor.visitPrefixElement(this); | |
| 4791 LibraryElement get enclosingElement => super.enclosingElement as LibraryElemen
t; | |
| 4792 List<LibraryElement> get importedLibraries => _importedLibraries; | |
| 4793 ElementKind get kind => ElementKind.PREFIX; | |
| 4794 | |
| 4795 /** | |
| 4796 * Set the libraries that are imported using this prefix to the given librarie
s. | |
| 4797 * | |
| 4798 * @param importedLibraries the libraries that are imported using this prefix | |
| 4799 */ | |
| 4800 void set importedLibraries(List<LibraryElement> importedLibraries) { | |
| 4801 for (LibraryElement library in importedLibraries) { | |
| 4802 ((library as LibraryElementImpl)).enclosingElement = this; | |
| 4803 } | |
| 4804 this._importedLibraries = importedLibraries; | |
| 4805 } | |
| 4806 void appendTo(JavaStringBuilder builder) { | |
| 4807 builder.append("as "); | |
| 4808 super.appendTo(builder); | |
| 4809 } | |
| 4810 String get identifier => "_${super.identifier}"; | |
| 4811 } | |
| 4812 /** | |
| 4813 * Instances of the class `PropertyAccessorElementImpl` implement a | |
| 4814 * `PropertyAccessorElement`. | |
| 4815 * | |
| 4816 * @coverage dart.engine.element | |
| 4817 */ | |
| 4818 class PropertyAccessorElementImpl extends ExecutableElementImpl implements Prope
rtyAccessorElement { | |
| 4819 | |
| 4820 /** | |
| 4821 * The variable associated with this accessor. | |
| 4822 */ | |
| 4823 PropertyInducingElement _variable; | |
| 4824 | |
| 4825 /** | |
| 4826 * An empty array of property accessor elements. | |
| 4827 */ | |
| 4828 static List<PropertyAccessorElement> EMPTY_ARRAY = new List<PropertyAccessorEl
ement>(0); | |
| 4829 | |
| 4830 /** | |
| 4831 * Initialize a newly created property accessor element to have the given name
. | |
| 4832 * | |
| 4833 * @param name the name of this element | |
| 4834 */ | |
| 4835 PropertyAccessorElementImpl.con1(Identifier name) : super.con1(name); | |
| 4836 | |
| 4837 /** | |
| 4838 * Initialize a newly created synthetic property accessor element to be associ
ated with the given | |
| 4839 * variable. | |
| 4840 * | |
| 4841 * @param variable the variable with which this access is associated | |
| 4842 */ | |
| 4843 PropertyAccessorElementImpl.con2(PropertyInducingElementImpl variable) : super
.con2(variable.name, variable.nameOffset) { | |
| 4844 this._variable = variable; | |
| 4845 synthetic = true; | |
| 4846 } | |
| 4847 accept(ElementVisitor visitor) => visitor.visitPropertyAccessorElement(this); | |
| 4848 bool operator ==(Object object) => super == object && identical(isGetter, ((ob
ject as PropertyAccessorElement)).isGetter); | |
| 4849 PropertyAccessorElement get correspondingGetter { | |
| 4850 if (isGetter || _variable == null) { | |
| 4851 return null; | |
| 4852 } | |
| 4853 return _variable.getter; | |
| 4854 } | |
| 4855 PropertyAccessorElement get correspondingSetter { | |
| 4856 if (isSetter || _variable == null) { | |
| 4857 return null; | |
| 4858 } | |
| 4859 return _variable.setter; | |
| 4860 } | |
| 4861 ElementKind get kind { | |
| 4862 if (isGetter) { | |
| 4863 return ElementKind.GETTER; | |
| 4864 } | |
| 4865 return ElementKind.SETTER; | |
| 4866 } | |
| 4867 String get name { | |
| 4868 if (isSetter) { | |
| 4869 return "${super.name}="; | |
| 4870 } | |
| 4871 return super.name; | |
| 4872 } | |
| 4873 PropertyInducingElement get variable => _variable; | |
| 4874 bool get isAbstract => hasModifier(Modifier.ABSTRACT); | |
| 4875 bool get isGetter => hasModifier(Modifier.GETTER); | |
| 4876 bool get isSetter => hasModifier(Modifier.SETTER); | |
| 4877 bool get isStatic => hasModifier(Modifier.STATIC); | |
| 4878 | |
| 4879 /** | |
| 4880 * Set whether this accessor is abstract to correspond to the given value. | |
| 4881 * | |
| 4882 * @param isAbstract `true` if the accessor is abstract | |
| 4883 */ | |
| 4884 void set abstract(bool isAbstract) { | |
| 4885 setModifier(Modifier.ABSTRACT, isAbstract); | |
| 4886 } | |
| 4887 | |
| 4888 /** | |
| 4889 * Set whether this accessor is a getter to correspond to the given value. | |
| 4890 * | |
| 4891 * @param isGetter `true` if the accessor is a getter | |
| 4892 */ | |
| 4893 void set getter(bool isGetter) { | |
| 4894 setModifier(Modifier.GETTER, isGetter); | |
| 4895 } | |
| 4896 | |
| 4897 /** | |
| 4898 * Set whether this accessor is a setter to correspond to the given value. | |
| 4899 * | |
| 4900 * @param isSetter `true` if the accessor is a setter | |
| 4901 */ | |
| 4902 void set setter(bool isSetter) { | |
| 4903 setModifier(Modifier.SETTER, isSetter); | |
| 4904 } | |
| 4905 | |
| 4906 /** | |
| 4907 * Set whether this accessor is static to correspond to the given value. | |
| 4908 * | |
| 4909 * @param isStatic `true` if the accessor is static | |
| 4910 */ | |
| 4911 void set static(bool isStatic) { | |
| 4912 setModifier(Modifier.STATIC, isStatic); | |
| 4913 } | |
| 4914 | |
| 4915 /** | |
| 4916 * Set the variable associated with this accessor to the given variable. | |
| 4917 * | |
| 4918 * @param variable the variable associated with this accessor | |
| 4919 */ | |
| 4920 void set variable(PropertyInducingElement variable) { | |
| 4921 this._variable = variable; | |
| 4922 } | |
| 4923 void appendTo(JavaStringBuilder builder) { | |
| 4924 builder.append(isGetter ? "get " : "set "); | |
| 4925 builder.append(variable.displayName); | |
| 4926 super.appendTo(builder); | |
| 4927 } | |
| 4928 } | |
| 4929 /** | |
| 4930 * Instances of the class `PropertyInducingElementImpl` implement a | |
| 4931 * `PropertyInducingElement`. | |
| 4932 * | |
| 4933 * @coverage dart.engine.element | |
| 4934 */ | |
| 4935 abstract class PropertyInducingElementImpl extends VariableElementImpl implement
s PropertyInducingElement { | |
| 4936 | |
| 4937 /** | |
| 4938 * The getter associated with this element. | |
| 4939 */ | |
| 4940 PropertyAccessorElement _getter; | |
| 4941 | |
| 4942 /** | |
| 4943 * The setter associated with this element, or `null` if the element is effect
ively | |
| 4944 * `final` and therefore does not have a setter associated with it. | |
| 4945 */ | |
| 4946 PropertyAccessorElement _setter; | |
| 4947 | |
| 4948 /** | |
| 4949 * An empty array of elements. | |
| 4950 */ | |
| 4951 static List<PropertyInducingElement> EMPTY_ARRAY = new List<PropertyInducingEl
ement>(0); | |
| 4952 | |
| 4953 /** | |
| 4954 * Initialize a newly created element to have the given name. | |
| 4955 * | |
| 4956 * @param name the name of this element | |
| 4957 */ | |
| 4958 PropertyInducingElementImpl.con1(Identifier name) : super.con1(name); | |
| 4959 | |
| 4960 /** | |
| 4961 * Initialize a newly created synthetic element to have the given name. | |
| 4962 * | |
| 4963 * @param name the name of this element | |
| 4964 */ | |
| 4965 PropertyInducingElementImpl.con2(String name) : super.con2(name, -1) { | |
| 4966 synthetic = true; | |
| 4967 } | |
| 4968 PropertyAccessorElement get getter => _getter; | |
| 4969 PropertyAccessorElement get setter => _setter; | |
| 4970 | |
| 4971 /** | |
| 4972 * Set the getter associated with this element to the given accessor. | |
| 4973 * | |
| 4974 * @param getter the getter associated with this element | |
| 4975 */ | |
| 4976 void set getter(PropertyAccessorElement getter) { | |
| 4977 this._getter = getter; | |
| 4978 } | |
| 4979 | |
| 4980 /** | |
| 4981 * Set the setter associated with this element to the given accessor. | |
| 4982 * | |
| 4983 * @param setter the setter associated with this element | |
| 4984 */ | |
| 4985 void set setter(PropertyAccessorElement setter) { | |
| 4986 this._setter = setter; | |
| 4987 } | |
| 4988 } | |
| 4989 /** | |
| 4990 * Instances of the class `ShowElementCombinatorImpl` implement a | |
| 4991 * [ShowElementCombinator]. | |
| 4992 * | |
| 4993 * @coverage dart.engine.element | |
| 4994 */ | |
| 4995 class ShowElementCombinatorImpl implements ShowElementCombinator { | |
| 4996 | |
| 4997 /** | |
| 4998 * The names that are to be made visible in the importing library if they are
defined in the | |
| 4999 * imported library. | |
| 5000 */ | |
| 5001 List<String> _shownNames = StringUtilities.EMPTY_ARRAY; | |
| 5002 | |
| 5003 /** | |
| 5004 * The offset of the character immediately following the last character of thi
s node. | |
| 5005 */ | |
| 5006 int _end = -1; | |
| 5007 | |
| 5008 /** | |
| 5009 * The offset of the 'show' keyword of this element. | |
| 5010 */ | |
| 5011 int _offset = 0; | |
| 5012 int get end => _end; | |
| 5013 int get offset => _offset; | |
| 5014 List<String> get shownNames => _shownNames; | |
| 5015 | |
| 5016 /** | |
| 5017 * Set the the offset of the character immediately following the last characte
r of this node. | |
| 5018 */ | |
| 5019 void set end(int endOffset) { | |
| 5020 this._end = endOffset; | |
| 5021 } | |
| 5022 | |
| 5023 /** | |
| 5024 * Sets the offset of the 'show' keyword of this directive. | |
| 5025 */ | |
| 5026 void set offset(int offset) { | |
| 5027 this._offset = offset; | |
| 5028 } | |
| 5029 | |
| 5030 /** | |
| 5031 * Set the names that are to be made visible in the importing library if they
are defined in the | |
| 5032 * imported library to the given names. | |
| 5033 * | |
| 5034 * @param shownNames the names that are to be made visible in the importing li
brary | |
| 5035 */ | |
| 5036 void set shownNames(List<String> shownNames) { | |
| 5037 this._shownNames = shownNames; | |
| 5038 } | |
| 5039 String toString() { | |
| 5040 JavaStringBuilder builder = new JavaStringBuilder(); | |
| 5041 builder.append("show "); | |
| 5042 int count = _shownNames.length; | |
| 5043 for (int i = 0; i < count; i++) { | |
| 5044 if (i > 0) { | |
| 5045 builder.append(", "); | |
| 5046 } | |
| 5047 builder.append(_shownNames[i]); | |
| 5048 } | |
| 5049 return builder.toString(); | |
| 5050 } | |
| 5051 } | |
| 5052 /** | |
| 5053 * Instances of the class `TopLevelVariableElementImpl` implement a | |
| 5054 * `TopLevelVariableElement`. | |
| 5055 * | |
| 5056 * @coverage dart.engine.element | |
| 5057 */ | |
| 5058 class TopLevelVariableElementImpl extends PropertyInducingElementImpl implements
TopLevelVariableElement { | |
| 5059 | |
| 5060 /** | |
| 5061 * An empty array of top-level variable elements. | |
| 5062 */ | |
| 5063 static List<TopLevelVariableElement> EMPTY_ARRAY = new List<TopLevelVariableEl
ement>(0); | |
| 5064 | |
| 5065 /** | |
| 5066 * Initialize a newly created top-level variable element to have the given nam
e. | |
| 5067 * | |
| 5068 * @param name the name of this element | |
| 5069 */ | |
| 5070 TopLevelVariableElementImpl.con1(Identifier name) : super.con1(name); | |
| 5071 | |
| 5072 /** | |
| 5073 * Initialize a newly created synthetic top-level variable element to have the
given name. | |
| 5074 * | |
| 5075 * @param name the name of this element | |
| 5076 */ | |
| 5077 TopLevelVariableElementImpl.con2(String name) : super.con2(name); | |
| 5078 accept(ElementVisitor visitor) => visitor.visitTopLevelVariableElement(this); | |
| 5079 ElementKind get kind => ElementKind.TOP_LEVEL_VARIABLE; | |
| 5080 bool get isStatic => true; | |
| 5081 } | |
| 5082 /** | |
| 5083 * Instances of the class `TypeParameterElementImpl` implement a [TypeParameterE
lement]. | |
| 5084 * | |
| 5085 * @coverage dart.engine.element | |
| 5086 */ | |
| 5087 class TypeParameterElementImpl extends ElementImpl implements TypeParameterEleme
nt { | |
| 5088 | |
| 5089 /** | |
| 5090 * The type defined by this type parameter. | |
| 5091 */ | |
| 5092 TypeParameterType _type; | |
| 5093 | |
| 5094 /** | |
| 5095 * The type representing the bound associated with this parameter, or `null` i
f this | |
| 5096 * parameter does not have an explicit bound. | |
| 5097 */ | |
| 5098 Type2 _bound; | |
| 5099 | |
| 5100 /** | |
| 5101 * An empty array of type parameter elements. | |
| 5102 */ | |
| 5103 static List<TypeParameterElement> EMPTY_ARRAY = new List<TypeParameterElement>
(0); | |
| 5104 | |
| 5105 /** | |
| 5106 * Initialize a newly created type parameter element to have the given name. | |
| 5107 * | |
| 5108 * @param name the name of this element | |
| 5109 */ | |
| 5110 TypeParameterElementImpl(Identifier name) : super.con1(name); | |
| 5111 accept(ElementVisitor visitor) => visitor.visitTypeParameterElement(this); | |
| 5112 Type2 get bound => _bound; | |
| 5113 ElementKind get kind => ElementKind.TYPE_PARAMETER; | |
| 5114 TypeParameterType get type => _type; | |
| 5115 | |
| 5116 /** | |
| 5117 * Set the type representing the bound associated with this parameter to the g
iven type. | |
| 5118 * | |
| 5119 * @param bound the type representing the bound associated with this parameter | |
| 5120 */ | |
| 5121 void set bound(Type2 bound) { | |
| 5122 this._bound = bound; | |
| 5123 } | |
| 5124 | |
| 5125 /** | |
| 5126 * Set the type defined by this type parameter to the given type | |
| 5127 * | |
| 5128 * @param type the type defined by this type parameter | |
| 5129 */ | |
| 5130 void set type(TypeParameterType type) { | |
| 5131 this._type = type; | |
| 5132 } | |
| 5133 void appendTo(JavaStringBuilder builder) { | |
| 5134 builder.append(displayName); | |
| 5135 if (_bound != null) { | |
| 5136 builder.append(" extends "); | |
| 5137 builder.append(_bound); | |
| 5138 } | |
| 5139 } | |
| 5140 } | |
| 5141 /** | |
| 5142 * Instances of the class `VariableElementImpl` implement a `VariableElement`. | |
| 5143 * | |
| 5144 * @coverage dart.engine.element | |
| 5145 */ | |
| 5146 abstract class VariableElementImpl extends ElementImpl implements VariableElemen
t { | |
| 5147 | |
| 5148 /** | |
| 5149 * The declared type of this variable. | |
| 5150 */ | |
| 5151 Type2 _type; | |
| 5152 | |
| 5153 /** | |
| 5154 * A synthetic function representing this variable's initializer, or `null` if
this variable | |
| 5155 * does not have an initializer. | |
| 5156 */ | |
| 5157 FunctionElement _initializer; | |
| 5158 | |
| 5159 /** | |
| 5160 * An empty array of variable elements. | |
| 5161 */ | |
| 5162 static List<VariableElement> EMPTY_ARRAY = new List<VariableElement>(0); | |
| 5163 | |
| 5164 /** | |
| 5165 * Initialize a newly created variable element to have the given name. | |
| 5166 * | |
| 5167 * @param name the name of this element | |
| 5168 */ | |
| 5169 VariableElementImpl.con1(Identifier name) : super.con1(name); | |
| 5170 | |
| 5171 /** | |
| 5172 * Initialize a newly created variable element to have the given name. | |
| 5173 * | |
| 5174 * @param name the name of this element | |
| 5175 * @param nameOffset the offset of the name of this element in the file that c
ontains the | |
| 5176 * declaration of this element | |
| 5177 */ | |
| 5178 VariableElementImpl.con2(String name, int nameOffset) : super.con2(name, nameO
ffset); | |
| 5179 | |
| 5180 /** | |
| 5181 * Return the result of evaluating this variable's initializer as a compile-ti
me constant | |
| 5182 * expression, or `null` if this variable is not a 'const' variable or does no
t have an | |
| 5183 * initializer. | |
| 5184 * | |
| 5185 * @return the result of evaluating this variable's initializer | |
| 5186 */ | |
| 5187 EvaluationResultImpl get evaluationResult => null; | |
| 5188 FunctionElement get initializer => _initializer; | |
| 5189 Type2 get type => _type; | |
| 5190 bool get isConst => hasModifier(Modifier.CONST); | |
| 5191 bool get isFinal => hasModifier(Modifier.FINAL); | |
| 5192 | |
| 5193 /** | |
| 5194 * Return `true` if this variable is potentially mutated somewhere in its scop
e. This | |
| 5195 * information is only available for local variables (including parameters). | |
| 5196 * | |
| 5197 * @return `true` if this variable is potentially mutated somewhere in its sco
pe | |
| 5198 */ | |
| 5199 bool get isPotentiallyMutated => false; | |
| 5200 | |
| 5201 /** | |
| 5202 * Set whether this variable is const to correspond to the given value. | |
| 5203 * | |
| 5204 * @param isConst `true` if the variable is const | |
| 5205 */ | |
| 5206 void set const3(bool isConst) { | |
| 5207 setModifier(Modifier.CONST, isConst); | |
| 5208 } | |
| 5209 | |
| 5210 /** | |
| 5211 * Set the result of evaluating this variable's initializer as a compile-time
constant expression | |
| 5212 * to the given result. | |
| 5213 * | |
| 5214 * @param result the result of evaluating this variable's initializer | |
| 5215 */ | |
| 5216 void set evaluationResult(EvaluationResultImpl result) { | |
| 5217 throw new IllegalStateException("Invalid attempt to set a compile-time const
ant result"); | |
| 5218 } | |
| 5219 | |
| 5220 /** | |
| 5221 * Set whether this variable is final to correspond to the given value. | |
| 5222 * | |
| 5223 * @param isFinal `true` if the variable is final | |
| 5224 */ | |
| 5225 void set final2(bool isFinal) { | |
| 5226 setModifier(Modifier.FINAL, isFinal); | |
| 5227 } | |
| 5228 | |
| 5229 /** | |
| 5230 * Set the function representing this variable's initializer to the given func
tion. | |
| 5231 * | |
| 5232 * @param initializer the function representing this variable's initializer | |
| 5233 */ | |
| 5234 void set initializer(FunctionElement initializer) { | |
| 5235 if (initializer != null) { | |
| 5236 ((initializer as FunctionElementImpl)).enclosingElement = this; | |
| 5237 } | |
| 5238 this._initializer = initializer; | |
| 5239 } | |
| 5240 | |
| 5241 /** | |
| 5242 * Set the declared type of this variable to the given type. | |
| 5243 * | |
| 5244 * @param type the declared type of this variable | |
| 5245 */ | |
| 5246 void set type(Type2 type) { | |
| 5247 this._type = type; | |
| 5248 } | |
| 5249 void visitChildren(ElementVisitor visitor) { | |
| 5250 super.visitChildren(visitor); | |
| 5251 safelyVisitChild(_initializer, visitor); | |
| 5252 } | |
| 5253 void appendTo(JavaStringBuilder builder) { | |
| 5254 builder.append(type); | |
| 5255 builder.append(" "); | |
| 5256 builder.append(displayName); | |
| 5257 } | |
| 5258 } | |
| 5259 /** | |
| 5260 * Instances of the class `ConstructorMember` represent a constructor element de
fined in a | |
| 5261 * parameterized type where the values of the type parameters are known. | |
| 5262 */ | |
| 5263 class ConstructorMember extends ExecutableMember implements ConstructorElement { | |
| 5264 | |
| 5265 /** | |
| 5266 * If the given constructor's type is different when any type parameters from
the defining type's | |
| 5267 * declaration are replaced with the actual type arguments from the defining t
ype, create a | |
| 5268 * constructor member representing the given constructor. Return the member th
at was created, or | |
| 5269 * the base constructor if no member was created. | |
| 5270 * | |
| 5271 * @param baseConstructor the base constructor for which a member might be cre
ated | |
| 5272 * @param definingType the type defining the parameters and arguments to be us
ed in the | |
| 5273 * substitution | |
| 5274 * @return the constructor element that will return the correctly substituted
types | |
| 5275 */ | |
| 5276 static ConstructorElement from(ConstructorElement baseConstructor, InterfaceTy
pe definingType) { | |
| 5277 if (baseConstructor == null || definingType.typeArguments.length == 0) { | |
| 5278 return baseConstructor; | |
| 5279 } | |
| 5280 FunctionType baseType = baseConstructor.type; | |
| 5281 if (baseType == null) { | |
| 5282 return baseConstructor; | |
| 5283 } | |
| 5284 List<Type2> argumentTypes = definingType.typeArguments; | |
| 5285 List<Type2> parameterTypes = definingType.element.type.typeArguments; | |
| 5286 FunctionType substitutedType = baseType.substitute2(argumentTypes, parameter
Types); | |
| 5287 if (baseType == substitutedType) { | |
| 5288 return baseConstructor; | |
| 5289 } | |
| 5290 return new ConstructorMember(baseConstructor, definingType); | |
| 5291 } | |
| 5292 | |
| 5293 /** | |
| 5294 * Initialize a newly created element to represent a constructor of the given
parameterized type. | |
| 5295 * | |
| 5296 * @param baseElement the element on which the parameterized element was creat
ed | |
| 5297 * @param definingType the type in which the element is defined | |
| 5298 */ | |
| 5299 ConstructorMember(ConstructorElement baseElement, InterfaceType definingType)
: super(baseElement, definingType); | |
| 5300 accept(ElementVisitor visitor) => visitor.visitConstructorElement(this); | |
| 5301 ConstructorElement get baseElement => super.baseElement as ConstructorElement; | |
| 5302 ClassElement get enclosingElement => baseElement.enclosingElement; | |
| 5303 ConstructorElement get redirectedConstructor => from(baseElement.redirectedCon
structor, definingType); | |
| 5304 bool get isConst => baseElement.isConst; | |
| 5305 bool get isDefaultConstructor => baseElement.isDefaultConstructor; | |
| 5306 bool get isFactory => baseElement.isFactory; | |
| 5307 String toString() { | |
| 5308 ConstructorElement baseElement = this.baseElement; | |
| 5309 List<ParameterElement> parameters = this.parameters; | |
| 5310 FunctionType type = this.type; | |
| 5311 JavaStringBuilder builder = new JavaStringBuilder(); | |
| 5312 builder.append(baseElement.enclosingElement.displayName); | |
| 5313 String name = displayName; | |
| 5314 if (name != null && !name.isEmpty) { | |
| 5315 builder.append("."); | |
| 5316 builder.append(name); | |
| 5317 } | |
| 5318 builder.append("("); | |
| 5319 int parameterCount = parameters.length; | |
| 5320 for (int i = 0; i < parameterCount; i++) { | |
| 5321 if (i > 0) { | |
| 5322 builder.append(", "); | |
| 5323 } | |
| 5324 builder.append(parameters[i]).toString(); | |
| 5325 } | |
| 5326 builder.append(")"); | |
| 5327 if (type != null) { | |
| 5328 builder.append(" -> "); | |
| 5329 builder.append(type.returnType); | |
| 5330 } | |
| 5331 return builder.toString(); | |
| 5332 } | |
| 5333 InterfaceType get definingType => super.definingType as InterfaceType; | |
| 5334 } | |
| 5335 /** | |
| 5336 * The abstract class `ExecutableMember` defines the behavior common to members
that represent | |
| 5337 * an executable element defined in a parameterized type where the values of the
type parameters are | |
| 5338 * known. | |
| 5339 */ | |
| 5340 abstract class ExecutableMember extends Member implements ExecutableElement { | |
| 5341 | |
| 5342 /** | |
| 5343 * Initialize a newly created element to represent an executable element of th
e given | |
| 5344 * parameterized type. | |
| 5345 * | |
| 5346 * @param baseElement the element on which the parameterized element was creat
ed | |
| 5347 * @param definingType the type in which the element is defined | |
| 5348 */ | |
| 5349 ExecutableMember(ExecutableElement baseElement, InterfaceType definingType) :
super(baseElement, definingType); | |
| 5350 ExecutableElement get baseElement => super.baseElement as ExecutableElement; | |
| 5351 List<FunctionElement> get functions { | |
| 5352 throw new UnsupportedOperationException(); | |
| 5353 } | |
| 5354 List<LabelElement> get labels => baseElement.labels; | |
| 5355 List<LocalVariableElement> get localVariables { | |
| 5356 throw new UnsupportedOperationException(); | |
| 5357 } | |
| 5358 List<ParameterElement> get parameters { | |
| 5359 List<ParameterElement> baseParameters = baseElement.parameters; | |
| 5360 int parameterCount = baseParameters.length; | |
| 5361 if (parameterCount == 0) { | |
| 5362 return baseParameters; | |
| 5363 } | |
| 5364 List<ParameterElement> parameterizedParameters = new List<ParameterElement>(
parameterCount); | |
| 5365 for (int i = 0; i < parameterCount; i++) { | |
| 5366 parameterizedParameters[i] = ParameterMember.from(baseParameters[i], defin
ingType); | |
| 5367 } | |
| 5368 return parameterizedParameters; | |
| 5369 } | |
| 5370 Type2 get returnType => substituteFor(baseElement.returnType); | |
| 5371 FunctionType get type => substituteFor(baseElement.type); | |
| 5372 bool get isOperator => baseElement.isOperator; | |
| 5373 bool get isStatic => baseElement.isStatic; | |
| 5374 void visitChildren(ElementVisitor visitor) { | |
| 5375 super.visitChildren(visitor); | |
| 5376 safelyVisitChildren(baseElement.functions, visitor); | |
| 5377 safelyVisitChildren(labels, visitor); | |
| 5378 safelyVisitChildren(baseElement.localVariables, visitor); | |
| 5379 safelyVisitChildren(parameters, visitor); | |
| 5380 } | |
| 5381 } | |
| 5382 /** | |
| 5383 * Instances of the class `FieldMember` represent a field element defined in a p
arameterized | |
| 5384 * type where the values of the type parameters are known. | |
| 5385 */ | |
| 5386 class FieldMember extends VariableMember implements FieldElement { | |
| 5387 | |
| 5388 /** | |
| 5389 * If the given field's type is different when any type parameters from the de
fining type's | |
| 5390 * declaration are replaced with the actual type arguments from the defining t
ype, create a field | |
| 5391 * member representing the given field. Return the member that was created, or
the base field if | |
| 5392 * no member was created. | |
| 5393 * | |
| 5394 * @param baseField the base field for which a member might be created | |
| 5395 * @param definingType the type defining the parameters and arguments to be us
ed in the | |
| 5396 * substitution | |
| 5397 * @return the field element that will return the correctly substituted types | |
| 5398 */ | |
| 5399 static FieldElement from(FieldElement baseField, InterfaceType definingType) { | |
| 5400 if (baseField == null || definingType.typeArguments.length == 0) { | |
| 5401 return baseField; | |
| 5402 } | |
| 5403 Type2 baseType = baseField.type; | |
| 5404 if (baseType == null) { | |
| 5405 return baseField; | |
| 5406 } | |
| 5407 List<Type2> argumentTypes = definingType.typeArguments; | |
| 5408 List<Type2> parameterTypes = definingType.element.type.typeArguments; | |
| 5409 Type2 substitutedType = baseType.substitute2(argumentTypes, parameterTypes); | |
| 5410 if (baseType == substitutedType) { | |
| 5411 return baseField; | |
| 5412 } | |
| 5413 return new FieldMember(baseField, definingType); | |
| 5414 } | |
| 5415 | |
| 5416 /** | |
| 5417 * Initialize a newly created element to represent a field of the given parame
terized type. | |
| 5418 * | |
| 5419 * @param baseElement the element on which the parameterized element was creat
ed | |
| 5420 * @param definingType the type in which the element is defined | |
| 5421 */ | |
| 5422 FieldMember(FieldElement baseElement, InterfaceType definingType) : super(base
Element, definingType); | |
| 5423 accept(ElementVisitor visitor) => visitor.visitFieldElement(this); | |
| 5424 FieldElement get baseElement => super.baseElement as FieldElement; | |
| 5425 ClassElement get enclosingElement => baseElement.enclosingElement; | |
| 5426 PropertyAccessorElement get getter => PropertyAccessorMember.from(baseElement.
getter, definingType); | |
| 5427 PropertyAccessorElement get setter => PropertyAccessorMember.from(baseElement.
setter, definingType); | |
| 5428 bool get isStatic => baseElement.isStatic; | |
| 5429 InterfaceType get definingType => super.definingType as InterfaceType; | |
| 5430 } | |
| 5431 /** | |
| 5432 * The abstract class `Member` defines the behavior common to elements that repr
esent members | |
| 5433 * of parameterized types. | |
| 5434 */ | |
| 5435 abstract class Member implements Element { | |
| 5436 | |
| 5437 /** | |
| 5438 * The element on which the parameterized element was created. | |
| 5439 */ | |
| 5440 Element _baseElement; | |
| 5441 | |
| 5442 /** | |
| 5443 * The type in which the element is defined. | |
| 5444 */ | |
| 5445 ParameterizedType _definingType; | |
| 5446 | |
| 5447 /** | |
| 5448 * Initialize a newly created element to represent the member of the given par
ameterized type. | |
| 5449 * | |
| 5450 * @param baseElement the element on which the parameterized element was creat
ed | |
| 5451 * @param definingType the type in which the element is defined | |
| 5452 */ | |
| 5453 Member(Element baseElement, ParameterizedType definingType) { | |
| 5454 this._baseElement = baseElement; | |
| 5455 this._definingType = definingType; | |
| 5456 } | |
| 5457 String computeDocumentationComment() => _baseElement.computeDocumentationComme
nt(); | |
| 5458 Element getAncestor(Type elementClass) => baseElement.getAncestor(elementClass
); | |
| 5459 | |
| 5460 /** | |
| 5461 * Return the element on which the parameterized element was created. | |
| 5462 * | |
| 5463 * @return the element on which the parameterized element was created | |
| 5464 */ | |
| 5465 Element get baseElement => _baseElement; | |
| 5466 AnalysisContext get context => _baseElement.context; | |
| 5467 String get displayName => _baseElement.displayName; | |
| 5468 ElementKind get kind => _baseElement.kind; | |
| 5469 LibraryElement get library => _baseElement.library; | |
| 5470 ElementLocation get location => _baseElement.location; | |
| 5471 List<ElementAnnotation> get metadata => _baseElement.metadata; | |
| 5472 String get name => _baseElement.name; | |
| 5473 int get nameOffset => _baseElement.nameOffset; | |
| 5474 Source get source => _baseElement.source; | |
| 5475 bool isAccessibleIn(LibraryElement library) => _baseElement.isAccessibleIn(lib
rary); | |
| 5476 bool get isSynthetic => _baseElement.isSynthetic; | |
| 5477 void visitChildren(ElementVisitor visitor) { | |
| 5478 } | |
| 5479 | |
| 5480 /** | |
| 5481 * Return the type in which the element is defined. | |
| 5482 * | |
| 5483 * @return the type in which the element is defined | |
| 5484 */ | |
| 5485 ParameterizedType get definingType => _definingType; | |
| 5486 | |
| 5487 /** | |
| 5488 * If the given child is not `null`, use the given visitor to visit it. | |
| 5489 * | |
| 5490 * @param child the child to be visited | |
| 5491 * @param visitor the visitor to be used to visit the child | |
| 5492 */ | |
| 5493 void safelyVisitChild(Element child, ElementVisitor visitor) { | |
| 5494 if (child != null) { | |
| 5495 child.accept(visitor); | |
| 5496 } | |
| 5497 } | |
| 5498 | |
| 5499 /** | |
| 5500 * Use the given visitor to visit all of the children in the given array. | |
| 5501 * | |
| 5502 * @param children the children to be visited | |
| 5503 * @param visitor the visitor being used to visit the children | |
| 5504 */ | |
| 5505 void safelyVisitChildren(List<Element> children, ElementVisitor visitor) { | |
| 5506 if (children != null) { | |
| 5507 for (Element child in children) { | |
| 5508 child.accept(visitor); | |
| 5509 } | |
| 5510 } | |
| 5511 } | |
| 5512 | |
| 5513 /** | |
| 5514 * Return the type that results from replacing the type parameters in the give
n type with the type | |
| 5515 * arguments. | |
| 5516 * | |
| 5517 * @param type the type to be transformed | |
| 5518 * @return the result of transforming the type | |
| 5519 */ | |
| 5520 Type2 substituteFor(Type2 type) { | |
| 5521 List<Type2> argumentTypes = _definingType.typeArguments; | |
| 5522 List<Type2> parameterTypes = TypeParameterTypeImpl.getTypes(_definingType.ty
peParameters); | |
| 5523 return type.substitute2(argumentTypes, parameterTypes) as Type2; | |
| 5524 } | |
| 5525 | |
| 5526 /** | |
| 5527 * Return the array of types that results from replacing the type parameters i
n the given types | |
| 5528 * with the type arguments. | |
| 5529 * | |
| 5530 * @param types the types to be transformed | |
| 5531 * @return the result of transforming the types | |
| 5532 */ | |
| 5533 List<InterfaceType> substituteFor2(List<InterfaceType> types) { | |
| 5534 int count = types.length; | |
| 5535 List<InterfaceType> substitutedTypes = new List<InterfaceType>(count); | |
| 5536 for (int i = 0; i < count; i++) { | |
| 5537 substitutedTypes[i] = substituteFor(types[i]); | |
| 5538 } | |
| 5539 return substitutedTypes; | |
| 5540 } | |
| 5541 } | |
| 5542 /** | |
| 5543 * Instances of the class `MethodMember` represent a method element defined in a
parameterized | |
| 5544 * type where the values of the type parameters are known. | |
| 5545 */ | |
| 5546 class MethodMember extends ExecutableMember implements MethodElement { | |
| 5547 | |
| 5548 /** | |
| 5549 * If the given method's type is different when any type parameters from the d
efining type's | |
| 5550 * declaration are replaced with the actual type arguments from the defining t
ype, create a method | |
| 5551 * member representing the given method. Return the member that was created, o
r the base method if | |
| 5552 * no member was created. | |
| 5553 * | |
| 5554 * @param baseMethod the base method for which a member might be created | |
| 5555 * @param definingType the type defining the parameters and arguments to be us
ed in the | |
| 5556 * substitution | |
| 5557 * @return the method element that will return the correctly substituted types | |
| 5558 */ | |
| 5559 static MethodElement from(MethodElement baseMethod, InterfaceType definingType
) { | |
| 5560 if (baseMethod == null || definingType.typeArguments.length == 0) { | |
| 5561 return baseMethod; | |
| 5562 } | |
| 5563 FunctionType baseType = baseMethod.type; | |
| 5564 List<Type2> argumentTypes = definingType.typeArguments; | |
| 5565 List<Type2> parameterTypes = definingType.element.type.typeArguments; | |
| 5566 FunctionType substitutedType = baseType.substitute2(argumentTypes, parameter
Types); | |
| 5567 if (baseType == substitutedType) { | |
| 5568 return baseMethod; | |
| 5569 } | |
| 5570 return new MethodMember(baseMethod, definingType); | |
| 5571 } | |
| 5572 | |
| 5573 /** | |
| 5574 * Initialize a newly created element to represent a method of the given param
eterized type. | |
| 5575 * | |
| 5576 * @param baseElement the element on which the parameterized element was creat
ed | |
| 5577 * @param definingType the type in which the element is defined | |
| 5578 */ | |
| 5579 MethodMember(MethodElement baseElement, InterfaceType definingType) : super(ba
seElement, definingType); | |
| 5580 accept(ElementVisitor visitor) => visitor.visitMethodElement(this); | |
| 5581 MethodElement get baseElement => super.baseElement as MethodElement; | |
| 5582 ClassElement get enclosingElement => baseElement.enclosingElement; | |
| 5583 bool get isAbstract => baseElement.isAbstract; | |
| 5584 String toString() { | |
| 5585 MethodElement baseElement = this.baseElement; | |
| 5586 List<ParameterElement> parameters = this.parameters; | |
| 5587 FunctionType type = this.type; | |
| 5588 JavaStringBuilder builder = new JavaStringBuilder(); | |
| 5589 builder.append(baseElement.enclosingElement.displayName); | |
| 5590 builder.append("."); | |
| 5591 builder.append(baseElement.displayName); | |
| 5592 builder.append("("); | |
| 5593 int parameterCount = parameters.length; | |
| 5594 for (int i = 0; i < parameterCount; i++) { | |
| 5595 if (i > 0) { | |
| 5596 builder.append(", "); | |
| 5597 } | |
| 5598 builder.append(parameters[i]).toString(); | |
| 5599 } | |
| 5600 builder.append(")"); | |
| 5601 if (type != null) { | |
| 5602 builder.append(" -> "); | |
| 5603 builder.append(type.returnType); | |
| 5604 } | |
| 5605 return builder.toString(); | |
| 5606 } | |
| 5607 } | |
| 5608 /** | |
| 5609 * Instances of the class `ParameterMember` represent a parameter element define
d in a | |
| 5610 * parameterized type where the values of the type parameters are known. | |
| 5611 */ | |
| 5612 class ParameterMember extends VariableMember implements ParameterElement { | |
| 5613 | |
| 5614 /** | |
| 5615 * If the given parameter's type is different when any type parameters from th
e defining type's | |
| 5616 * declaration are replaced with the actual type arguments from the defining t
ype, create a | |
| 5617 * parameter member representing the given parameter. Return the member that w
as created, or the | |
| 5618 * base parameter if no member was created. | |
| 5619 * | |
| 5620 * @param baseParameter the base parameter for which a member might be created | |
| 5621 * @param definingType the type defining the parameters and arguments to be us
ed in the | |
| 5622 * substitution | |
| 5623 * @return the parameter element that will return the correctly substituted ty
pes | |
| 5624 */ | |
| 5625 static ParameterElement from(ParameterElement baseParameter, ParameterizedType
definingType) { | |
| 5626 if (baseParameter == null || definingType.typeArguments.length == 0) { | |
| 5627 return baseParameter; | |
| 5628 } | |
| 5629 if (baseParameter is! FieldFormalParameterElement) { | |
| 5630 Type2 baseType = baseParameter.type; | |
| 5631 List<Type2> argumentTypes = definingType.typeArguments; | |
| 5632 List<Type2> parameterTypes = TypeParameterTypeImpl.getTypes(definingType.t
ypeParameters); | |
| 5633 Type2 substitutedType = baseType.substitute2(argumentTypes, parameterTypes
); | |
| 5634 if (baseType == substitutedType) { | |
| 5635 return baseParameter; | |
| 5636 } | |
| 5637 } | |
| 5638 return new ParameterMember(baseParameter, definingType); | |
| 5639 } | |
| 5640 | |
| 5641 /** | |
| 5642 * Initialize a newly created element to represent a parameter of the given pa
rameterized type. | |
| 5643 * | |
| 5644 * @param baseElement the element on which the parameterized element was creat
ed | |
| 5645 * @param definingType the type in which the element is defined | |
| 5646 */ | |
| 5647 ParameterMember(ParameterElement baseElement, ParameterizedType definingType)
: super(baseElement, definingType); | |
| 5648 accept(ElementVisitor visitor) => visitor.visitParameterElement(this); | |
| 5649 Element getAncestor(Type elementClass) { | |
| 5650 Element element = baseElement.getAncestor(elementClass); | |
| 5651 ParameterizedType definingType = this.definingType; | |
| 5652 if (definingType is InterfaceType) { | |
| 5653 InterfaceType definingInterfaceType = definingType as InterfaceType; | |
| 5654 if (element is ConstructorElement) { | |
| 5655 return ConstructorMember.from(element as ConstructorElement, definingInt
erfaceType) as Element; | |
| 5656 } else if (element is MethodElement) { | |
| 5657 return MethodMember.from(element as MethodElement, definingInterfaceType
) as Element; | |
| 5658 } else if (element is PropertyAccessorElement) { | |
| 5659 return PropertyAccessorMember.from(element as PropertyAccessorElement, d
efiningInterfaceType) as Element; | |
| 5660 } | |
| 5661 } | |
| 5662 return element; | |
| 5663 } | |
| 5664 ParameterElement get baseElement => super.baseElement as ParameterElement; | |
| 5665 SourceRange get defaultValueRange => baseElement.defaultValueRange; | |
| 5666 Element get enclosingElement => baseElement.enclosingElement; | |
| 5667 ParameterKind get parameterKind => baseElement.parameterKind; | |
| 5668 List<ParameterElement> get parameters { | |
| 5669 List<ParameterElement> baseParameters = baseElement.parameters; | |
| 5670 int parameterCount = baseParameters.length; | |
| 5671 if (parameterCount == 0) { | |
| 5672 return baseParameters; | |
| 5673 } | |
| 5674 List<ParameterElement> parameterizedParameters = new List<ParameterElement>(
parameterCount); | |
| 5675 for (int i = 0; i < parameterCount; i++) { | |
| 5676 parameterizedParameters[i] = ParameterMember.from(baseParameters[i], defin
ingType); | |
| 5677 } | |
| 5678 return parameterizedParameters; | |
| 5679 } | |
| 5680 SourceRange get visibleRange => baseElement.visibleRange; | |
| 5681 bool get isInitializingFormal => baseElement.isInitializingFormal; | |
| 5682 String toString() { | |
| 5683 ParameterElement baseElement = this.baseElement; | |
| 5684 String left = ""; | |
| 5685 String right = ""; | |
| 5686 while (true) { | |
| 5687 if (baseElement.parameterKind == ParameterKind.NAMED) { | |
| 5688 left = "{"; | |
| 5689 right = "}"; | |
| 5690 } else if (baseElement.parameterKind == ParameterKind.POSITIONAL) { | |
| 5691 left = "["; | |
| 5692 right = "]"; | |
| 5693 } | |
| 5694 break; | |
| 5695 } | |
| 5696 JavaStringBuilder builder = new JavaStringBuilder(); | |
| 5697 builder.append(left); | |
| 5698 builder.append(type); | |
| 5699 builder.append(" "); | |
| 5700 builder.append(baseElement.displayName); | |
| 5701 builder.append(right); | |
| 5702 return builder.toString(); | |
| 5703 } | |
| 5704 void visitChildren(ElementVisitor visitor) { | |
| 5705 super.visitChildren(visitor); | |
| 5706 safelyVisitChildren(parameters, visitor); | |
| 5707 } | |
| 5708 } | |
| 5709 /** | |
| 5710 * Instances of the class `PropertyAccessorMember` represent a property accessor
element | |
| 5711 * defined in a parameterized type where the values of the type parameters are k
nown. | |
| 5712 */ | |
| 5713 class PropertyAccessorMember extends ExecutableMember implements PropertyAccesso
rElement { | |
| 5714 | |
| 5715 /** | |
| 5716 * If the given property accessor's type is different when any type parameters
from the defining | |
| 5717 * type's declaration are replaced with the actual type arguments from the def
ining type, create a | |
| 5718 * property accessor member representing the given property accessor. Return t
he member that was | |
| 5719 * created, or the base accessor if no member was created. | |
| 5720 * | |
| 5721 * @param baseAccessor the base property accessor for which a member might be
created | |
| 5722 * @param definingType the type defining the parameters and arguments to be us
ed in the | |
| 5723 * substitution | |
| 5724 * @return the property accessor element that will return the correctly substi
tuted types | |
| 5725 */ | |
| 5726 static PropertyAccessorElement from(PropertyAccessorElement baseAccessor, Inte
rfaceType definingType) { | |
| 5727 if (baseAccessor == null || definingType.typeArguments.length == 0) { | |
| 5728 return baseAccessor; | |
| 5729 } | |
| 5730 FunctionType baseType = baseAccessor.type; | |
| 5731 List<Type2> argumentTypes = definingType.typeArguments; | |
| 5732 List<Type2> parameterTypes = definingType.element.type.typeArguments; | |
| 5733 FunctionType substitutedType = baseType.substitute2(argumentTypes, parameter
Types); | |
| 5734 if (baseType == substitutedType) { | |
| 5735 return baseAccessor; | |
| 5736 } | |
| 5737 return new PropertyAccessorMember(baseAccessor, definingType); | |
| 5738 } | |
| 5739 | |
| 5740 /** | |
| 5741 * Initialize a newly created element to represent a property accessor of the
given parameterized | |
| 5742 * type. | |
| 5743 * | |
| 5744 * @param baseElement the element on which the parameterized element was creat
ed | |
| 5745 * @param definingType the type in which the element is defined | |
| 5746 */ | |
| 5747 PropertyAccessorMember(PropertyAccessorElement baseElement, InterfaceType defi
ningType) : super(baseElement, definingType); | |
| 5748 accept(ElementVisitor visitor) => visitor.visitPropertyAccessorElement(this); | |
| 5749 PropertyAccessorElement get baseElement => super.baseElement as PropertyAccess
orElement; | |
| 5750 PropertyAccessorElement get correspondingGetter => from(baseElement.correspond
ingGetter, definingType); | |
| 5751 PropertyAccessorElement get correspondingSetter => from(baseElement.correspond
ingSetter, definingType); | |
| 5752 Element get enclosingElement => baseElement.enclosingElement; | |
| 5753 PropertyInducingElement get variable { | |
| 5754 PropertyInducingElement variable = baseElement.variable; | |
| 5755 if (variable is FieldElement) { | |
| 5756 return FieldMember.from(variable as FieldElement, definingType); | |
| 5757 } | |
| 5758 return variable; | |
| 5759 } | |
| 5760 bool get isAbstract => baseElement.isAbstract; | |
| 5761 bool get isGetter => baseElement.isGetter; | |
| 5762 bool get isSetter => baseElement.isSetter; | |
| 5763 String toString() { | |
| 5764 PropertyAccessorElement baseElement = this.baseElement; | |
| 5765 List<ParameterElement> parameters = this.parameters; | |
| 5766 FunctionType type = this.type; | |
| 5767 JavaStringBuilder builder = new JavaStringBuilder(); | |
| 5768 if (isGetter) { | |
| 5769 builder.append("get "); | |
| 5770 } else { | |
| 5771 builder.append("set "); | |
| 5772 } | |
| 5773 builder.append(baseElement.enclosingElement.displayName); | |
| 5774 builder.append("."); | |
| 5775 builder.append(baseElement.displayName); | |
| 5776 builder.append("("); | |
| 5777 int parameterCount = parameters.length; | |
| 5778 for (int i = 0; i < parameterCount; i++) { | |
| 5779 if (i > 0) { | |
| 5780 builder.append(", "); | |
| 5781 } | |
| 5782 builder.append(parameters[i]).toString(); | |
| 5783 } | |
| 5784 builder.append(")"); | |
| 5785 if (type != null) { | |
| 5786 builder.append(" -> "); | |
| 5787 builder.append(type.returnType); | |
| 5788 } | |
| 5789 return builder.toString(); | |
| 5790 } | |
| 5791 InterfaceType get definingType => super.definingType as InterfaceType; | |
| 5792 } | |
| 5793 /** | |
| 5794 * The abstract class `VariableMember` defines the behavior common to members th
at represent a | |
| 5795 * variable element defined in a parameterized type where the values of the type
parameters are | |
| 5796 * known. | |
| 5797 */ | |
| 5798 abstract class VariableMember extends Member implements VariableElement { | |
| 5799 | |
| 5800 /** | |
| 5801 * Initialize a newly created element to represent an executable element of th
e given | |
| 5802 * parameterized type. | |
| 5803 * | |
| 5804 * @param baseElement the element on which the parameterized element was creat
ed | |
| 5805 * @param definingType the type in which the element is defined | |
| 5806 */ | |
| 5807 VariableMember(VariableElement baseElement, ParameterizedType definingType) :
super(baseElement, definingType); | |
| 5808 VariableElement get baseElement => super.baseElement as VariableElement; | |
| 5809 FunctionElement get initializer { | |
| 5810 throw new UnsupportedOperationException(); | |
| 5811 } | |
| 5812 Type2 get type => substituteFor(baseElement.type); | |
| 5813 bool get isConst => baseElement.isConst; | |
| 5814 bool get isFinal => baseElement.isFinal; | |
| 5815 void visitChildren(ElementVisitor visitor) { | |
| 5816 super.visitChildren(visitor); | |
| 5817 safelyVisitChild(baseElement.initializer, visitor); | |
| 5818 } | |
| 5819 } | |
| 5820 /** | |
| 5821 * The unique instance of the class `BottomTypeImpl` implements the type `bottom
`. | |
| 5822 * | |
| 5823 * @coverage dart.engine.type | |
| 5824 */ | |
| 5825 class BottomTypeImpl extends TypeImpl { | |
| 5826 | |
| 5827 /** | |
| 5828 * The unique instance of this class. | |
| 5829 */ | |
| 5830 static final BottomTypeImpl instance = new BottomTypeImpl(); | |
| 5831 | |
| 5832 /** | |
| 5833 * Prevent the creation of instances of this class. | |
| 5834 */ | |
| 5835 BottomTypeImpl() : super(null, "<bottom>"); | |
| 5836 bool operator ==(Object object) => identical(object, this); | |
| 5837 bool get isBottom => true; | |
| 5838 bool isMoreSpecificThan(Type2 type) => true; | |
| 5839 bool isSubtypeOf(Type2 type) => true; | |
| 5840 bool isSupertypeOf(Type2 type) => false; | |
| 5841 BottomTypeImpl substitute2(List<Type2> argumentTypes, List<Type2> parameterTyp
es) => this; | |
| 5842 } | |
| 5843 /** | |
| 5844 * The unique instance of the class `DynamicTypeImpl` implements the type `dynam
ic`. | |
| 5845 * | |
| 5846 * @coverage dart.engine.type | |
| 5847 */ | |
| 5848 class DynamicTypeImpl extends TypeImpl { | |
| 5849 | |
| 5850 /** | |
| 5851 * The unique instance of this class. | |
| 5852 */ | |
| 5853 static final DynamicTypeImpl instance = new DynamicTypeImpl(); | |
| 5854 | |
| 5855 /** | |
| 5856 * Prevent the creation of instances of this class. | |
| 5857 */ | |
| 5858 DynamicTypeImpl() : super(new DynamicElementImpl(), Keyword.DYNAMIC.syntax) { | |
| 5859 ((element as DynamicElementImpl)).type = this; | |
| 5860 } | |
| 5861 bool operator ==(Object object) => object is DynamicTypeImpl; | |
| 5862 bool get isDynamic => true; | |
| 5863 bool isMoreSpecificThan(Type2 type) { | |
| 5864 if (identical(this, type)) { | |
| 5865 return true; | |
| 5866 } | |
| 5867 return false; | |
| 5868 } | |
| 5869 bool isSubtypeOf(Type2 type) => true; | |
| 5870 bool isSupertypeOf(Type2 type) => true; | |
| 5871 Type2 substitute2(List<Type2> argumentTypes, List<Type2> parameterTypes) { | |
| 5872 int length = parameterTypes.length; | |
| 5873 for (int i = 0; i < length; i++) { | |
| 5874 if (parameterTypes[i] == this) { | |
| 5875 return argumentTypes[i]; | |
| 5876 } | |
| 5877 } | |
| 5878 return this; | |
| 5879 } | |
| 5880 } | |
| 5881 /** | |
| 5882 * Instances of the class `FunctionTypeImpl` defines the behavior common to obje
cts | |
| 5883 * representing the type of a function, method, constructor, getter, or setter. | |
| 5884 * | |
| 5885 * @coverage dart.engine.type | |
| 5886 */ | |
| 5887 class FunctionTypeImpl extends TypeImpl implements FunctionType { | |
| 5888 | |
| 5889 /** | |
| 5890 * Return `true` if all of the name/type pairs in the first map are equal to t
he | |
| 5891 * corresponding name/type pairs in the second map. The maps are expected to i
terate over their | |
| 5892 * entries in the same order in which those entries were added to the map. | |
| 5893 * | |
| 5894 * @param firstTypes the first map of name/type pairs being compared | |
| 5895 * @param secondTypes the second map of name/type pairs being compared | |
| 5896 * @return `true` if all of the name/type pairs in the first map are equal to
the | |
| 5897 * corresponding name/type pairs in the second map | |
| 5898 */ | |
| 5899 static bool equals2(Map<String, Type2> firstTypes, Map<String, Type2> secondTy
pes) { | |
| 5900 if (secondTypes.length != firstTypes.length) { | |
| 5901 return false; | |
| 5902 } | |
| 5903 JavaIterator<MapEntry<String, Type2>> firstIterator = new JavaIterator(getMa
pEntrySet(firstTypes)); | |
| 5904 JavaIterator<MapEntry<String, Type2>> secondIterator = new JavaIterator(getM
apEntrySet(secondTypes)); | |
| 5905 while (firstIterator.hasNext) { | |
| 5906 MapEntry<String, Type2> firstEntry = firstIterator.next(); | |
| 5907 MapEntry<String, Type2> secondEntry = secondIterator.next(); | |
| 5908 if (firstEntry.getKey() != secondEntry.getKey() || firstEntry.getValue() !
= secondEntry.getValue()) { | |
| 5909 return false; | |
| 5910 } | |
| 5911 } | |
| 5912 return true; | |
| 5913 } | |
| 5914 | |
| 5915 /** | |
| 5916 * An array containing the actual types of the type arguments. | |
| 5917 */ | |
| 5918 List<Type2> _typeArguments = TypeImpl.EMPTY_ARRAY; | |
| 5919 | |
| 5920 /** | |
| 5921 * Initialize a newly created function type to be declared by the given elemen
t and to have the | |
| 5922 * given name. | |
| 5923 * | |
| 5924 * @param element the element representing the declaration of the function typ
e | |
| 5925 */ | |
| 5926 FunctionTypeImpl.con1(ExecutableElement element) : super(element, element == n
ull ? null : element.name); | |
| 5927 | |
| 5928 /** | |
| 5929 * Initialize a newly created function type to be declared by the given elemen
t and to have the | |
| 5930 * given name. | |
| 5931 * | |
| 5932 * @param element the element representing the declaration of the function typ
e | |
| 5933 */ | |
| 5934 FunctionTypeImpl.con2(FunctionTypeAliasElement element) : super(element, eleme
nt == null ? null : element.name); | |
| 5935 bool operator ==(Object object) { | |
| 5936 if (object is! FunctionTypeImpl) { | |
| 5937 return false; | |
| 5938 } | |
| 5939 FunctionTypeImpl otherType = object as FunctionTypeImpl; | |
| 5940 return (element == otherType.element) && JavaArrays.equals(normalParameterTy
pes, otherType.normalParameterTypes) && JavaArrays.equals(optionalParameterTypes
, otherType.optionalParameterTypes) && equals2(namedParameterTypes, otherType.na
medParameterTypes) && (returnType == otherType.returnType); | |
| 5941 } | |
| 5942 String get displayName { | |
| 5943 String name = this.name; | |
| 5944 if (name == null || name.length == 0) { | |
| 5945 List<Type2> normalParameterTypes = this.normalParameterTypes; | |
| 5946 List<Type2> optionalParameterTypes = this.optionalParameterTypes; | |
| 5947 Map<String, Type2> namedParameterTypes = this.namedParameterTypes; | |
| 5948 Type2 returnType = this.returnType; | |
| 5949 JavaStringBuilder builder = new JavaStringBuilder(); | |
| 5950 builder.append("("); | |
| 5951 bool needsComma = false; | |
| 5952 if (normalParameterTypes.length > 0) { | |
| 5953 for (Type2 type in normalParameterTypes) { | |
| 5954 if (needsComma) { | |
| 5955 builder.append(", "); | |
| 5956 } else { | |
| 5957 needsComma = true; | |
| 5958 } | |
| 5959 builder.append(type.displayName); | |
| 5960 } | |
| 5961 } | |
| 5962 if (optionalParameterTypes.length > 0) { | |
| 5963 if (needsComma) { | |
| 5964 builder.append(", "); | |
| 5965 needsComma = false; | |
| 5966 } | |
| 5967 builder.append("["); | |
| 5968 for (Type2 type in optionalParameterTypes) { | |
| 5969 if (needsComma) { | |
| 5970 builder.append(", "); | |
| 5971 } else { | |
| 5972 needsComma = true; | |
| 5973 } | |
| 5974 builder.append(type.displayName); | |
| 5975 } | |
| 5976 builder.append("]"); | |
| 5977 needsComma = true; | |
| 5978 } | |
| 5979 if (namedParameterTypes.length > 0) { | |
| 5980 if (needsComma) { | |
| 5981 builder.append(", "); | |
| 5982 needsComma = false; | |
| 5983 } | |
| 5984 builder.append("{"); | |
| 5985 for (MapEntry<String, Type2> entry in getMapEntrySet(namedParameterTypes
)) { | |
| 5986 if (needsComma) { | |
| 5987 builder.append(", "); | |
| 5988 } else { | |
| 5989 needsComma = true; | |
| 5990 } | |
| 5991 builder.append(entry.getKey()); | |
| 5992 builder.append(": "); | |
| 5993 builder.append(entry.getValue().displayName); | |
| 5994 } | |
| 5995 builder.append("}"); | |
| 5996 needsComma = true; | |
| 5997 } | |
| 5998 builder.append(") -> "); | |
| 5999 if (returnType == null) { | |
| 6000 builder.append("null"); | |
| 6001 } else { | |
| 6002 builder.append(returnType.displayName); | |
| 6003 } | |
| 6004 name = builder.toString(); | |
| 6005 } | |
| 6006 return name; | |
| 6007 } | |
| 6008 Map<String, Type2> get namedParameterTypes { | |
| 6009 LinkedHashMap<String, Type2> namedParameterTypes = new LinkedHashMap<String,
Type2>(); | |
| 6010 List<ParameterElement> parameters = baseParameters; | |
| 6011 if (parameters.length == 0) { | |
| 6012 return namedParameterTypes; | |
| 6013 } | |
| 6014 List<Type2> typeParameters = TypeParameterTypeImpl.getTypes(this.typeParamet
ers); | |
| 6015 for (ParameterElement parameter in parameters) { | |
| 6016 if (identical(parameter.parameterKind, ParameterKind.NAMED)) { | |
| 6017 namedParameterTypes[parameter.name] = parameter.type.substitute2(_typeAr
guments, typeParameters); | |
| 6018 } | |
| 6019 } | |
| 6020 return namedParameterTypes; | |
| 6021 } | |
| 6022 List<Type2> get normalParameterTypes { | |
| 6023 List<ParameterElement> parameters = baseParameters; | |
| 6024 if (parameters.length == 0) { | |
| 6025 return TypeImpl.EMPTY_ARRAY; | |
| 6026 } | |
| 6027 List<Type2> typeParameters = TypeParameterTypeImpl.getTypes(this.typeParamet
ers); | |
| 6028 List<Type2> types = new List<Type2>(); | |
| 6029 for (ParameterElement parameter in parameters) { | |
| 6030 if (identical(parameter.parameterKind, ParameterKind.REQUIRED)) { | |
| 6031 types.add(parameter.type.substitute2(_typeArguments, typeParameters)); | |
| 6032 } | |
| 6033 } | |
| 6034 return new List.from(types); | |
| 6035 } | |
| 6036 List<Type2> get optionalParameterTypes { | |
| 6037 List<ParameterElement> parameters = baseParameters; | |
| 6038 if (parameters.length == 0) { | |
| 6039 return TypeImpl.EMPTY_ARRAY; | |
| 6040 } | |
| 6041 List<Type2> typeParameters = TypeParameterTypeImpl.getTypes(this.typeParamet
ers); | |
| 6042 List<Type2> types = new List<Type2>(); | |
| 6043 for (ParameterElement parameter in parameters) { | |
| 6044 if (identical(parameter.parameterKind, ParameterKind.POSITIONAL)) { | |
| 6045 types.add(parameter.type.substitute2(_typeArguments, typeParameters)); | |
| 6046 } | |
| 6047 } | |
| 6048 return new List.from(types); | |
| 6049 } | |
| 6050 List<ParameterElement> get parameters { | |
| 6051 List<ParameterElement> baseParameters = this.baseParameters; | |
| 6052 int parameterCount = baseParameters.length; | |
| 6053 if (parameterCount == 0) { | |
| 6054 return baseParameters; | |
| 6055 } | |
| 6056 List<ParameterElement> specializedParameters = new List<ParameterElement>(pa
rameterCount); | |
| 6057 for (int i = 0; i < parameterCount; i++) { | |
| 6058 specializedParameters[i] = ParameterMember.from(baseParameters[i], this); | |
| 6059 } | |
| 6060 return specializedParameters; | |
| 6061 } | |
| 6062 Type2 get returnType { | |
| 6063 Type2 baseReturnType = this.baseReturnType; | |
| 6064 if (baseReturnType == null) { | |
| 6065 return DynamicTypeImpl.instance; | |
| 6066 } | |
| 6067 return baseReturnType.substitute2(_typeArguments, TypeParameterTypeImpl.getT
ypes(typeParameters)); | |
| 6068 } | |
| 6069 List<Type2> get typeArguments => _typeArguments; | |
| 6070 List<TypeParameterElement> get typeParameters { | |
| 6071 Element element = this.element; | |
| 6072 if (element is FunctionTypeAliasElement) { | |
| 6073 return ((element as FunctionTypeAliasElement)).typeParameters; | |
| 6074 } | |
| 6075 ClassElement definingClass = element.getAncestor(ClassElement); | |
| 6076 if (definingClass != null) { | |
| 6077 return definingClass.typeParameters; | |
| 6078 } | |
| 6079 return TypeParameterElementImpl.EMPTY_ARRAY; | |
| 6080 } | |
| 6081 int get hashCode { | |
| 6082 Element element = this.element; | |
| 6083 if (element == null) { | |
| 6084 return 0; | |
| 6085 } | |
| 6086 return element.hashCode; | |
| 6087 } | |
| 6088 bool isAssignableTo(Type2 type) => this.isSubtypeOf(type); | |
| 6089 bool isMoreSpecificThan(Type2 type) { | |
| 6090 if (type == null) { | |
| 6091 return false; | |
| 6092 } else if (identical(this, type) || type.isDynamic || type.isDartCoreFunctio
n || type.isObject) { | |
| 6093 return true; | |
| 6094 } else if (type is! FunctionType) { | |
| 6095 return false; | |
| 6096 } else if (this == type) { | |
| 6097 return true; | |
| 6098 } | |
| 6099 FunctionType t = this; | |
| 6100 FunctionType s = type as FunctionType; | |
| 6101 List<Type2> tTypes = t.normalParameterTypes; | |
| 6102 List<Type2> tOpTypes = t.optionalParameterTypes; | |
| 6103 List<Type2> sTypes = s.normalParameterTypes; | |
| 6104 List<Type2> sOpTypes = s.optionalParameterTypes; | |
| 6105 if ((sOpTypes.length > 0 && t.namedParameterTypes.length > 0) || (tOpTypes.l
ength > 0 && s.namedParameterTypes.length > 0)) { | |
| 6106 return false; | |
| 6107 } | |
| 6108 if (t.namedParameterTypes.length > 0) { | |
| 6109 if (t.normalParameterTypes.length != s.normalParameterTypes.length) { | |
| 6110 return false; | |
| 6111 } else if (t.normalParameterTypes.length > 0) { | |
| 6112 for (int i = 0; i < tTypes.length; i++) { | |
| 6113 if (!tTypes[i].isMoreSpecificThan(sTypes[i])) { | |
| 6114 return false; | |
| 6115 } | |
| 6116 } | |
| 6117 } | |
| 6118 Map<String, Type2> namedTypesT = t.namedParameterTypes; | |
| 6119 Map<String, Type2> namedTypesS = s.namedParameterTypes; | |
| 6120 if (namedTypesT.length < namedTypesS.length) { | |
| 6121 return false; | |
| 6122 } | |
| 6123 JavaIterator<MapEntry<String, Type2>> iteratorS = new JavaIterator(getMapE
ntrySet(namedTypesS)); | |
| 6124 while (iteratorS.hasNext) { | |
| 6125 MapEntry<String, Type2> entryS = iteratorS.next(); | |
| 6126 Type2 typeT = namedTypesT[entryS.getKey()]; | |
| 6127 if (typeT == null) { | |
| 6128 return false; | |
| 6129 } | |
| 6130 if (!typeT.isMoreSpecificThan(entryS.getValue())) { | |
| 6131 return false; | |
| 6132 } | |
| 6133 } | |
| 6134 } else if (s.namedParameterTypes.length > 0) { | |
| 6135 return false; | |
| 6136 } else { | |
| 6137 int tArgLength = tTypes.length + tOpTypes.length; | |
| 6138 int sArgLength = sTypes.length + sOpTypes.length; | |
| 6139 if (tArgLength < sArgLength || sTypes.length < tTypes.length) { | |
| 6140 return false; | |
| 6141 } | |
| 6142 if (tOpTypes.length == 0 && sOpTypes.length == 0) { | |
| 6143 for (int i = 0; i < sTypes.length; i++) { | |
| 6144 if (!tTypes[i].isMoreSpecificThan(sTypes[i])) { | |
| 6145 return false; | |
| 6146 } | |
| 6147 } | |
| 6148 } else { | |
| 6149 List<Type2> tAllTypes = new List<Type2>(sArgLength); | |
| 6150 for (int i = 0; i < tTypes.length; i++) { | |
| 6151 tAllTypes[i] = tTypes[i]; | |
| 6152 } | |
| 6153 for (int i = tTypes.length, j = 0; i < sArgLength; i++, j++) { | |
| 6154 tAllTypes[i] = tOpTypes[j]; | |
| 6155 } | |
| 6156 List<Type2> sAllTypes = new List<Type2>(sArgLength); | |
| 6157 for (int i = 0; i < sTypes.length; i++) { | |
| 6158 sAllTypes[i] = sTypes[i]; | |
| 6159 } | |
| 6160 for (int i = sTypes.length, j = 0; i < sArgLength; i++, j++) { | |
| 6161 sAllTypes[i] = sOpTypes[j]; | |
| 6162 } | |
| 6163 for (int i = 0; i < sAllTypes.length; i++) { | |
| 6164 if (!tAllTypes[i].isMoreSpecificThan(sAllTypes[i])) { | |
| 6165 return false; | |
| 6166 } | |
| 6167 } | |
| 6168 } | |
| 6169 } | |
| 6170 Type2 tRetType = t.returnType; | |
| 6171 Type2 sRetType = s.returnType; | |
| 6172 return sRetType.isVoid || tRetType.isMoreSpecificThan(sRetType); | |
| 6173 } | |
| 6174 bool isSubtypeOf(Type2 type) { | |
| 6175 if (type == null) { | |
| 6176 return false; | |
| 6177 } else if (identical(this, type) || type.isDynamic || type.isDartCoreFunctio
n || type.isObject) { | |
| 6178 return true; | |
| 6179 } else if (type is! FunctionType) { | |
| 6180 return false; | |
| 6181 } else if (this == type) { | |
| 6182 return true; | |
| 6183 } | |
| 6184 FunctionType t = this; | |
| 6185 FunctionType s = type as FunctionType; | |
| 6186 List<Type2> tTypes = t.normalParameterTypes; | |
| 6187 List<Type2> tOpTypes = t.optionalParameterTypes; | |
| 6188 List<Type2> sTypes = s.normalParameterTypes; | |
| 6189 List<Type2> sOpTypes = s.optionalParameterTypes; | |
| 6190 if ((sOpTypes.length > 0 && t.namedParameterTypes.length > 0) || (tOpTypes.l
ength > 0 && s.namedParameterTypes.length > 0)) { | |
| 6191 return false; | |
| 6192 } | |
| 6193 if (t.namedParameterTypes.length > 0) { | |
| 6194 if (t.normalParameterTypes.length != s.normalParameterTypes.length) { | |
| 6195 return false; | |
| 6196 } else if (t.normalParameterTypes.length > 0) { | |
| 6197 for (int i = 0; i < tTypes.length; i++) { | |
| 6198 if (!tTypes[i].isAssignableTo(sTypes[i])) { | |
| 6199 return false; | |
| 6200 } | |
| 6201 } | |
| 6202 } | |
| 6203 Map<String, Type2> namedTypesT = t.namedParameterTypes; | |
| 6204 Map<String, Type2> namedTypesS = s.namedParameterTypes; | |
| 6205 if (namedTypesT.length < namedTypesS.length) { | |
| 6206 return false; | |
| 6207 } | |
| 6208 JavaIterator<MapEntry<String, Type2>> iteratorS = new JavaIterator(getMapE
ntrySet(namedTypesS)); | |
| 6209 while (iteratorS.hasNext) { | |
| 6210 MapEntry<String, Type2> entryS = iteratorS.next(); | |
| 6211 Type2 typeT = namedTypesT[entryS.getKey()]; | |
| 6212 if (typeT == null) { | |
| 6213 return false; | |
| 6214 } | |
| 6215 if (!typeT.isAssignableTo(entryS.getValue())) { | |
| 6216 return false; | |
| 6217 } | |
| 6218 } | |
| 6219 } else if (s.namedParameterTypes.length > 0) { | |
| 6220 return false; | |
| 6221 } else { | |
| 6222 int tArgLength = tTypes.length + tOpTypes.length; | |
| 6223 int sArgLength = sTypes.length + sOpTypes.length; | |
| 6224 if (tArgLength < sArgLength || sTypes.length < tTypes.length) { | |
| 6225 return false; | |
| 6226 } | |
| 6227 if (tOpTypes.length == 0 && sOpTypes.length == 0) { | |
| 6228 for (int i = 0; i < sTypes.length; i++) { | |
| 6229 if (!tTypes[i].isAssignableTo(sTypes[i])) { | |
| 6230 return false; | |
| 6231 } | |
| 6232 } | |
| 6233 } else { | |
| 6234 List<Type2> tAllTypes = new List<Type2>(sArgLength); | |
| 6235 for (int i = 0; i < tTypes.length; i++) { | |
| 6236 tAllTypes[i] = tTypes[i]; | |
| 6237 } | |
| 6238 for (int i = tTypes.length, j = 0; i < sArgLength; i++, j++) { | |
| 6239 tAllTypes[i] = tOpTypes[j]; | |
| 6240 } | |
| 6241 List<Type2> sAllTypes = new List<Type2>(sArgLength); | |
| 6242 for (int i = 0; i < sTypes.length; i++) { | |
| 6243 sAllTypes[i] = sTypes[i]; | |
| 6244 } | |
| 6245 for (int i = sTypes.length, j = 0; i < sArgLength; i++, j++) { | |
| 6246 sAllTypes[i] = sOpTypes[j]; | |
| 6247 } | |
| 6248 for (int i = 0; i < sAllTypes.length; i++) { | |
| 6249 if (!tAllTypes[i].isAssignableTo(sAllTypes[i])) { | |
| 6250 return false; | |
| 6251 } | |
| 6252 } | |
| 6253 } | |
| 6254 } | |
| 6255 Type2 tRetType = t.returnType; | |
| 6256 Type2 sRetType = s.returnType; | |
| 6257 return sRetType.isVoid || tRetType.isAssignableTo(sRetType); | |
| 6258 } | |
| 6259 | |
| 6260 /** | |
| 6261 * Set the actual types of the type arguments to the given types. | |
| 6262 * | |
| 6263 * @param typeArguments the actual types of the type arguments | |
| 6264 */ | |
| 6265 void set typeArguments(List<Type2> typeArguments) { | |
| 6266 this._typeArguments = typeArguments; | |
| 6267 } | |
| 6268 FunctionTypeImpl substitute3(List<Type2> argumentTypes) => substitute2(argumen
tTypes, typeArguments); | |
| 6269 FunctionTypeImpl substitute2(List<Type2> argumentTypes, List<Type2> parameterT
ypes) { | |
| 6270 if (argumentTypes.length != parameterTypes.length) { | |
| 6271 throw new IllegalArgumentException("argumentTypes.length (${argumentTypes.
length}) != parameterTypes.length (${parameterTypes.length})"); | |
| 6272 } | |
| 6273 if (argumentTypes.length == 0) { | |
| 6274 return this; | |
| 6275 } | |
| 6276 Element element = this.element; | |
| 6277 FunctionTypeImpl newType = (element is ExecutableElement) ? new FunctionType
Impl.con1(element as ExecutableElement) : new FunctionTypeImpl.con2(element as F
unctionTypeAliasElement); | |
| 6278 newType.typeArguments = TypeImpl.substitute(_typeArguments, argumentTypes, p
arameterTypes); | |
| 6279 return newType; | |
| 6280 } | |
| 6281 void appendTo(JavaStringBuilder builder) { | |
| 6282 List<Type2> normalParameterTypes = this.normalParameterTypes; | |
| 6283 List<Type2> optionalParameterTypes = this.optionalParameterTypes; | |
| 6284 Map<String, Type2> namedParameterTypes = this.namedParameterTypes; | |
| 6285 Type2 returnType = this.returnType; | |
| 6286 builder.append("("); | |
| 6287 bool needsComma = false; | |
| 6288 if (normalParameterTypes.length > 0) { | |
| 6289 for (Type2 type in normalParameterTypes) { | |
| 6290 if (needsComma) { | |
| 6291 builder.append(", "); | |
| 6292 } else { | |
| 6293 needsComma = true; | |
| 6294 } | |
| 6295 ((type as TypeImpl)).appendTo(builder); | |
| 6296 } | |
| 6297 } | |
| 6298 if (optionalParameterTypes.length > 0) { | |
| 6299 if (needsComma) { | |
| 6300 builder.append(", "); | |
| 6301 needsComma = false; | |
| 6302 } | |
| 6303 builder.append("["); | |
| 6304 for (Type2 type in optionalParameterTypes) { | |
| 6305 if (needsComma) { | |
| 6306 builder.append(", "); | |
| 6307 } else { | |
| 6308 needsComma = true; | |
| 6309 } | |
| 6310 ((type as TypeImpl)).appendTo(builder); | |
| 6311 } | |
| 6312 builder.append("]"); | |
| 6313 needsComma = true; | |
| 6314 } | |
| 6315 if (namedParameterTypes.length > 0) { | |
| 6316 if (needsComma) { | |
| 6317 builder.append(", "); | |
| 6318 needsComma = false; | |
| 6319 } | |
| 6320 builder.append("{"); | |
| 6321 for (MapEntry<String, Type2> entry in getMapEntrySet(namedParameterTypes))
{ | |
| 6322 if (needsComma) { | |
| 6323 builder.append(", "); | |
| 6324 } else { | |
| 6325 needsComma = true; | |
| 6326 } | |
| 6327 builder.append(entry.getKey()); | |
| 6328 builder.append(": "); | |
| 6329 ((entry.getValue() as TypeImpl)).appendTo(builder); | |
| 6330 } | |
| 6331 builder.append("}"); | |
| 6332 needsComma = true; | |
| 6333 } | |
| 6334 builder.append(") -> "); | |
| 6335 if (returnType == null) { | |
| 6336 builder.append("null"); | |
| 6337 } else { | |
| 6338 ((returnType as TypeImpl)).appendTo(builder); | |
| 6339 } | |
| 6340 } | |
| 6341 | |
| 6342 /** | |
| 6343 * @return the base parameter elements of this function element, not `null`. | |
| 6344 */ | |
| 6345 List<ParameterElement> get baseParameters { | |
| 6346 Element element = this.element; | |
| 6347 if (element is ExecutableElement) { | |
| 6348 return ((element as ExecutableElement)).parameters; | |
| 6349 } else { | |
| 6350 return ((element as FunctionTypeAliasElement)).parameters; | |
| 6351 } | |
| 6352 } | |
| 6353 | |
| 6354 /** | |
| 6355 * Return the return type defined by this function's element. | |
| 6356 * | |
| 6357 * @return the return type defined by this function's element | |
| 6358 */ | |
| 6359 Type2 get baseReturnType { | |
| 6360 Element element = this.element; | |
| 6361 if (element is ExecutableElement) { | |
| 6362 return ((element as ExecutableElement)).returnType; | |
| 6363 } else { | |
| 6364 return ((element as FunctionTypeAliasElement)).returnType; | |
| 6365 } | |
| 6366 } | |
| 6367 } | |
| 6368 /** | |
| 6369 * Instances of the class `InterfaceTypeImpl` defines the behavior common to obj
ects | |
| 6370 * representing the type introduced by either a class or an interface, or a refe
rence to such a | |
| 6371 * type. | |
| 6372 * | |
| 6373 * @coverage dart.engine.type | |
| 6374 */ | |
| 6375 class InterfaceTypeImpl extends TypeImpl implements InterfaceType { | |
| 6376 | |
| 6377 /** | |
| 6378 * An empty array of types. | |
| 6379 */ | |
| 6380 static List<InterfaceType> EMPTY_ARRAY = new List<InterfaceType>(0); | |
| 6381 | |
| 6382 /** | |
| 6383 * This method computes the longest inheritance path from some passed [Type] t
o Object. | |
| 6384 * | |
| 6385 * @param type the [Type] to compute the longest inheritance path of from the
passed | |
| 6386 * [Type] to Object | |
| 6387 * @return the computed longest inheritance path to Object | |
| 6388 * @see InterfaceType#getLeastUpperBound(Type) | |
| 6389 */ | |
| 6390 static int computeLongestInheritancePathToObject(InterfaceType type) => comput
eLongestInheritancePathToObject2(type, 0, new Set<ClassElement>()); | |
| 6391 | |
| 6392 /** | |
| 6393 * Returns the set of all superinterfaces of the passed [Type]. | |
| 6394 * | |
| 6395 * @param type the [Type] to compute the set of superinterfaces of | |
| 6396 * @return the [Set] of superinterfaces of the passed [Type] | |
| 6397 * @see #getLeastUpperBound(Type) | |
| 6398 */ | |
| 6399 static Set<InterfaceType> computeSuperinterfaceSet(InterfaceType type) => comp
uteSuperinterfaceSet2(type, new Set<InterfaceType>()); | |
| 6400 | |
| 6401 /** | |
| 6402 * This method computes the longest inheritance path from some passed [Type] t
o Object. This | |
| 6403 * method calls itself recursively, callers should use the public method | |
| 6404 * [computeLongestInheritancePathToObject]. | |
| 6405 * | |
| 6406 * @param type the [Type] to compute the longest inheritance path of from the
passed | |
| 6407 * [Type] to Object | |
| 6408 * @param depth a field used recursively | |
| 6409 * @param visitedClasses the classes that have already been visited | |
| 6410 * @return the computed longest inheritance path to Object | |
| 6411 * @see #computeLongestInheritancePathToObject(Type) | |
| 6412 * @see #getLeastUpperBound(Type) | |
| 6413 */ | |
| 6414 static int computeLongestInheritancePathToObject2(InterfaceType type, int dept
h, Set<ClassElement> visitedClasses) { | |
| 6415 ClassElement classElement = type.element; | |
| 6416 if (classElement.supertype == null || visitedClasses.contains(classElement))
{ | |
| 6417 return depth; | |
| 6418 } | |
| 6419 int longestPath = 1; | |
| 6420 try { | |
| 6421 javaSetAdd(visitedClasses, classElement); | |
| 6422 List<InterfaceType> superinterfaces = classElement.interfaces; | |
| 6423 int pathLength; | |
| 6424 if (superinterfaces.length > 0) { | |
| 6425 for (InterfaceType superinterface in superinterfaces) { | |
| 6426 pathLength = computeLongestInheritancePathToObject2(superinterface, de
pth + 1, visitedClasses); | |
| 6427 if (pathLength > longestPath) { | |
| 6428 longestPath = pathLength; | |
| 6429 } | |
| 6430 } | |
| 6431 } | |
| 6432 InterfaceType supertype = classElement.supertype; | |
| 6433 pathLength = computeLongestInheritancePathToObject2(supertype, depth + 1,
visitedClasses); | |
| 6434 if (pathLength > longestPath) { | |
| 6435 longestPath = pathLength; | |
| 6436 } | |
| 6437 } finally { | |
| 6438 visitedClasses.remove(classElement); | |
| 6439 } | |
| 6440 return longestPath; | |
| 6441 } | |
| 6442 | |
| 6443 /** | |
| 6444 * Returns the set of all superinterfaces of the passed [Type]. This is a recu
rsive method, | |
| 6445 * callers should call the public [computeSuperinterfaceSet]. | |
| 6446 * | |
| 6447 * @param type the [Type] to compute the set of superinterfaces of | |
| 6448 * @param set a [HashSet] used recursively by this method | |
| 6449 * @return the [Set] of superinterfaces of the passed [Type] | |
| 6450 * @see #computeSuperinterfaceSet(Type) | |
| 6451 * @see #getLeastUpperBound(Type) | |
| 6452 */ | |
| 6453 static Set<InterfaceType> computeSuperinterfaceSet2(InterfaceType type, Set<In
terfaceType> set) { | |
| 6454 Element element = type.element; | |
| 6455 if (element != null && element is ClassElement) { | |
| 6456 ClassElement classElement = element as ClassElement; | |
| 6457 List<InterfaceType> superinterfaces = classElement.interfaces; | |
| 6458 for (InterfaceType superinterface in superinterfaces) { | |
| 6459 if (javaSetAdd(set, superinterface)) { | |
| 6460 computeSuperinterfaceSet2(superinterface, set); | |
| 6461 } | |
| 6462 } | |
| 6463 InterfaceType supertype = classElement.supertype; | |
| 6464 if (supertype != null) { | |
| 6465 if (javaSetAdd(set, supertype)) { | |
| 6466 computeSuperinterfaceSet2(supertype, set); | |
| 6467 } | |
| 6468 } | |
| 6469 } | |
| 6470 return set; | |
| 6471 } | |
| 6472 | |
| 6473 /** | |
| 6474 * Return the intersection of the given sets of types, where intersection is b
ased on the equality | |
| 6475 * of the elements of the types rather than on the equality of the types thems
elves. In cases | |
| 6476 * where two non-equal types have equal elements, which only happens when the
class is | |
| 6477 * parameterized, the type that is added to the intersection is the base type
with type arguments | |
| 6478 * that are the least upper bound of the type arguments of the two types. | |
| 6479 * | |
| 6480 * @param first the first set of types to be intersected | |
| 6481 * @param second the second set of types to be intersected | |
| 6482 * @return the intersection of the given sets of types | |
| 6483 */ | |
| 6484 static List<InterfaceType> intersection(Set<InterfaceType> first, Set<Interfac
eType> second) { | |
| 6485 Map<ClassElement, InterfaceType> firstMap = new Map<ClassElement, InterfaceT
ype>(); | |
| 6486 for (InterfaceType firstType in first) { | |
| 6487 firstMap[firstType.element] = firstType; | |
| 6488 } | |
| 6489 Set<InterfaceType> result = new Set<InterfaceType>(); | |
| 6490 for (InterfaceType secondType in second) { | |
| 6491 InterfaceType firstType = firstMap[secondType.element]; | |
| 6492 if (firstType != null) { | |
| 6493 javaSetAdd(result, leastUpperBound(firstType, secondType)); | |
| 6494 } | |
| 6495 } | |
| 6496 return new List.from(result); | |
| 6497 } | |
| 6498 | |
| 6499 /** | |
| 6500 * Return the "least upper bound" of the given types under the assumption that
the types have the | |
| 6501 * same element and differ only in terms of the type arguments. The resulting
type is composed by | |
| 6502 * comparing the corresponding type arguments, keeping those that are the same
, and using | |
| 6503 * 'dynamic' for those that are different. | |
| 6504 * | |
| 6505 * @param firstType the first type | |
| 6506 * @param secondType the second type | |
| 6507 * @return the "least upper bound" of the given types | |
| 6508 */ | |
| 6509 static InterfaceType leastUpperBound(InterfaceType firstType, InterfaceType se
condType) { | |
| 6510 if (firstType == secondType) { | |
| 6511 return firstType; | |
| 6512 } | |
| 6513 List<Type2> firstArguments = firstType.typeArguments; | |
| 6514 List<Type2> secondArguments = secondType.typeArguments; | |
| 6515 int argumentCount = firstArguments.length; | |
| 6516 if (argumentCount == 0) { | |
| 6517 return firstType; | |
| 6518 } | |
| 6519 List<Type2> lubArguments = new List<Type2>(argumentCount); | |
| 6520 for (int i = 0; i < argumentCount; i++) { | |
| 6521 if (firstArguments[i] == secondArguments[i]) { | |
| 6522 lubArguments[i] = firstArguments[i]; | |
| 6523 } | |
| 6524 if (lubArguments[i] == null) { | |
| 6525 lubArguments[i] = DynamicTypeImpl.instance; | |
| 6526 } | |
| 6527 } | |
| 6528 InterfaceTypeImpl lub = new InterfaceTypeImpl.con1(firstType.element); | |
| 6529 lub.typeArguments = lubArguments; | |
| 6530 return lub; | |
| 6531 } | |
| 6532 | |
| 6533 /** | |
| 6534 * An array containing the actual types of the type arguments. | |
| 6535 */ | |
| 6536 List<Type2> _typeArguments = TypeImpl.EMPTY_ARRAY; | |
| 6537 | |
| 6538 /** | |
| 6539 * Initialize a newly created type to be declared by the given element. | |
| 6540 * | |
| 6541 * @param element the element representing the declaration of the type | |
| 6542 */ | |
| 6543 InterfaceTypeImpl.con1(ClassElement element) : super(element, element.displayN
ame); | |
| 6544 | |
| 6545 /** | |
| 6546 * Initialize a newly created type to have the given name. This constructor sh
ould only be used in | |
| 6547 * cases where there is no declaration of the type. | |
| 6548 * | |
| 6549 * @param name the name of the type | |
| 6550 */ | |
| 6551 InterfaceTypeImpl.con2(String name) : super(null, name); | |
| 6552 bool operator ==(Object object) { | |
| 6553 if (object is! InterfaceTypeImpl) { | |
| 6554 return false; | |
| 6555 } | |
| 6556 InterfaceTypeImpl otherType = object as InterfaceTypeImpl; | |
| 6557 return (element == otherType.element) && JavaArrays.equals(_typeArguments, o
therType._typeArguments); | |
| 6558 } | |
| 6559 List<PropertyAccessorElement> get accessors { | |
| 6560 List<PropertyAccessorElement> accessors = element.accessors; | |
| 6561 List<PropertyAccessorElement> members = new List<PropertyAccessorElement>(ac
cessors.length); | |
| 6562 for (int i = 0; i < accessors.length; i++) { | |
| 6563 members[i] = PropertyAccessorMember.from(accessors[i], this); | |
| 6564 } | |
| 6565 return members; | |
| 6566 } | |
| 6567 String get displayName { | |
| 6568 String name = this.name; | |
| 6569 List<Type2> typeArguments = this.typeArguments; | |
| 6570 bool allDynamic = true; | |
| 6571 for (Type2 type in typeArguments) { | |
| 6572 if (type != null && !type.isDynamic) { | |
| 6573 allDynamic = false; | |
| 6574 break; | |
| 6575 } | |
| 6576 } | |
| 6577 if (!allDynamic) { | |
| 6578 JavaStringBuilder builder = new JavaStringBuilder(); | |
| 6579 builder.append(name); | |
| 6580 builder.append("<"); | |
| 6581 for (int i = 0; i < typeArguments.length; i++) { | |
| 6582 if (i != 0) { | |
| 6583 builder.append(", "); | |
| 6584 } | |
| 6585 Type2 typeArg = typeArguments[i]; | |
| 6586 builder.append(typeArg.displayName); | |
| 6587 } | |
| 6588 builder.append(">"); | |
| 6589 name = builder.toString(); | |
| 6590 } | |
| 6591 return name; | |
| 6592 } | |
| 6593 ClassElement get element => super.element as ClassElement; | |
| 6594 PropertyAccessorElement getGetter(String getterName) => PropertyAccessorMember
.from(((element as ClassElementImpl)).getGetter(getterName), this); | |
| 6595 List<InterfaceType> get interfaces { | |
| 6596 ClassElement classElement = element; | |
| 6597 List<InterfaceType> interfaces = classElement.interfaces; | |
| 6598 List<TypeParameterElement> typeParameters = classElement.typeParameters; | |
| 6599 List<Type2> parameterTypes = classElement.type.typeArguments; | |
| 6600 if (typeParameters.length == 0) { | |
| 6601 return interfaces; | |
| 6602 } | |
| 6603 int count = interfaces.length; | |
| 6604 List<InterfaceType> typedInterfaces = new List<InterfaceType>(count); | |
| 6605 for (int i = 0; i < count; i++) { | |
| 6606 typedInterfaces[i] = interfaces[i].substitute2(_typeArguments, parameterTy
pes); | |
| 6607 } | |
| 6608 return typedInterfaces; | |
| 6609 } | |
| 6610 Type2 getLeastUpperBound(Type2 type) { | |
| 6611 if (identical(type, this)) { | |
| 6612 return this; | |
| 6613 } | |
| 6614 Type2 dynamicType = DynamicTypeImpl.instance; | |
| 6615 if (identical(this, dynamicType) || identical(type, dynamicType)) { | |
| 6616 return dynamicType; | |
| 6617 } | |
| 6618 if (type is! InterfaceType) { | |
| 6619 return null; | |
| 6620 } | |
| 6621 InterfaceType i = this; | |
| 6622 InterfaceType j = type as InterfaceType; | |
| 6623 Set<InterfaceType> si = computeSuperinterfaceSet(i); | |
| 6624 Set<InterfaceType> sj = computeSuperinterfaceSet(j); | |
| 6625 javaSetAdd(si, i); | |
| 6626 javaSetAdd(sj, j); | |
| 6627 List<InterfaceType> s = intersection(si, sj); | |
| 6628 List<int> depths = new List<int>.filled(s.length, 0); | |
| 6629 int maxDepth = 0; | |
| 6630 for (int n = 0; n < s.length; n++) { | |
| 6631 depths[n] = computeLongestInheritancePathToObject(s[n]); | |
| 6632 if (depths[n] > maxDepth) { | |
| 6633 maxDepth = depths[n]; | |
| 6634 } | |
| 6635 } | |
| 6636 for (; maxDepth >= 0; maxDepth--) { | |
| 6637 int indexOfLeastUpperBound = -1; | |
| 6638 int numberOfTypesAtMaxDepth = 0; | |
| 6639 for (int m = 0; m < depths.length; m++) { | |
| 6640 if (depths[m] == maxDepth) { | |
| 6641 numberOfTypesAtMaxDepth++; | |
| 6642 indexOfLeastUpperBound = m; | |
| 6643 } | |
| 6644 } | |
| 6645 if (numberOfTypesAtMaxDepth == 1) { | |
| 6646 return s[indexOfLeastUpperBound]; | |
| 6647 } | |
| 6648 } | |
| 6649 return null; | |
| 6650 } | |
| 6651 MethodElement getMethod(String methodName) => MethodMember.from(((element as C
lassElementImpl)).getMethod(methodName), this); | |
| 6652 List<MethodElement> get methods { | |
| 6653 List<MethodElement> methods = element.methods; | |
| 6654 List<MethodElement> members = new List<MethodElement>(methods.length); | |
| 6655 for (int i = 0; i < methods.length; i++) { | |
| 6656 members[i] = MethodMember.from(methods[i], this); | |
| 6657 } | |
| 6658 return members; | |
| 6659 } | |
| 6660 List<InterfaceType> get mixins { | |
| 6661 ClassElement classElement = element; | |
| 6662 List<InterfaceType> mixins = classElement.mixins; | |
| 6663 List<TypeParameterElement> typeParameters = classElement.typeParameters; | |
| 6664 List<Type2> parameterTypes = classElement.type.typeArguments; | |
| 6665 if (typeParameters.length == 0) { | |
| 6666 return mixins; | |
| 6667 } | |
| 6668 int count = mixins.length; | |
| 6669 List<InterfaceType> typedMixins = new List<InterfaceType>(count); | |
| 6670 for (int i = 0; i < count; i++) { | |
| 6671 typedMixins[i] = mixins[i].substitute2(_typeArguments, parameterTypes); | |
| 6672 } | |
| 6673 return typedMixins; | |
| 6674 } | |
| 6675 PropertyAccessorElement getSetter(String setterName) => PropertyAccessorMember
.from(((element as ClassElementImpl)).getSetter(setterName), this); | |
| 6676 InterfaceType get superclass { | |
| 6677 ClassElement classElement = element; | |
| 6678 InterfaceType supertype = classElement.supertype; | |
| 6679 if (supertype == null) { | |
| 6680 return null; | |
| 6681 } | |
| 6682 return supertype.substitute2(_typeArguments, classElement.type.typeArguments
); | |
| 6683 } | |
| 6684 List<Type2> get typeArguments => _typeArguments; | |
| 6685 List<TypeParameterElement> get typeParameters => element.typeParameters; | |
| 6686 int get hashCode { | |
| 6687 ClassElement element = this.element; | |
| 6688 if (element == null) { | |
| 6689 return 0; | |
| 6690 } | |
| 6691 return element.hashCode; | |
| 6692 } | |
| 6693 bool get isDartCoreFunction { | |
| 6694 ClassElement element = this.element; | |
| 6695 if (element == null) { | |
| 6696 return false; | |
| 6697 } | |
| 6698 return element.name == "Function" && element.library.isDartCore; | |
| 6699 } | |
| 6700 bool isDirectSupertypeOf(InterfaceType type) { | |
| 6701 ClassElement i = element; | |
| 6702 ClassElement j = type.element; | |
| 6703 InterfaceType supertype = j.supertype; | |
| 6704 if (supertype == null) { | |
| 6705 return false; | |
| 6706 } | |
| 6707 ClassElement supertypeElement = supertype.element; | |
| 6708 if (supertypeElement == i) { | |
| 6709 return true; | |
| 6710 } | |
| 6711 for (InterfaceType interfaceType in j.interfaces) { | |
| 6712 if (interfaceType.element == i) { | |
| 6713 return true; | |
| 6714 } | |
| 6715 } | |
| 6716 for (InterfaceType mixinType in j.mixins) { | |
| 6717 if (mixinType.element == i) { | |
| 6718 return true; | |
| 6719 } | |
| 6720 } | |
| 6721 return false; | |
| 6722 } | |
| 6723 bool isMoreSpecificThan(Type2 type) { | |
| 6724 if (identical(type, DynamicTypeImpl.instance)) { | |
| 6725 return true; | |
| 6726 } else if (type is! InterfaceType) { | |
| 6727 return false; | |
| 6728 } | |
| 6729 return isMoreSpecificThan2(type as InterfaceType, new Set<ClassElement>()); | |
| 6730 } | |
| 6731 bool get isObject => element.supertype == null; | |
| 6732 bool isSubtypeOf(Type2 type) { | |
| 6733 if (identical(type, DynamicTypeImpl.instance)) { | |
| 6734 return true; | |
| 6735 } else if (type is TypeParameterType) { | |
| 6736 return true; | |
| 6737 } else if (type is FunctionType) { | |
| 6738 ClassElement element = this.element; | |
| 6739 MethodElement callMethod = element.lookUpMethod("call", element.library); | |
| 6740 if (callMethod != null) { | |
| 6741 return callMethod.type.isSubtypeOf(type); | |
| 6742 } | |
| 6743 return false; | |
| 6744 } else if (type is! InterfaceType) { | |
| 6745 return false; | |
| 6746 } else if (this == type) { | |
| 6747 return true; | |
| 6748 } | |
| 6749 return isSubtypeOf2(type as InterfaceType, new Set<ClassElement>()); | |
| 6750 } | |
| 6751 ConstructorElement lookUpConstructor(String constructorName, LibraryElement li
brary) { | |
| 6752 ConstructorElement constructorElement; | |
| 6753 if (constructorName == null) { | |
| 6754 constructorElement = element.unnamedConstructor; | |
| 6755 } else { | |
| 6756 constructorElement = element.getNamedConstructor(constructorName); | |
| 6757 } | |
| 6758 if (constructorElement == null || !constructorElement.isAccessibleIn(library
)) { | |
| 6759 return null; | |
| 6760 } | |
| 6761 return ConstructorMember.from(constructorElement, this); | |
| 6762 } | |
| 6763 PropertyAccessorElement lookUpGetter(String getterName, LibraryElement library
) { | |
| 6764 PropertyAccessorElement element = getGetter(getterName); | |
| 6765 if (element != null && element.isAccessibleIn(library)) { | |
| 6766 return element; | |
| 6767 } | |
| 6768 return lookUpGetterInSuperclass(getterName, library); | |
| 6769 } | |
| 6770 PropertyAccessorElement lookUpGetterInSuperclass(String getterName, LibraryEle
ment library) { | |
| 6771 for (InterfaceType mixin in mixins) { | |
| 6772 PropertyAccessorElement element = mixin.getGetter(getterName); | |
| 6773 if (element != null && element.isAccessibleIn(library)) { | |
| 6774 return element; | |
| 6775 } | |
| 6776 } | |
| 6777 Set<ClassElement> visitedClasses = new Set<ClassElement>(); | |
| 6778 InterfaceType supertype = superclass; | |
| 6779 ClassElement supertypeElement = supertype == null ? null : supertype.element
; | |
| 6780 while (supertype != null && !visitedClasses.contains(supertypeElement)) { | |
| 6781 javaSetAdd(visitedClasses, supertypeElement); | |
| 6782 PropertyAccessorElement element = supertype.getGetter(getterName); | |
| 6783 if (element != null && element.isAccessibleIn(library)) { | |
| 6784 return element; | |
| 6785 } | |
| 6786 for (InterfaceType mixin in supertype.mixins) { | |
| 6787 element = mixin.getGetter(getterName); | |
| 6788 if (element != null && element.isAccessibleIn(library)) { | |
| 6789 return element; | |
| 6790 } | |
| 6791 } | |
| 6792 supertype = supertype.superclass; | |
| 6793 supertypeElement = supertype == null ? null : supertype.element; | |
| 6794 } | |
| 6795 return null; | |
| 6796 } | |
| 6797 MethodElement lookUpMethod(String methodName, LibraryElement library) { | |
| 6798 MethodElement element = getMethod(methodName); | |
| 6799 if (element != null && element.isAccessibleIn(library)) { | |
| 6800 return element; | |
| 6801 } | |
| 6802 return lookUpMethodInSuperclass(methodName, library); | |
| 6803 } | |
| 6804 MethodElement lookUpMethodInSuperclass(String methodName, LibraryElement libra
ry) { | |
| 6805 for (InterfaceType mixin in mixins) { | |
| 6806 MethodElement element = mixin.getMethod(methodName); | |
| 6807 if (element != null && element.isAccessibleIn(library)) { | |
| 6808 return element; | |
| 6809 } | |
| 6810 } | |
| 6811 Set<ClassElement> visitedClasses = new Set<ClassElement>(); | |
| 6812 InterfaceType supertype = superclass; | |
| 6813 ClassElement supertypeElement = supertype == null ? null : supertype.element
; | |
| 6814 while (supertype != null && !visitedClasses.contains(supertypeElement)) { | |
| 6815 javaSetAdd(visitedClasses, supertypeElement); | |
| 6816 MethodElement element = supertype.getMethod(methodName); | |
| 6817 if (element != null && element.isAccessibleIn(library)) { | |
| 6818 return element; | |
| 6819 } | |
| 6820 for (InterfaceType mixin in supertype.mixins) { | |
| 6821 element = mixin.getMethod(methodName); | |
| 6822 if (element != null && element.isAccessibleIn(library)) { | |
| 6823 return element; | |
| 6824 } | |
| 6825 } | |
| 6826 supertype = supertype.superclass; | |
| 6827 supertypeElement = supertype == null ? null : supertype.element; | |
| 6828 } | |
| 6829 return null; | |
| 6830 } | |
| 6831 PropertyAccessorElement lookUpSetter(String setterName, LibraryElement library
) { | |
| 6832 PropertyAccessorElement element = getSetter(setterName); | |
| 6833 if (element != null && element.isAccessibleIn(library)) { | |
| 6834 return element; | |
| 6835 } | |
| 6836 return lookUpSetterInSuperclass(setterName, library); | |
| 6837 } | |
| 6838 PropertyAccessorElement lookUpSetterInSuperclass(String setterName, LibraryEle
ment library) { | |
| 6839 for (InterfaceType mixin in mixins) { | |
| 6840 PropertyAccessorElement element = mixin.getSetter(setterName); | |
| 6841 if (element != null && element.isAccessibleIn(library)) { | |
| 6842 return element; | |
| 6843 } | |
| 6844 } | |
| 6845 Set<ClassElement> visitedClasses = new Set<ClassElement>(); | |
| 6846 InterfaceType supertype = superclass; | |
| 6847 ClassElement supertypeElement = supertype == null ? null : supertype.element
; | |
| 6848 while (supertype != null && !visitedClasses.contains(supertypeElement)) { | |
| 6849 javaSetAdd(visitedClasses, supertypeElement); | |
| 6850 PropertyAccessorElement element = supertype.getSetter(setterName); | |
| 6851 if (element != null && element.isAccessibleIn(library)) { | |
| 6852 return element; | |
| 6853 } | |
| 6854 for (InterfaceType mixin in supertype.mixins) { | |
| 6855 element = mixin.getSetter(setterName); | |
| 6856 if (element != null && element.isAccessibleIn(library)) { | |
| 6857 return element; | |
| 6858 } | |
| 6859 } | |
| 6860 supertype = supertype.superclass; | |
| 6861 supertypeElement = supertype == null ? null : supertype.element; | |
| 6862 } | |
| 6863 return null; | |
| 6864 } | |
| 6865 | |
| 6866 /** | |
| 6867 * Set the actual types of the type arguments to those in the given array. | |
| 6868 * | |
| 6869 * @param typeArguments the actual types of the type arguments | |
| 6870 */ | |
| 6871 void set typeArguments(List<Type2> typeArguments) { | |
| 6872 this._typeArguments = typeArguments; | |
| 6873 } | |
| 6874 InterfaceTypeImpl substitute4(List<Type2> argumentTypes) => substitute2(argume
ntTypes, typeArguments); | |
| 6875 InterfaceTypeImpl substitute2(List<Type2> argumentTypes, List<Type2> parameter
Types) { | |
| 6876 if (argumentTypes.length != parameterTypes.length) { | |
| 6877 throw new IllegalArgumentException("argumentTypes.length (${argumentTypes.
length}) != parameterTypes.length (${parameterTypes.length})"); | |
| 6878 } | |
| 6879 if (argumentTypes.length == 0 || _typeArguments.length == 0) { | |
| 6880 return this; | |
| 6881 } | |
| 6882 List<Type2> newTypeArguments = TypeImpl.substitute(_typeArguments, argumentT
ypes, parameterTypes); | |
| 6883 if (JavaArrays.equals(newTypeArguments, _typeArguments)) { | |
| 6884 return this; | |
| 6885 } | |
| 6886 InterfaceTypeImpl newType = new InterfaceTypeImpl.con1(element); | |
| 6887 newType.typeArguments = newTypeArguments; | |
| 6888 return newType; | |
| 6889 } | |
| 6890 void appendTo(JavaStringBuilder builder) { | |
| 6891 builder.append(name); | |
| 6892 int argumentCount = _typeArguments.length; | |
| 6893 if (argumentCount > 0) { | |
| 6894 builder.append("<"); | |
| 6895 for (int i = 0; i < argumentCount; i++) { | |
| 6896 if (i > 0) { | |
| 6897 builder.append(", "); | |
| 6898 } | |
| 6899 ((_typeArguments[i] as TypeImpl)).appendTo(builder); | |
| 6900 } | |
| 6901 builder.append(">"); | |
| 6902 } | |
| 6903 } | |
| 6904 bool isMoreSpecificThan2(InterfaceType s, Set<ClassElement> visitedClasses) { | |
| 6905 if (this == s) { | |
| 6906 return true; | |
| 6907 } | |
| 6908 if (s.isDirectSupertypeOf(this)) { | |
| 6909 return true; | |
| 6910 } | |
| 6911 ClassElement tElement = this.element; | |
| 6912 ClassElement sElement = s.element; | |
| 6913 if (tElement == sElement) { | |
| 6914 List<Type2> tArguments = typeArguments; | |
| 6915 List<Type2> sArguments = s.typeArguments; | |
| 6916 if (tArguments.length != sArguments.length) { | |
| 6917 return false; | |
| 6918 } | |
| 6919 for (int i = 0; i < tArguments.length; i++) { | |
| 6920 if (!tArguments[i].isMoreSpecificThan(sArguments[i])) { | |
| 6921 return false; | |
| 6922 } | |
| 6923 } | |
| 6924 return true; | |
| 6925 } | |
| 6926 ClassElement element = this.element; | |
| 6927 if (element == null || visitedClasses.contains(element)) { | |
| 6928 return false; | |
| 6929 } | |
| 6930 javaSetAdd(visitedClasses, element); | |
| 6931 InterfaceType supertype = superclass; | |
| 6932 if (supertype != null && ((supertype as InterfaceTypeImpl)).isMoreSpecificTh
an2(s, visitedClasses)) { | |
| 6933 return true; | |
| 6934 } | |
| 6935 for (InterfaceType interfaceType in interfaces) { | |
| 6936 if (((interfaceType as InterfaceTypeImpl)).isMoreSpecificThan2(s, visitedC
lasses)) { | |
| 6937 return true; | |
| 6938 } | |
| 6939 } | |
| 6940 for (InterfaceType mixinType in mixins) { | |
| 6941 if (((mixinType as InterfaceTypeImpl)).isMoreSpecificThan2(s, visitedClass
es)) { | |
| 6942 return true; | |
| 6943 } | |
| 6944 } | |
| 6945 return false; | |
| 6946 } | |
| 6947 bool isSubtypeOf2(InterfaceType type, Set<ClassElement> visitedClasses) { | |
| 6948 InterfaceType typeT = this; | |
| 6949 InterfaceType typeS = type; | |
| 6950 ClassElement elementT = element; | |
| 6951 if (elementT == null || visitedClasses.contains(elementT)) { | |
| 6952 return false; | |
| 6953 } | |
| 6954 javaSetAdd(visitedClasses, elementT); | |
| 6955 typeT = substitute2(_typeArguments, elementT.type.typeArguments); | |
| 6956 if (typeT == typeS) { | |
| 6957 return true; | |
| 6958 } else if (elementT == typeS.element) { | |
| 6959 List<Type2> typeTArgs = typeT.typeArguments; | |
| 6960 List<Type2> typeSArgs = typeS.typeArguments; | |
| 6961 if (typeTArgs.length != typeSArgs.length) { | |
| 6962 return false; | |
| 6963 } | |
| 6964 for (int i = 0; i < typeTArgs.length; i++) { | |
| 6965 if (!typeTArgs[i].isSubtypeOf(typeSArgs[i])) { | |
| 6966 return false; | |
| 6967 } | |
| 6968 } | |
| 6969 return true; | |
| 6970 } else if (typeS.isDartCoreFunction && elementT.getMethod("call") != null) { | |
| 6971 return true; | |
| 6972 } | |
| 6973 InterfaceType supertype = superclass; | |
| 6974 if (supertype != null && ((supertype as InterfaceTypeImpl)).isSubtypeOf2(typ
eS, visitedClasses)) { | |
| 6975 return true; | |
| 6976 } | |
| 6977 List<InterfaceType> interfaceTypes = interfaces; | |
| 6978 for (InterfaceType interfaceType in interfaceTypes) { | |
| 6979 if (((interfaceType as InterfaceTypeImpl)).isSubtypeOf2(typeS, visitedClas
ses)) { | |
| 6980 return true; | |
| 6981 } | |
| 6982 } | |
| 6983 List<InterfaceType> mixinTypes = mixins; | |
| 6984 for (InterfaceType mixinType in mixinTypes) { | |
| 6985 if (((mixinType as InterfaceTypeImpl)).isSubtypeOf2(typeS, visitedClasses)
) { | |
| 6986 return true; | |
| 6987 } | |
| 6988 } | |
| 6989 return false; | |
| 6990 } | |
| 6991 } | |
| 6992 /** | |
| 6993 * The abstract class `TypeImpl` implements the behavior common to objects repre
senting the | |
| 6994 * declared type of elements in the element model. | |
| 6995 * | |
| 6996 * @coverage dart.engine.type | |
| 6997 */ | |
| 6998 abstract class TypeImpl implements Type2 { | |
| 6999 | |
| 7000 /** | |
| 7001 * Return an array containing the results of using the given argument types an
d parameter types to | |
| 7002 * perform a substitution on all of the given types. | |
| 7003 * | |
| 7004 * @param types the types on which a substitution is to be performed | |
| 7005 * @param argumentTypes the argument types for the substitution | |
| 7006 * @param parameterTypes the parameter types for the substitution | |
| 7007 * @return the result of performing the substitution on each of the types | |
| 7008 */ | |
| 7009 static List<Type2> substitute(List<Type2> types, List<Type2> argumentTypes, Li
st<Type2> parameterTypes) { | |
| 7010 int length = types.length; | |
| 7011 if (length == 0) { | |
| 7012 return types; | |
| 7013 } | |
| 7014 List<Type2> newTypes = new List<Type2>(length); | |
| 7015 for (int i = 0; i < length; i++) { | |
| 7016 newTypes[i] = types[i].substitute2(argumentTypes, parameterTypes); | |
| 7017 } | |
| 7018 return newTypes; | |
| 7019 } | |
| 7020 | |
| 7021 /** | |
| 7022 * The element representing the declaration of this type, or `null` if the typ
e has not, or | |
| 7023 * cannot, be associated with an element. | |
| 7024 */ | |
| 7025 Element _element; | |
| 7026 | |
| 7027 /** | |
| 7028 * The name of this type, or `null` if the type does not have a name. | |
| 7029 */ | |
| 7030 String _name; | |
| 7031 | |
| 7032 /** | |
| 7033 * An empty array of types. | |
| 7034 */ | |
| 7035 static List<Type2> EMPTY_ARRAY = new List<Type2>(0); | |
| 7036 | |
| 7037 /** | |
| 7038 * Initialize a newly created type to be declared by the given element and to
have the given name. | |
| 7039 * | |
| 7040 * @param element the element representing the declaration of the type | |
| 7041 * @param name the name of the type | |
| 7042 */ | |
| 7043 TypeImpl(Element element, String name) { | |
| 7044 this._element = element; | |
| 7045 this._name = name; | |
| 7046 } | |
| 7047 String get displayName => name; | |
| 7048 Element get element => _element; | |
| 7049 Type2 getLeastUpperBound(Type2 type) => null; | |
| 7050 String get name => _name; | |
| 7051 bool isAssignableTo(Type2 type) => this.isSubtypeOf(type) || type.isSubtypeOf(
this); | |
| 7052 bool get isBottom => false; | |
| 7053 bool get isDartCoreFunction => false; | |
| 7054 bool get isDynamic => false; | |
| 7055 bool isMoreSpecificThan(Type2 type) => false; | |
| 7056 bool get isObject => false; | |
| 7057 bool isSupertypeOf(Type2 type) => type.isSubtypeOf(this); | |
| 7058 bool get isVoid => false; | |
| 7059 String toString() { | |
| 7060 JavaStringBuilder builder = new JavaStringBuilder(); | |
| 7061 appendTo(builder); | |
| 7062 return builder.toString(); | |
| 7063 } | |
| 7064 | |
| 7065 /** | |
| 7066 * Append a textual representation of this type to the given builder. | |
| 7067 * | |
| 7068 * @param builder the builder to which the text is to be appended | |
| 7069 */ | |
| 7070 void appendTo(JavaStringBuilder builder) { | |
| 7071 if (_name == null) { | |
| 7072 builder.append("<unnamed type>"); | |
| 7073 } else { | |
| 7074 builder.append(_name); | |
| 7075 } | |
| 7076 } | |
| 7077 } | |
| 7078 /** | |
| 7079 * Instances of the class `TypeParameterTypeImpl` defines the behavior of object
s representing | |
| 7080 * the type introduced by a type parameter. | |
| 7081 * | |
| 7082 * @coverage dart.engine.type | |
| 7083 */ | |
| 7084 class TypeParameterTypeImpl extends TypeImpl implements TypeParameterType { | |
| 7085 | |
| 7086 /** | |
| 7087 * An empty array of type parameter types. | |
| 7088 */ | |
| 7089 static List<TypeParameterType> EMPTY_ARRAY = new List<TypeParameterType>(0); | |
| 7090 | |
| 7091 /** | |
| 7092 * Return an array containing the type parameter types defined by the given ar
ray of type | |
| 7093 * parameter elements. | |
| 7094 * | |
| 7095 * @param typeParameters the type parameter elements defining the type paramet
er types to be | |
| 7096 * returned | |
| 7097 * @return the type parameter types defined by the type parameter elements | |
| 7098 */ | |
| 7099 static List<TypeParameterType> getTypes(List<TypeParameterElement> typeParamet
ers) { | |
| 7100 int count = typeParameters.length; | |
| 7101 if (count == 0) { | |
| 7102 return EMPTY_ARRAY; | |
| 7103 } | |
| 7104 List<TypeParameterType> types = new List<TypeParameterType>(count); | |
| 7105 for (int i = 0; i < count; i++) { | |
| 7106 types[i] = typeParameters[i].type; | |
| 7107 } | |
| 7108 return types; | |
| 7109 } | |
| 7110 | |
| 7111 /** | |
| 7112 * Initialize a newly created type parameter type to be declared by the given
element and to have | |
| 7113 * the given name. | |
| 7114 * | |
| 7115 * @param element the element representing the declaration of the type paramet
er | |
| 7116 */ | |
| 7117 TypeParameterTypeImpl(TypeParameterElement element) : super(element, element.n
ame); | |
| 7118 bool operator ==(Object object) => object is TypeParameterTypeImpl && (element
== ((object as TypeParameterTypeImpl)).element); | |
| 7119 TypeParameterElement get element => super.element as TypeParameterElement; | |
| 7120 int get hashCode => element.hashCode; | |
| 7121 bool isMoreSpecificThan(Type2 s) { | |
| 7122 if (this == s) { | |
| 7123 return true; | |
| 7124 } | |
| 7125 if (s.isBottom) { | |
| 7126 return true; | |
| 7127 } | |
| 7128 if (s.isDynamic) { | |
| 7129 return true; | |
| 7130 } | |
| 7131 return isMoreSpecificThan3(s, new Set<Type2>()); | |
| 7132 } | |
| 7133 bool isSubtypeOf(Type2 s) => isMoreSpecificThan(s); | |
| 7134 Type2 substitute2(List<Type2> argumentTypes, List<Type2> parameterTypes) { | |
| 7135 int length = parameterTypes.length; | |
| 7136 for (int i = 0; i < length; i++) { | |
| 7137 if (parameterTypes[i] == this) { | |
| 7138 return argumentTypes[i]; | |
| 7139 } | |
| 7140 } | |
| 7141 return this; | |
| 7142 } | |
| 7143 bool isMoreSpecificThan3(Type2 s, Set<Type2> visitedTypes) { | |
| 7144 Type2 bound = element.bound; | |
| 7145 if (s == bound) { | |
| 7146 return true; | |
| 7147 } | |
| 7148 if (s.isObject) { | |
| 7149 return true; | |
| 7150 } | |
| 7151 if (bound == null) { | |
| 7152 return false; | |
| 7153 } | |
| 7154 if (bound is TypeParameterTypeImpl) { | |
| 7155 TypeParameterTypeImpl boundTypeParameter = bound as TypeParameterTypeImpl; | |
| 7156 if (visitedTypes.contains(bound)) { | |
| 7157 return false; | |
| 7158 } | |
| 7159 javaSetAdd(visitedTypes, bound); | |
| 7160 return boundTypeParameter.isMoreSpecificThan3(s, visitedTypes); | |
| 7161 } | |
| 7162 return bound.isMoreSpecificThan(s); | |
| 7163 } | |
| 7164 } | |
| 7165 /** | |
| 7166 * The unique instance of the class `VoidTypeImpl` implements the type `void`. | |
| 7167 * | |
| 7168 * @coverage dart.engine.type | |
| 7169 */ | |
| 7170 class VoidTypeImpl extends TypeImpl implements VoidType { | |
| 7171 | |
| 7172 /** | |
| 7173 * The unique instance of this class. | |
| 7174 */ | |
| 7175 static final VoidTypeImpl instance = new VoidTypeImpl(); | |
| 7176 | |
| 7177 /** | |
| 7178 * Prevent the creation of instances of this class. | |
| 7179 */ | |
| 7180 VoidTypeImpl() : super(null, Keyword.VOID.syntax); | |
| 7181 bool operator ==(Object object) => identical(object, this); | |
| 7182 bool isSubtypeOf(Type2 type) => identical(type, this) || identical(type, Dynam
icTypeImpl.instance); | |
| 7183 bool get isVoid => true; | |
| 7184 VoidTypeImpl substitute2(List<Type2> argumentTypes, List<Type2> parameterTypes
) => this; | |
| 7185 } | |
| 7186 /** | |
| 7187 * The interface `FunctionType` defines the behavior common to objects represent
ing the type | |
| 7188 * of a function, method, constructor, getter, or setter. Function types come in
three variations: | |
| 7189 * <ol> | |
| 7190 * * The types of functions that only have required parameters. These have the g
eneral form | |
| 7191 * <i>(T<sub>1</sub>, …, T<sub>n</sub>) → T</i>. | |
| 7192 * * The types of functions with optional positional parameters. These have the
general form | |
| 7193 * <i>(T<sub>1</sub>, …, T<sub>n</sub>, [T<sub>n+1</sub>, …, T<sub
>n+k</sub>]) → | |
| 7194 * T</i>. | |
| 7195 * * The types of functions with named parameters. These have the general form <
i>(T<sub>1</sub>, | |
| 7196 * …, T<sub>n</sub>, {T<sub>x1</sub> x1, …, T<sub>xk</sub> xk}) &r
arr; T</i>. | |
| 7197 * </ol> | |
| 7198 * | |
| 7199 * @coverage dart.engine.type | |
| 7200 */ | |
| 7201 abstract class FunctionType implements ParameterizedType { | |
| 7202 | |
| 7203 /** | |
| 7204 * Return a map from the names of named parameters to the types of the named p
arameters of this | |
| 7205 * type of function. The entries in the map will be iterated in the same order
as the order in | |
| 7206 * which the named parameters were defined. If there were no named parameters
declared then the | |
| 7207 * map will be empty. | |
| 7208 * | |
| 7209 * @return a map from the name to the types of the named parameters of this ty
pe of function | |
| 7210 */ | |
| 7211 Map<String, Type2> get namedParameterTypes; | |
| 7212 | |
| 7213 /** | |
| 7214 * Return an array containing the types of the normal parameters of this type
of function. The | |
| 7215 * parameter types are in the same order as they appear in the declaration of
the function. | |
| 7216 * | |
| 7217 * @return the types of the normal parameters of this type of function | |
| 7218 */ | |
| 7219 List<Type2> get normalParameterTypes; | |
| 7220 | |
| 7221 /** | |
| 7222 * Return a map from the names of optional (positional) parameters to the type
s of the optional | |
| 7223 * parameters of this type of function. The entries in the map will be iterate
d in the same order | |
| 7224 * as the order in which the optional parameters were defined. If there were n
o optional | |
| 7225 * parameters declared then the map will be empty. | |
| 7226 * | |
| 7227 * @return a map from the name to the types of the optional parameters of this
type of function | |
| 7228 */ | |
| 7229 List<Type2> get optionalParameterTypes; | |
| 7230 | |
| 7231 /** | |
| 7232 * Return an array containing the parameters elements of this type of function
. The parameter | |
| 7233 * types are in the same order as they appear in the declaration of the functi
on. | |
| 7234 * | |
| 7235 * @return the parameters elements of this type of function | |
| 7236 */ | |
| 7237 List<ParameterElement> get parameters; | |
| 7238 | |
| 7239 /** | |
| 7240 * Return the type of object returned by this type of function. | |
| 7241 * | |
| 7242 * @return the type of object returned by this type of function | |
| 7243 */ | |
| 7244 Type2 get returnType; | |
| 7245 | |
| 7246 /** | |
| 7247 * Return `true` if this type is a subtype of the given type. | |
| 7248 * | |
| 7249 * A function type <i>(T<sub>1</sub>, …, T<sub>n</sub>) → T</i> is
a subtype of the | |
| 7250 * function type <i>(S<sub>1</sub>, …, S<sub>n</sub>) → S</i>, if
all of the following | |
| 7251 * conditions are met: | |
| 7252 * | |
| 7253 * * Either | |
| 7254 * | |
| 7255 * * <i>S</i> is void, or | |
| 7256 * * <i>T ⇔ S</i>. | |
| 7257 * | |
| 7258 * | |
| 7259 * * For all <i>i</i>, 1 <= <i>i</i> <= <i>n</i>, <i>T<sub>i</sub> ⇔ S<su
b>i</sub></i>. | |
| 7260 * | |
| 7261 * A function type <i>(T<sub>1</sub>, …, T<sub>n</sub>, [T<sub>n+1</sub
>, …, | |
| 7262 * T<sub>n+k</sub>]) → T</i> is a subtype of the function type <i>(S<sub>
1</sub>, …, | |
| 7263 * S<sub>n</sub>, [S<sub>n+1</sub>, …, S<sub>n+m</sub>]) → S</i>,
if all of the | |
| 7264 * following conditions are met: | |
| 7265 * | |
| 7266 * * Either | |
| 7267 * | |
| 7268 * * <i>S</i> is void, or | |
| 7269 * * <i>T ⇔ S</i>. | |
| 7270 * | |
| 7271 * | |
| 7272 * * <i>k</i> >= <i>m</i> and for all <i>i</i>, 1 <= <i>i</i> <= <i>n+m</i>, <
i>T<sub>i</sub> | |
| 7273 * ⇔ S<sub>i</sub></i>. | |
| 7274 * | |
| 7275 * A function type <i>(T<sub>1</sub>, …, T<sub>n</sub>, {T<sub>x1</sub>
x1, …, | |
| 7276 * T<sub>xk</sub> xk}) → T</i> is a subtype of the function type <i>(S<su
b>1</sub>, …, | |
| 7277 * S<sub>n</sub>, {S<sub>y1</sub> y1, …, S<sub>ym</sub> ym}) → S</
i>, if all of the | |
| 7278 * following conditions are met: | |
| 7279 * | |
| 7280 * * Either | |
| 7281 * | |
| 7282 * * <i>S</i> is void, | |
| 7283 * * or <i>T ⇔ S</i>. | |
| 7284 * | |
| 7285 * | |
| 7286 * * For all <i>i</i>, 1 <= <i>i</i> <= <i>n</i>, <i>T<sub>i</sub> ⇔ S<su
b>i</sub></i>. | |
| 7287 * * <i>k</i> >= <i>m</i> and <i>y<sub>i</sub></i> in <i>{x<sub>1</sub>, &hell
ip;, | |
| 7288 * x<sub>k</sub>}</i>, 1 <= <i>i</i> <= <i>m</i>. | |
| 7289 * * For all <i>y<sub>i</sub></i> in <i>{y<sub>1</sub>, …, y<sub>m</sub
>}</i>, | |
| 7290 * <i>y<sub>i</sub> = x<sub>j</sub> => Tj ⇔ Si</i>. | |
| 7291 * | |
| 7292 * In addition, the following subtype rules apply: | |
| 7293 * | |
| 7294 * <i>(T<sub>1</sub>, …, T<sub>n</sub>, []) → T <: (T<sub>1</sub>,
…, | |
| 7295 * T<sub>n</sub>) → T.</i><br> | |
| 7296 * <i>(T<sub>1</sub>, …, T<sub>n</sub>) → T <: (T<sub>1</sub>, &he
llip;, | |
| 7297 * T<sub>n</sub>, {}) → T.</i><br> | |
| 7298 * <i>(T<sub>1</sub>, …, T<sub>n</sub>, {}) → T <: (T<sub>1</sub>,
…, | |
| 7299 * T<sub>n</sub>) → T.</i><br> | |
| 7300 * <i>(T<sub>1</sub>, …, T<sub>n</sub>) → T <: (T<sub>1</sub>, &he
llip;, | |
| 7301 * T<sub>n</sub>, []) → T.</i> | |
| 7302 * | |
| 7303 * All functions implement the class `Function`. However not all function type
s are a | |
| 7304 * subtype of `Function`. If an interface type <i>I</i> includes a method name
d | |
| 7305 * `call()`, and the type of `call()` is the function type <i>F</i>, then <i>I
</i> is | |
| 7306 * considered to be a subtype of <i>F</i>. | |
| 7307 * | |
| 7308 * @param type the type being compared with this type | |
| 7309 * @return `true` if this type is a subtype of the given type | |
| 7310 */ | |
| 7311 bool isSubtypeOf(Type2 type); | |
| 7312 | |
| 7313 /** | |
| 7314 * Return the type resulting from substituting the given arguments for this ty
pe's parameters. | |
| 7315 * This is fully equivalent to `substitute(argumentTypes, getTypeArguments())`
. | |
| 7316 * | |
| 7317 * @param argumentTypes the actual type arguments being substituted for the ty
pe parameters | |
| 7318 * @return the result of performing the substitution | |
| 7319 */ | |
| 7320 FunctionType substitute3(List<Type2> argumentTypes); | |
| 7321 FunctionType substitute2(List<Type2> argumentTypes, List<Type2> parameterTypes
); | |
| 7322 } | |
| 7323 /** | |
| 7324 * The interface `InterfaceType` defines the behavior common to objects represen
ting the type | |
| 7325 * introduced by either a class or an interface, or a reference to such a type. | |
| 7326 * | |
| 7327 * @coverage dart.engine.type | |
| 7328 */ | |
| 7329 abstract class InterfaceType implements ParameterizedType { | |
| 7330 | |
| 7331 /** | |
| 7332 * Return an array containing all of the accessors (getters and setters) decla
red in this type. | |
| 7333 * | |
| 7334 * @return the accessors declared in this type | |
| 7335 */ | |
| 7336 List<PropertyAccessorElement> get accessors; | |
| 7337 ClassElement get element; | |
| 7338 | |
| 7339 /** | |
| 7340 * Return the element representing the getter with the given name that is decl
ared in this class, | |
| 7341 * or `null` if this class does not declare a getter with the given name. | |
| 7342 * | |
| 7343 * @param getterName the name of the getter to be returned | |
| 7344 * @return the getter declared in this class with the given name | |
| 7345 */ | |
| 7346 PropertyAccessorElement getGetter(String getterName); | |
| 7347 | |
| 7348 /** | |
| 7349 * Return an array containing all of the interfaces that are implemented by th
is interface. Note | |
| 7350 * that this is <b>not</b>, in general, equivalent to getting the interfaces f
rom this type's | |
| 7351 * element because the types returned by this method will have had their type
parameters replaced. | |
| 7352 * | |
| 7353 * @return the interfaces that are implemented by this type | |
| 7354 */ | |
| 7355 List<InterfaceType> get interfaces; | |
| 7356 | |
| 7357 /** | |
| 7358 * Return the least upper bound of this type and the given type, or `null` if
there is no | |
| 7359 * least upper bound. | |
| 7360 * | |
| 7361 * Given two interfaces <i>I</i> and <i>J</i>, let <i>S<sub>I</sub></i> be the
set of | |
| 7362 * superinterfaces of <i>I<i>, let <i>S<sub>J</sub></i> be the set of superint
erfaces of <i>J</i> | |
| 7363 * and let <i>S = (I ∪ S<sub>I</sub>) ∩ (J ∪ S<sub>J</sub>)</i>. F
urthermore, we | |
| 7364 * define <i>S<sub>n</sub> = {T | T ∈ S ∧ depth(T) = n}</i> for any f
inite <i>n</i>, | |
| 7365 * where <i>depth(T)</i> is the number of steps in the longest inheritance pat
h from <i>T</i> to | |
| 7366 * <i>Object</i>. Let <i>q</i> be the largest number such that <i>S<sub>q</sub
></i> has | |
| 7367 * cardinality one. The least upper bound of <i>I</i> and <i>J</i> is the sole
element of | |
| 7368 * <i>S<sub>q</sub></i>. | |
| 7369 * | |
| 7370 * @param type the other type used to compute the least upper bound | |
| 7371 * @return the least upper bound of this type and the given type | |
| 7372 */ | |
| 7373 Type2 getLeastUpperBound(Type2 type); | |
| 7374 | |
| 7375 /** | |
| 7376 * Return the element representing the method with the given name that is decl
ared in this class, | |
| 7377 * or `null` if this class does not declare a method with the given name. | |
| 7378 * | |
| 7379 * @param methodName the name of the method to be returned | |
| 7380 * @return the method declared in this class with the given name | |
| 7381 */ | |
| 7382 MethodElement getMethod(String methodName); | |
| 7383 | |
| 7384 /** | |
| 7385 * Return an array containing all of the methods declared in this type. | |
| 7386 * | |
| 7387 * @return the methods declared in this type | |
| 7388 */ | |
| 7389 List<MethodElement> get methods; | |
| 7390 | |
| 7391 /** | |
| 7392 * Return an array containing all of the mixins that are applied to the class
being extended in | |
| 7393 * order to derive the superclass of this class. Note that this is <b>not</b>,
in general, | |
| 7394 * equivalent to getting the mixins from this type's element because the types
returned by this | |
| 7395 * method will have had their type parameters replaced. | |
| 7396 * | |
| 7397 * @return the mixins that are applied to derive the superclass of this class | |
| 7398 */ | |
| 7399 List<InterfaceType> get mixins; | |
| 7400 | |
| 7401 /** | |
| 7402 * Return the element representing the setter with the given name that is decl
ared in this class, | |
| 7403 * or `null` if this class does not declare a setter with the given name. | |
| 7404 * | |
| 7405 * @param setterName the name of the setter to be returned | |
| 7406 * @return the setter declared in this class with the given name | |
| 7407 */ | |
| 7408 PropertyAccessorElement getSetter(String setterName); | |
| 7409 | |
| 7410 /** | |
| 7411 * Return the type representing the superclass of this type, or null if this t
ype represents the | |
| 7412 * class 'Object'. Note that this is <b>not</b>, in general, equivalent to get
ting the superclass | |
| 7413 * from this type's element because the type returned by this method will have
had it's type | |
| 7414 * parameters replaced. | |
| 7415 * | |
| 7416 * @return the superclass of this type | |
| 7417 */ | |
| 7418 InterfaceType get superclass; | |
| 7419 | |
| 7420 /** | |
| 7421 * Return `true` if this type is a direct supertype of the given type. The imp
licit | |
| 7422 * interface of class <i>I</i> is a direct supertype of the implicit interface
of class <i>J</i> | |
| 7423 * iff: | |
| 7424 * | |
| 7425 * * <i>I</i> is Object, and <i>J</i> has no extends clause. | |
| 7426 * * <i>I</i> is listed in the extends clause of <i>J</i>. | |
| 7427 * * <i>I</i> is listed in the implements clause of <i>J</i>. | |
| 7428 * * <i>I</i> is listed in the with clause of <i>J</i>. | |
| 7429 * * <i>J</i> is a mixin application of the mixin of <i>I</i>. | |
| 7430 * | |
| 7431 * | |
| 7432 * @param type the type being compared with this type | |
| 7433 * @return `true` if this type is a direct supertype of the given type | |
| 7434 */ | |
| 7435 bool isDirectSupertypeOf(InterfaceType type); | |
| 7436 | |
| 7437 /** | |
| 7438 * Return `true` if this type is more specific than the given type. An interfa
ce type | |
| 7439 * <i>T</i> is more specific than an interface type <i>S</i>, written <i>T &la
quo; S</i>, if one | |
| 7440 * of the following conditions is met: | |
| 7441 * | |
| 7442 * * Reflexivity: <i>T</i> is <i>S</i>. | |
| 7443 * * <i>T</i> is bottom. | |
| 7444 * * <i>S</i> is dynamic. | |
| 7445 * * Direct supertype: <i>S</i> is a direct supertype of <i>T</i>. | |
| 7446 * * <i>T</i> is a type parameter and <i>S</i> is the upper bound of <i>T</i>. | |
| 7447 * * Covariance: <i>T</i> is of the form <i>I<T<sub>1</sub>, …, T<su
b>n</sub>></i> | |
| 7448 * and S</i> is of the form <i>I<S<sub>1</sub>, …, S<sub>n</sub>>
</i> and | |
| 7449 * <i>T<sub>i</sub> « S<sub>i</sub></i>, <i>1 <= i <= n</i>. | |
| 7450 * * Transitivity: <i>T « U</i> and <i>U « S</i>. | |
| 7451 * | |
| 7452 * | |
| 7453 * @param type the type being compared with this type | |
| 7454 * @return `true` if this type is more specific than the given type | |
| 7455 */ | |
| 7456 bool isMoreSpecificThan(Type2 type); | |
| 7457 | |
| 7458 /** | |
| 7459 * Return `true` if this type is a subtype of the given type. An interface typ
e <i>T</i> is | |
| 7460 * a subtype of an interface type <i>S</i>, written <i>T</i> <: <i>S</i>, iff | |
| 7461 * <i>[bottom/dynamic]T</i> « <i>S</i> (<i>T</i> is more specific than <
i>S</i>). If an | |
| 7462 * interface type <i>I</i> includes a method named <i>call()</i>, and the type
of <i>call()</i> is | |
| 7463 * the function type <i>F</i>, then <i>I</i> is considered to be a subtype of
<i>F</i>. | |
| 7464 * | |
| 7465 * @param type the type being compared with this type | |
| 7466 * @return `true` if this type is a subtype of the given type | |
| 7467 */ | |
| 7468 bool isSubtypeOf(Type2 type); | |
| 7469 | |
| 7470 /** | |
| 7471 * Return the element representing the constructor that results from looking u
p the given | |
| 7472 * constructor in this class with respect to the given library, or `null` if t
he look up | |
| 7473 * fails. The behavior of this method is defined by the Dart Language Specific
ation in section | |
| 7474 * 12.11.1: <blockquote>If <i>e</i> is of the form <b>new</b> <i>T.id()</i> th
en let <i>q<i> be | |
| 7475 * the constructor <i>T.id</i>, otherwise let <i>q<i> be the constructor <i>T<
i>. Otherwise, if | |
| 7476 * <i>q</i> is not defined or not accessible, a NoSuchMethodException is throw
n. </blockquote> | |
| 7477 * | |
| 7478 * @param constructorName the name of the constructor being looked up | |
| 7479 * @param library the library with respect to which the lookup is being perfor
med | |
| 7480 * @return the result of looking up the given constructor in this class with r
espect to the given | |
| 7481 * library | |
| 7482 */ | |
| 7483 ConstructorElement lookUpConstructor(String constructorName, LibraryElement li
brary); | |
| 7484 | |
| 7485 /** | |
| 7486 * Return the element representing the getter that results from looking up the
given getter in | |
| 7487 * this class with respect to the given library, or `null` if the look up fail
s. The | |
| 7488 * behavior of this method is defined by the Dart Language Specification in se
ction 12.15.1: | |
| 7489 * <blockquote>The result of looking up getter (respectively setter) <i>m</i>
in class <i>C</i> | |
| 7490 * with respect to library <i>L</i> is: | |
| 7491 * | |
| 7492 * * If <i>C</i> declares an instance getter (respectively setter) named <i>m<
/i> that is | |
| 7493 * accessible to <i>L</i>, then that getter (respectively setter) is the resul
t of the lookup. | |
| 7494 * Otherwise, if <i>C</i> has a superclass <i>S</i>, then the result of the lo
okup is the result | |
| 7495 * of looking up getter (respectively setter) <i>m</i> in <i>S</i> with respec
t to <i>L</i>. | |
| 7496 * Otherwise, we say that the lookup has failed. | |
| 7497 * | |
| 7498 * </blockquote> | |
| 7499 * | |
| 7500 * @param getterName the name of the getter being looked up | |
| 7501 * @param library the library with respect to which the lookup is being perfor
med | |
| 7502 * @return the result of looking up the given getter in this class with respec
t to the given | |
| 7503 * library | |
| 7504 */ | |
| 7505 PropertyAccessorElement lookUpGetter(String getterName, LibraryElement library
); | |
| 7506 | |
| 7507 /** | |
| 7508 * Return the element representing the getter that results from looking up the
given getter in the | |
| 7509 * superclass of this class with respect to the given library, or `null` if th
e look up | |
| 7510 * fails. The behavior of this method is defined by the Dart Language Specific
ation in section | |
| 7511 * 12.15.1: <blockquote>The result of looking up getter (respectively setter)
<i>m</i> in class | |
| 7512 * <i>C</i> with respect to library <i>L</i> is: | |
| 7513 * | |
| 7514 * * If <i>C</i> declares an instance getter (respectively setter) named <i>m<
/i> that is | |
| 7515 * accessible to <i>L</i>, then that getter (respectively setter) is the resul
t of the lookup. | |
| 7516 * Otherwise, if <i>C</i> has a superclass <i>S</i>, then the result of the lo
okup is the result | |
| 7517 * of looking up getter (respectively setter) <i>m</i> in <i>S</i> with respec
t to <i>L</i>. | |
| 7518 * Otherwise, we say that the lookup has failed. | |
| 7519 * | |
| 7520 * </blockquote> | |
| 7521 * | |
| 7522 * @param getterName the name of the getter being looked up | |
| 7523 * @param library the library with respect to which the lookup is being perfor
med | |
| 7524 * @return the result of looking up the given getter in this class with respec
t to the given | |
| 7525 * library | |
| 7526 */ | |
| 7527 PropertyAccessorElement lookUpGetterInSuperclass(String getterName, LibraryEle
ment library); | |
| 7528 | |
| 7529 /** | |
| 7530 * Return the element representing the method that results from looking up the
given method in | |
| 7531 * this class with respect to the given library, or `null` if the look up fail
s. The | |
| 7532 * behavior of this method is defined by the Dart Language Specification in se
ction 12.15.1: | |
| 7533 * <blockquote> The result of looking up method <i>m</i> in class <i>C</i> wit
h respect to library | |
| 7534 * <i>L</i> is: | |
| 7535 * | |
| 7536 * * If <i>C</i> declares an instance method named <i>m</i> that is accessible
to <i>L</i>, then | |
| 7537 * that method is the result of the lookup. Otherwise, if <i>C</i> has a super
class <i>S</i>, then | |
| 7538 * the result of the lookup is the result of looking up method <i>m</i> in <i>
S</i> with respect | |
| 7539 * to <i>L</i>. Otherwise, we say that the lookup has failed. | |
| 7540 * | |
| 7541 * </blockquote> | |
| 7542 * | |
| 7543 * @param methodName the name of the method being looked up | |
| 7544 * @param library the library with respect to which the lookup is being perfor
med | |
| 7545 * @return the result of looking up the given method in this class with respec
t to the given | |
| 7546 * library | |
| 7547 */ | |
| 7548 MethodElement lookUpMethod(String methodName, LibraryElement library); | |
| 7549 | |
| 7550 /** | |
| 7551 * Return the element representing the method that results from looking up the
given method in the | |
| 7552 * superclass of this class with respect to the given library, or `null` if th
e look up | |
| 7553 * fails. The behavior of this method is defined by the Dart Language Specific
ation in section | |
| 7554 * 12.15.1: <blockquote> The result of looking up method <i>m</i> in class <i>
C</i> with respect | |
| 7555 * to library <i>L</i> is: | |
| 7556 * | |
| 7557 * * If <i>C</i> declares an instance method named <i>m</i> that is accessible
to <i>L</i>, then | |
| 7558 * that method is the result of the lookup. Otherwise, if <i>C</i> has a super
class <i>S</i>, then | |
| 7559 * the result of the lookup is the result of looking up method <i>m</i> in <i>
S</i> with respect | |
| 7560 * to <i>L</i>. Otherwise, we say that the lookup has failed. | |
| 7561 * | |
| 7562 * </blockquote> | |
| 7563 * | |
| 7564 * @param methodName the name of the method being looked up | |
| 7565 * @param library the library with respect to which the lookup is being perfor
med | |
| 7566 * @return the result of looking up the given method in this class with respec
t to the given | |
| 7567 * library | |
| 7568 */ | |
| 7569 MethodElement lookUpMethodInSuperclass(String methodName, LibraryElement libra
ry); | |
| 7570 | |
| 7571 /** | |
| 7572 * Return the element representing the setter that results from looking up the
given setter in | |
| 7573 * this class with respect to the given library, or `null` if the look up fail
s. The | |
| 7574 * behavior of this method is defined by the Dart Language Specification in se
ction 12.16: | |
| 7575 * <blockquote> The result of looking up getter (respectively setter) <i>m</i>
in class <i>C</i> | |
| 7576 * with respect to library <i>L</i> is: | |
| 7577 * | |
| 7578 * * If <i>C</i> declares an instance getter (respectively setter) named <i>m<
/i> that is | |
| 7579 * accessible to <i>L</i>, then that getter (respectively setter) is the resul
t of the lookup. | |
| 7580 * Otherwise, if <i>C</i> has a superclass <i>S</i>, then the result of the lo
okup is the result | |
| 7581 * of looking up getter (respectively setter) <i>m</i> in <i>S</i> with respec
t to <i>L</i>. | |
| 7582 * Otherwise, we say that the lookup has failed. | |
| 7583 * | |
| 7584 * </blockquote> | |
| 7585 * | |
| 7586 * @param setterName the name of the setter being looked up | |
| 7587 * @param library the library with respect to which the lookup is being perfor
med | |
| 7588 * @return the result of looking up the given setter in this class with respec
t to the given | |
| 7589 * library | |
| 7590 */ | |
| 7591 PropertyAccessorElement lookUpSetter(String setterName, LibraryElement library
); | |
| 7592 | |
| 7593 /** | |
| 7594 * Return the element representing the setter that results from looking up the
given setter in the | |
| 7595 * superclass of this class with respect to the given library, or `null` if th
e look up | |
| 7596 * fails. The behavior of this method is defined by the Dart Language Specific
ation in section | |
| 7597 * 12.16: <blockquote> The result of looking up getter (respectively setter) <
i>m</i> in class | |
| 7598 * <i>C</i> with respect to library <i>L</i> is: | |
| 7599 * | |
| 7600 * * If <i>C</i> declares an instance getter (respectively setter) named <i>m<
/i> that is | |
| 7601 * accessible to <i>L</i>, then that getter (respectively setter) is the resul
t of the lookup. | |
| 7602 * Otherwise, if <i>C</i> has a superclass <i>S</i>, then the result of the lo
okup is the result | |
| 7603 * of looking up getter (respectively setter) <i>m</i> in <i>S</i> with respec
t to <i>L</i>. | |
| 7604 * Otherwise, we say that the lookup has failed. | |
| 7605 * | |
| 7606 * </blockquote> | |
| 7607 * | |
| 7608 * @param setterName the name of the setter being looked up | |
| 7609 * @param library the library with respect to which the lookup is being perfor
med | |
| 7610 * @return the result of looking up the given setter in this class with respec
t to the given | |
| 7611 * library | |
| 7612 */ | |
| 7613 PropertyAccessorElement lookUpSetterInSuperclass(String setterName, LibraryEle
ment library); | |
| 7614 | |
| 7615 /** | |
| 7616 * Return the type resulting from substituting the given arguments for this ty
pe's parameters. | |
| 7617 * This is fully equivalent to `substitute(argumentTypes, getTypeArguments())`
. | |
| 7618 * | |
| 7619 * @param argumentTypes the actual type arguments being substituted for the ty
pe parameters | |
| 7620 * @return the result of performing the substitution | |
| 7621 */ | |
| 7622 InterfaceType substitute4(List<Type2> argumentTypes); | |
| 7623 InterfaceType substitute2(List<Type2> argumentTypes, List<Type2> parameterType
s); | |
| 7624 } | |
| 7625 /** | |
| 7626 * The interface `ParameterizedType` defines the behavior common to objects repr
esenting a | |
| 7627 * type with type parameters, such as a class or function type alias. | |
| 7628 * | |
| 7629 * @coverage dart.engine.type | |
| 7630 */ | |
| 7631 abstract class ParameterizedType implements Type2 { | |
| 7632 | |
| 7633 /** | |
| 7634 * Return an array containing the actual types of the type arguments. If this
type's element does | |
| 7635 * not have type parameters, then the array should be empty (although it is po
ssible for type | |
| 7636 * arguments to be erroneously declared). If the element has type parameters a
nd the actual type | |
| 7637 * does not explicitly include argument values, then the type "dynamic" will b
e automatically | |
| 7638 * provided. | |
| 7639 * | |
| 7640 * @return the actual types of the type arguments | |
| 7641 */ | |
| 7642 List<Type2> get typeArguments; | |
| 7643 | |
| 7644 /** | |
| 7645 * Return an array containing all of the type parameters declared for this typ
e. | |
| 7646 * | |
| 7647 * @return the type parameters declared for this type | |
| 7648 */ | |
| 7649 List<TypeParameterElement> get typeParameters; | |
| 7650 } | |
| 7651 /** | |
| 7652 * The interface `Type` defines the behavior of objects representing the declare
d type of | |
| 7653 * elements in the element model. | |
| 7654 * | |
| 7655 * @coverage dart.engine.type | |
| 7656 */ | |
| 7657 abstract class Type2 { | |
| 7658 | |
| 7659 /** | |
| 7660 * Return the name of this type as it should appear when presented to users in
contexts such as | |
| 7661 * error messages. | |
| 7662 * | |
| 7663 * @return the name of this type | |
| 7664 */ | |
| 7665 String get displayName; | |
| 7666 | |
| 7667 /** | |
| 7668 * Return the element representing the declaration of this type, or `null` if
the type has | |
| 7669 * not, or cannot, be associated with an element. The former case will occur i
f the element model | |
| 7670 * is not yet complete; the latter case will occur if this object represents a
n undefined type. | |
| 7671 * | |
| 7672 * @return the element representing the declaration of this type | |
| 7673 */ | |
| 7674 Element get element; | |
| 7675 | |
| 7676 /** | |
| 7677 * Return the least upper bound of this type and the given type, or `null` if
there is no | |
| 7678 * least upper bound. | |
| 7679 * | |
| 7680 * @param type the other type used to compute the least upper bound | |
| 7681 * @return the least upper bound of this type and the given type | |
| 7682 */ | |
| 7683 Type2 getLeastUpperBound(Type2 type); | |
| 7684 | |
| 7685 /** | |
| 7686 * Return the name of this type, or `null` if the type does not have a name, s
uch as when | |
| 7687 * the type represents the type of an unnamed function. | |
| 7688 * | |
| 7689 * @return the name of this type | |
| 7690 */ | |
| 7691 String get name; | |
| 7692 | |
| 7693 /** | |
| 7694 * Return `true` if this type is assignable to the given type. A type <i>T</i>
may be | |
| 7695 * assigned to a type <i>S</i>, written <i>T</i> ⇔ <i>S</i>, iff either <
i>T</i> <: <i>S</i> | |
| 7696 * or <i>S</i> <: <i>T</i>. | |
| 7697 * | |
| 7698 * @param type the type being compared with this type | |
| 7699 * @return `true` if this type is assignable to the given type | |
| 7700 */ | |
| 7701 bool isAssignableTo(Type2 type); | |
| 7702 | |
| 7703 /** | |
| 7704 * Return `true` if this type represents the bottom type. | |
| 7705 * | |
| 7706 * @return `true` if this type represents the bottom type | |
| 7707 */ | |
| 7708 bool get isBottom; | |
| 7709 | |
| 7710 /** | |
| 7711 * Return `true` if this type represents the type 'Function' defined in the da
rt:core | |
| 7712 * library. | |
| 7713 * | |
| 7714 * @return `true` if this type represents the type 'Function' defined in the d
art:core | |
| 7715 * library | |
| 7716 */ | |
| 7717 bool get isDartCoreFunction; | |
| 7718 | |
| 7719 /** | |
| 7720 * Return `true` if this type represents the type 'dynamic'. | |
| 7721 * | |
| 7722 * @return `true` if this type represents the type 'dynamic' | |
| 7723 */ | |
| 7724 bool get isDynamic; | |
| 7725 | |
| 7726 /** | |
| 7727 * Return `true` if this type is more specific than the given type. | |
| 7728 * | |
| 7729 * @param type the type being compared with this type | |
| 7730 * @return `true` if this type is more specific than the given type | |
| 7731 */ | |
| 7732 bool isMoreSpecificThan(Type2 type); | |
| 7733 | |
| 7734 /** | |
| 7735 * Return `true` if this type represents the type 'Object'. | |
| 7736 * | |
| 7737 * @return `true` if this type represents the type 'Object' | |
| 7738 */ | |
| 7739 bool get isObject; | |
| 7740 | |
| 7741 /** | |
| 7742 * Return `true` if this type is a subtype of the given type. | |
| 7743 * | |
| 7744 * @param type the type being compared with this type | |
| 7745 * @return `true` if this type is a subtype of the given type | |
| 7746 */ | |
| 7747 bool isSubtypeOf(Type2 type); | |
| 7748 | |
| 7749 /** | |
| 7750 * Return `true` if this type is a supertype of the given type. A type <i>S</i
> is a | |
| 7751 * supertype of <i>T</i>, written <i>S</i> :> <i>T</i>, iff <i>T</i> is a subt
ype of <i>S</i>. | |
| 7752 * | |
| 7753 * @param type the type being compared with this type | |
| 7754 * @return `true` if this type is a supertype of the given type | |
| 7755 */ | |
| 7756 bool isSupertypeOf(Type2 type); | |
| 7757 | |
| 7758 /** | |
| 7759 * Return `true` if this type represents the type 'void'. | |
| 7760 * | |
| 7761 * @return `true` if this type represents the type 'void' | |
| 7762 */ | |
| 7763 bool get isVoid; | |
| 7764 | |
| 7765 /** | |
| 7766 * Return the type resulting from substituting the given arguments for the giv
en parameters in | |
| 7767 * this type. The specification defines this operation in section 2: <blockquo
te> The notation | |
| 7768 * <i>[x<sub>1</sub>, ..., x<sub>n</sub>/y<sub>1</sub>, ..., y<sub>n</sub>]E</
i> denotes a copy of | |
| 7769 * <i>E</i> in which all occurrences of <i>y<sub>i</sub>, 1 <= i <= n</i> have
been replaced with | |
| 7770 * <i>x<sub>i</sub></i>.</blockquote> Note that, contrary to the specification
, this method will | |
| 7771 * not create a copy of this type if no substitutions were required, but will
return this type | |
| 7772 * directly. | |
| 7773 * | |
| 7774 * @param argumentTypes the actual type arguments being substituted for the pa
rameters | |
| 7775 * @param parameterTypes the parameters to be replaced | |
| 7776 * @return the result of performing the substitution | |
| 7777 */ | |
| 7778 Type2 substitute2(List<Type2> argumentTypes, List<Type2> parameterTypes); | |
| 7779 } | |
| 7780 /** | |
| 7781 * The interface `TypeParameterType` defines the behavior of objects representin
g the type | |
| 7782 * introduced by a type parameter. | |
| 7783 * | |
| 7784 * @coverage dart.engine.type | |
| 7785 */ | |
| 7786 abstract class TypeParameterType implements Type2 { | |
| 7787 TypeParameterElement get element; | |
| 7788 } | |
| 7789 /** | |
| 7790 * The interface `VoidType` defines the behavior of the unique object representi
ng the type | |
| 7791 * `void`. | |
| 7792 * | |
| 7793 * @coverage dart.engine.type | |
| 7794 */ | |
| 7795 abstract class VoidType implements Type2 { | |
| 7796 VoidType substitute2(List<Type2> argumentTypes, List<Type2> parameterTypes); | |
| 7797 } | |
| OLD | NEW |