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

Side by Side Diff: pkg/analyzer/lib/src/dart/element/element.dart

Issue 1986853003: Move TypeParameterizedElementForLink and TypeParameterElementForLink to impl. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 /** 54 /**
55 * Initialize a newly created pair to have both the [staticElement] and the 55 * Initialize a newly created pair to have both the [staticElement] and the
56 * [propagatedElement]. 56 * [propagatedElement].
57 */ 57 */
58 AuxiliaryElements(this.staticElement, this.propagatedElement); 58 AuxiliaryElements(this.staticElement, this.propagatedElement);
59 } 59 }
60 60
61 /** 61 /**
62 * A concrete implementation of a [ClassElement]. 62 * A concrete implementation of a [ClassElement].
63 */ 63 */
64 class ClassElementImpl extends ElementImpl implements ClassElement { 64 class ClassElementImpl extends ElementImpl
65 with TypeParameterizedElementMixin
66 implements ClassElement {
65 /** 67 /**
66 * The unlinked representation of the class in the summary. 68 * The unlinked representation of the class in the summary.
67 */ 69 */
68 final UnlinkedClass _unlinkedClass; 70 final UnlinkedClass _unlinkedClass;
69 71
70 /** 72 /**
71 * A list containing all of the accessors (getters and setters) contained in 73 * A list containing all of the accessors (getters and setters) contained in
72 * this class. 74 * this class.
73 */ 75 */
74 List<PropertyAccessorElement> _accessors = PropertyAccessorElement.EMPTY_LIST; 76 List<PropertyAccessorElement> _accessors = PropertyAccessorElement.EMPTY_LIST;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 /** 144 /**
143 * Initialize a newly created class element to have the given [name]. 145 * Initialize a newly created class element to have the given [name].
144 */ 146 */
145 ClassElementImpl.forNode(Identifier name) 147 ClassElementImpl.forNode(Identifier name)
146 : _unlinkedClass = null, 148 : _unlinkedClass = null,
147 super.forNode(name); 149 super.forNode(name);
148 150
149 /** 151 /**
150 * Initialize using the given serialized information. 152 * Initialize using the given serialized information.
151 */ 153 */
152 ClassElementImpl.forSerialized(this._unlinkedClass) : super.forSerialized(); 154 ClassElementImpl.forSerialized(
155 ResynthesizerContext resynthesizerContext, this._unlinkedClass)
156 : super.forSerialized(resynthesizerContext);
153 157
154 /** 158 /**
155 * Set whether this class is abstract. 159 * Set whether this class is abstract.
156 */ 160 */
157 void set abstract(bool isAbstract) { 161 void set abstract(bool isAbstract) {
158 assert(_unlinkedClass == null); 162 assert(_unlinkedClass == null);
159 setModifier(Modifier.ABSTRACT, isAbstract); 163 setModifier(Modifier.ABSTRACT, isAbstract);
160 } 164 }
161 165
162 @override 166 @override
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 // supertype, and it is not a mixin application. 281 // supertype, and it is not a mixin application.
278 assert(false); 282 assert(false);
279 return false; 283 return false;
280 } 284 }
281 nearestNonMixinClass = nearestNonMixinClass.supertype.element; 285 nearestNonMixinClass = nearestNonMixinClass.supertype.element;
282 } 286 }
283 } 287 }
284 return !nearestNonMixinClass.constructors.any(isSuperConstructorAccessible); 288 return !nearestNonMixinClass.constructors.any(isSuperConstructorAccessible);
285 } 289 }
286 290
291 @override
292 TypeParameterizedElementMixin get enclosingTypeParameterContext => null;
293
287 /** 294 /**
288 * Set whether this class is defined by an enum declaration. 295 * Set whether this class is defined by an enum declaration.
289 */ 296 */
290 void set enum2(bool isEnum) { 297 void set enum2(bool isEnum) {
291 setModifier(Modifier.ENUM, isEnum); 298 setModifier(Modifier.ENUM, isEnum);
292 } 299 }
293 300
294 @override 301 @override
295 List<FieldElement> get fields => _fields; 302 List<FieldElement> get fields => _fields;
296 303
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 451
445 @override 452 @override
446 int get nameOffset { 453 int get nameOffset {
447 if (_unlinkedClass != null) { 454 if (_unlinkedClass != null) {
448 return _unlinkedClass.nameOffset; 455 return _unlinkedClass.nameOffset;
449 } 456 }
450 return super.nameOffset; 457 return super.nameOffset;
451 } 458 }
452 459
453 @override 460 @override
454 List<TypeParameterElement> get typeParameters => _typeParameters; 461 List<TypeParameterElement> get typeParameters {
462 if (_unlinkedClass != null) {
463 return super.typeParameters;
464 }
465 return _typeParameters;
466 }
455 467
456 /** 468 /**
457 * Set the type parameters defined for this class to the given 469 * Set the type parameters defined for this class to the given
458 * [typeParameters]. 470 * [typeParameters].
459 */ 471 */
460 void set typeParameters(List<TypeParameterElement> typeParameters) { 472 void set typeParameters(List<TypeParameterElement> typeParameters) {
473 assert(resynthesizerContext == null);
461 for (TypeParameterElement typeParameter in typeParameters) { 474 for (TypeParameterElement typeParameter in typeParameters) {
462 (typeParameter as TypeParameterElementImpl).enclosingElement = this; 475 (typeParameter as TypeParameterElementImpl).enclosingElement = this;
463 } 476 }
464 this._typeParameters = typeParameters; 477 this._typeParameters = typeParameters;
465 } 478 }
466 479
467 @override 480 @override
481 List<UnlinkedTypeParam> get unlinkedTypeParams =>
482 _unlinkedClass.typeParameters;
483
484 @override
468 ConstructorElement get unnamedConstructor { 485 ConstructorElement get unnamedConstructor {
469 for (ConstructorElement element in constructors) { 486 for (ConstructorElement element in constructors) {
470 String name = element.displayName; 487 String name = element.displayName;
471 if (name == null || name.isEmpty) { 488 if (name == null || name.isEmpty) {
472 return element; 489 return element;
473 } 490 }
474 } 491 }
475 return null; 492 return null;
476 } 493 }
477 494
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 ConstructorElementImpl(String name, int offset) : super(name, offset); 1428 ConstructorElementImpl(String name, int offset) : super(name, offset);
1412 1429
1413 /** 1430 /**
1414 * Initialize a newly created constructor element to have the given [name]. 1431 * Initialize a newly created constructor element to have the given [name].
1415 */ 1432 */
1416 ConstructorElementImpl.forNode(Identifier name) : super.forNode(name); 1433 ConstructorElementImpl.forNode(Identifier name) : super.forNode(name);
1417 1434
1418 /** 1435 /**
1419 * Initialize using the given serialized information. 1436 * Initialize using the given serialized information.
1420 */ 1437 */
1421 ConstructorElementImpl.forSerialized(UnlinkedExecutable serializedExecutable) 1438 ConstructorElementImpl.forSerialized(
1422 : super.forSerialized(serializedExecutable); 1439 ResynthesizerContext resynthesizerContext,
1440 UnlinkedExecutable serializedExecutable)
1441 : super.forSerialized(resynthesizerContext, serializedExecutable);
1423 1442
1424 /** 1443 /**
1425 * Set whether this constructor represents a 'const' constructor. 1444 * Set whether this constructor represents a 'const' constructor.
1426 */ 1445 */
1427 void set const2(bool isConst) { 1446 void set const2(bool isConst) {
1428 assert(serializedExecutable == null); 1447 assert(serializedExecutable == null);
1429 setModifier(Modifier.CONST, isConst); 1448 setModifier(Modifier.CONST, isConst);
1430 } 1449 }
1431 1450
1432 @override 1451 @override
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 1847
1829 final int id = _NEXT_ID++; 1848 final int id = _NEXT_ID++;
1830 1849
1831 /** 1850 /**
1832 * The enclosing element of this element, or `null` if this element is at the 1851 * The enclosing element of this element, or `null` if this element is at the
1833 * root of the element structure. 1852 * root of the element structure.
1834 */ 1853 */
1835 ElementImpl _enclosingElement; 1854 ElementImpl _enclosingElement;
1836 1855
1837 /** 1856 /**
1838 * Is `true` is this element is resynthesized from summary. 1857 * The context in which this element is resynthesized.
Paul Berry 2016/05/17 19:28:02 Nit: the comment should specify that this value is
scheglov 2016/05/17 19:42:21 Done.
1839 */ 1858 */
1840 final bool _isResynthesized; 1859 final ResynthesizerContext resynthesizerContext;
1841 1860
1842 /** 1861 /**
1843 * The name of this element. 1862 * The name of this element.
1844 */ 1863 */
1845 String _name; 1864 String _name;
1846 1865
1847 /** 1866 /**
1848 * The offset of the name of this element in the file that contains the 1867 * The offset of the name of this element in the file that contains the
1849 * declaration of this element. 1868 * declaration of this element.
1850 */ 1869 */
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1894 1913
1895 /** 1914 /**
1896 * The length of the element's code, or `null` if the element is synthetic. 1915 * The length of the element's code, or `null` if the element is synthetic.
1897 */ 1916 */
1898 int _codeLength; 1917 int _codeLength;
1899 1918
1900 /** 1919 /**
1901 * Initialize a newly created element to have the given [name] at the given 1920 * Initialize a newly created element to have the given [name] at the given
1902 * [_nameOffset]. 1921 * [_nameOffset].
1903 */ 1922 */
1904 ElementImpl(String name, this._nameOffset) : _isResynthesized = false { 1923 ElementImpl(String name, this._nameOffset) : resynthesizerContext = null {
1905 this._name = StringUtilities.intern(name); 1924 this._name = StringUtilities.intern(name);
1906 } 1925 }
1907 1926
1908 /** 1927 /**
1909 * Initialize a newly created element to have the given [name]. 1928 * Initialize a newly created element to have the given [name].
1910 */ 1929 */
1911 ElementImpl.forNode(Identifier name) 1930 ElementImpl.forNode(Identifier name)
1912 : this(name == null ? "" : name.name, name == null ? -1 : name.offset); 1931 : this(name == null ? "" : name.name, name == null ? -1 : name.offset);
1913 1932
1914 /** 1933 /**
1915 * Initialize from serialized information. 1934 * Initialize from serialized information.
1916 */ 1935 */
1917 ElementImpl.forSerialized() : _isResynthesized = true; 1936 ElementImpl.forSerialized(this.resynthesizerContext);
1918 1937
1919 /** 1938 /**
1920 * The length of the element's code, or `null` if the element is synthetic. 1939 * The length of the element's code, or `null` if the element is synthetic.
1921 */ 1940 */
1922 int get codeLength => _codeLength; 1941 int get codeLength => _codeLength;
1923 1942
1924 /** 1943 /**
1925 * The offset of the beginning of the element's code in the file that contains 1944 * The offset of the beginning of the element's code in the file that contains
1926 * the element, or `null` if the element is synthetic. 1945 * the element, or `null` if the element is synthetic.
1927 */ 1946 */
(...skipping 18 matching lines...) Expand all
1946 return null; 1965 return null;
1947 } 1966 }
1948 1967
1949 @override 1968 @override
1950 String get documentationComment => _docComment; 1969 String get documentationComment => _docComment;
1951 1970
1952 /** 1971 /**
1953 * The documentation comment source for this element. 1972 * The documentation comment source for this element.
1954 */ 1973 */
1955 void set documentationComment(String doc) { 1974 void set documentationComment(String doc) {
1956 assert(!_isResynthesized); 1975 assert(resynthesizerContext == null);
1957 _docComment = doc?.replaceAll('\r\n', '\n'); 1976 _docComment = doc?.replaceAll('\r\n', '\n');
1958 } 1977 }
1959 1978
1960 @override 1979 @override
1961 Element get enclosingElement => _enclosingElement; 1980 Element get enclosingElement => _enclosingElement;
1962 1981
1963 /** 1982 /**
1964 * Set the enclosing element of this element to the given [element]. 1983 * Set the enclosing element of this element to the given [element].
1965 * 1984 *
1966 * Throws [FrozenHashCodeException] if the hashCode can't be changed. 1985 * Throws [FrozenHashCodeException] if the hashCode can't be changed.
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
2237 for (Element child in children) { 2256 for (Element child in children) {
2238 child.accept(visitor); 2257 child.accept(visitor);
2239 } 2258 }
2240 } 2259 }
2241 } 2260 }
2242 2261
2243 /** 2262 /**
2244 * Set the code range for this element. 2263 * Set the code range for this element.
2245 */ 2264 */
2246 void setCodeRange(int offset, int length) { 2265 void setCodeRange(int offset, int length) {
2247 assert(!_isResynthesized); 2266 assert(resynthesizerContext == null);
2248 _codeOffset = offset; 2267 _codeOffset = offset;
2249 _codeLength = length; 2268 _codeLength = length;
2250 } 2269 }
2251 2270
2252 /** 2271 /**
2253 * Set the documentation comment source range for this element. 2272 * Set the documentation comment source range for this element.
2254 */ 2273 */
2255 void setDocRange(int offset, int length) { 2274 void setDocRange(int offset, int length) {
2256 assert(!_isResynthesized); 2275 assert(resynthesizerContext == null);
2257 _docRangeOffset = offset; 2276 _docRangeOffset = offset;
2258 _docRangeLength = length; 2277 _docRangeLength = length;
2259 } 2278 }
2260 2279
2261 /** 2280 /**
2262 * Set whether the given [modifier] is associated with this element to 2281 * Set whether the given [modifier] is associated with this element to
2263 * correspond to the given [value]. 2282 * correspond to the given [value].
2264 */ 2283 */
2265 void setModifier(Modifier modifier, bool value) { 2284 void setModifier(Modifier modifier, bool value) {
2266 _modifiers = BooleanArray.setEnum(_modifiers, modifier, value); 2285 _modifiers = BooleanArray.setEnum(_modifiers, modifier, value);
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
2518 /** 2537 /**
2519 * Initialize a newly created executable element to have the given [name]. 2538 * Initialize a newly created executable element to have the given [name].
2520 */ 2539 */
2521 ExecutableElementImpl.forNode(Identifier name) 2540 ExecutableElementImpl.forNode(Identifier name)
2522 : serializedExecutable = null, 2541 : serializedExecutable = null,
2523 super.forNode(name); 2542 super.forNode(name);
2524 2543
2525 /** 2544 /**
2526 * Initialize using the given serialized information. 2545 * Initialize using the given serialized information.
2527 */ 2546 */
2528 ExecutableElementImpl.forSerialized(this.serializedExecutable) 2547 ExecutableElementImpl.forSerialized(
2529 : super.forSerialized(); 2548 ResynthesizerContext resynthesizerContext, this.serializedExecutable)
2549 : super.forSerialized(resynthesizerContext);
2530 2550
2531 /** 2551 /**
2532 * Set whether this executable element's body is asynchronous. 2552 * Set whether this executable element's body is asynchronous.
2533 */ 2553 */
2534 void set asynchronous(bool isAsynchronous) { 2554 void set asynchronous(bool isAsynchronous) {
2535 assert(serializedExecutable == null); 2555 assert(serializedExecutable == null);
2536 setModifier(Modifier.ASYNCHRONOUS, isAsynchronous); 2556 setModifier(Modifier.ASYNCHRONOUS, isAsynchronous);
2537 } 2557 }
2538 2558
2539 @override 2559 @override
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
2977 2997
2978 /** 2998 /**
2979 * Initialize a newly created function element to have no name and the given 2999 * Initialize a newly created function element to have no name and the given
2980 * [offset]. This is used for function expressions, that have no name. 3000 * [offset]. This is used for function expressions, that have no name.
2981 */ 3001 */
2982 FunctionElementImpl.forOffset(int nameOffset) : super("", nameOffset); 3002 FunctionElementImpl.forOffset(int nameOffset) : super("", nameOffset);
2983 3003
2984 /** 3004 /**
2985 * Initialize using the given serialized information. 3005 * Initialize using the given serialized information.
2986 */ 3006 */
2987 FunctionElementImpl.forSerialized(UnlinkedExecutable serializedExecutable) 3007 FunctionElementImpl.forSerialized(ResynthesizerContext resynthesizerContext,
2988 : super.forSerialized(serializedExecutable); 3008 UnlinkedExecutable serializedExecutable)
3009 : super.forSerialized(resynthesizerContext, serializedExecutable);
2989 3010
2990 /** 3011 /**
2991 * Synthesize an unnamed function element that takes [parameters] and returns 3012 * Synthesize an unnamed function element that takes [parameters] and returns
2992 * [returnType]. 3013 * [returnType].
2993 */ 3014 */
2994 FunctionElementImpl.synthetic( 3015 FunctionElementImpl.synthetic(
2995 List<ParameterElement> parameters, DartType returnType) 3016 List<ParameterElement> parameters, DartType returnType)
2996 : super("", -1) { 3017 : super("", -1) {
2997 synthetic = true; 3018 synthetic = true;
2998 this.returnType = returnType; 3019 this.returnType = returnType;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
3118 /** 3139 /**
3119 * Initialize a newly created type alias element to have the given [name]. 3140 * Initialize a newly created type alias element to have the given [name].
3120 */ 3141 */
3121 FunctionTypeAliasElementImpl.forNode(Identifier name) 3142 FunctionTypeAliasElementImpl.forNode(Identifier name)
3122 : _unlinkedTypedef = null, 3143 : _unlinkedTypedef = null,
3123 super.forNode(name); 3144 super.forNode(name);
3124 3145
3125 /** 3146 /**
3126 * Initialize using the given serialized information. 3147 * Initialize using the given serialized information.
3127 */ 3148 */
3128 FunctionTypeAliasElementImpl.forSerialized(this._unlinkedTypedef) 3149 FunctionTypeAliasElementImpl.forSerialized(
3129 : super.forSerialized(); 3150 ResynthesizerContext resynthesizerContext, this._unlinkedTypedef)
3151 : super.forSerialized(resynthesizerContext);
3130 3152
3131 @override 3153 @override
3132 int get codeLength { 3154 int get codeLength {
3133 if (_unlinkedTypedef != null) { 3155 if (_unlinkedTypedef != null) {
3134 return _unlinkedTypedef.codeRange?.length; 3156 return _unlinkedTypedef.codeRange?.length;
3135 } 3157 }
3136 return super.codeLength; 3158 return super.codeLength;
3137 } 3159 }
3138 3160
3139 @override 3161 @override
(...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after
4112 MethodElementImpl(String name, int offset) : super(name, offset); 4134 MethodElementImpl(String name, int offset) : super(name, offset);
4113 4135
4114 /** 4136 /**
4115 * Initialize a newly created method element to have the given [name]. 4137 * Initialize a newly created method element to have the given [name].
4116 */ 4138 */
4117 MethodElementImpl.forNode(Identifier name) : super.forNode(name); 4139 MethodElementImpl.forNode(Identifier name) : super.forNode(name);
4118 4140
4119 /** 4141 /**
4120 * Initialize using the given serialized information. 4142 * Initialize using the given serialized information.
4121 */ 4143 */
4122 MethodElementImpl.forSerialized(UnlinkedExecutable serializedExecutable) 4144 MethodElementImpl.forSerialized(ResynthesizerContext resynthesizerContext,
4123 : super.forSerialized(serializedExecutable); 4145 UnlinkedExecutable serializedExecutable)
4146 : super.forSerialized(resynthesizerContext, serializedExecutable);
4124 4147
4125 /** 4148 /**
4126 * Set whether this method is abstract. 4149 * Set whether this method is abstract.
4127 */ 4150 */
4128 void set abstract(bool isAbstract) { 4151 void set abstract(bool isAbstract) {
4129 assert(serializedExecutable == null); 4152 assert(serializedExecutable == null);
4130 setModifier(Modifier.ABSTRACT, isAbstract); 4153 setModifier(Modifier.ABSTRACT, isAbstract);
4131 } 4154 }
4132 4155
4133 @override 4156 @override
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
4841 /** 4864 /**
4842 * Initialize a newly created property accessor element to have the given 4865 * Initialize a newly created property accessor element to have the given
4843 * [name]. 4866 * [name].
4844 */ 4867 */
4845 PropertyAccessorElementImpl.forNode(Identifier name) : super.forNode(name); 4868 PropertyAccessorElementImpl.forNode(Identifier name) : super.forNode(name);
4846 4869
4847 /** 4870 /**
4848 * Initialize using the given serialized information. 4871 * Initialize using the given serialized information.
4849 */ 4872 */
4850 PropertyAccessorElementImpl.forSerialized( 4873 PropertyAccessorElementImpl.forSerialized(
4874 ResynthesizerContext resynthesizerContext,
4851 UnlinkedExecutable serializedExecutable) 4875 UnlinkedExecutable serializedExecutable)
4852 : super.forSerialized(serializedExecutable); 4876 : super.forSerialized(resynthesizerContext, serializedExecutable);
4853 4877
4854 /** 4878 /**
4855 * Initialize a newly created synthetic property accessor element to be 4879 * Initialize a newly created synthetic property accessor element to be
4856 * associated with the given [variable]. 4880 * associated with the given [variable].
4857 */ 4881 */
4858 PropertyAccessorElementImpl.forVariable(PropertyInducingElementImpl variable) 4882 PropertyAccessorElementImpl.forVariable(PropertyInducingElementImpl variable)
4859 : super(variable.name, variable.nameOffset) { 4883 : super(variable.name, variable.nameOffset) {
4860 this.variable = variable; 4884 this.variable = variable;
4861 static = variable.isStatic; 4885 static = variable.isStatic;
4862 synthetic = true; 4886 synthetic = true;
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
5032 */ 5056 */
5033 PropertyInducingElementImpl(String name, int offset) : super(name, offset); 5057 PropertyInducingElementImpl(String name, int offset) : super(name, offset);
5034 5058
5035 /** 5059 /**
5036 * Initialize a newly created element to have the given [name]. 5060 * Initialize a newly created element to have the given [name].
5037 */ 5061 */
5038 PropertyInducingElementImpl.forNode(Identifier name) : super.forNode(name); 5062 PropertyInducingElementImpl.forNode(Identifier name) : super.forNode(name);
5039 } 5063 }
5040 5064
5041 /** 5065 /**
5066 * The context in which elements are resynthesized.
5067 */
5068 abstract class ResynthesizerContext {
5069 /**
5070 * Resolve an [EntityRef] into a type. If the reference is
5071 * unresolved, return [DynamicTypeImpl.instance].
5072 *
5073 * TODO(paulberry): or should we have a class representing an
5074 * unresolved type, for consistency with the full element model?
5075 */
5076 DartType resolveTypeRef(
5077 EntityRef type, TypeParameterizedElementMixin typeParameterContext,
5078 {bool defaultVoid: false, bool instantiateToBoundsAllowed: true});
5079 }
5080
5081 /**
5042 * A concrete implementation of a [ShowElementCombinator]. 5082 * A concrete implementation of a [ShowElementCombinator].
5043 */ 5083 */
5044 class ShowElementCombinatorImpl implements ShowElementCombinator { 5084 class ShowElementCombinatorImpl implements ShowElementCombinator {
5045 /** 5085 /**
5046 * The names that are to be made visible in the importing library if they are 5086 * The names that are to be made visible in the importing library if they are
5047 * defined in the imported library. 5087 * defined in the imported library.
5048 */ 5088 */
5049 List<String> shownNames = StringUtilities.EMPTY_ARRAY; 5089 List<String> shownNames = StringUtilities.EMPTY_ARRAY;
5050 5090
5051 /** 5091 /**
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
5104 VariableDeclaration computeNode() => 5144 VariableDeclaration computeNode() =>
5105 getNodeMatching((node) => node is VariableDeclaration); 5145 getNodeMatching((node) => node is VariableDeclaration);
5106 } 5146 }
5107 5147
5108 /** 5148 /**
5109 * A concrete implementation of a [TypeParameterElement]. 5149 * A concrete implementation of a [TypeParameterElement].
5110 */ 5150 */
5111 class TypeParameterElementImpl extends ElementImpl 5151 class TypeParameterElementImpl extends ElementImpl
5112 implements TypeParameterElement { 5152 implements TypeParameterElement {
5113 /** 5153 /**
5154 * The unlinked representation of the type parameter in the summary.
5155 */
5156 final UnlinkedTypeParam _unlinkedTypeParam;
5157
5158 /**
5159 * Get the type parameter context enclosing this one, if any.
5160 */
5161 final TypeParameterizedElementMixin _enclosingTypeParameterContext;
Brian Wilkerson 2016/05/17 19:42:26 It looks wrong to me to use a mixin as a type this
5162
5163 /**
5164 * The number of type parameters whose scope overlaps this one, and which are
5165 * declared earlier in the file.
5166 *
5167 * TODO(scheglov) make private?
5168 */
5169 final int nestingLevel;
5170
5171 /**
5114 * The type defined by this type parameter. 5172 * The type defined by this type parameter.
5115 */ 5173 */
5116 TypeParameterType type; 5174 TypeParameterType _type;
5117 5175
5118 /** 5176 /**
5119 * The type representing the bound associated with this parameter, or `null` 5177 * The type representing the bound associated with this parameter, or `null`
5120 * if this parameter does not have an explicit bound. 5178 * if this parameter does not have an explicit bound.
5121 */ 5179 */
5122 DartType bound; 5180 DartType _bound;
5123 5181
5124 /** 5182 /**
5125 * Initialize a newly created method element to have the given [name] and 5183 * Initialize a newly created method element to have the given [name] and
5126 * [offset]. 5184 * [offset].
5127 */ 5185 */
5128 TypeParameterElementImpl(String name, int offset) : super(name, offset); 5186 TypeParameterElementImpl(String name, int offset)
5187 : _unlinkedTypeParam = null,
5188 nestingLevel = null,
5189 _enclosingTypeParameterContext = null,
5190 super(name, offset);
5129 5191
5130 /** 5192 /**
5131 * Initialize a newly created type parameter element to have the given [name]. 5193 * Initialize a newly created type parameter element to have the given [name].
5132 */ 5194 */
5133 TypeParameterElementImpl.forNode(Identifier name) : super.forNode(name); 5195 TypeParameterElementImpl.forNode(Identifier name)
5196 : _unlinkedTypeParam = null,
5197 nestingLevel = null,
5198 _enclosingTypeParameterContext = null,
5199 super.forNode(name);
5200
5201 /**
5202 * Initialize using the given serialized information.
5203 */
5204 TypeParameterElementImpl.forSerialized(
5205 ResynthesizerContext resynthesizerContext,
5206 this._unlinkedTypeParam,
5207 this._enclosingTypeParameterContext,
5208 this.nestingLevel)
5209 : super.forSerialized(resynthesizerContext);
5134 5210
5135 /** 5211 /**
5136 * Initialize a newly created synthetic type parameter element to have the 5212 * Initialize a newly created synthetic type parameter element to have the
5137 * given [name], and with [synthetic] set to true. 5213 * given [name], and with [synthetic] set to true.
5138 */ 5214 */
5139 TypeParameterElementImpl.synthetic(String name) : super(name, -1) { 5215 TypeParameterElementImpl.synthetic(String name)
5216 : _unlinkedTypeParam = null,
5217 nestingLevel = null,
5218 _enclosingTypeParameterContext = null,
5219 super(name, -1) {
5140 synthetic = true; 5220 synthetic = true;
5141 } 5221 }
5142 5222
5223 DartType get bound {
5224 if (_unlinkedTypeParam != null) {
5225 if (_unlinkedTypeParam.bound == null) {
5226 return null;
5227 }
5228 return _bound ??= resynthesizerContext.resolveTypeRef(
Brian Wilkerson 2016/05/17 19:42:26 Is it safe to assume here that "resynthesizerConte
5229 _unlinkedTypeParam.bound, enclosingElement,
5230 instantiateToBoundsAllowed: false);
5231 }
5232 return _bound;
5233 }
5234
5235 void set bound(DartType bound) {
5236 assert(resynthesizerContext == null);
5237 _bound = bound;
5238 }
5239
5240 @override
5241 int get codeLength {
5242 if (_unlinkedTypeParam != null) {
5243 return _unlinkedTypeParam.codeRange?.length;
5244 }
5245 return super.codeLength;
5246 }
5247
5248 @override
5249 int get codeOffset {
5250 if (_unlinkedTypeParam != null) {
5251 return _unlinkedTypeParam.codeRange?.offset;
5252 }
5253 return super.codeOffset;
5254 }
5255
5256 @override
5257 String get displayName => name;
5258
5259 @override
5260 Element get enclosingElement {
5261 if (_unlinkedTypeParam != null) {
5262 return _enclosingTypeParameterContext;
5263 }
5264 return super.enclosingElement;
5265 }
5266
5143 @override 5267 @override
5144 ElementKind get kind => ElementKind.TYPE_PARAMETER; 5268 ElementKind get kind => ElementKind.TYPE_PARAMETER;
5145 5269
5146 @override 5270 @override
5271 String get name {
5272 if (_unlinkedTypeParam != null) {
5273 return _unlinkedTypeParam.name;
5274 }
5275 return super.name;
5276 }
5277
5278 @override
5279 int get nameOffset {
5280 if (_unlinkedTypeParam != null) {
5281 return _unlinkedTypeParam.nameOffset;
5282 }
5283 return super.nameOffset;
5284 }
5285
5286 TypeParameterType get type {
5287 if (_unlinkedTypeParam != null) {
5288 _type ??= new TypeParameterTypeImpl(this);
5289 }
5290 return _type;
5291 }
5292
5293 void set type(TypeParameterType type) {
5294 _type = type;
5295 }
5296
5297 @override
5147 accept(ElementVisitor visitor) => visitor.visitTypeParameterElement(this); 5298 accept(ElementVisitor visitor) => visitor.visitTypeParameterElement(this);
5148 5299
5149 @override 5300 @override
5150 void appendTo(StringBuffer buffer) { 5301 void appendTo(StringBuffer buffer) {
5151 buffer.write(displayName); 5302 buffer.write(displayName);
5152 if (bound != null) { 5303 if (bound != null) {
5153 buffer.write(" extends "); 5304 buffer.write(" extends ");
5154 buffer.write(bound); 5305 buffer.write(bound);
5155 } 5306 }
5156 } 5307 }
5157 } 5308 }
5158 5309
5159 /** 5310 /**
5311 * Mixin representing an element which can have type parameters.
5312 */
5313 abstract class TypeParameterizedElementMixin
5314 implements TypeParameterizedElement {
5315 List<TypeParameterType> _typeParameterTypes;
5316 List<TypeParameterElement> _typeParameterElements;
5317 int _nestingLevel;
5318
5319 /**
5320 * Get the type parameter context enclosing this one, if any.
5321 */
5322 TypeParameterizedElementMixin get enclosingTypeParameterContext;
5323
5324 /**
5325 * The context in which this element is resynthesized.
5326 */
5327 ResynthesizerContext get resynthesizerContext;
5328
5329 /**
5330 * Find out how many type parameters are in scope in this context.
5331 */
5332 int get typeParameterNestingLevel =>
5333 _nestingLevel ??= unlinkedTypeParams.length +
5334 (enclosingTypeParameterContext?.typeParameterNestingLevel ?? 0);
5335
5336 List<TypeParameterElement> get typeParameters {
5337 if (_typeParameterElements == null) {
5338 int enclosingNestingLevel =
5339 enclosingTypeParameterContext?.typeParameterNestingLevel ?? 0;
5340 int numTypeParameters = unlinkedTypeParams.length;
5341 _typeParameterElements =
5342 new List<TypeParameterElement>(numTypeParameters);
5343 for (int i = 0; i < numTypeParameters; i++) {
5344 _typeParameterElements[i] = new TypeParameterElementImpl.forSerialized(
5345 resynthesizerContext,
5346 unlinkedTypeParams[i],
5347 this,
5348 enclosingNestingLevel + i);
5349 }
5350 }
5351 return _typeParameterElements;
5352 }
5353
5354 /**
5355 * Get a list of [TypeParameterType] objects corresponding to the
5356 * element's type parameters.
5357 */
5358 List<TypeParameterType> get typeParameterTypes {
5359 if (_typeParameterTypes == null) {
5360 _typeParameterTypes =
5361 typeParameters.map((TypeParameterElement e) => e.type).toList();
5362 }
5363 return _typeParameterTypes;
5364 }
5365
5366 /**
5367 * Get the [UnlinkedTypeParam]s representing the type parameters declared by
5368 * this element.
5369 *
5370 * TODO(scheglov) make private after MLI
Paul Berry 2016/05/17 19:28:02 Can you expand on this comment? It's not clear to
scheglov 2016/05/17 19:42:21 Done.
5371 */
5372 List<UnlinkedTypeParam> get unlinkedTypeParams;
5373
5374 /**
5375 * Convert the given [index] into a type parameter type.
5376 */
5377 TypeParameterType getTypeParameterType(int index) {
5378 List<TypeParameterType> types = typeParameterTypes;
5379 if (index <= types.length) {
5380 return types[types.length - index];
5381 } else if (enclosingTypeParameterContext != null) {
5382 return enclosingTypeParameterContext
5383 .getTypeParameterType(index - types.length);
5384 } else {
5385 // If we get here, it means that a summary contained a type parameter inde x
5386 // that was out of range.
5387 throw new RangeError('Invalid type parameter index');
5388 }
5389 }
5390
5391 /**
5392 * Find out if the given [typeParameter] is in scope in this context.
5393 */
5394 bool isTypeParameterInScope(TypeParameterElement typeParameter) {
5395 if (typeParameter.enclosingElement == this) {
5396 return true;
5397 } else if (enclosingTypeParameterContext != null) {
5398 return enclosingTypeParameterContext
5399 .isTypeParameterInScope(typeParameter);
5400 } else {
5401 return false;
5402 }
5403 }
5404 }
5405
5406 /**
5160 * A concrete implementation of a [UriReferencedElement]. 5407 * A concrete implementation of a [UriReferencedElement].
5161 */ 5408 */
5162 abstract class UriReferencedElementImpl extends ElementImpl 5409 abstract class UriReferencedElementImpl extends ElementImpl
5163 implements UriReferencedElement { 5410 implements UriReferencedElement {
5164 /** 5411 /**
5165 * The offset of the URI in the file, may be `-1` if synthetic. 5412 * The offset of the URI in the file, may be `-1` if synthetic.
5166 */ 5413 */
5167 int uriOffset = -1; 5414 int uriOffset = -1;
5168 5415
5169 /** 5416 /**
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
5322 5569
5323 @override 5570 @override
5324 void visitElement(Element element) { 5571 void visitElement(Element element) {
5325 int offset = element.nameOffset; 5572 int offset = element.nameOffset;
5326 if (offset != -1) { 5573 if (offset != -1) {
5327 map[offset] = element; 5574 map[offset] = element;
5328 } 5575 }
5329 super.visitElement(element); 5576 super.visitElement(element);
5330 } 5577 }
5331 } 5578 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/summary/link.dart » ('j') | pkg/analyzer/lib/src/summary/link.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698