Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.src.dart.element.element; | 5 library analyzer.src.dart.element.element; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:math' show min; | 8 import 'dart:math' show min; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 /** | 55 /** |
| 56 * Initialize a newly created pair to have both the [staticElement] and the | 56 * Initialize a newly created pair to have both the [staticElement] and the |
| 57 * [propagatedElement]. | 57 * [propagatedElement]. |
| 58 */ | 58 */ |
| 59 AuxiliaryElements(this.staticElement, this.propagatedElement); | 59 AuxiliaryElements(this.staticElement, this.propagatedElement); |
| 60 } | 60 } |
| 61 | 61 |
| 62 /** | 62 /** |
| 63 * A concrete implementation of a [ClassElement]. | 63 * A concrete implementation of a [ClassElement]. |
| 64 */ | 64 */ |
| 65 class ClassElementImpl extends ElementImpl | 65 abstract class ClassElementImpl extends ElementImpl |
|
Brian Wilkerson
2016/06/01 14:08:30
I'll just note that this is a breaking change. I d
Paul Berry
2016/06/01 17:33:14
As discussed in person, I'm ok with making this ch
| |
| 66 with TypeParameterizedElementMixin | 66 with TypeParameterizedElementMixin |
| 67 implements ClassElement { | 67 implements ClassElement { |
| 68 /** | 68 /** |
| 69 * The unlinked representation of the class in the summary. | |
| 70 */ | |
| 71 final UnlinkedClass _unlinkedClass; | |
| 72 | |
| 73 /** | |
| 74 * A list containing all of the accessors (getters and setters) contained in | 69 * A list containing all of the accessors (getters and setters) contained in |
| 75 * this class. | 70 * this class. |
| 76 */ | 71 */ |
| 77 List<PropertyAccessorElement> _accessors = PropertyAccessorElement.EMPTY_LIST; | 72 List<PropertyAccessorElement> _accessors = PropertyAccessorElement.EMPTY_LIST; |
| 78 | 73 |
| 79 /** | 74 /** |
| 80 * For classes which are not mixin applications, a list containing all of the | 75 * For classes which are not mixin applications, a list containing all of the |
| 81 * constructors contained in this class, or `null` if the list of | 76 * constructors contained in this class, or `null` if the list of |
| 82 * constructors has not yet been built. | 77 * constructors has not yet been built. |
| 83 * | 78 * |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 /** | 124 /** |
| 130 * A flag indicating whether the types associated with the instance members of | 125 * A flag indicating whether the types associated with the instance members of |
| 131 * this class have been inferred. | 126 * this class have been inferred. |
| 132 */ | 127 */ |
| 133 bool hasBeenInferred = false; | 128 bool hasBeenInferred = false; |
| 134 | 129 |
| 135 /** | 130 /** |
| 136 * Initialize a newly created class element to have the given [name] at the | 131 * Initialize a newly created class element to have the given [name] at the |
| 137 * given [offset] in the file that contains the declaration of this element. | 132 * given [offset] in the file that contains the declaration of this element. |
| 138 */ | 133 */ |
| 139 ClassElementImpl(String name, int offset) | 134 ClassElementImpl(String name, int offset) : super(name, offset); |
| 140 : _unlinkedClass = null, | |
| 141 super(name, offset); | |
| 142 | 135 |
| 143 /** | 136 /** |
| 144 * Initialize a newly created class element to have the given [name]. | 137 * Initialize a newly created class element to have the given [name]. |
| 145 */ | 138 */ |
| 146 ClassElementImpl.forNode(Identifier name) | 139 ClassElementImpl.forNode(Identifier name) : super.forNode(name); |
|
Paul Berry
2016/06/01 17:33:13
As a side note, we could reduce the impact of this
| |
| 147 : _unlinkedClass = null, | |
| 148 super.forNode(name); | |
| 149 | 140 |
| 150 /** | 141 /** |
| 151 * Initialize using the given serialized information. | 142 * Initialize using the given serialized information. |
| 152 */ | 143 */ |
| 153 ClassElementImpl.forSerialized( | 144 ClassElementImpl.forSerialized(CompilationUnitElementImpl enclosingUnit) |
| 154 this._unlinkedClass, CompilationUnitElementImpl enclosingUnit) | |
| 155 : super.forSerialized(enclosingUnit); | 145 : super.forSerialized(enclosingUnit); |
| 156 | 146 |
| 157 /** | 147 /** |
| 158 * Set whether this class is abstract. | 148 * Set whether this class is abstract. |
| 159 */ | 149 */ |
| 160 void set abstract(bool isAbstract) { | 150 void set abstract(bool isAbstract) { |
| 161 assert(_unlinkedClass == null); | |
| 162 setModifier(Modifier.ABSTRACT, isAbstract); | 151 setModifier(Modifier.ABSTRACT, isAbstract); |
| 163 } | 152 } |
| 164 | 153 |
| 165 @override | 154 @override |
| 166 List<PropertyAccessorElement> get accessors => _accessors; | 155 List<PropertyAccessorElement> get accessors => _accessors; |
| 167 | 156 |
| 168 /** | 157 /** |
| 169 * Set the accessors contained in this class to the given [accessors]. | 158 * Set the accessors contained in this class to the given [accessors]. |
| 170 */ | 159 */ |
| 171 void set accessors(List<PropertyAccessorElement> accessors) { | 160 void set accessors(List<PropertyAccessorElement> accessors) { |
| 172 for (PropertyAccessorElement accessor in accessors) { | 161 for (PropertyAccessorElement accessor in accessors) { |
| 173 (accessor as PropertyAccessorElementImpl).enclosingElement = this; | 162 (accessor as PropertyAccessorElementImpl).enclosingElement = this; |
| 174 } | 163 } |
| 175 this._accessors = accessors; | 164 this._accessors = accessors; |
| 176 } | 165 } |
| 177 | 166 |
| 178 @override | 167 @override |
| 179 List<InterfaceType> get allSupertypes { | 168 List<InterfaceType> get allSupertypes { |
| 180 List<InterfaceType> list = new List<InterfaceType>(); | 169 List<InterfaceType> list = new List<InterfaceType>(); |
| 181 _collectAllSupertypes(list); | 170 _collectAllSupertypes(list); |
| 182 return list; | 171 return list; |
| 183 } | 172 } |
| 184 | 173 |
| 185 @override | 174 @override |
| 186 int get codeLength { | |
| 187 if (_unlinkedClass != null) { | |
| 188 return _unlinkedClass.codeRange?.length; | |
| 189 } | |
| 190 return super.codeLength; | |
| 191 } | |
| 192 | |
| 193 @override | |
| 194 int get codeOffset { | |
| 195 if (_unlinkedClass != null) { | |
| 196 return _unlinkedClass.codeRange?.offset; | |
| 197 } | |
| 198 return super.codeOffset; | |
| 199 } | |
| 200 | |
| 201 @override | |
| 202 List<ConstructorElement> get constructors { | 175 List<ConstructorElement> get constructors { |
| 203 if (!isMixinApplication) { | 176 if (!isMixinApplication) { |
| 204 assert(_constructors != null); | 177 assert(_constructors != null); |
| 205 return _constructors ?? ConstructorElement.EMPTY_LIST; | 178 return _constructors ?? ConstructorElement.EMPTY_LIST; |
| 206 } | 179 } |
| 207 return _computeMixinAppConstructors(); | 180 return _computeMixinAppConstructors(); |
| 208 } | 181 } |
| 209 | 182 |
| 210 /** | 183 /** |
| 211 * Set the constructors contained in this class to the given [constructors]. | 184 * Set the constructors contained in this class to the given [constructors]. |
| 212 * | 185 * |
| 213 * Should only be used for class elements that are not mixin applications. | 186 * Should only be used for class elements that are not mixin applications. |
| 214 */ | 187 */ |
| 215 void set constructors(List<ConstructorElement> constructors) { | 188 void set constructors(List<ConstructorElement> constructors) { |
| 216 assert(!isMixinApplication); | 189 assert(!isMixinApplication); |
| 217 for (ConstructorElement constructor in constructors) { | 190 for (ConstructorElement constructor in constructors) { |
| 218 (constructor as ConstructorElementImpl).enclosingElement = this; | 191 (constructor as ConstructorElementImpl).enclosingElement = this; |
| 219 } | 192 } |
| 220 this._constructors = constructors; | 193 this._constructors = constructors; |
| 221 } | 194 } |
| 222 | 195 |
| 223 @override | 196 @override |
| 224 String get displayName => name; | 197 String get displayName => name; |
| 225 | 198 |
| 226 @override | |
| 227 SourceRange get docRange { | |
| 228 if (_unlinkedClass != null) { | |
| 229 UnlinkedDocumentationComment comment = | |
| 230 _unlinkedClass.documentationComment; | |
| 231 return comment != null | |
| 232 ? new SourceRange(comment.offset, comment.length) | |
| 233 : null; | |
| 234 } | |
| 235 return super.docRange; | |
| 236 } | |
| 237 | |
| 238 @override | |
| 239 String get documentationComment { | |
| 240 if (_unlinkedClass != null) { | |
| 241 return _unlinkedClass?.documentationComment?.text; | |
| 242 } | |
| 243 return super.documentationComment; | |
| 244 } | |
| 245 | |
| 246 /** | 199 /** |
| 247 * Return `true` if [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS] should | 200 * Return `true` if [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS] should |
| 248 * be reported for this class. | 201 * be reported for this class. |
| 249 */ | 202 */ |
| 250 bool get doesMixinLackConstructors { | 203 bool get doesMixinLackConstructors { |
| 251 if (!isMixinApplication && mixins.isEmpty) { | 204 if (!isMixinApplication && mixins.isEmpty) { |
| 252 // This class is not a mixin application and it doesn't have a "with" | 205 // This class is not a mixin application and it doesn't have a "with" |
| 253 // clause, so CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS is | 206 // clause, so CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS is |
| 254 // inapplicable. | 207 // inapplicable. |
| 255 return false; | 208 return false; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 283 } | 236 } |
| 284 nearestNonMixinClass = nearestNonMixinClass.supertype.element; | 237 nearestNonMixinClass = nearestNonMixinClass.supertype.element; |
| 285 } | 238 } |
| 286 } | 239 } |
| 287 return !nearestNonMixinClass.constructors.any(isSuperConstructorAccessible); | 240 return !nearestNonMixinClass.constructors.any(isSuperConstructorAccessible); |
| 288 } | 241 } |
| 289 | 242 |
| 290 @override | 243 @override |
| 291 TypeParameterizedElementMixin get enclosingTypeParameterContext => null; | 244 TypeParameterizedElementMixin get enclosingTypeParameterContext => null; |
| 292 | 245 |
| 293 /** | |
| 294 * Set whether this class is defined by an enum declaration. | |
| 295 */ | |
| 296 void set enum2(bool isEnum) { | |
| 297 setModifier(Modifier.ENUM, isEnum); | |
| 298 } | |
| 299 | |
| 300 @override | 246 @override |
| 301 List<FieldElement> get fields => _fields; | 247 List<FieldElement> get fields => _fields; |
| 302 | 248 |
| 303 /** | 249 /** |
| 304 * Set the fields contained in this class to the given [fields]. | 250 * Set the fields contained in this class to the given [fields]. |
| 305 */ | 251 */ |
| 306 void set fields(List<FieldElement> fields) { | 252 void set fields(List<FieldElement> fields) { |
| 307 for (FieldElement field in fields) { | 253 for (FieldElement field in fields) { |
| 308 (field as FieldElementImpl).enclosingElement = this; | 254 (field as FieldElementImpl).enclosingElement = this; |
| 309 } | 255 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 for (PropertyAccessorElement accessor in _accessors) { | 312 for (PropertyAccessorElement accessor in _accessors) { |
| 367 if (accessor.isStatic) { | 313 if (accessor.isStatic) { |
| 368 return true; | 314 return true; |
| 369 } | 315 } |
| 370 } | 316 } |
| 371 return false; | 317 return false; |
| 372 } | 318 } |
| 373 | 319 |
| 374 @override | 320 @override |
| 375 List<InterfaceType> get interfaces { | 321 List<InterfaceType> get interfaces { |
| 376 if (_unlinkedClass != null && _interfaces == null) { | |
| 377 ResynthesizerContext context = enclosingUnit.resynthesizerContext; | |
| 378 _interfaces = _unlinkedClass.interfaces | |
| 379 .map((EntityRef t) => context.resolveTypeRef(t, this)) | |
| 380 .toList(growable: false); | |
| 381 } | |
| 382 return _interfaces ?? const <InterfaceType>[]; | 322 return _interfaces ?? const <InterfaceType>[]; |
| 383 } | 323 } |
| 384 | 324 |
| 385 void set interfaces(List<InterfaceType> interfaces) { | 325 void set interfaces(List<InterfaceType> interfaces) { |
| 386 assert(_unlinkedClass == null); | |
| 387 _interfaces = interfaces; | 326 _interfaces = interfaces; |
| 388 } | 327 } |
| 389 | 328 |
| 390 @override | 329 @override |
| 391 bool get isAbstract { | 330 bool get isAbstract { |
| 392 if (_unlinkedClass != null) { | |
| 393 return _unlinkedClass.isAbstract; | |
| 394 } | |
| 395 return hasModifier(Modifier.ABSTRACT); | 331 return hasModifier(Modifier.ABSTRACT); |
| 396 } | 332 } |
| 397 | 333 |
| 398 @override | 334 @override |
| 399 bool get isEnum => hasModifier(Modifier.ENUM); | 335 bool get isEnum; |
| 400 | 336 |
| 401 @override | 337 @override |
| 402 bool get isMixinApplication { | 338 bool get isMixinApplication { |
| 403 if (_unlinkedClass != null) { | |
| 404 return _unlinkedClass.isMixinApplication; | |
| 405 } | |
| 406 return hasModifier(Modifier.MIXIN_APPLICATION); | 339 return hasModifier(Modifier.MIXIN_APPLICATION); |
|
Brian Wilkerson
2016/06/01 17:29:44
Seems like this (and several other members) ought
| |
| 407 } | 340 } |
| 408 | 341 |
| 409 @override | 342 @override |
| 410 bool get isOrInheritsProxy => | 343 bool get isOrInheritsProxy => |
| 411 _safeIsOrInheritsProxy(this, new HashSet<ClassElement>()); | 344 _safeIsOrInheritsProxy(this, new HashSet<ClassElement>()); |
| 412 | 345 |
| 413 @override | 346 @override |
| 414 bool get isProxy { | 347 bool get isProxy { |
| 415 for (ElementAnnotation annotation in metadata) { | 348 for (ElementAnnotation annotation in metadata) { |
| 416 if (annotation.isProxy) { | 349 if (annotation.isProxy) { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 435 return false; | 368 return false; |
| 436 } | 369 } |
| 437 } | 370 } |
| 438 return true; | 371 return true; |
| 439 } | 372 } |
| 440 | 373 |
| 441 @override | 374 @override |
| 442 ElementKind get kind => ElementKind.CLASS; | 375 ElementKind get kind => ElementKind.CLASS; |
| 443 | 376 |
| 444 @override | 377 @override |
| 445 List<ElementAnnotation> get metadata { | |
| 446 if (_unlinkedClass != null) { | |
| 447 return _metadata ??= | |
| 448 _buildAnnotations(enclosingUnit, _unlinkedClass.annotations); | |
| 449 } | |
| 450 return super.metadata; | |
| 451 } | |
| 452 | |
| 453 @override | |
| 454 List<MethodElement> get methods => _methods; | 378 List<MethodElement> get methods => _methods; |
| 455 | 379 |
| 456 /** | 380 /** |
| 457 * Set the methods contained in this class to the given [methods]. | 381 * Set the methods contained in this class to the given [methods]. |
| 458 */ | 382 */ |
| 459 void set methods(List<MethodElement> methods) { | 383 void set methods(List<MethodElement> methods) { |
| 460 for (MethodElement method in methods) { | 384 for (MethodElement method in methods) { |
| 461 (method as MethodElementImpl).enclosingElement = this; | 385 (method as MethodElementImpl).enclosingElement = this; |
| 462 } | 386 } |
| 463 this._methods = methods; | 387 this._methods = methods; |
| 464 } | 388 } |
| 465 | 389 |
| 466 /** | 390 /** |
| 467 * Set whether this class is a mixin application. | 391 * Set whether this class is a mixin application. |
| 468 */ | 392 */ |
| 469 void set mixinApplication(bool isMixinApplication) { | 393 void set mixinApplication(bool isMixinApplication) { |
| 470 assert(_unlinkedClass == null); | |
| 471 setModifier(Modifier.MIXIN_APPLICATION, isMixinApplication); | 394 setModifier(Modifier.MIXIN_APPLICATION, isMixinApplication); |
| 472 } | 395 } |
| 473 | 396 |
| 474 @override | 397 @override |
| 475 List<InterfaceType> get mixins { | 398 List<InterfaceType> get mixins { |
| 476 if (_unlinkedClass != null && _mixins == null) { | |
| 477 ResynthesizerContext context = enclosingUnit.resynthesizerContext; | |
| 478 _mixins = _unlinkedClass.mixins | |
| 479 .map((EntityRef t) => context.resolveTypeRef(t, this)) | |
| 480 .toList(growable: false); | |
| 481 } | |
| 482 return _mixins ?? const <InterfaceType>[]; | 399 return _mixins ?? const <InterfaceType>[]; |
| 483 } | 400 } |
| 484 | 401 |
| 485 void set mixins(List<InterfaceType> mixins) { | 402 void set mixins(List<InterfaceType> mixins) { |
| 486 assert(_unlinkedClass == null); | |
| 487 _mixins = mixins; | 403 _mixins = mixins; |
| 488 } | 404 } |
| 489 | 405 |
| 490 @override | 406 /** |
| 491 String get name { | 407 * Return resynthesized type parameter elements. |
| 492 if (_unlinkedClass != null) { | 408 */ |
| 493 return _unlinkedClass.name; | 409 List<TypeParameterElement> get resynthesizedTypeParameters { |
| 494 } | 410 return super.typeParameters; |
| 495 return super.name; | |
| 496 } | 411 } |
| 497 | 412 |
| 498 @override | 413 @override |
| 499 int get nameOffset { | |
| 500 if (_unlinkedClass != null) { | |
| 501 return _unlinkedClass.nameOffset; | |
| 502 } | |
| 503 return super.nameOffset; | |
| 504 } | |
| 505 | |
| 506 @override | |
| 507 TypeParameterizedElementMixin get typeParameterContext => this; | 414 TypeParameterizedElementMixin get typeParameterContext => this; |
| 508 | 415 |
| 509 @override | 416 @override |
| 510 List<TypeParameterElement> get typeParameters { | 417 List<TypeParameterElement> get typeParameters { |
| 511 if (_unlinkedClass != null) { | |
| 512 return super.typeParameters; | |
| 513 } | |
| 514 return _typeParameters; | 418 return _typeParameters; |
| 515 } | 419 } |
| 516 | 420 |
| 517 /** | 421 /** |
| 518 * Set the type parameters defined for this class to the given | 422 * Set the type parameters defined for this class to the given |
| 519 * [typeParameters]. | 423 * [typeParameters]. |
| 520 */ | 424 */ |
| 521 void set typeParameters(List<TypeParameterElement> typeParameters) { | 425 void set typeParameters(List<TypeParameterElement> typeParameters) { |
| 522 assert(_unlinkedClass == null); | |
| 523 for (TypeParameterElement typeParameter in typeParameters) { | 426 for (TypeParameterElement typeParameter in typeParameters) { |
| 524 (typeParameter as TypeParameterElementImpl).enclosingElement = this; | 427 (typeParameter as TypeParameterElementImpl).enclosingElement = this; |
| 525 } | 428 } |
| 526 this._typeParameters = typeParameters; | 429 this._typeParameters = typeParameters; |
| 527 } | 430 } |
| 528 | 431 |
| 529 @override | 432 @override |
| 530 List<UnlinkedTypeParam> get unlinkedTypeParams => | 433 List<UnlinkedTypeParam> get unlinkedTypeParams => const <UnlinkedTypeParam>[]; |
| 531 _unlinkedClass.typeParameters; | |
| 532 | 434 |
| 533 @override | 435 @override |
| 534 ConstructorElement get unnamedConstructor { | 436 ConstructorElement get unnamedConstructor { |
| 535 for (ConstructorElement element in constructors) { | 437 for (ConstructorElement element in constructors) { |
| 536 String name = element.displayName; | 438 String name = element.displayName; |
| 537 if (name == null || name.isEmpty) { | 439 if (name == null || name.isEmpty) { |
| 538 return element; | 440 return element; |
| 539 } | 441 } |
| 540 } | 442 } |
| 541 return null; | 443 return null; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 553 buffer.write('enum '); | 455 buffer.write('enum '); |
| 554 } else { | 456 } else { |
| 555 buffer.write('class '); | 457 buffer.write('class '); |
| 556 } | 458 } |
| 557 String name = displayName; | 459 String name = displayName; |
| 558 if (name == null) { | 460 if (name == null) { |
| 559 buffer.write("{unnamed class}"); | 461 buffer.write("{unnamed class}"); |
| 560 } else { | 462 } else { |
| 561 buffer.write(name); | 463 buffer.write(name); |
| 562 } | 464 } |
| 563 int variableCount = _typeParameters.length; | 465 int variableCount = typeParameters.length; |
| 564 if (variableCount > 0) { | 466 if (variableCount > 0) { |
| 565 buffer.write("<"); | 467 buffer.write("<"); |
| 566 for (int i = 0; i < variableCount; i++) { | 468 for (int i = 0; i < variableCount; i++) { |
| 567 if (i > 0) { | 469 if (i > 0) { |
| 568 buffer.write(", "); | 470 buffer.write(", "); |
| 569 } | 471 } |
| 570 (_typeParameters[i] as TypeParameterElementImpl).appendTo(buffer); | 472 (typeParameters[i] as TypeParameterElementImpl).appendTo(buffer); |
| 571 } | 473 } |
| 572 buffer.write(">"); | 474 buffer.write(">"); |
| 573 } | 475 } |
| 574 if (supertype != null && !supertype.isObject) { | 476 if (supertype != null && !supertype.isObject) { |
| 575 buffer.write(' extends '); | 477 buffer.write(' extends '); |
| 576 buffer.write(supertype.displayName); | 478 buffer.write(supertype.displayName); |
| 577 } | 479 } |
| 578 if (mixins.isNotEmpty) { | 480 if (mixins.isNotEmpty) { |
| 579 buffer.write(' with '); | 481 buffer.write(' with '); |
| 580 buffer.write(mixins.map((t) => t.displayName).join(', ')); | 482 buffer.write(mixins.map((t) => t.displayName).join(', ')); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 619 if (fieldImpl.identifier == identifier) { | 521 if (fieldImpl.identifier == identifier) { |
| 620 return fieldImpl; | 522 return fieldImpl; |
| 621 } | 523 } |
| 622 } | 524 } |
| 623 for (MethodElement method in _methods) { | 525 for (MethodElement method in _methods) { |
| 624 MethodElementImpl methodImpl = method; | 526 MethodElementImpl methodImpl = method; |
| 625 if (methodImpl.identifier == identifier) { | 527 if (methodImpl.identifier == identifier) { |
| 626 return methodImpl; | 528 return methodImpl; |
| 627 } | 529 } |
| 628 } | 530 } |
| 629 for (TypeParameterElement typeParameter in _typeParameters) { | 531 for (TypeParameterElement typeParameter in typeParameters) { |
| 630 TypeParameterElementImpl typeParameterImpl = typeParameter; | 532 TypeParameterElementImpl typeParameterImpl = typeParameter; |
| 631 if (typeParameterImpl.identifier == identifier) { | 533 if (typeParameterImpl.identifier == identifier) { |
| 632 return typeParameterImpl; | 534 return typeParameterImpl; |
| 633 } | 535 } |
| 634 } | 536 } |
| 635 return null; | 537 return null; |
| 636 } | 538 } |
| 637 | 539 |
| 638 @override | 540 @override |
| 639 FieldElement getField(String name) { | 541 FieldElement getField(String name) { |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1069 static ClassElementImpl getImpl(ClassElement classElement) { | 971 static ClassElementImpl getImpl(ClassElement classElement) { |
| 1070 if (classElement is ClassElementHandle) { | 972 if (classElement is ClassElementHandle) { |
| 1071 classElement.ensureActualElementComplete(); | 973 classElement.ensureActualElementComplete(); |
| 1072 return getImpl(classElement.actualElement); | 974 return getImpl(classElement.actualElement); |
| 1073 } | 975 } |
| 1074 return classElement as ClassElementImpl; | 976 return classElement as ClassElementImpl; |
| 1075 } | 977 } |
| 1076 } | 978 } |
| 1077 | 979 |
| 1078 /** | 980 /** |
| 981 * A [ClassElementImpl], which is a class. | |
| 982 */ | |
| 983 class ClassElementImpl_Class extends ClassElementImpl { | |
| 984 /** | |
| 985 * The unlinked representation of the class in the summary. | |
| 986 */ | |
| 987 final UnlinkedClass _unlinkedClass; | |
| 988 | |
| 989 /** | |
| 990 * Initialize a newly created class element to have the given [name] at the | |
| 991 * given [offset] in the file that contains the declaration of this element. | |
| 992 */ | |
| 993 ClassElementImpl_Class(String name, int offset) | |
| 994 : _unlinkedClass = null, | |
| 995 super(name, offset); | |
| 996 | |
| 997 /** | |
| 998 * Initialize a newly created class element to have the given [name]. | |
| 999 */ | |
| 1000 ClassElementImpl_Class.forNode(Identifier name) | |
| 1001 : _unlinkedClass = null, | |
| 1002 super.forNode(name); | |
| 1003 | |
| 1004 /** | |
| 1005 * Initialize using the given serialized information. | |
| 1006 */ | |
| 1007 ClassElementImpl_Class.forSerialized( | |
| 1008 this._unlinkedClass, CompilationUnitElementImpl enclosingUnit) | |
| 1009 : super.forSerialized(enclosingUnit); | |
| 1010 | |
| 1011 /** | |
| 1012 * Set whether this class is abstract. | |
| 1013 */ | |
| 1014 void set abstract(bool isAbstract) { | |
| 1015 assert(_unlinkedClass == null); | |
| 1016 super.abstract = isAbstract; | |
| 1017 } | |
| 1018 | |
| 1019 @override | |
| 1020 int get codeLength { | |
| 1021 if (_unlinkedClass != null) { | |
| 1022 return _unlinkedClass.codeRange?.length; | |
| 1023 } | |
| 1024 return super.codeLength; | |
| 1025 } | |
| 1026 | |
| 1027 @override | |
| 1028 int get codeOffset { | |
| 1029 if (_unlinkedClass != null) { | |
| 1030 return _unlinkedClass.codeRange?.offset; | |
| 1031 } | |
| 1032 return super.codeOffset; | |
| 1033 } | |
| 1034 | |
| 1035 @override | |
| 1036 SourceRange get docRange { | |
| 1037 if (_unlinkedClass != null) { | |
| 1038 UnlinkedDocumentationComment comment = | |
| 1039 _unlinkedClass.documentationComment; | |
| 1040 return comment != null | |
| 1041 ? new SourceRange(comment.offset, comment.length) | |
| 1042 : null; | |
| 1043 } | |
| 1044 return super.docRange; | |
| 1045 } | |
| 1046 | |
| 1047 @override | |
| 1048 String get documentationComment { | |
| 1049 if (_unlinkedClass != null) { | |
| 1050 return _unlinkedClass?.documentationComment?.text; | |
| 1051 } | |
| 1052 return super.documentationComment; | |
| 1053 } | |
| 1054 | |
| 1055 @override | |
| 1056 List<InterfaceType> get interfaces { | |
| 1057 if (_unlinkedClass != null && _interfaces == null) { | |
| 1058 ResynthesizerContext context = enclosingUnit.resynthesizerContext; | |
| 1059 _interfaces = _unlinkedClass.interfaces | |
| 1060 .map((EntityRef t) => context.resolveTypeRef(t, this)) | |
| 1061 .toList(growable: false); | |
| 1062 } | |
| 1063 return super.interfaces; | |
| 1064 } | |
| 1065 | |
| 1066 void set interfaces(List<InterfaceType> interfaces) { | |
| 1067 assert(_unlinkedClass == null); | |
| 1068 super.interfaces = interfaces; | |
| 1069 } | |
| 1070 | |
| 1071 @override | |
| 1072 bool get isAbstract { | |
| 1073 if (_unlinkedClass != null) { | |
| 1074 return _unlinkedClass.isAbstract; | |
| 1075 } | |
| 1076 return super.isAbstract; | |
| 1077 } | |
| 1078 | |
| 1079 @override | |
| 1080 bool get isEnum => false; | |
| 1081 | |
| 1082 @override | |
| 1083 bool get isMixinApplication { | |
| 1084 if (_unlinkedClass != null) { | |
| 1085 return _unlinkedClass.isMixinApplication; | |
| 1086 } | |
| 1087 return super.isMixinApplication; | |
| 1088 } | |
| 1089 | |
| 1090 @override | |
| 1091 List<ElementAnnotation> get metadata { | |
| 1092 if (_unlinkedClass != null) { | |
| 1093 return _metadata ??= | |
| 1094 _buildAnnotations(enclosingUnit, _unlinkedClass.annotations); | |
| 1095 } | |
| 1096 return super.metadata; | |
| 1097 } | |
| 1098 | |
| 1099 /** | |
| 1100 * Set whether this class is a mixin application. | |
| 1101 */ | |
| 1102 void set mixinApplication(bool isMixinApplication) { | |
| 1103 assert(_unlinkedClass == null); | |
| 1104 super.mixinApplication = isMixinApplication; | |
| 1105 } | |
| 1106 | |
| 1107 @override | |
| 1108 List<InterfaceType> get mixins { | |
| 1109 if (_unlinkedClass != null && _mixins == null) { | |
| 1110 ResynthesizerContext context = enclosingUnit.resynthesizerContext; | |
| 1111 _mixins = _unlinkedClass.mixins | |
| 1112 .map((EntityRef t) => context.resolveTypeRef(t, this)) | |
| 1113 .toList(growable: false); | |
| 1114 } | |
| 1115 return super.mixins; | |
| 1116 } | |
| 1117 | |
| 1118 void set mixins(List<InterfaceType> mixins) { | |
| 1119 assert(_unlinkedClass == null); | |
| 1120 super.mixins = mixins; | |
| 1121 } | |
| 1122 | |
| 1123 @override | |
| 1124 String get name { | |
| 1125 if (_unlinkedClass != null) { | |
| 1126 return _unlinkedClass.name; | |
| 1127 } | |
| 1128 return super.name; | |
| 1129 } | |
| 1130 | |
| 1131 @override | |
| 1132 int get nameOffset { | |
| 1133 if (_unlinkedClass != null) { | |
| 1134 return _unlinkedClass.nameOffset; | |
| 1135 } | |
| 1136 return super.nameOffset; | |
| 1137 } | |
| 1138 | |
| 1139 @override | |
| 1140 List<TypeParameterElement> get typeParameters { | |
| 1141 if (_unlinkedClass != null) { | |
| 1142 return resynthesizedTypeParameters; | |
| 1143 } | |
| 1144 return super.typeParameters; | |
| 1145 } | |
| 1146 | |
| 1147 /** | |
| 1148 * Set the type parameters defined for this class to the given | |
| 1149 * [typeParameters]. | |
| 1150 */ | |
| 1151 void set typeParameters(List<TypeParameterElement> typeParameters) { | |
| 1152 assert(_unlinkedClass == null); | |
| 1153 super.typeParameters = typeParameters; | |
| 1154 } | |
| 1155 | |
| 1156 @override | |
| 1157 List<UnlinkedTypeParam> get unlinkedTypeParams => | |
| 1158 _unlinkedClass.typeParameters; | |
| 1159 } | |
| 1160 | |
| 1161 /** | |
| 1162 * A [ClassElementImpl], which is an enum. | |
| 1163 */ | |
| 1164 class ClassElementImpl_Enum extends ClassElementImpl { | |
| 1165 /** | |
| 1166 * The unlinked representation of the enum in the summary. | |
| 1167 */ | |
| 1168 final UnlinkedEnum _unlinkedEnum; | |
| 1169 | |
| 1170 /** | |
| 1171 * Initialize a newly created class element to have the given [name] at the | |
| 1172 * given [offset] in the file that contains the declaration of this element. | |
| 1173 */ | |
| 1174 ClassElementImpl_Enum(String name, int offset) | |
| 1175 : _unlinkedEnum = null, | |
| 1176 super(name, offset); | |
| 1177 | |
| 1178 /** | |
| 1179 * Initialize a newly created class element to have the given [name]. | |
| 1180 */ | |
| 1181 ClassElementImpl_Enum.forNode(Identifier name) | |
| 1182 : _unlinkedEnum = null, | |
| 1183 super.forNode(name); | |
| 1184 | |
| 1185 /** | |
| 1186 * Initialize using the given serialized information. | |
| 1187 */ | |
| 1188 ClassElementImpl_Enum.forSerialized( | |
| 1189 this._unlinkedEnum, CompilationUnitElementImpl enclosingUnit) | |
| 1190 : super.forSerialized(enclosingUnit); | |
| 1191 | |
| 1192 /** | |
| 1193 * Set whether this class is abstract. | |
| 1194 */ | |
| 1195 void set abstract(bool isAbstract) { | |
| 1196 assert(_unlinkedEnum == null); | |
| 1197 super.abstract = isAbstract; | |
|
Brian Wilkerson
2016/06/01 14:08:30
Why isn't this an error?
scheglov
2016/06/01 17:25:28
Fixed.
| |
| 1198 } | |
| 1199 | |
| 1200 @override | |
| 1201 int get codeLength { | |
| 1202 if (_unlinkedEnum != null) { | |
| 1203 return _unlinkedEnum.codeRange?.length; | |
| 1204 } | |
| 1205 return super.codeLength; | |
| 1206 } | |
| 1207 | |
| 1208 @override | |
| 1209 int get codeOffset { | |
| 1210 if (_unlinkedEnum != null) { | |
| 1211 return _unlinkedEnum.codeRange?.offset; | |
| 1212 } | |
| 1213 return super.codeOffset; | |
| 1214 } | |
| 1215 | |
| 1216 @override | |
| 1217 SourceRange get docRange { | |
| 1218 if (_unlinkedEnum != null) { | |
| 1219 UnlinkedDocumentationComment comment = _unlinkedEnum.documentationComment; | |
| 1220 return comment != null | |
| 1221 ? new SourceRange(comment.offset, comment.length) | |
| 1222 : null; | |
| 1223 } | |
| 1224 return super.docRange; | |
| 1225 } | |
| 1226 | |
| 1227 @override | |
| 1228 String get documentationComment { | |
| 1229 if (_unlinkedEnum != null) { | |
| 1230 return _unlinkedEnum?.documentationComment?.text; | |
| 1231 } | |
| 1232 return super.documentationComment; | |
| 1233 } | |
| 1234 | |
| 1235 @override | |
| 1236 List<InterfaceType> get interfaces => const <InterfaceType>[]; | |
| 1237 | |
| 1238 void set interfaces(List<InterfaceType> interfaces) { | |
| 1239 assert(false); | |
|
Brian Wilkerson
2016/06/01 14:08:30
Do we really want to only throw in checked mode?
scheglov
2016/06/01 17:25:28
Well, this is what we do everywhere.
| |
| 1240 } | |
| 1241 | |
| 1242 @override | |
| 1243 bool get isAbstract => false; | |
| 1244 | |
| 1245 @override | |
| 1246 bool get isEnum => true; | |
| 1247 | |
| 1248 @override | |
| 1249 bool get isMixinApplication => false; | |
| 1250 | |
| 1251 @override | |
| 1252 List<ElementAnnotation> get metadata { | |
| 1253 if (_unlinkedEnum != null) { | |
| 1254 return _metadata ??= | |
| 1255 _buildAnnotations(enclosingUnit, _unlinkedEnum.annotations); | |
| 1256 } | |
| 1257 return super.metadata; | |
| 1258 } | |
| 1259 | |
| 1260 /** | |
| 1261 * Set whether this class is a mixin application. | |
| 1262 */ | |
| 1263 void set mixinApplication(bool isMixinApplication) { | |
| 1264 assert(false); | |
| 1265 } | |
| 1266 | |
| 1267 @override | |
| 1268 List<InterfaceType> get mixins => const <InterfaceType>[]; | |
| 1269 | |
| 1270 void set mixins(List<InterfaceType> mixins) { | |
| 1271 assert(false); | |
| 1272 } | |
| 1273 | |
| 1274 @override | |
| 1275 String get name { | |
| 1276 if (_unlinkedEnum != null) { | |
| 1277 return _unlinkedEnum.name; | |
| 1278 } | |
| 1279 return super.name; | |
| 1280 } | |
| 1281 | |
| 1282 @override | |
| 1283 int get nameOffset { | |
| 1284 if (_unlinkedEnum != null) { | |
| 1285 return _unlinkedEnum.nameOffset; | |
| 1286 } | |
| 1287 return super.nameOffset; | |
| 1288 } | |
| 1289 | |
| 1290 @override | |
| 1291 List<TypeParameterElement> get typeParameters => | |
| 1292 const <TypeParameterElement>[]; | |
| 1293 | |
| 1294 /** | |
| 1295 * Set the type parameters defined for this class to the given | |
| 1296 * [typeParameters]. | |
| 1297 */ | |
| 1298 void set typeParameters(List<TypeParameterElement> typeParameters) { | |
| 1299 assert(false); | |
| 1300 } | |
| 1301 } | |
| 1302 | |
| 1303 /** | |
| 1079 * A concrete implementation of a [CompilationUnitElement]. | 1304 * A concrete implementation of a [CompilationUnitElement]. |
| 1080 */ | 1305 */ |
| 1081 class CompilationUnitElementImpl extends UriReferencedElementImpl | 1306 class CompilationUnitElementImpl extends UriReferencedElementImpl |
| 1082 implements CompilationUnitElement { | 1307 implements CompilationUnitElement { |
| 1083 /** | 1308 /** |
| 1084 * The context in which this unit is resynthesized, or `null` if the | 1309 * The context in which this unit is resynthesized, or `null` if the |
| 1085 * element is not resynthesized a summary. | 1310 * element is not resynthesized a summary. |
| 1086 */ | 1311 */ |
| 1087 final ResynthesizerContext resynthesizerContext; | 1312 final ResynthesizerContext resynthesizerContext; |
| 1088 | 1313 |
| (...skipping 6320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7409 } | 7634 } |
| 7410 } | 7635 } |
| 7411 return _typeParameterElements; | 7636 return _typeParameterElements; |
| 7412 } | 7637 } |
| 7413 | 7638 |
| 7414 /** | 7639 /** |
| 7415 * Get a list of [TypeParameterType] objects corresponding to the | 7640 * Get a list of [TypeParameterType] objects corresponding to the |
| 7416 * element's type parameters. | 7641 * element's type parameters. |
| 7417 */ | 7642 */ |
| 7418 List<TypeParameterType> get typeParameterTypes { | 7643 List<TypeParameterType> get typeParameterTypes { |
| 7419 return _typeParameterTypes ??= typeParameters | 7644 var zzz = typeParameters; |
|
Brian Wilkerson
2016/06/01 14:08:30
nit: Perhaps a better name and an explicit type?
scheglov
2016/06/01 17:25:27
Sorry, forgot to inline after debugging.
Fixed.
| |
| 7420 .map((TypeParameterElement e) => e.type) | 7645 return _typeParameterTypes ??= |
| 7421 .toList(growable: false); | 7646 zzz.map((TypeParameterElement e) => e.type).toList(growable: false); |
| 7422 } | 7647 } |
| 7423 | 7648 |
| 7424 /** | 7649 /** |
| 7425 * Get the [UnlinkedTypeParam]s representing the type parameters declared by | 7650 * Get the [UnlinkedTypeParam]s representing the type parameters declared by |
| 7426 * this element. | 7651 * this element. |
| 7427 * | 7652 * |
| 7428 * TODO(scheglov) make private after switching linker to Impl | 7653 * TODO(scheglov) make private after switching linker to Impl |
| 7429 */ | 7654 */ |
| 7430 List<UnlinkedTypeParam> get unlinkedTypeParams; | 7655 List<UnlinkedTypeParam> get unlinkedTypeParams; |
| 7431 | 7656 |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7696 | 7921 |
| 7697 @override | 7922 @override |
| 7698 void visitElement(Element element) { | 7923 void visitElement(Element element) { |
| 7699 int offset = element.nameOffset; | 7924 int offset = element.nameOffset; |
| 7700 if (offset != -1) { | 7925 if (offset != -1) { |
| 7701 map[offset] = element; | 7926 map[offset] = element; |
| 7702 } | 7927 } |
| 7703 super.visitElement(element); | 7928 super.visitElement(element); |
| 7704 } | 7929 } |
| 7705 } | 7930 } |
| OLD | NEW |