| 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 1671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1682 */ | 1682 */ |
| 1683 void set functions(List<FunctionElement> functions) { | 1683 void set functions(List<FunctionElement> functions) { |
| 1684 for (FunctionElement function in functions) { | 1684 for (FunctionElement function in functions) { |
| 1685 (function as FunctionElementImpl).enclosingElement = this; | 1685 (function as FunctionElementImpl).enclosingElement = this; |
| 1686 } | 1686 } |
| 1687 this._functions = functions; | 1687 this._functions = functions; |
| 1688 } | 1688 } |
| 1689 | 1689 |
| 1690 @override | 1690 @override |
| 1691 List<FunctionTypeAliasElement> get functionTypeAliases { | 1691 List<FunctionTypeAliasElement> get functionTypeAliases { |
| 1692 if (_kernelContext != null) { |
| 1693 _typeAliases ??= _kernelContext.library.typedefs |
| 1694 .map((k) => new FunctionTypeAliasElementImpl.forKernel(this, k)) |
| 1695 .toList(growable: false); |
| 1696 } |
| 1692 if (_unlinkedUnit != null) { | 1697 if (_unlinkedUnit != null) { |
| 1693 _typeAliases ??= _unlinkedUnit.typedefs.map((t) { | 1698 _typeAliases ??= _unlinkedUnit.typedefs.map((t) { |
| 1694 if (t.style == TypedefStyle.functionType) { | 1699 if (t.style == TypedefStyle.functionType) { |
| 1695 return new FunctionTypeAliasElementImpl.forSerialized(t, this); | 1700 return new FunctionTypeAliasElementImpl.forSerialized(t, this); |
| 1696 } else if (t.style == TypedefStyle.genericFunctionType) { | 1701 } else if (t.style == TypedefStyle.genericFunctionType) { |
| 1697 return new GenericTypeAliasElementImpl.forSerialized(t, this); | 1702 return new GenericTypeAliasElementImpl.forSerialized(t, this); |
| 1698 } | 1703 } |
| 1699 }).toList(growable: false); | 1704 }).toList(growable: false); |
| 1700 } | 1705 } |
| 1701 return _typeAliases ?? const <FunctionTypeAliasElement>[]; | 1706 return _typeAliases ?? const <FunctionTypeAliasElement>[]; |
| (...skipping 3274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4976 */ | 4981 */ |
| 4977 class FunctionTypeAliasElementImpl extends ElementImpl | 4982 class FunctionTypeAliasElementImpl extends ElementImpl |
| 4978 with TypeParameterizedElementMixin | 4983 with TypeParameterizedElementMixin |
| 4979 implements FunctionTypeAliasElement { | 4984 implements FunctionTypeAliasElement { |
| 4980 /** | 4985 /** |
| 4981 * The unlinked representation of the type in the summary. | 4986 * The unlinked representation of the type in the summary. |
| 4982 */ | 4987 */ |
| 4983 final UnlinkedTypedef _unlinkedTypedef; | 4988 final UnlinkedTypedef _unlinkedTypedef; |
| 4984 | 4989 |
| 4985 /** | 4990 /** |
| 4991 * The kernel of the element. |
| 4992 */ |
| 4993 final kernel.Typedef _kernel; |
| 4994 |
| 4995 /** |
| 4986 * A list containing all of the parameters defined by this type alias. | 4996 * A list containing all of the parameters defined by this type alias. |
| 4987 */ | 4997 */ |
| 4988 List<ParameterElement> _parameters; | 4998 List<ParameterElement> _parameters; |
| 4989 | 4999 |
| 4990 /** | 5000 /** |
| 4991 * The return type defined by this type alias. | 5001 * The return type defined by this type alias. |
| 4992 */ | 5002 */ |
| 4993 DartType _returnType; | 5003 DartType _returnType; |
| 4994 | 5004 |
| 4995 /** | 5005 /** |
| 4996 * The type of function defined by this type alias. | 5006 * The type of function defined by this type alias. |
| 4997 */ | 5007 */ |
| 4998 FunctionType _type; | 5008 FunctionType _type; |
| 4999 | 5009 |
| 5000 /** | 5010 /** |
| 5001 * Initialize a newly created type alias element to have the given name. | 5011 * Initialize a newly created type alias element to have the given name. |
| 5002 * | 5012 * |
| 5003 * [name] the name of this element | 5013 * [name] the name of this element |
| 5004 * [nameOffset] the offset of the name of this element in the file that | 5014 * [nameOffset] the offset of the name of this element in the file that |
| 5005 * contains the declaration of this element | 5015 * contains the declaration of this element |
| 5006 */ | 5016 */ |
| 5007 FunctionTypeAliasElementImpl(String name, int nameOffset) | 5017 FunctionTypeAliasElementImpl(String name, int nameOffset) |
| 5008 : _unlinkedTypedef = null, | 5018 : _unlinkedTypedef = null, |
| 5019 _kernel = null, |
| 5009 super(name, nameOffset); | 5020 super(name, nameOffset); |
| 5010 | 5021 |
| 5011 /** | 5022 /** |
| 5023 * Initialize using the given kernel. |
| 5024 */ |
| 5025 FunctionTypeAliasElementImpl.forKernel( |
| 5026 CompilationUnitElementImpl enclosingUnit, this._kernel) |
| 5027 : _unlinkedTypedef = null, |
| 5028 super.forSerialized(enclosingUnit); |
| 5029 |
| 5030 /** |
| 5012 * Initialize a newly created type alias element to have the given [name]. | 5031 * Initialize a newly created type alias element to have the given [name]. |
| 5013 */ | 5032 */ |
| 5014 FunctionTypeAliasElementImpl.forNode(Identifier name) | 5033 FunctionTypeAliasElementImpl.forNode(Identifier name) |
| 5015 : _unlinkedTypedef = null, | 5034 : _unlinkedTypedef = null, |
| 5035 _kernel = null, |
| 5016 super.forNode(name); | 5036 super.forNode(name); |
| 5017 | 5037 |
| 5018 /** | 5038 /** |
| 5019 * Initialize using the given serialized information. | 5039 * Initialize using the given serialized information. |
| 5020 */ | 5040 */ |
| 5021 FunctionTypeAliasElementImpl.forSerialized( | 5041 FunctionTypeAliasElementImpl.forSerialized( |
| 5022 this._unlinkedTypedef, CompilationUnitElementImpl enclosingUnit) | 5042 this._unlinkedTypedef, CompilationUnitElementImpl enclosingUnit) |
| 5023 : super.forSerialized(enclosingUnit); | 5043 : _kernel = null, |
| 5044 super.forSerialized(enclosingUnit); |
| 5024 | 5045 |
| 5025 @override | 5046 @override |
| 5026 int get codeLength { | 5047 int get codeLength { |
| 5027 if (_unlinkedTypedef != null) { | 5048 if (_unlinkedTypedef != null) { |
| 5028 return _unlinkedTypedef.codeRange?.length; | 5049 return _unlinkedTypedef.codeRange?.length; |
| 5029 } | 5050 } |
| 5030 return super.codeLength; | 5051 return super.codeLength; |
| 5031 } | 5052 } |
| 5032 | 5053 |
| 5033 @override | 5054 @override |
| (...skipping 20 matching lines...) Expand all Loading... |
| 5054 super.enclosingElement as CompilationUnitElement; | 5075 super.enclosingElement as CompilationUnitElement; |
| 5055 | 5076 |
| 5056 @override | 5077 @override |
| 5057 TypeParameterizedElementMixin get enclosingTypeParameterContext => null; | 5078 TypeParameterizedElementMixin get enclosingTypeParameterContext => null; |
| 5058 | 5079 |
| 5059 @override | 5080 @override |
| 5060 CompilationUnitElementImpl get enclosingUnit => | 5081 CompilationUnitElementImpl get enclosingUnit => |
| 5061 _enclosingElement as CompilationUnitElementImpl; | 5082 _enclosingElement as CompilationUnitElementImpl; |
| 5062 | 5083 |
| 5063 @override | 5084 @override |
| 5064 List<kernel.TypeParameter> get kernelTypeParams => null; | 5085 List<kernel.TypeParameter> get kernelTypeParams => _kernel?.typeParameters; |
| 5065 | 5086 |
| 5066 @override | 5087 @override |
| 5067 ElementKind get kind => ElementKind.FUNCTION_TYPE_ALIAS; | 5088 ElementKind get kind => ElementKind.FUNCTION_TYPE_ALIAS; |
| 5068 | 5089 |
| 5069 @override | 5090 @override |
| 5070 List<ElementAnnotation> get metadata { | 5091 List<ElementAnnotation> get metadata { |
| 5071 if (_unlinkedTypedef != null) { | 5092 if (_unlinkedTypedef != null) { |
| 5072 return _metadata ??= | 5093 return _metadata ??= |
| 5073 _buildAnnotations(enclosingUnit, _unlinkedTypedef.annotations); | 5094 _buildAnnotations(enclosingUnit, _unlinkedTypedef.annotations); |
| 5074 } | 5095 } |
| 5075 return super.metadata; | 5096 return super.metadata; |
| 5076 } | 5097 } |
| 5077 | 5098 |
| 5078 @override | 5099 @override |
| 5079 String get name { | 5100 String get name { |
| 5101 if (_kernel != null) { |
| 5102 return _kernel.name; |
| 5103 } |
| 5080 if (_unlinkedTypedef != null) { | 5104 if (_unlinkedTypedef != null) { |
| 5081 return _unlinkedTypedef.name; | 5105 return _unlinkedTypedef.name; |
| 5082 } | 5106 } |
| 5083 return super.name; | 5107 return super.name; |
| 5084 } | 5108 } |
| 5085 | 5109 |
| 5086 @override | 5110 @override |
| 5087 int get nameOffset { | 5111 int get nameOffset { |
| 5088 int offset = super.nameOffset; | 5112 int offset = super.nameOffset; |
| 5089 if (offset == 0 && _unlinkedTypedef != null) { | 5113 if (offset == 0 && _unlinkedTypedef != null) { |
| 5090 return _unlinkedTypedef.nameOffset; | 5114 return _unlinkedTypedef.nameOffset; |
| 5091 } | 5115 } |
| 5092 return offset; | 5116 return offset; |
| 5093 } | 5117 } |
| 5094 | 5118 |
| 5095 @override | 5119 @override |
| 5096 List<ParameterElement> get parameters { | 5120 List<ParameterElement> get parameters { |
| 5097 if (_unlinkedTypedef != null) { | 5121 if (_parameters == null) { |
| 5098 _parameters ??= ParameterElementImpl.resynthesizeList( | 5122 if (_kernel != null) { |
| 5099 _unlinkedTypedef.parameters, this); | 5123 var type = _kernel.type as kernel.FunctionType; |
| 5124 |
| 5125 var parameters = |
| 5126 enclosingUnit._kernelContext.getFunctionTypeParameters(type); |
| 5127 var positionalParameters = parameters[0]; |
| 5128 var namedParameters = parameters[1]; |
| 5129 _parameters = ParameterElementImpl.forKernelParameters(this, |
| 5130 type.requiredParameterCount, positionalParameters, namedParameters); |
| 5131 } |
| 5132 if (_unlinkedTypedef != null) { |
| 5133 _parameters = ParameterElementImpl.resynthesizeList( |
| 5134 _unlinkedTypedef.parameters, this); |
| 5135 } |
| 5100 } | 5136 } |
| 5101 return _parameters ?? const <ParameterElement>[]; | 5137 return _parameters ?? const <ParameterElement>[]; |
| 5102 } | 5138 } |
| 5103 | 5139 |
| 5104 /** | 5140 /** |
| 5105 * Set the parameters defined by this type alias to the given [parameters]. | 5141 * Set the parameters defined by this type alias to the given [parameters]. |
| 5106 */ | 5142 */ |
| 5107 void set parameters(List<ParameterElement> parameters) { | 5143 void set parameters(List<ParameterElement> parameters) { |
| 5108 _assertNotResynthesized(_unlinkedTypedef); | 5144 _assertNotResynthesized(_unlinkedTypedef); |
| 5109 if (parameters != null) { | 5145 if (parameters != null) { |
| 5110 for (ParameterElement parameter in parameters) { | 5146 for (ParameterElement parameter in parameters) { |
| 5111 (parameter as ParameterElementImpl).enclosingElement = this; | 5147 (parameter as ParameterElementImpl).enclosingElement = this; |
| 5112 } | 5148 } |
| 5113 } | 5149 } |
| 5114 this._parameters = parameters; | 5150 this._parameters = parameters; |
| 5115 } | 5151 } |
| 5116 | 5152 |
| 5117 @override | 5153 @override |
| 5118 DartType get returnType { | 5154 DartType get returnType { |
| 5119 if (_unlinkedTypedef != null && _returnType == null) { | 5155 if (_returnType == null) { |
| 5120 _returnType = enclosingUnit.resynthesizerContext.resolveTypeRef( | 5156 if (_kernel != null) { |
| 5121 this, _unlinkedTypedef.returnType, | 5157 var type = _kernel.type as kernel.FunctionType; |
| 5122 declaredType: true); | 5158 _returnType = |
| 5159 enclosingUnit._kernelContext.getType(this, type.returnType); |
| 5160 } |
| 5161 if (_unlinkedTypedef != null) { |
| 5162 _returnType = enclosingUnit.resynthesizerContext.resolveTypeRef( |
| 5163 this, _unlinkedTypedef.returnType, |
| 5164 declaredType: true); |
| 5165 } |
| 5123 } | 5166 } |
| 5124 return _returnType; | 5167 return _returnType; |
| 5125 } | 5168 } |
| 5126 | 5169 |
| 5127 void set returnType(DartType returnType) { | 5170 void set returnType(DartType returnType) { |
| 5128 _assertNotResynthesized(_unlinkedTypedef); | 5171 _assertNotResynthesized(_unlinkedTypedef); |
| 5129 _returnType = _checkElementOfType(returnType); | 5172 _returnType = _checkElementOfType(returnType); |
| 5130 } | 5173 } |
| 5131 | 5174 |
| 5132 @override | 5175 @override |
| 5133 FunctionType get type { | 5176 FunctionType get type { |
| 5134 if (_unlinkedTypedef != null && _type == null) { | 5177 if (_type == null) { |
| 5135 _type = new FunctionTypeImpl.forTypedef(this); | 5178 if (_kernel != null || _unlinkedTypedef != null) { |
| 5179 _type = new FunctionTypeImpl.forTypedef(this); |
| 5180 } |
| 5136 } | 5181 } |
| 5137 return _type; | 5182 return _type; |
| 5138 } | 5183 } |
| 5139 | 5184 |
| 5140 void set type(FunctionType type) { | 5185 void set type(FunctionType type) { |
| 5141 _assertNotResynthesized(_unlinkedTypedef); | 5186 _assertNotResynthesized(_unlinkedTypedef); |
| 5142 _type = type; | 5187 _type = type; |
| 5143 } | 5188 } |
| 5144 | 5189 |
| 5145 /** | 5190 /** |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5667 * The names that are not to be made visible in the importing library even if | 5712 * The names that are not to be made visible in the importing library even if |
| 5668 * they are defined in the imported library. | 5713 * they are defined in the imported library. |
| 5669 */ | 5714 */ |
| 5670 List<String> _hiddenNames; | 5715 List<String> _hiddenNames; |
| 5671 | 5716 |
| 5672 HideElementCombinatorImpl() | 5717 HideElementCombinatorImpl() |
| 5673 : _unlinkedCombinator = null, | 5718 : _unlinkedCombinator = null, |
| 5674 _kernel = null; | 5719 _kernel = null; |
| 5675 | 5720 |
| 5676 /** | 5721 /** |
| 5722 * Initialize using the given kernel. |
| 5723 */ |
| 5724 HideElementCombinatorImpl.forKernel(this._kernel) |
| 5725 : _unlinkedCombinator = null; |
| 5726 |
| 5727 /** |
| 5677 * Initialize using the given serialized information. | 5728 * Initialize using the given serialized information. |
| 5678 */ | 5729 */ |
| 5679 HideElementCombinatorImpl.forSerialized(this._unlinkedCombinator) | 5730 HideElementCombinatorImpl.forSerialized(this._unlinkedCombinator) |
| 5680 : _kernel = null; | 5731 : _kernel = null; |
| 5681 | 5732 |
| 5682 /** | |
| 5683 * Initialize using the given kernel. | |
| 5684 */ | |
| 5685 HideElementCombinatorImpl.forKernel(this._kernel) | |
| 5686 : _unlinkedCombinator = null; | |
| 5687 | |
| 5688 @override | 5733 @override |
| 5689 List<String> get hiddenNames { | 5734 List<String> get hiddenNames { |
| 5690 if (_kernel != null) { | 5735 if (_kernel != null) { |
| 5691 _hiddenNames ??= _kernel.names; | 5736 _hiddenNames ??= _kernel.names; |
| 5692 } | 5737 } |
| 5693 if (_unlinkedCombinator != null) { | 5738 if (_unlinkedCombinator != null) { |
| 5694 _hiddenNames ??= _unlinkedCombinator.hides.toList(growable: false); | 5739 _hiddenNames ??= _unlinkedCombinator.hides.toList(growable: false); |
| 5695 } | 5740 } |
| 5696 return _hiddenNames ?? const <String>[]; | 5741 return _hiddenNames ?? const <String>[]; |
| 5697 } | 5742 } |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6060 */ | 6105 */ |
| 6061 ConstructorInitializer getConstructorInitializer( | 6106 ConstructorInitializer getConstructorInitializer( |
| 6062 ConstructorElementImpl constructor, kernel.Initializer initializer); | 6107 ConstructorElementImpl constructor, kernel.Initializer initializer); |
| 6063 | 6108 |
| 6064 /** | 6109 /** |
| 6065 * Return the [Expression] for the given kernel. | 6110 * Return the [Expression] for the given kernel. |
| 6066 */ | 6111 */ |
| 6067 Expression getExpression(kernel.Expression expression); | 6112 Expression getExpression(kernel.Expression expression); |
| 6068 | 6113 |
| 6069 /** | 6114 /** |
| 6115 * Return the list with exactly two elements - positional and named parameter |
| 6116 * lists. |
| 6117 */ |
| 6118 List<List<kernel.VariableDeclaration>> getFunctionTypeParameters( |
| 6119 kernel.FunctionType functionType); |
| 6120 |
| 6121 /** |
| 6070 * Return the [InterfaceType] for the given Kernel [type], or `null` if the | 6122 * Return the [InterfaceType] for the given Kernel [type], or `null` if the |
| 6071 * [type] does not correspond to an [InterfaceType]. | 6123 * [type] does not correspond to an [InterfaceType]. |
| 6072 */ | 6124 */ |
| 6073 InterfaceType getInterfaceType(ElementImpl context, kernel.Supertype type); | 6125 InterfaceType getInterfaceType(ElementImpl context, kernel.Supertype type); |
| 6074 | 6126 |
| 6075 /** | 6127 /** |
| 6076 * Return the [LibraryElement] for the given absolute [uriStr]. | 6128 * Return the [LibraryElement] for the given absolute [uriStr]. |
| 6077 */ | 6129 */ |
| 6078 LibraryElement getLibrary(String uriStr); | 6130 LibraryElement getLibrary(String uriStr); |
| 6079 | 6131 |
| (...skipping 3047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9127 /** | 9179 /** |
| 9128 * The offset of the 'show' keyword of this element. | 9180 * The offset of the 'show' keyword of this element. |
| 9129 */ | 9181 */ |
| 9130 int _offset = 0; | 9182 int _offset = 0; |
| 9131 | 9183 |
| 9132 ShowElementCombinatorImpl() | 9184 ShowElementCombinatorImpl() |
| 9133 : _unlinkedCombinator = null, | 9185 : _unlinkedCombinator = null, |
| 9134 _kernel = null; | 9186 _kernel = null; |
| 9135 | 9187 |
| 9136 /** | 9188 /** |
| 9189 * Initialize using the given kernel. |
| 9190 */ |
| 9191 ShowElementCombinatorImpl.forKernel(this._kernel) |
| 9192 : _unlinkedCombinator = null; |
| 9193 |
| 9194 /** |
| 9137 * Initialize using the given serialized information. | 9195 * Initialize using the given serialized information. |
| 9138 */ | 9196 */ |
| 9139 ShowElementCombinatorImpl.forSerialized(this._unlinkedCombinator) | 9197 ShowElementCombinatorImpl.forSerialized(this._unlinkedCombinator) |
| 9140 : _kernel = null; | 9198 : _kernel = null; |
| 9141 | 9199 |
| 9142 /** | |
| 9143 * Initialize using the given kernel. | |
| 9144 */ | |
| 9145 ShowElementCombinatorImpl.forKernel(this._kernel) | |
| 9146 : _unlinkedCombinator = null; | |
| 9147 | |
| 9148 @override | 9200 @override |
| 9149 int get end { | 9201 int get end { |
| 9150 if (_unlinkedCombinator != null) { | 9202 if (_unlinkedCombinator != null) { |
| 9151 return _unlinkedCombinator.end; | 9203 return _unlinkedCombinator.end; |
| 9152 } | 9204 } |
| 9153 return _end; | 9205 return _end; |
| 9154 } | 9206 } |
| 9155 | 9207 |
| 9156 void set end(int end) { | 9208 void set end(int end) { |
| 9157 _assertNotResynthesized(_unlinkedCombinator); | 9209 _assertNotResynthesized(_unlinkedCombinator); |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9864 | 9916 |
| 9865 @override | 9917 @override |
| 9866 DartObject computeConstantValue() => null; | 9918 DartObject computeConstantValue() => null; |
| 9867 | 9919 |
| 9868 @override | 9920 @override |
| 9869 void visitChildren(ElementVisitor visitor) { | 9921 void visitChildren(ElementVisitor visitor) { |
| 9870 super.visitChildren(visitor); | 9922 super.visitChildren(visitor); |
| 9871 _initializer?.accept(visitor); | 9923 _initializer?.accept(visitor); |
| 9872 } | 9924 } |
| 9873 } | 9925 } |
| OLD | NEW |