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

Side by Side Diff: pkg/analyzer/lib/src/summary/link.dart

Issue 1887213002: Add PropertyAccessorElementForLink_Variable.library getter. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/linker_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 /** 5 /**
6 * This library is capable of producing linked summaries from unlinked 6 * This library is capable of producing linked summaries from unlinked
7 * ones (or prelinked ones). It functions by building a miniature 7 * ones (or prelinked ones). It functions by building a miniature
8 * element model to represent the contents of the summaries, and then 8 * element model to represent the contents of the summaries, and then
9 * scanning the element model to gather linked information and adding 9 * scanning the element model to gather linked information and adding
10 * it to the summary data structures. 10 * it to the summary data structures.
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 for (PropertyAccessorElementForLink propertyAccessorElement 528 for (PropertyAccessorElementForLink propertyAccessorElement
529 in accessors) { 529 in accessors) {
530 propertyAccessorElement.link(compilationUnit); 530 propertyAccessorElement.link(compilationUnit);
531 } 531 }
532 for (FieldElementForLink_ClassField fieldElement in fields) { 532 for (FieldElementForLink_ClassField fieldElement in fields) {
533 fieldElement.link(compilationUnit); 533 fieldElement.link(compilationUnit);
534 } 534 }
535 } 535 }
536 } 536 }
537 537
538 @override
539 String toString() => '$enclosingElement.$name';
540
538 /** 541 /**
539 * Convert [typeRef] into an [InterfaceType]. 542 * Convert [typeRef] into an [InterfaceType].
540 */ 543 */
541 InterfaceType _computeInterfaceType(EntityRef typeRef) { 544 InterfaceType _computeInterfaceType(EntityRef typeRef) {
542 if (typeRef != null) { 545 if (typeRef != null) {
543 DartType type = enclosingElement._resolveTypeRef(typeRef, this); 546 DartType type = enclosingElement._resolveTypeRef(typeRef, this);
544 if (type is InterfaceType) { 547 if (type is InterfaceType) {
545 return type; 548 return type;
546 } 549 }
547 // In the event that the `typeRef` isn't an interface type (which may 550 // In the event that the `typeRef` isn't an interface type (which may
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 @override 623 @override
621 ConstructorElementForLink get unnamedConstructor => null; 624 ConstructorElementForLink get unnamedConstructor => null;
622 625
623 @override 626 @override
624 DartType buildType(DartType getTypeArgument(int i), 627 DartType buildType(DartType getTypeArgument(int i),
625 List<int> implicitFunctionTypeIndices) => 628 List<int> implicitFunctionTypeIndices) =>
626 type; 629 type;
627 630
628 @override 631 @override
629 void link(CompilationUnitElementInBuildUnit compilationUnit) {} 632 void link(CompilationUnitElementInBuildUnit compilationUnit) {}
633
634 @override
635 String toString() => '$enclosingElement.$name';
630 } 636 }
631 637
632 /** 638 /**
633 * Element representing a compilation unit resynthesized from a 639 * Element representing a compilation unit resynthesized from a
634 * summary during linking. 640 * summary during linking.
635 */ 641 */
636 abstract class CompilationUnitElementForLink implements CompilationUnitElement { 642 abstract class CompilationUnitElementForLink implements CompilationUnitElement {
637 /** 643 /**
638 * The unlinked representation of the compilation unit in the 644 * The unlinked representation of the compilation unit in the
639 * summary. 645 * summary.
640 */ 646 */
641 final UnlinkedUnit _unlinkedUnit; 647 final UnlinkedUnit _unlinkedUnit;
642 648
643 /** 649 /**
644 * For each entry in [UnlinkedUnit.references], the element referred 650 * For each entry in [UnlinkedUnit.references], the element referred
645 * to by the reference, or `null` if it hasn't been located yet. 651 * to by the reference, or `null` if it hasn't been located yet.
646 */ 652 */
647 final List<ReferenceableElementForLink> _references; 653 final List<ReferenceableElementForLink> _references;
648 654
649 List<ClassElementForLink_Class> _types; 655 List<ClassElementForLink_Class> _types;
650
651 Map<String, ReferenceableElementForLink> _containedNames; 656 Map<String, ReferenceableElementForLink> _containedNames;
652 List<TopLevelVariableElementForLink> _topLevelVariables; 657 List<TopLevelVariableElementForLink> _topLevelVariables;
653 List<ClassElementForLink_Enum> _enums; 658 List<ClassElementForLink_Enum> _enums;
654 659
655 /** 660 /**
656 * Index of this unit in the list of units in the enclosing library. 661 * Index of this unit in the list of units in the enclosing library.
657 */ 662 */
658 final int unitNum; 663 final int unitNum;
659 664
660 CompilationUnitElementForLink( 665 CompilationUnitElementForLink(
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 * Compute the type referred to by the given linked type [slot] (interpreted 759 * Compute the type referred to by the given linked type [slot] (interpreted
755 * relative to [typeParameterContext]). If there is no inferred type in the 760 * relative to [typeParameterContext]). If there is no inferred type in the
756 * given slot, `dynamic` is returned. 761 * given slot, `dynamic` is returned.
757 */ 762 */
758 DartType getLinkedType( 763 DartType getLinkedType(
759 int slot, TypeParameterizedElementForLink typeParameterContext); 764 int slot, TypeParameterizedElementForLink typeParameterContext);
760 765
761 @override 766 @override
762 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 767 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
763 768
769 @override
770 String toString() => enclosingElement.toString();
771
764 /** 772 /**
765 * Return the element referred to by the given [index] in 773 * Return the element referred to by the given [index] in
766 * [UnlinkedUnit.references]. If the reference is unresolved, 774 * [UnlinkedUnit.references]. If the reference is unresolved,
767 * return [UndefinedElementForLink.instance]. 775 * return [UndefinedElementForLink.instance].
768 */ 776 */
769 ReferenceableElementForLink _resolveRef(int index) { 777 ReferenceableElementForLink _resolveRef(int index) {
770 if (_references[index] == null) { 778 if (_references[index] == null) {
771 UnlinkedReference unlinkedReference = 779 UnlinkedReference unlinkedReference =
772 index < _unlinkedUnit.references.length 780 index < _unlinkedUnit.references.length
773 ? _unlinkedUnit.references[index] 781 ? _unlinkedUnit.references[index]
(...skipping 1548 matching lines...) Expand 10 before | Expand all | Expand 10 after
2322 if (typeInferenceNode != null) { 2330 if (typeInferenceNode != null) {
2323 compilationUnit._storeLinkedType(unlinkedVariable.inferredTypeSlot, 2331 compilationUnit._storeLinkedType(unlinkedVariable.inferredTypeSlot,
2324 typeInferenceNode.inferredType, enclosingElement); 2332 typeInferenceNode.inferredType, enclosingElement);
2325 } 2333 }
2326 } else { 2334 } else {
2327 compilationUnit._storeLinkedType(unlinkedVariable.inferredTypeSlot, 2335 compilationUnit._storeLinkedType(unlinkedVariable.inferredTypeSlot,
2328 _inferredInstanceType, enclosingElement); 2336 _inferredInstanceType, enclosingElement);
2329 } 2337 }
2330 } 2338 }
2331 } 2339 }
2340
2341 @override
2342 String toString() => '$enclosingElement.$name';
2332 } 2343 }
2333 2344
2334 /** 2345 /**
2335 * Specialization of [FieldElementForLink] for enum fields. 2346 * Specialization of [FieldElementForLink] for enum fields.
2336 */ 2347 */
2337 class FieldElementForLink_EnumField extends FieldElementForLink 2348 class FieldElementForLink_EnumField extends FieldElementForLink
2338 implements FieldElement { 2349 implements FieldElement {
2339 /** 2350 /**
2340 * The unlinked representation of the field in the summary, or `null` if this 2351 * The unlinked representation of the field in the summary, or `null` if this
2341 * is an enum's `values` field. 2352 * is an enum's `values` field.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2378 DartType buildType(DartType getTypeArgument(int i), 2389 DartType buildType(DartType getTypeArgument(int i),
2379 List<int> implicitFunctionTypeIndices) => 2390 List<int> implicitFunctionTypeIndices) =>
2380 DynamicTypeImpl.instance; 2391 DynamicTypeImpl.instance;
2381 2392
2382 @override 2393 @override
2383 ReferenceableElementForLink getContainedName(String name) => 2394 ReferenceableElementForLink getContainedName(String name) =>
2384 UndefinedElementForLink.instance; 2395 UndefinedElementForLink.instance;
2385 2396
2386 @override 2397 @override
2387 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 2398 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
2399
2400 @override
2401 String toString() => '$enclosingElement.$name';
2388 } 2402 }
2389 2403
2390 /** 2404 /**
2391 * Element representing a function-typed parameter resynthesied from a summary 2405 * Element representing a function-typed parameter resynthesied from a summary
2392 * during linking. 2406 * during linking.
2393 */ 2407 */
2394 class FunctionElementForLink_FunctionTypedParam implements FunctionElement { 2408 class FunctionElementForLink_FunctionTypedParam implements FunctionElement {
2395 @override 2409 @override
2396 final ParameterElementForLink enclosingElement; 2410 final ParameterElementForLink enclosingElement;
2397 2411
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
2677 if (!identical(element, UndefinedElementForLink.instance)) { 2691 if (!identical(element, UndefinedElementForLink.instance)) {
2678 return element; 2692 return element;
2679 } 2693 }
2680 } 2694 }
2681 return UndefinedElementForLink.instance; 2695 return UndefinedElementForLink.instance;
2682 }); 2696 });
2683 2697
2684 @override 2698 @override
2685 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 2699 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
2686 2700
2701 @override
2702 String toString() => _absoluteUri.toString();
2703
2687 /** 2704 /**
2688 * Return the [LibraryElement] corresponding to the given dependency [index]. 2705 * Return the [LibraryElement] corresponding to the given dependency [index].
2689 */ 2706 */
2690 LibraryElementForLink _getDependency(int index) { 2707 LibraryElementForLink _getDependency(int index) {
2691 return _dependencies[index] ??= _linker.getLibrary(resolveRelativeUri( 2708 return _dependencies[index] ??= _linker.getLibrary(resolveRelativeUri(
2692 _absoluteUri, Uri.parse(_linkedLibrary.dependencies[index].uri))); 2709 _absoluteUri, Uri.parse(_linkedLibrary.dependencies[index].uri)));
2693 } 2710 }
2694 2711
2695 /** 2712 /**
2696 * Create a [UnitElement] for one of the library's compilation 2713 * Create a [UnitElement] for one of the library's compilation
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
3213 @override 3230 @override
3214 bool get isSetter => 3231 bool get isSetter =>
3215 _unlinkedExecutable.kind == UnlinkedExecutableKind.setter; 3232 _unlinkedExecutable.kind == UnlinkedExecutableKind.setter;
3216 3233
3217 @override 3234 @override
3218 ElementKind get kind => _unlinkedExecutable.kind == 3235 ElementKind get kind => _unlinkedExecutable.kind ==
3219 UnlinkedExecutableKind.getter ? ElementKind.GETTER : ElementKind.SETTER; 3236 UnlinkedExecutableKind.getter ? ElementKind.GETTER : ElementKind.SETTER;
3220 3237
3221 @override 3238 @override
3222 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 3239 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
3240
3241 @override
3242 String toString() => '$enclosingElement.$name';
3223 } 3243 }
3224 3244
3225 /** 3245 /**
3226 * Specialization of [PropertyAccessorElementForLink] for synthetic accessors 3246 * Specialization of [PropertyAccessorElementForLink] for synthetic accessors
3227 * implied by a field or variable declaration. 3247 * implied by a field or variable declaration.
3228 */ 3248 */
3229 class PropertyAccessorElementForLink_Variable 3249 class PropertyAccessorElementForLink_Variable
3230 implements PropertyAccessorElementForLink { 3250 implements PropertyAccessorElementForLink {
3231 @override 3251 @override
3232 final bool isSetter; 3252 final bool isSetter;
(...skipping 12 matching lines...) Expand all
3245 @override 3265 @override
3246 bool get isStatic => _variable.isStatic; 3266 bool get isStatic => _variable.isStatic;
3247 3267
3248 @override 3268 @override
3249 bool get isSynthetic => true; 3269 bool get isSynthetic => true;
3250 3270
3251 @override 3271 @override
3252 ElementKind get kind => isSetter ? ElementKind.SETTER : ElementKind.GETTER; 3272 ElementKind get kind => isSetter ? ElementKind.SETTER : ElementKind.GETTER;
3253 3273
3254 @override 3274 @override
3275 LibraryElementForLink get library =>
3276 _variable.compilationUnit.enclosingElement;
3277
3278 @override
3255 String get name => isSetter ? '${_variable.name}=' : _variable.name; 3279 String get name => isSetter ? '${_variable.name}=' : _variable.name;
3256 3280
3257 @override 3281 @override
3258 DartType get returnType { 3282 DartType get returnType {
3259 if (isSetter) { 3283 if (isSetter) {
3260 return VoidTypeImpl.instance; 3284 return VoidTypeImpl.instance;
3261 } else if (_variable.hasImplicitType && 3285 } else if (_variable.hasImplicitType &&
3262 !isStatic && 3286 !isStatic &&
3263 !_variable.compilationUnit.isTypeInferenceComplete) { 3287 !_variable.compilationUnit.isTypeInferenceComplete) {
3264 // This is an instance field and we are currently inferring types in the 3288 // This is an instance field and we are currently inferring types in the
(...skipping 17 matching lines...) Expand all
3282 3306
3283 @override 3307 @override
3284 bool isAccessibleIn(LibraryElement library) => 3308 bool isAccessibleIn(LibraryElement library) =>
3285 !Identifier.isPrivateName(name) || identical(this.library, library); 3309 !Identifier.isPrivateName(name) || identical(this.library, library);
3286 3310
3287 @override 3311 @override
3288 void link(CompilationUnitElementInBuildUnit compilationUnit) {} 3312 void link(CompilationUnitElementInBuildUnit compilationUnit) {}
3289 3313
3290 @override 3314 @override
3291 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 3315 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
3316
3317 @override
3318 String toString() => '$enclosingElement.$name';
3292 } 3319 }
3293 3320
3294 /** 3321 /**
3295 * Abstract base class representing an element which can be the target 3322 * Abstract base class representing an element which can be the target
3296 * of a reference. 3323 * of a reference.
3297 */ 3324 */
3298 abstract class ReferenceableElementForLink { 3325 abstract class ReferenceableElementForLink {
3299 /** 3326 /**
3300 * If this element can be used in a constructor invocation context, 3327 * If this element can be used in a constructor invocation context,
3301 * return the associated constructor (which may be `this` or some 3328 * return the associated constructor (which may be `this` or some
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
3957 List<int> implicitFunctionTypeIndices) => 3984 List<int> implicitFunctionTypeIndices) =>
3958 DynamicTypeImpl.instance; 3985 DynamicTypeImpl.instance;
3959 3986
3960 ReferenceableElementForLink getContainedName(String name) { 3987 ReferenceableElementForLink getContainedName(String name) {
3961 return new NonstaticMemberElementForLink(_constNode); 3988 return new NonstaticMemberElementForLink(_constNode);
3962 } 3989 }
3963 3990
3964 @override 3991 @override
3965 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 3992 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
3966 } 3993 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/linker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698