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 13 matching lines...) Expand all Loading... |
24 import 'package:analyzer/src/generated/resolver.dart'; | 24 import 'package:analyzer/src/generated/resolver.dart'; |
25 import 'package:analyzer/src/generated/sdk.dart' show DartSdk; | 25 import 'package:analyzer/src/generated/sdk.dart' show DartSdk; |
26 import 'package:analyzer/src/generated/source.dart'; | 26 import 'package:analyzer/src/generated/source.dart'; |
27 import 'package:analyzer/src/generated/testing/ast_test_factory.dart'; | 27 import 'package:analyzer/src/generated/testing/ast_test_factory.dart'; |
28 import 'package:analyzer/src/generated/utilities_collection.dart'; | 28 import 'package:analyzer/src/generated/utilities_collection.dart'; |
29 import 'package:analyzer/src/generated/utilities_dart.dart'; | 29 import 'package:analyzer/src/generated/utilities_dart.dart'; |
30 import 'package:analyzer/src/generated/utilities_general.dart'; | 30 import 'package:analyzer/src/generated/utilities_general.dart'; |
31 import 'package:analyzer/src/summary/idl.dart'; | 31 import 'package:analyzer/src/summary/idl.dart'; |
32 import 'package:analyzer/src/task/dart.dart'; | 32 import 'package:analyzer/src/task/dart.dart'; |
33 import 'package:kernel/kernel.dart' as kernel; | 33 import 'package:kernel/kernel.dart' as kernel; |
| 34 import 'package:kernel/type_algebra.dart' as kernel; |
34 | 35 |
35 /** | 36 /** |
36 * Assert that the given [object] is null, which in the places where this | 37 * Assert that the given [object] is null, which in the places where this |
37 * function is called means that the element is not resynthesized. | 38 * function is called means that the element is not resynthesized. |
38 */ | 39 */ |
39 void _assertNotResynthesized(Object object) { | 40 void _assertNotResynthesized(Object object) { |
40 // TODO(scheglov) I comment this check for now. | 41 // TODO(scheglov) I comment this check for now. |
41 // When we make a decision about switch to the new analysis driver, | 42 // When we make a decision about switch to the new analysis driver, |
42 // we will need to rework the analysis code to don't call the setters | 43 // we will need to rework the analysis code to don't call the setters |
43 // or restore / inline it. | 44 // or restore / inline it. |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 * The unlinked representation of the class in the summary. | 411 * The unlinked representation of the class in the summary. |
411 */ | 412 */ |
412 final UnlinkedClass _unlinkedClass; | 413 final UnlinkedClass _unlinkedClass; |
413 | 414 |
414 /** | 415 /** |
415 * The kernel of the element. | 416 * The kernel of the element. |
416 */ | 417 */ |
417 final kernel.Class _kernel; | 418 final kernel.Class _kernel; |
418 | 419 |
419 /** | 420 /** |
| 421 * The actual supertype extracted from desugared [_kernel]. |
| 422 */ |
| 423 kernel.Supertype _kernelSupertype; |
| 424 |
| 425 /** |
| 426 * The mixed-in types extracted from desugared [_kernel]. |
| 427 */ |
| 428 List<kernel.Supertype> _kernelMixins; |
| 429 |
| 430 /** |
420 * The superclass of the class, or `null` for [Object]. | 431 * The superclass of the class, or `null` for [Object]. |
421 */ | 432 */ |
422 InterfaceType _supertype; | 433 InterfaceType _supertype; |
423 | 434 |
424 /** | 435 /** |
425 * The type defined by the class. | 436 * The type defined by the class. |
426 */ | 437 */ |
427 InterfaceType _type; | 438 InterfaceType _type; |
428 | 439 |
429 /** | 440 /** |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 return _unlinkedClass.isAbstract; | 795 return _unlinkedClass.isAbstract; |
785 } | 796 } |
786 return hasModifier(Modifier.ABSTRACT); | 797 return hasModifier(Modifier.ABSTRACT); |
787 } | 798 } |
788 | 799 |
789 @override | 800 @override |
790 bool get isEnum => false; | 801 bool get isEnum => false; |
791 | 802 |
792 @override | 803 @override |
793 bool get isMixinApplication { | 804 bool get isMixinApplication { |
| 805 if (_kernel != null) { |
| 806 return _kernel.mixedInType != null; |
| 807 } |
794 if (_unlinkedClass != null) { | 808 if (_unlinkedClass != null) { |
795 return _unlinkedClass.isMixinApplication; | 809 return _unlinkedClass.isMixinApplication; |
796 } | 810 } |
797 return hasModifier(Modifier.MIXIN_APPLICATION); | 811 return hasModifier(Modifier.MIXIN_APPLICATION); |
798 } | 812 } |
799 | 813 |
800 @override | 814 @override |
801 bool get isOrInheritsProxy => | 815 bool get isOrInheritsProxy => |
802 _safeIsOrInheritsProxy(this, new HashSet<ClassElement>()); | 816 _safeIsOrInheritsProxy(this, new HashSet<ClassElement>()); |
803 | 817 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 /** | 888 /** |
875 * Set whether this class is a mixin application. | 889 * Set whether this class is a mixin application. |
876 */ | 890 */ |
877 void set mixinApplication(bool isMixinApplication) { | 891 void set mixinApplication(bool isMixinApplication) { |
878 _assertNotResynthesized(_unlinkedClass); | 892 _assertNotResynthesized(_unlinkedClass); |
879 setModifier(Modifier.MIXIN_APPLICATION, isMixinApplication); | 893 setModifier(Modifier.MIXIN_APPLICATION, isMixinApplication); |
880 } | 894 } |
881 | 895 |
882 @override | 896 @override |
883 List<InterfaceType> get mixins { | 897 List<InterfaceType> get mixins { |
884 if (_unlinkedClass != null && _mixins == null) { | 898 if (_mixins == null) { |
885 ResynthesizerContext context = enclosingUnit.resynthesizerContext; | 899 if (_kernel != null) { |
886 _mixins = _unlinkedClass.mixins | 900 _initializeKernelMixins(); |
887 .map((EntityRef t) => context.resolveTypeRef(this, t)) | 901 var context = enclosingUnit._kernelContext; |
888 .where(_isClassInterfaceType) | 902 _mixins = _kernelMixins.map((k) { |
889 .toList(growable: false); | 903 return context.getInterfaceType(this, k); |
| 904 }).toList(growable: false); |
| 905 } |
| 906 if (_unlinkedClass != null) { |
| 907 ResynthesizerContext context = enclosingUnit.resynthesizerContext; |
| 908 _mixins = _unlinkedClass.mixins |
| 909 .map((EntityRef t) => context.resolveTypeRef(this, t)) |
| 910 .where(_isClassInterfaceType) |
| 911 .toList(growable: false); |
| 912 } |
890 } | 913 } |
891 return _mixins ?? const <InterfaceType>[]; | 914 return _mixins ?? const <InterfaceType>[]; |
892 } | 915 } |
893 | 916 |
894 void set mixins(List<InterfaceType> mixins) { | 917 void set mixins(List<InterfaceType> mixins) { |
895 _assertNotResynthesized(_unlinkedClass); | 918 _assertNotResynthesized(_unlinkedClass); |
896 _mixins = mixins; | 919 _mixins = mixins; |
897 } | 920 } |
898 | 921 |
899 @override | 922 @override |
(...skipping 13 matching lines...) Expand all Loading... |
913 if (offset == 0 && _unlinkedClass != null) { | 936 if (offset == 0 && _unlinkedClass != null) { |
914 return _unlinkedClass.nameOffset; | 937 return _unlinkedClass.nameOffset; |
915 } | 938 } |
916 return offset; | 939 return offset; |
917 } | 940 } |
918 | 941 |
919 @override | 942 @override |
920 InterfaceType get supertype { | 943 InterfaceType get supertype { |
921 if (_supertype == null) { | 944 if (_supertype == null) { |
922 if (_kernel != null) { | 945 if (_kernel != null) { |
923 if (_kernel.supertype != null) { | 946 _initializeKernelMixins(); |
| 947 if (_kernelSupertype != null) { |
924 _supertype = enclosingUnit._kernelContext | 948 _supertype = enclosingUnit._kernelContext |
925 .getInterfaceType(this, _kernel.supertype); | 949 .getInterfaceType(this, _kernelSupertype); |
926 _supertype ??= context.typeProvider.objectType; | 950 _supertype ??= context.typeProvider.objectType; |
927 } else { | 951 } else { |
928 return null; | 952 return null; |
929 } | 953 } |
930 } | 954 } |
931 if (_unlinkedClass != null) { | 955 if (_unlinkedClass != null) { |
932 if (_unlinkedClass.supertype != null) { | 956 if (_unlinkedClass.supertype != null) { |
933 DartType type = enclosingUnit.resynthesizerContext | 957 DartType type = enclosingUnit.resynthesizerContext |
934 .resolveTypeRef(this, _unlinkedClass.supertype); | 958 .resolveTypeRef(this, _unlinkedClass.supertype); |
935 if (_isClassInterfaceType(type)) { | 959 if (_isClassInterfaceType(type)) { |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1221 implicitParameters[i] = implicitParameter; | 1245 implicitParameters[i] = implicitParameter; |
1222 } | 1246 } |
1223 implicitConstructor.parameters = implicitParameters; | 1247 implicitConstructor.parameters = implicitParameters; |
1224 } | 1248 } |
1225 implicitConstructor.enclosingElement = this; | 1249 implicitConstructor.enclosingElement = this; |
1226 return implicitConstructor; | 1250 return implicitConstructor; |
1227 }).toList(growable: false); | 1251 }).toList(growable: false); |
1228 } | 1252 } |
1229 | 1253 |
1230 /** | 1254 /** |
| 1255 * Extract actual supertypes and mixed-in types from [_kernel]. |
| 1256 */ |
| 1257 void _initializeKernelMixins() { |
| 1258 if (_kernelSupertype == null) { |
| 1259 _kernelMixins = <kernel.Supertype>[]; |
| 1260 kernel.Supertype supertype = _kernel.supertype; |
| 1261 if (supertype != null) { |
| 1262 if (_kernel.mixedInType != null) { |
| 1263 _kernelMixins.add(_kernel.mixedInType); |
| 1264 } |
| 1265 while (supertype.classNode.isSyntheticMixinImplementation) { |
| 1266 var superNode = supertype.classNode; |
| 1267 var substitute = kernel.Substitution.fromSupertype(supertype); |
| 1268 var thisMixin = substitute.substituteSupertype(superNode.mixedInType); |
| 1269 _kernelMixins.add(thisMixin); |
| 1270 supertype = substitute.substituteSupertype(superNode.supertype); |
| 1271 } |
| 1272 _kernelMixins = _kernelMixins.reversed.toList(); |
| 1273 } |
| 1274 _kernelSupertype = supertype; |
| 1275 } |
| 1276 } |
| 1277 |
| 1278 /** |
1231 * Resynthesize explicit fields and property accessors and fill [_fields] and | 1279 * Resynthesize explicit fields and property accessors and fill [_fields] and |
1232 * [_accessors] with explicit and implicit elements. | 1280 * [_accessors] with explicit and implicit elements. |
1233 */ | 1281 */ |
1234 void _resynthesizeFieldsAndPropertyAccessors() { | 1282 void _resynthesizeFieldsAndPropertyAccessors() { |
1235 assert(_fields == null); | 1283 assert(_fields == null); |
1236 assert(_accessors == null); | 1284 assert(_accessors == null); |
1237 var explicitFields = <FieldElement>[]; | 1285 var explicitFields = <FieldElement>[]; |
1238 var implicitAccessors = <PropertyAccessorElement>[]; | 1286 var implicitAccessors = <PropertyAccessorElement>[]; |
1239 var explicitAccessors = <PropertyAccessorElement>[]; | 1287 var explicitAccessors = <PropertyAccessorElement>[]; |
1240 var implicitFields = <String, FieldElementImpl>{}; | 1288 var implicitFields = <String, FieldElementImpl>{}; |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1719 this._typeAliases = typeAliases; | 1767 this._typeAliases = typeAliases; |
1720 } | 1768 } |
1721 | 1769 |
1722 @override | 1770 @override |
1723 TypeParameterizedElementMixin get typeParameterContext => null; | 1771 TypeParameterizedElementMixin get typeParameterContext => null; |
1724 | 1772 |
1725 @override | 1773 @override |
1726 List<ClassElement> get types { | 1774 List<ClassElement> get types { |
1727 if (_kernelContext != null) { | 1775 if (_kernelContext != null) { |
1728 _types ??= _kernelContext.library.classes | 1776 _types ??= _kernelContext.library.classes |
| 1777 .where((k) => !k.isSyntheticMixinImplementation) |
1729 .map((k) => new ClassElementImpl.forKernel(this, k)) | 1778 .map((k) => new ClassElementImpl.forKernel(this, k)) |
1730 .toList(growable: false); | 1779 .toList(growable: false); |
1731 } | 1780 } |
1732 if (_unlinkedUnit != null) { | 1781 if (_unlinkedUnit != null) { |
1733 _types ??= _unlinkedUnit.classes | 1782 _types ??= _unlinkedUnit.classes |
1734 .map((c) => new ClassElementImpl.forSerialized(c, this)) | 1783 .map((c) => new ClassElementImpl.forSerialized(c, this)) |
1735 .toList(growable: false); | 1784 .toList(growable: false); |
1736 } | 1785 } |
1737 return _types ?? const <ClassElement>[]; | 1786 return _types ?? const <ClassElement>[]; |
1738 } | 1787 } |
(...skipping 7553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9292 | 9341 |
9293 @override | 9342 @override |
9294 DartObject computeConstantValue() => null; | 9343 DartObject computeConstantValue() => null; |
9295 | 9344 |
9296 @override | 9345 @override |
9297 void visitChildren(ElementVisitor visitor) { | 9346 void visitChildren(ElementVisitor visitor) { |
9298 super.visitChildren(visitor); | 9347 super.visitChildren(visitor); |
9299 _initializer?.accept(visitor); | 9348 _initializer?.accept(visitor); |
9300 } | 9349 } |
9301 } | 9350 } |
OLD | NEW |