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 1665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1676 */ | 1676 */ |
1677 void set functions(List<FunctionElement> functions) { | 1677 void set functions(List<FunctionElement> functions) { |
1678 for (FunctionElement function in functions) { | 1678 for (FunctionElement function in functions) { |
1679 (function as FunctionElementImpl).enclosingElement = this; | 1679 (function as FunctionElementImpl).enclosingElement = this; |
1680 } | 1680 } |
1681 this._functions = functions; | 1681 this._functions = functions; |
1682 } | 1682 } |
1683 | 1683 |
1684 @override | 1684 @override |
1685 List<FunctionTypeAliasElement> get functionTypeAliases { | 1685 List<FunctionTypeAliasElement> get functionTypeAliases { |
| 1686 if (_kernelContext != null) { |
| 1687 _typeAliases ??= _kernelContext.library.typedefs |
| 1688 .map((k) => new FunctionTypeAliasElementImpl.forKernel(this, k)) |
| 1689 .toList(growable: false); |
| 1690 } |
1686 if (_unlinkedUnit != null) { | 1691 if (_unlinkedUnit != null) { |
1687 _typeAliases ??= _unlinkedUnit.typedefs.map((t) { | 1692 _typeAliases ??= _unlinkedUnit.typedefs.map((t) { |
1688 if (t.style == TypedefStyle.functionType) { | 1693 if (t.style == TypedefStyle.functionType) { |
1689 return new FunctionTypeAliasElementImpl.forSerialized(t, this); | 1694 return new FunctionTypeAliasElementImpl.forSerialized(t, this); |
1690 } else if (t.style == TypedefStyle.genericFunctionType) { | 1695 } else if (t.style == TypedefStyle.genericFunctionType) { |
1691 return new GenericTypeAliasElementImpl.forSerialized(t, this); | 1696 return new GenericTypeAliasElementImpl.forSerialized(t, this); |
1692 } | 1697 } |
1693 }).toList(growable: false); | 1698 }).toList(growable: false); |
1694 } | 1699 } |
1695 return _typeAliases ?? const <FunctionTypeAliasElement>[]; | 1700 return _typeAliases ?? const <FunctionTypeAliasElement>[]; |
(...skipping 3218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4914 */ | 4919 */ |
4915 class FunctionTypeAliasElementImpl extends ElementImpl | 4920 class FunctionTypeAliasElementImpl extends ElementImpl |
4916 with TypeParameterizedElementMixin | 4921 with TypeParameterizedElementMixin |
4917 implements FunctionTypeAliasElement { | 4922 implements FunctionTypeAliasElement { |
4918 /** | 4923 /** |
4919 * The unlinked representation of the type in the summary. | 4924 * The unlinked representation of the type in the summary. |
4920 */ | 4925 */ |
4921 final UnlinkedTypedef _unlinkedTypedef; | 4926 final UnlinkedTypedef _unlinkedTypedef; |
4922 | 4927 |
4923 /** | 4928 /** |
| 4929 * The kernel of the element. |
| 4930 */ |
| 4931 final kernel.Typedef _kernel; |
| 4932 |
| 4933 /** |
4924 * A list containing all of the parameters defined by this type alias. | 4934 * A list containing all of the parameters defined by this type alias. |
4925 */ | 4935 */ |
4926 List<ParameterElement> _parameters; | 4936 List<ParameterElement> _parameters; |
4927 | 4937 |
4928 /** | 4938 /** |
4929 * The return type defined by this type alias. | 4939 * The return type defined by this type alias. |
4930 */ | 4940 */ |
4931 DartType _returnType; | 4941 DartType _returnType; |
4932 | 4942 |
4933 /** | 4943 /** |
4934 * The type of function defined by this type alias. | 4944 * The type of function defined by this type alias. |
4935 */ | 4945 */ |
4936 FunctionType _type; | 4946 FunctionType _type; |
4937 | 4947 |
4938 /** | 4948 /** |
4939 * Initialize a newly created type alias element to have the given name. | 4949 * Initialize a newly created type alias element to have the given name. |
4940 * | 4950 * |
4941 * [name] the name of this element | 4951 * [name] the name of this element |
4942 * [nameOffset] the offset of the name of this element in the file that | 4952 * [nameOffset] the offset of the name of this element in the file that |
4943 * contains the declaration of this element | 4953 * contains the declaration of this element |
4944 */ | 4954 */ |
4945 FunctionTypeAliasElementImpl(String name, int nameOffset) | 4955 FunctionTypeAliasElementImpl(String name, int nameOffset) |
4946 : _unlinkedTypedef = null, | 4956 : _unlinkedTypedef = null, |
| 4957 _kernel = null, |
4947 super(name, nameOffset); | 4958 super(name, nameOffset); |
4948 | 4959 |
4949 /** | 4960 /** |
| 4961 * Initialize using the given kernel. |
| 4962 */ |
| 4963 FunctionTypeAliasElementImpl.forKernel( |
| 4964 CompilationUnitElementImpl enclosingUnit, this._kernel) |
| 4965 : _unlinkedTypedef = null, |
| 4966 super.forSerialized(enclosingUnit); |
| 4967 |
| 4968 /** |
4950 * Initialize a newly created type alias element to have the given [name]. | 4969 * Initialize a newly created type alias element to have the given [name]. |
4951 */ | 4970 */ |
4952 FunctionTypeAliasElementImpl.forNode(Identifier name) | 4971 FunctionTypeAliasElementImpl.forNode(Identifier name) |
4953 : _unlinkedTypedef = null, | 4972 : _unlinkedTypedef = null, |
| 4973 _kernel = null, |
4954 super.forNode(name); | 4974 super.forNode(name); |
4955 | 4975 |
4956 /** | 4976 /** |
4957 * Initialize using the given serialized information. | 4977 * Initialize using the given serialized information. |
4958 */ | 4978 */ |
4959 FunctionTypeAliasElementImpl.forSerialized( | 4979 FunctionTypeAliasElementImpl.forSerialized( |
4960 this._unlinkedTypedef, CompilationUnitElementImpl enclosingUnit) | 4980 this._unlinkedTypedef, CompilationUnitElementImpl enclosingUnit) |
4961 : super.forSerialized(enclosingUnit); | 4981 : _kernel = null, |
| 4982 super.forSerialized(enclosingUnit); |
4962 | 4983 |
4963 @override | 4984 @override |
4964 int get codeLength { | 4985 int get codeLength { |
4965 if (_unlinkedTypedef != null) { | 4986 if (_unlinkedTypedef != null) { |
4966 return _unlinkedTypedef.codeRange?.length; | 4987 return _unlinkedTypedef.codeRange?.length; |
4967 } | 4988 } |
4968 return super.codeLength; | 4989 return super.codeLength; |
4969 } | 4990 } |
4970 | 4991 |
4971 @override | 4992 @override |
(...skipping 20 matching lines...) Expand all Loading... |
4992 super.enclosingElement as CompilationUnitElement; | 5013 super.enclosingElement as CompilationUnitElement; |
4993 | 5014 |
4994 @override | 5015 @override |
4995 TypeParameterizedElementMixin get enclosingTypeParameterContext => null; | 5016 TypeParameterizedElementMixin get enclosingTypeParameterContext => null; |
4996 | 5017 |
4997 @override | 5018 @override |
4998 CompilationUnitElementImpl get enclosingUnit => | 5019 CompilationUnitElementImpl get enclosingUnit => |
4999 _enclosingElement as CompilationUnitElementImpl; | 5020 _enclosingElement as CompilationUnitElementImpl; |
5000 | 5021 |
5001 @override | 5022 @override |
5002 List<kernel.TypeParameter> get kernelTypeParams => null; | 5023 List<kernel.TypeParameter> get kernelTypeParams => _kernel?.typeParameters; |
5003 | 5024 |
5004 @override | 5025 @override |
5005 ElementKind get kind => ElementKind.FUNCTION_TYPE_ALIAS; | 5026 ElementKind get kind => ElementKind.FUNCTION_TYPE_ALIAS; |
5006 | 5027 |
5007 @override | 5028 @override |
5008 List<ElementAnnotation> get metadata { | 5029 List<ElementAnnotation> get metadata { |
5009 if (_unlinkedTypedef != null) { | 5030 if (_unlinkedTypedef != null) { |
5010 return _metadata ??= | 5031 return _metadata ??= |
5011 _buildAnnotations(enclosingUnit, _unlinkedTypedef.annotations); | 5032 _buildAnnotations(enclosingUnit, _unlinkedTypedef.annotations); |
5012 } | 5033 } |
5013 return super.metadata; | 5034 return super.metadata; |
5014 } | 5035 } |
5015 | 5036 |
5016 @override | 5037 @override |
5017 String get name { | 5038 String get name { |
| 5039 if (_kernel != null) { |
| 5040 return _kernel.name; |
| 5041 } |
5018 if (_unlinkedTypedef != null) { | 5042 if (_unlinkedTypedef != null) { |
5019 return _unlinkedTypedef.name; | 5043 return _unlinkedTypedef.name; |
5020 } | 5044 } |
5021 return super.name; | 5045 return super.name; |
5022 } | 5046 } |
5023 | 5047 |
5024 @override | 5048 @override |
5025 int get nameOffset { | 5049 int get nameOffset { |
5026 int offset = super.nameOffset; | 5050 int offset = super.nameOffset; |
5027 if (offset == 0 && _unlinkedTypedef != null) { | 5051 if (offset == 0 && _unlinkedTypedef != null) { |
5028 return _unlinkedTypedef.nameOffset; | 5052 return _unlinkedTypedef.nameOffset; |
5029 } | 5053 } |
5030 return offset; | 5054 return offset; |
5031 } | 5055 } |
5032 | 5056 |
5033 @override | 5057 @override |
5034 List<ParameterElement> get parameters { | 5058 List<ParameterElement> get parameters { |
| 5059 if (_kernel != null) { |
| 5060 _parameters ??= ParameterElementImpl.forKernelParameters( |
| 5061 this, |
| 5062 _kernel.requiredParameterCount, |
| 5063 _kernel.positionalParameters, |
| 5064 _kernel.namedParameters); |
| 5065 } |
5035 if (_unlinkedTypedef != null) { | 5066 if (_unlinkedTypedef != null) { |
5036 _parameters ??= ParameterElementImpl.resynthesizeList( | 5067 _parameters ??= ParameterElementImpl.resynthesizeList( |
5037 _unlinkedTypedef.parameters, this); | 5068 _unlinkedTypedef.parameters, this); |
5038 } | 5069 } |
5039 return _parameters ?? const <ParameterElement>[]; | 5070 return _parameters ?? const <ParameterElement>[]; |
5040 } | 5071 } |
5041 | 5072 |
5042 /** | 5073 /** |
5043 * Set the parameters defined by this type alias to the given [parameters]. | 5074 * Set the parameters defined by this type alias to the given [parameters]. |
5044 */ | 5075 */ |
5045 void set parameters(List<ParameterElement> parameters) { | 5076 void set parameters(List<ParameterElement> parameters) { |
5046 _assertNotResynthesized(_unlinkedTypedef); | 5077 _assertNotResynthesized(_unlinkedTypedef); |
5047 if (parameters != null) { | 5078 if (parameters != null) { |
5048 for (ParameterElement parameter in parameters) { | 5079 for (ParameterElement parameter in parameters) { |
5049 (parameter as ParameterElementImpl).enclosingElement = this; | 5080 (parameter as ParameterElementImpl).enclosingElement = this; |
5050 } | 5081 } |
5051 } | 5082 } |
5052 this._parameters = parameters; | 5083 this._parameters = parameters; |
5053 } | 5084 } |
5054 | 5085 |
5055 @override | 5086 @override |
5056 DartType get returnType { | 5087 DartType get returnType { |
5057 if (_unlinkedTypedef != null && _returnType == null) { | 5088 if (_returnType == null) { |
5058 _returnType = enclosingUnit.resynthesizerContext.resolveTypeRef( | 5089 if (_kernel != null) { |
5059 this, _unlinkedTypedef.returnType, | 5090 var type = _kernel.type as kernel.FunctionType; |
5060 declaredType: true); | 5091 _returnType = |
| 5092 enclosingUnit._kernelContext.getType(this, type.returnType); |
| 5093 } |
| 5094 if (_unlinkedTypedef != null) { |
| 5095 _returnType = enclosingUnit.resynthesizerContext.resolveTypeRef( |
| 5096 this, _unlinkedTypedef.returnType, |
| 5097 declaredType: true); |
| 5098 } |
5061 } | 5099 } |
5062 return _returnType; | 5100 return _returnType; |
5063 } | 5101 } |
5064 | 5102 |
5065 void set returnType(DartType returnType) { | 5103 void set returnType(DartType returnType) { |
5066 _assertNotResynthesized(_unlinkedTypedef); | 5104 _assertNotResynthesized(_unlinkedTypedef); |
5067 _returnType = _checkElementOfType(returnType); | 5105 _returnType = _checkElementOfType(returnType); |
5068 } | 5106 } |
5069 | 5107 |
5070 @override | 5108 @override |
5071 FunctionType get type { | 5109 FunctionType get type { |
5072 if (_unlinkedTypedef != null && _type == null) { | 5110 if (_type == null) { |
5073 _type = new FunctionTypeImpl.forTypedef(this); | 5111 if (_kernel != null || _unlinkedTypedef != null) { |
| 5112 _type = new FunctionTypeImpl.forTypedef(this); |
| 5113 } |
5074 } | 5114 } |
5075 return _type; | 5115 return _type; |
5076 } | 5116 } |
5077 | 5117 |
5078 void set type(FunctionType type) { | 5118 void set type(FunctionType type) { |
5079 _assertNotResynthesized(_unlinkedTypedef); | 5119 _assertNotResynthesized(_unlinkedTypedef); |
5080 _type = type; | 5120 _type = type; |
5081 } | 5121 } |
5082 | 5122 |
5083 /** | 5123 /** |
(...skipping 4617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9701 | 9741 |
9702 @override | 9742 @override |
9703 DartObject computeConstantValue() => null; | 9743 DartObject computeConstantValue() => null; |
9704 | 9744 |
9705 @override | 9745 @override |
9706 void visitChildren(ElementVisitor visitor) { | 9746 void visitChildren(ElementVisitor visitor) { |
9707 super.visitChildren(visitor); | 9747 super.visitChildren(visitor); |
9708 _initializer?.accept(visitor); | 9748 _initializer?.accept(visitor); |
9709 } | 9749 } |
9710 } | 9750 } |
OLD | NEW |