| 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 } | |
| 1691 if (_unlinkedUnit != null) { | 1686 if (_unlinkedUnit != null) { |
| 1692 _typeAliases ??= _unlinkedUnit.typedefs.map((t) { | 1687 _typeAliases ??= _unlinkedUnit.typedefs.map((t) { |
| 1693 if (t.style == TypedefStyle.functionType) { | 1688 if (t.style == TypedefStyle.functionType) { |
| 1694 return new FunctionTypeAliasElementImpl.forSerialized(t, this); | 1689 return new FunctionTypeAliasElementImpl.forSerialized(t, this); |
| 1695 } else if (t.style == TypedefStyle.genericFunctionType) { | 1690 } else if (t.style == TypedefStyle.genericFunctionType) { |
| 1696 return new GenericTypeAliasElementImpl.forSerialized(t, this); | 1691 return new GenericTypeAliasElementImpl.forSerialized(t, this); |
| 1697 } | 1692 } |
| 1698 }).toList(growable: false); | 1693 }).toList(growable: false); |
| 1699 } | 1694 } |
| 1700 return _typeAliases ?? const <FunctionTypeAliasElement>[]; | 1695 return _typeAliases ?? const <FunctionTypeAliasElement>[]; |
| (...skipping 2266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3967 return _kernel.name.name; | 3962 return _kernel.name.name; |
| 3968 } | 3963 } |
| 3969 if (serializedExecutable != null) { | 3964 if (serializedExecutable != null) { |
| 3970 return serializedExecutable.name; | 3965 return serializedExecutable.name; |
| 3971 } | 3966 } |
| 3972 return super.displayName; | 3967 return super.displayName; |
| 3973 } | 3968 } |
| 3974 | 3969 |
| 3975 @override | 3970 @override |
| 3976 String get documentationComment { | 3971 String get documentationComment { |
| 3977 if (_kernel != null) { | |
| 3978 return _kernel.documentationComment; | |
| 3979 } | |
| 3980 if (serializedExecutable != null) { | 3972 if (serializedExecutable != null) { |
| 3981 return serializedExecutable?.documentationComment?.text; | 3973 return serializedExecutable?.documentationComment?.text; |
| 3982 } | 3974 } |
| 3983 return super.documentationComment; | 3975 return super.documentationComment; |
| 3984 } | 3976 } |
| 3985 | 3977 |
| 3986 /** | 3978 /** |
| 3987 * Set whether this executable element is external. | 3979 * Set whether this executable element is external. |
| 3988 */ | 3980 */ |
| 3989 void set external(bool isExternal) { | 3981 void set external(bool isExternal) { |
| (...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4922 */ | 4914 */ |
| 4923 class FunctionTypeAliasElementImpl extends ElementImpl | 4915 class FunctionTypeAliasElementImpl extends ElementImpl |
| 4924 with TypeParameterizedElementMixin | 4916 with TypeParameterizedElementMixin |
| 4925 implements FunctionTypeAliasElement { | 4917 implements FunctionTypeAliasElement { |
| 4926 /** | 4918 /** |
| 4927 * The unlinked representation of the type in the summary. | 4919 * The unlinked representation of the type in the summary. |
| 4928 */ | 4920 */ |
| 4929 final UnlinkedTypedef _unlinkedTypedef; | 4921 final UnlinkedTypedef _unlinkedTypedef; |
| 4930 | 4922 |
| 4931 /** | 4923 /** |
| 4932 * The kernel of the element. | |
| 4933 */ | |
| 4934 final kernel.Typedef _kernel; | |
| 4935 | |
| 4936 /** | |
| 4937 * A list containing all of the parameters defined by this type alias. | 4924 * A list containing all of the parameters defined by this type alias. |
| 4938 */ | 4925 */ |
| 4939 List<ParameterElement> _parameters; | 4926 List<ParameterElement> _parameters; |
| 4940 | 4927 |
| 4941 /** | 4928 /** |
| 4942 * The return type defined by this type alias. | 4929 * The return type defined by this type alias. |
| 4943 */ | 4930 */ |
| 4944 DartType _returnType; | 4931 DartType _returnType; |
| 4945 | 4932 |
| 4946 /** | 4933 /** |
| 4947 * The type of function defined by this type alias. | 4934 * The type of function defined by this type alias. |
| 4948 */ | 4935 */ |
| 4949 FunctionType _type; | 4936 FunctionType _type; |
| 4950 | 4937 |
| 4951 /** | 4938 /** |
| 4952 * Initialize a newly created type alias element to have the given name. | 4939 * Initialize a newly created type alias element to have the given name. |
| 4953 * | 4940 * |
| 4954 * [name] the name of this element | 4941 * [name] the name of this element |
| 4955 * [nameOffset] the offset of the name of this element in the file that | 4942 * [nameOffset] the offset of the name of this element in the file that |
| 4956 * contains the declaration of this element | 4943 * contains the declaration of this element |
| 4957 */ | 4944 */ |
| 4958 FunctionTypeAliasElementImpl(String name, int nameOffset) | 4945 FunctionTypeAliasElementImpl(String name, int nameOffset) |
| 4959 : _unlinkedTypedef = null, | 4946 : _unlinkedTypedef = null, |
| 4960 _kernel = null, | |
| 4961 super(name, nameOffset); | 4947 super(name, nameOffset); |
| 4962 | 4948 |
| 4963 /** | 4949 /** |
| 4964 * Initialize using the given kernel. | |
| 4965 */ | |
| 4966 FunctionTypeAliasElementImpl.forKernel( | |
| 4967 CompilationUnitElementImpl enclosingUnit, this._kernel) | |
| 4968 : _unlinkedTypedef = null, | |
| 4969 super.forSerialized(enclosingUnit); | |
| 4970 | |
| 4971 /** | |
| 4972 * Initialize a newly created type alias element to have the given [name]. | 4950 * Initialize a newly created type alias element to have the given [name]. |
| 4973 */ | 4951 */ |
| 4974 FunctionTypeAliasElementImpl.forNode(Identifier name) | 4952 FunctionTypeAliasElementImpl.forNode(Identifier name) |
| 4975 : _unlinkedTypedef = null, | 4953 : _unlinkedTypedef = null, |
| 4976 _kernel = null, | |
| 4977 super.forNode(name); | 4954 super.forNode(name); |
| 4978 | 4955 |
| 4979 /** | 4956 /** |
| 4980 * Initialize using the given serialized information. | 4957 * Initialize using the given serialized information. |
| 4981 */ | 4958 */ |
| 4982 FunctionTypeAliasElementImpl.forSerialized( | 4959 FunctionTypeAliasElementImpl.forSerialized( |
| 4983 this._unlinkedTypedef, CompilationUnitElementImpl enclosingUnit) | 4960 this._unlinkedTypedef, CompilationUnitElementImpl enclosingUnit) |
| 4984 : _kernel = null, | 4961 : super.forSerialized(enclosingUnit); |
| 4985 super.forSerialized(enclosingUnit); | |
| 4986 | 4962 |
| 4987 @override | 4963 @override |
| 4988 int get codeLength { | 4964 int get codeLength { |
| 4989 if (_unlinkedTypedef != null) { | 4965 if (_unlinkedTypedef != null) { |
| 4990 return _unlinkedTypedef.codeRange?.length; | 4966 return _unlinkedTypedef.codeRange?.length; |
| 4991 } | 4967 } |
| 4992 return super.codeLength; | 4968 return super.codeLength; |
| 4993 } | 4969 } |
| 4994 | 4970 |
| 4995 @override | 4971 @override |
| (...skipping 20 matching lines...) Expand all Loading... |
| 5016 super.enclosingElement as CompilationUnitElement; | 4992 super.enclosingElement as CompilationUnitElement; |
| 5017 | 4993 |
| 5018 @override | 4994 @override |
| 5019 TypeParameterizedElementMixin get enclosingTypeParameterContext => null; | 4995 TypeParameterizedElementMixin get enclosingTypeParameterContext => null; |
| 5020 | 4996 |
| 5021 @override | 4997 @override |
| 5022 CompilationUnitElementImpl get enclosingUnit => | 4998 CompilationUnitElementImpl get enclosingUnit => |
| 5023 _enclosingElement as CompilationUnitElementImpl; | 4999 _enclosingElement as CompilationUnitElementImpl; |
| 5024 | 5000 |
| 5025 @override | 5001 @override |
| 5026 List<kernel.TypeParameter> get kernelTypeParams => _kernel?.typeParameters; | 5002 List<kernel.TypeParameter> get kernelTypeParams => null; |
| 5027 | 5003 |
| 5028 @override | 5004 @override |
| 5029 ElementKind get kind => ElementKind.FUNCTION_TYPE_ALIAS; | 5005 ElementKind get kind => ElementKind.FUNCTION_TYPE_ALIAS; |
| 5030 | 5006 |
| 5031 @override | 5007 @override |
| 5032 List<ElementAnnotation> get metadata { | 5008 List<ElementAnnotation> get metadata { |
| 5033 if (_unlinkedTypedef != null) { | 5009 if (_unlinkedTypedef != null) { |
| 5034 return _metadata ??= | 5010 return _metadata ??= |
| 5035 _buildAnnotations(enclosingUnit, _unlinkedTypedef.annotations); | 5011 _buildAnnotations(enclosingUnit, _unlinkedTypedef.annotations); |
| 5036 } | 5012 } |
| 5037 return super.metadata; | 5013 return super.metadata; |
| 5038 } | 5014 } |
| 5039 | 5015 |
| 5040 @override | 5016 @override |
| 5041 String get name { | 5017 String get name { |
| 5042 if (_kernel != null) { | |
| 5043 return _kernel.name; | |
| 5044 } | |
| 5045 if (_unlinkedTypedef != null) { | 5018 if (_unlinkedTypedef != null) { |
| 5046 return _unlinkedTypedef.name; | 5019 return _unlinkedTypedef.name; |
| 5047 } | 5020 } |
| 5048 return super.name; | 5021 return super.name; |
| 5049 } | 5022 } |
| 5050 | 5023 |
| 5051 @override | 5024 @override |
| 5052 int get nameOffset { | 5025 int get nameOffset { |
| 5053 int offset = super.nameOffset; | 5026 int offset = super.nameOffset; |
| 5054 if (offset == 0 && _unlinkedTypedef != null) { | 5027 if (offset == 0 && _unlinkedTypedef != null) { |
| 5055 return _unlinkedTypedef.nameOffset; | 5028 return _unlinkedTypedef.nameOffset; |
| 5056 } | 5029 } |
| 5057 return offset; | 5030 return offset; |
| 5058 } | 5031 } |
| 5059 | 5032 |
| 5060 @override | 5033 @override |
| 5061 List<ParameterElement> get parameters { | 5034 List<ParameterElement> get parameters { |
| 5062 if (_kernel != null) { | |
| 5063 _parameters ??= ParameterElementImpl.forKernelParameters( | |
| 5064 this, | |
| 5065 _kernel.requiredParameterCount, | |
| 5066 _kernel.positionalParameters, | |
| 5067 _kernel.namedParameters); | |
| 5068 } | |
| 5069 if (_unlinkedTypedef != null) { | 5035 if (_unlinkedTypedef != null) { |
| 5070 _parameters ??= ParameterElementImpl.resynthesizeList( | 5036 _parameters ??= ParameterElementImpl.resynthesizeList( |
| 5071 _unlinkedTypedef.parameters, this); | 5037 _unlinkedTypedef.parameters, this); |
| 5072 } | 5038 } |
| 5073 return _parameters ?? const <ParameterElement>[]; | 5039 return _parameters ?? const <ParameterElement>[]; |
| 5074 } | 5040 } |
| 5075 | 5041 |
| 5076 /** | 5042 /** |
| 5077 * Set the parameters defined by this type alias to the given [parameters]. | 5043 * Set the parameters defined by this type alias to the given [parameters]. |
| 5078 */ | 5044 */ |
| 5079 void set parameters(List<ParameterElement> parameters) { | 5045 void set parameters(List<ParameterElement> parameters) { |
| 5080 _assertNotResynthesized(_unlinkedTypedef); | 5046 _assertNotResynthesized(_unlinkedTypedef); |
| 5081 if (parameters != null) { | 5047 if (parameters != null) { |
| 5082 for (ParameterElement parameter in parameters) { | 5048 for (ParameterElement parameter in parameters) { |
| 5083 (parameter as ParameterElementImpl).enclosingElement = this; | 5049 (parameter as ParameterElementImpl).enclosingElement = this; |
| 5084 } | 5050 } |
| 5085 } | 5051 } |
| 5086 this._parameters = parameters; | 5052 this._parameters = parameters; |
| 5087 } | 5053 } |
| 5088 | 5054 |
| 5089 @override | 5055 @override |
| 5090 DartType get returnType { | 5056 DartType get returnType { |
| 5091 if (_returnType == null) { | 5057 if (_unlinkedTypedef != null && _returnType == null) { |
| 5092 if (_kernel != null) { | 5058 _returnType = enclosingUnit.resynthesizerContext.resolveTypeRef( |
| 5093 var type = _kernel.type as kernel.FunctionType; | 5059 this, _unlinkedTypedef.returnType, |
| 5094 _returnType = | 5060 declaredType: true); |
| 5095 enclosingUnit._kernelContext.getType(this, type.returnType); | |
| 5096 } | |
| 5097 if (_unlinkedTypedef != null) { | |
| 5098 _returnType = enclosingUnit.resynthesizerContext.resolveTypeRef( | |
| 5099 this, _unlinkedTypedef.returnType, | |
| 5100 declaredType: true); | |
| 5101 } | |
| 5102 } | 5061 } |
| 5103 return _returnType; | 5062 return _returnType; |
| 5104 } | 5063 } |
| 5105 | 5064 |
| 5106 void set returnType(DartType returnType) { | 5065 void set returnType(DartType returnType) { |
| 5107 _assertNotResynthesized(_unlinkedTypedef); | 5066 _assertNotResynthesized(_unlinkedTypedef); |
| 5108 _returnType = _checkElementOfType(returnType); | 5067 _returnType = _checkElementOfType(returnType); |
| 5109 } | 5068 } |
| 5110 | 5069 |
| 5111 @override | 5070 @override |
| 5112 FunctionType get type { | 5071 FunctionType get type { |
| 5113 if (_type == null) { | 5072 if (_unlinkedTypedef != null && _type == null) { |
| 5114 if (_kernel != null || _unlinkedTypedef != null) { | 5073 _type = new FunctionTypeImpl.forTypedef(this); |
| 5115 _type = new FunctionTypeImpl.forTypedef(this); | |
| 5116 } | |
| 5117 } | 5074 } |
| 5118 return _type; | 5075 return _type; |
| 5119 } | 5076 } |
| 5120 | 5077 |
| 5121 void set type(FunctionType type) { | 5078 void set type(FunctionType type) { |
| 5122 _assertNotResynthesized(_unlinkedTypedef); | 5079 _assertNotResynthesized(_unlinkedTypedef); |
| 5123 _type = type; | 5080 _type = type; |
| 5124 } | 5081 } |
| 5125 | 5082 |
| 5126 /** | 5083 /** |
| (...skipping 2479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7606 @override | 7563 @override |
| 7607 int get codeOffset { | 7564 int get codeOffset { |
| 7608 if (_unlinkedVariable != null) { | 7565 if (_unlinkedVariable != null) { |
| 7609 return _unlinkedVariable.codeRange?.offset; | 7566 return _unlinkedVariable.codeRange?.offset; |
| 7610 } | 7567 } |
| 7611 return super.codeOffset; | 7568 return super.codeOffset; |
| 7612 } | 7569 } |
| 7613 | 7570 |
| 7614 @override | 7571 @override |
| 7615 String get documentationComment { | 7572 String get documentationComment { |
| 7616 if (_kernel != null) { | |
| 7617 return _kernel.documentationComment; | |
| 7618 } | |
| 7619 if (_unlinkedVariable != null) { | 7573 if (_unlinkedVariable != null) { |
| 7620 return _unlinkedVariable?.documentationComment?.text; | 7574 return _unlinkedVariable?.documentationComment?.text; |
| 7621 } | 7575 } |
| 7622 return super.documentationComment; | 7576 return super.documentationComment; |
| 7623 } | 7577 } |
| 7624 | 7578 |
| 7625 @override | 7579 @override |
| 7626 bool get hasImplicitType { | 7580 bool get hasImplicitType { |
| 7627 if (_unlinkedVariable != null) { | 7581 if (_unlinkedVariable != null) { |
| 7628 return _unlinkedVariable.type == null; | 7582 return _unlinkedVariable.type == null; |
| (...skipping 2118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9747 | 9701 |
| 9748 @override | 9702 @override |
| 9749 DartObject computeConstantValue() => null; | 9703 DartObject computeConstantValue() => null; |
| 9750 | 9704 |
| 9751 @override | 9705 @override |
| 9752 void visitChildren(ElementVisitor visitor) { | 9706 void visitChildren(ElementVisitor visitor) { |
| 9753 super.visitChildren(visitor); | 9707 super.visitChildren(visitor); |
| 9754 _initializer?.accept(visitor); | 9708 _initializer?.accept(visitor); |
| 9755 } | 9709 } |
| 9756 } | 9710 } |
| OLD | NEW |