| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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, or `null` if the |
| 1858 * element is not resynthesized a summary. |
| 1839 */ | 1859 */ |
| 1840 final bool _isResynthesized; | 1860 final ResynthesizerContext resynthesizerContext; |
| 1841 | 1861 |
| 1842 /** | 1862 /** |
| 1843 * The name of this element. | 1863 * The name of this element. |
| 1844 */ | 1864 */ |
| 1845 String _name; | 1865 String _name; |
| 1846 | 1866 |
| 1847 /** | 1867 /** |
| 1848 * The offset of the name of this element in the file that contains the | 1868 * The offset of the name of this element in the file that contains the |
| 1849 * declaration of this element. | 1869 * declaration of this element. |
| 1850 */ | 1870 */ |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1894 | 1914 |
| 1895 /** | 1915 /** |
| 1896 * The length of the element's code, or `null` if the element is synthetic. | 1916 * The length of the element's code, or `null` if the element is synthetic. |
| 1897 */ | 1917 */ |
| 1898 int _codeLength; | 1918 int _codeLength; |
| 1899 | 1919 |
| 1900 /** | 1920 /** |
| 1901 * Initialize a newly created element to have the given [name] at the given | 1921 * Initialize a newly created element to have the given [name] at the given |
| 1902 * [_nameOffset]. | 1922 * [_nameOffset]. |
| 1903 */ | 1923 */ |
| 1904 ElementImpl(String name, this._nameOffset) : _isResynthesized = false { | 1924 ElementImpl(String name, this._nameOffset) : resynthesizerContext = null { |
| 1905 this._name = StringUtilities.intern(name); | 1925 this._name = StringUtilities.intern(name); |
| 1906 } | 1926 } |
| 1907 | 1927 |
| 1908 /** | 1928 /** |
| 1909 * Initialize a newly created element to have the given [name]. | 1929 * Initialize a newly created element to have the given [name]. |
| 1910 */ | 1930 */ |
| 1911 ElementImpl.forNode(Identifier name) | 1931 ElementImpl.forNode(Identifier name) |
| 1912 : this(name == null ? "" : name.name, name == null ? -1 : name.offset); | 1932 : this(name == null ? "" : name.name, name == null ? -1 : name.offset); |
| 1913 | 1933 |
| 1914 /** | 1934 /** |
| 1915 * Initialize from serialized information. | 1935 * Initialize from serialized information. |
| 1916 */ | 1936 */ |
| 1917 ElementImpl.forSerialized() : _isResynthesized = true; | 1937 ElementImpl.forSerialized(this.resynthesizerContext); |
| 1918 | 1938 |
| 1919 /** | 1939 /** |
| 1920 * The length of the element's code, or `null` if the element is synthetic. | 1940 * The length of the element's code, or `null` if the element is synthetic. |
| 1921 */ | 1941 */ |
| 1922 int get codeLength => _codeLength; | 1942 int get codeLength => _codeLength; |
| 1923 | 1943 |
| 1924 /** | 1944 /** |
| 1925 * The offset of the beginning of the element's code in the file that contains | 1945 * 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. | 1946 * the element, or `null` if the element is synthetic. |
| 1927 */ | 1947 */ |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1946 return null; | 1966 return null; |
| 1947 } | 1967 } |
| 1948 | 1968 |
| 1949 @override | 1969 @override |
| 1950 String get documentationComment => _docComment; | 1970 String get documentationComment => _docComment; |
| 1951 | 1971 |
| 1952 /** | 1972 /** |
| 1953 * The documentation comment source for this element. | 1973 * The documentation comment source for this element. |
| 1954 */ | 1974 */ |
| 1955 void set documentationComment(String doc) { | 1975 void set documentationComment(String doc) { |
| 1956 assert(!_isResynthesized); | 1976 assert(resynthesizerContext == null); |
| 1957 _docComment = doc?.replaceAll('\r\n', '\n'); | 1977 _docComment = doc?.replaceAll('\r\n', '\n'); |
| 1958 } | 1978 } |
| 1959 | 1979 |
| 1960 @override | 1980 @override |
| 1961 Element get enclosingElement => _enclosingElement; | 1981 Element get enclosingElement => _enclosingElement; |
| 1962 | 1982 |
| 1963 /** | 1983 /** |
| 1964 * Set the enclosing element of this element to the given [element]. | 1984 * Set the enclosing element of this element to the given [element]. |
| 1965 * | 1985 * |
| 1966 * Throws [FrozenHashCodeException] if the hashCode can't be changed. | 1986 * Throws [FrozenHashCodeException] if the hashCode can't be changed. |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2237 for (Element child in children) { | 2257 for (Element child in children) { |
| 2238 child.accept(visitor); | 2258 child.accept(visitor); |
| 2239 } | 2259 } |
| 2240 } | 2260 } |
| 2241 } | 2261 } |
| 2242 | 2262 |
| 2243 /** | 2263 /** |
| 2244 * Set the code range for this element. | 2264 * Set the code range for this element. |
| 2245 */ | 2265 */ |
| 2246 void setCodeRange(int offset, int length) { | 2266 void setCodeRange(int offset, int length) { |
| 2247 assert(!_isResynthesized); | 2267 assert(resynthesizerContext == null); |
| 2248 _codeOffset = offset; | 2268 _codeOffset = offset; |
| 2249 _codeLength = length; | 2269 _codeLength = length; |
| 2250 } | 2270 } |
| 2251 | 2271 |
| 2252 /** | 2272 /** |
| 2253 * Set the documentation comment source range for this element. | 2273 * Set the documentation comment source range for this element. |
| 2254 */ | 2274 */ |
| 2255 void setDocRange(int offset, int length) { | 2275 void setDocRange(int offset, int length) { |
| 2256 assert(!_isResynthesized); | 2276 assert(resynthesizerContext == null); |
| 2257 _docRangeOffset = offset; | 2277 _docRangeOffset = offset; |
| 2258 _docRangeLength = length; | 2278 _docRangeLength = length; |
| 2259 } | 2279 } |
| 2260 | 2280 |
| 2261 /** | 2281 /** |
| 2262 * Set whether the given [modifier] is associated with this element to | 2282 * Set whether the given [modifier] is associated with this element to |
| 2263 * correspond to the given [value]. | 2283 * correspond to the given [value]. |
| 2264 */ | 2284 */ |
| 2265 void setModifier(Modifier modifier, bool value) { | 2285 void setModifier(Modifier modifier, bool value) { |
| 2266 _modifiers = BooleanArray.setEnum(_modifiers, modifier, value); | 2286 _modifiers = BooleanArray.setEnum(_modifiers, modifier, value); |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2518 /** | 2538 /** |
| 2519 * Initialize a newly created executable element to have the given [name]. | 2539 * Initialize a newly created executable element to have the given [name]. |
| 2520 */ | 2540 */ |
| 2521 ExecutableElementImpl.forNode(Identifier name) | 2541 ExecutableElementImpl.forNode(Identifier name) |
| 2522 : serializedExecutable = null, | 2542 : serializedExecutable = null, |
| 2523 super.forNode(name); | 2543 super.forNode(name); |
| 2524 | 2544 |
| 2525 /** | 2545 /** |
| 2526 * Initialize using the given serialized information. | 2546 * Initialize using the given serialized information. |
| 2527 */ | 2547 */ |
| 2528 ExecutableElementImpl.forSerialized(this.serializedExecutable) | 2548 ExecutableElementImpl.forSerialized( |
| 2529 : super.forSerialized(); | 2549 ResynthesizerContext resynthesizerContext, this.serializedExecutable) |
| 2550 : super.forSerialized(resynthesizerContext); |
| 2530 | 2551 |
| 2531 /** | 2552 /** |
| 2532 * Set whether this executable element's body is asynchronous. | 2553 * Set whether this executable element's body is asynchronous. |
| 2533 */ | 2554 */ |
| 2534 void set asynchronous(bool isAsynchronous) { | 2555 void set asynchronous(bool isAsynchronous) { |
| 2535 assert(serializedExecutable == null); | 2556 assert(serializedExecutable == null); |
| 2536 setModifier(Modifier.ASYNCHRONOUS, isAsynchronous); | 2557 setModifier(Modifier.ASYNCHRONOUS, isAsynchronous); |
| 2537 } | 2558 } |
| 2538 | 2559 |
| 2539 @override | 2560 @override |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2977 | 2998 |
| 2978 /** | 2999 /** |
| 2979 * Initialize a newly created function element to have no name and the given | 3000 * 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. | 3001 * [offset]. This is used for function expressions, that have no name. |
| 2981 */ | 3002 */ |
| 2982 FunctionElementImpl.forOffset(int nameOffset) : super("", nameOffset); | 3003 FunctionElementImpl.forOffset(int nameOffset) : super("", nameOffset); |
| 2983 | 3004 |
| 2984 /** | 3005 /** |
| 2985 * Initialize using the given serialized information. | 3006 * Initialize using the given serialized information. |
| 2986 */ | 3007 */ |
| 2987 FunctionElementImpl.forSerialized(UnlinkedExecutable serializedExecutable) | 3008 FunctionElementImpl.forSerialized(ResynthesizerContext resynthesizerContext, |
| 2988 : super.forSerialized(serializedExecutable); | 3009 UnlinkedExecutable serializedExecutable) |
| 3010 : super.forSerialized(resynthesizerContext, serializedExecutable); |
| 2989 | 3011 |
| 2990 /** | 3012 /** |
| 2991 * Synthesize an unnamed function element that takes [parameters] and returns | 3013 * Synthesize an unnamed function element that takes [parameters] and returns |
| 2992 * [returnType]. | 3014 * [returnType]. |
| 2993 */ | 3015 */ |
| 2994 FunctionElementImpl.synthetic( | 3016 FunctionElementImpl.synthetic( |
| 2995 List<ParameterElement> parameters, DartType returnType) | 3017 List<ParameterElement> parameters, DartType returnType) |
| 2996 : super("", -1) { | 3018 : super("", -1) { |
| 2997 synthetic = true; | 3019 synthetic = true; |
| 2998 this.returnType = returnType; | 3020 this.returnType = returnType; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3118 /** | 3140 /** |
| 3119 * Initialize a newly created type alias element to have the given [name]. | 3141 * Initialize a newly created type alias element to have the given [name]. |
| 3120 */ | 3142 */ |
| 3121 FunctionTypeAliasElementImpl.forNode(Identifier name) | 3143 FunctionTypeAliasElementImpl.forNode(Identifier name) |
| 3122 : _unlinkedTypedef = null, | 3144 : _unlinkedTypedef = null, |
| 3123 super.forNode(name); | 3145 super.forNode(name); |
| 3124 | 3146 |
| 3125 /** | 3147 /** |
| 3126 * Initialize using the given serialized information. | 3148 * Initialize using the given serialized information. |
| 3127 */ | 3149 */ |
| 3128 FunctionTypeAliasElementImpl.forSerialized(this._unlinkedTypedef) | 3150 FunctionTypeAliasElementImpl.forSerialized( |
| 3129 : super.forSerialized(); | 3151 ResynthesizerContext resynthesizerContext, this._unlinkedTypedef) |
| 3152 : super.forSerialized(resynthesizerContext); |
| 3130 | 3153 |
| 3131 @override | 3154 @override |
| 3132 int get codeLength { | 3155 int get codeLength { |
| 3133 if (_unlinkedTypedef != null) { | 3156 if (_unlinkedTypedef != null) { |
| 3134 return _unlinkedTypedef.codeRange?.length; | 3157 return _unlinkedTypedef.codeRange?.length; |
| 3135 } | 3158 } |
| 3136 return super.codeLength; | 3159 return super.codeLength; |
| 3137 } | 3160 } |
| 3138 | 3161 |
| 3139 @override | 3162 @override |
| (...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4112 MethodElementImpl(String name, int offset) : super(name, offset); | 4135 MethodElementImpl(String name, int offset) : super(name, offset); |
| 4113 | 4136 |
| 4114 /** | 4137 /** |
| 4115 * Initialize a newly created method element to have the given [name]. | 4138 * Initialize a newly created method element to have the given [name]. |
| 4116 */ | 4139 */ |
| 4117 MethodElementImpl.forNode(Identifier name) : super.forNode(name); | 4140 MethodElementImpl.forNode(Identifier name) : super.forNode(name); |
| 4118 | 4141 |
| 4119 /** | 4142 /** |
| 4120 * Initialize using the given serialized information. | 4143 * Initialize using the given serialized information. |
| 4121 */ | 4144 */ |
| 4122 MethodElementImpl.forSerialized(UnlinkedExecutable serializedExecutable) | 4145 MethodElementImpl.forSerialized(ResynthesizerContext resynthesizerContext, |
| 4123 : super.forSerialized(serializedExecutable); | 4146 UnlinkedExecutable serializedExecutable) |
| 4147 : super.forSerialized(resynthesizerContext, serializedExecutable); |
| 4124 | 4148 |
| 4125 /** | 4149 /** |
| 4126 * Set whether this method is abstract. | 4150 * Set whether this method is abstract. |
| 4127 */ | 4151 */ |
| 4128 void set abstract(bool isAbstract) { | 4152 void set abstract(bool isAbstract) { |
| 4129 assert(serializedExecutable == null); | 4153 assert(serializedExecutable == null); |
| 4130 setModifier(Modifier.ABSTRACT, isAbstract); | 4154 setModifier(Modifier.ABSTRACT, isAbstract); |
| 4131 } | 4155 } |
| 4132 | 4156 |
| 4133 @override | 4157 @override |
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4841 /** | 4865 /** |
| 4842 * Initialize a newly created property accessor element to have the given | 4866 * Initialize a newly created property accessor element to have the given |
| 4843 * [name]. | 4867 * [name]. |
| 4844 */ | 4868 */ |
| 4845 PropertyAccessorElementImpl.forNode(Identifier name) : super.forNode(name); | 4869 PropertyAccessorElementImpl.forNode(Identifier name) : super.forNode(name); |
| 4846 | 4870 |
| 4847 /** | 4871 /** |
| 4848 * Initialize using the given serialized information. | 4872 * Initialize using the given serialized information. |
| 4849 */ | 4873 */ |
| 4850 PropertyAccessorElementImpl.forSerialized( | 4874 PropertyAccessorElementImpl.forSerialized( |
| 4875 ResynthesizerContext resynthesizerContext, |
| 4851 UnlinkedExecutable serializedExecutable) | 4876 UnlinkedExecutable serializedExecutable) |
| 4852 : super.forSerialized(serializedExecutable); | 4877 : super.forSerialized(resynthesizerContext, serializedExecutable); |
| 4853 | 4878 |
| 4854 /** | 4879 /** |
| 4855 * Initialize a newly created synthetic property accessor element to be | 4880 * Initialize a newly created synthetic property accessor element to be |
| 4856 * associated with the given [variable]. | 4881 * associated with the given [variable]. |
| 4857 */ | 4882 */ |
| 4858 PropertyAccessorElementImpl.forVariable(PropertyInducingElementImpl variable) | 4883 PropertyAccessorElementImpl.forVariable(PropertyInducingElementImpl variable) |
| 4859 : super(variable.name, variable.nameOffset) { | 4884 : super(variable.name, variable.nameOffset) { |
| 4860 this.variable = variable; | 4885 this.variable = variable; |
| 4861 static = variable.isStatic; | 4886 static = variable.isStatic; |
| 4862 synthetic = true; | 4887 synthetic = true; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5032 */ | 5057 */ |
| 5033 PropertyInducingElementImpl(String name, int offset) : super(name, offset); | 5058 PropertyInducingElementImpl(String name, int offset) : super(name, offset); |
| 5034 | 5059 |
| 5035 /** | 5060 /** |
| 5036 * Initialize a newly created element to have the given [name]. | 5061 * Initialize a newly created element to have the given [name]. |
| 5037 */ | 5062 */ |
| 5038 PropertyInducingElementImpl.forNode(Identifier name) : super.forNode(name); | 5063 PropertyInducingElementImpl.forNode(Identifier name) : super.forNode(name); |
| 5039 } | 5064 } |
| 5040 | 5065 |
| 5041 /** | 5066 /** |
| 5067 * The context in which elements are resynthesized. |
| 5068 */ |
| 5069 abstract class ResynthesizerContext { |
| 5070 /** |
| 5071 * Resolve an [EntityRef] into a type. If the reference is |
| 5072 * unresolved, return [DynamicTypeImpl.instance]. |
| 5073 * |
| 5074 * TODO(paulberry): or should we have a class representing an |
| 5075 * unresolved type, for consistency with the full element model? |
| 5076 */ |
| 5077 DartType resolveTypeRef( |
| 5078 EntityRef type, TypeParameterizedElementMixin typeParameterContext, |
| 5079 {bool defaultVoid: false, bool instantiateToBoundsAllowed: true}); |
| 5080 } |
| 5081 |
| 5082 /** |
| 5042 * A concrete implementation of a [ShowElementCombinator]. | 5083 * A concrete implementation of a [ShowElementCombinator]. |
| 5043 */ | 5084 */ |
| 5044 class ShowElementCombinatorImpl implements ShowElementCombinator { | 5085 class ShowElementCombinatorImpl implements ShowElementCombinator { |
| 5045 /** | 5086 /** |
| 5046 * The names that are to be made visible in the importing library if they are | 5087 * The names that are to be made visible in the importing library if they are |
| 5047 * defined in the imported library. | 5088 * defined in the imported library. |
| 5048 */ | 5089 */ |
| 5049 List<String> shownNames = StringUtilities.EMPTY_ARRAY; | 5090 List<String> shownNames = StringUtilities.EMPTY_ARRAY; |
| 5050 | 5091 |
| 5051 /** | 5092 /** |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5104 VariableDeclaration computeNode() => | 5145 VariableDeclaration computeNode() => |
| 5105 getNodeMatching((node) => node is VariableDeclaration); | 5146 getNodeMatching((node) => node is VariableDeclaration); |
| 5106 } | 5147 } |
| 5107 | 5148 |
| 5108 /** | 5149 /** |
| 5109 * A concrete implementation of a [TypeParameterElement]. | 5150 * A concrete implementation of a [TypeParameterElement]. |
| 5110 */ | 5151 */ |
| 5111 class TypeParameterElementImpl extends ElementImpl | 5152 class TypeParameterElementImpl extends ElementImpl |
| 5112 implements TypeParameterElement { | 5153 implements TypeParameterElement { |
| 5113 /** | 5154 /** |
| 5155 * The unlinked representation of the type parameter in the summary. |
| 5156 */ |
| 5157 final UnlinkedTypeParam _unlinkedTypeParam; |
| 5158 |
| 5159 /** |
| 5160 * Get the type parameter context enclosing this one, if any. |
| 5161 */ |
| 5162 final TypeParameterizedElementMixin _enclosingTypeParameterContext; |
| 5163 |
| 5164 /** |
| 5165 * The number of type parameters whose scope overlaps this one, and which are |
| 5166 * declared earlier in the file. |
| 5167 * |
| 5168 * TODO(scheglov) make private? |
| 5169 */ |
| 5170 final int nestingLevel; |
| 5171 |
| 5172 /** |
| 5114 * The type defined by this type parameter. | 5173 * The type defined by this type parameter. |
| 5115 */ | 5174 */ |
| 5116 TypeParameterType type; | 5175 TypeParameterType _type; |
| 5117 | 5176 |
| 5118 /** | 5177 /** |
| 5119 * The type representing the bound associated with this parameter, or `null` | 5178 * The type representing the bound associated with this parameter, or `null` |
| 5120 * if this parameter does not have an explicit bound. | 5179 * if this parameter does not have an explicit bound. |
| 5121 */ | 5180 */ |
| 5122 DartType bound; | 5181 DartType _bound; |
| 5123 | 5182 |
| 5124 /** | 5183 /** |
| 5125 * Initialize a newly created method element to have the given [name] and | 5184 * Initialize a newly created method element to have the given [name] and |
| 5126 * [offset]. | 5185 * [offset]. |
| 5127 */ | 5186 */ |
| 5128 TypeParameterElementImpl(String name, int offset) : super(name, offset); | 5187 TypeParameterElementImpl(String name, int offset) |
| 5188 : _unlinkedTypeParam = null, |
| 5189 nestingLevel = null, |
| 5190 _enclosingTypeParameterContext = null, |
| 5191 super(name, offset); |
| 5129 | 5192 |
| 5130 /** | 5193 /** |
| 5131 * Initialize a newly created type parameter element to have the given [name]. | 5194 * Initialize a newly created type parameter element to have the given [name]. |
| 5132 */ | 5195 */ |
| 5133 TypeParameterElementImpl.forNode(Identifier name) : super.forNode(name); | 5196 TypeParameterElementImpl.forNode(Identifier name) |
| 5197 : _unlinkedTypeParam = null, |
| 5198 nestingLevel = null, |
| 5199 _enclosingTypeParameterContext = null, |
| 5200 super.forNode(name); |
| 5201 |
| 5202 /** |
| 5203 * Initialize using the given serialized information. |
| 5204 */ |
| 5205 TypeParameterElementImpl.forSerialized( |
| 5206 ResynthesizerContext resynthesizerContext, |
| 5207 this._unlinkedTypeParam, |
| 5208 this._enclosingTypeParameterContext, |
| 5209 this.nestingLevel) |
| 5210 : super.forSerialized(resynthesizerContext); |
| 5134 | 5211 |
| 5135 /** | 5212 /** |
| 5136 * Initialize a newly created synthetic type parameter element to have the | 5213 * Initialize a newly created synthetic type parameter element to have the |
| 5137 * given [name], and with [synthetic] set to true. | 5214 * given [name], and with [synthetic] set to true. |
| 5138 */ | 5215 */ |
| 5139 TypeParameterElementImpl.synthetic(String name) : super(name, -1) { | 5216 TypeParameterElementImpl.synthetic(String name) |
| 5217 : _unlinkedTypeParam = null, |
| 5218 nestingLevel = null, |
| 5219 _enclosingTypeParameterContext = null, |
| 5220 super(name, -1) { |
| 5140 synthetic = true; | 5221 synthetic = true; |
| 5141 } | 5222 } |
| 5142 | 5223 |
| 5224 DartType get bound { |
| 5225 if (_unlinkedTypeParam != null) { |
| 5226 if (_unlinkedTypeParam.bound == null) { |
| 5227 return null; |
| 5228 } |
| 5229 return _bound ??= resynthesizerContext.resolveTypeRef( |
| 5230 _unlinkedTypeParam.bound, enclosingElement, |
| 5231 instantiateToBoundsAllowed: false); |
| 5232 } |
| 5233 return _bound; |
| 5234 } |
| 5235 |
| 5236 void set bound(DartType bound) { |
| 5237 assert(resynthesizerContext == null); |
| 5238 _bound = bound; |
| 5239 } |
| 5240 |
| 5241 @override |
| 5242 int get codeLength { |
| 5243 if (_unlinkedTypeParam != null) { |
| 5244 return _unlinkedTypeParam.codeRange?.length; |
| 5245 } |
| 5246 return super.codeLength; |
| 5247 } |
| 5248 |
| 5249 @override |
| 5250 int get codeOffset { |
| 5251 if (_unlinkedTypeParam != null) { |
| 5252 return _unlinkedTypeParam.codeRange?.offset; |
| 5253 } |
| 5254 return super.codeOffset; |
| 5255 } |
| 5256 |
| 5257 @override |
| 5258 String get displayName => name; |
| 5259 |
| 5260 @override |
| 5261 Element get enclosingElement { |
| 5262 if (_unlinkedTypeParam != null) { |
| 5263 return _enclosingTypeParameterContext; |
| 5264 } |
| 5265 return super.enclosingElement; |
| 5266 } |
| 5267 |
| 5143 @override | 5268 @override |
| 5144 ElementKind get kind => ElementKind.TYPE_PARAMETER; | 5269 ElementKind get kind => ElementKind.TYPE_PARAMETER; |
| 5145 | 5270 |
| 5146 @override | 5271 @override |
| 5272 String get name { |
| 5273 if (_unlinkedTypeParam != null) { |
| 5274 return _unlinkedTypeParam.name; |
| 5275 } |
| 5276 return super.name; |
| 5277 } |
| 5278 |
| 5279 @override |
| 5280 int get nameOffset { |
| 5281 if (_unlinkedTypeParam != null) { |
| 5282 return _unlinkedTypeParam.nameOffset; |
| 5283 } |
| 5284 return super.nameOffset; |
| 5285 } |
| 5286 |
| 5287 TypeParameterType get type { |
| 5288 if (_unlinkedTypeParam != null) { |
| 5289 _type ??= new TypeParameterTypeImpl(this); |
| 5290 } |
| 5291 return _type; |
| 5292 } |
| 5293 |
| 5294 void set type(TypeParameterType type) { |
| 5295 _type = type; |
| 5296 } |
| 5297 |
| 5298 @override |
| 5147 accept(ElementVisitor visitor) => visitor.visitTypeParameterElement(this); | 5299 accept(ElementVisitor visitor) => visitor.visitTypeParameterElement(this); |
| 5148 | 5300 |
| 5149 @override | 5301 @override |
| 5150 void appendTo(StringBuffer buffer) { | 5302 void appendTo(StringBuffer buffer) { |
| 5151 buffer.write(displayName); | 5303 buffer.write(displayName); |
| 5152 if (bound != null) { | 5304 if (bound != null) { |
| 5153 buffer.write(" extends "); | 5305 buffer.write(" extends "); |
| 5154 buffer.write(bound); | 5306 buffer.write(bound); |
| 5155 } | 5307 } |
| 5156 } | 5308 } |
| 5157 } | 5309 } |
| 5158 | 5310 |
| 5159 /** | 5311 /** |
| 5312 * Mixin representing an element which can have type parameters. |
| 5313 */ |
| 5314 abstract class TypeParameterizedElementMixin |
| 5315 implements TypeParameterizedElement { |
| 5316 List<TypeParameterType> _typeParameterTypes; |
| 5317 List<TypeParameterElement> _typeParameterElements; |
| 5318 int _nestingLevel; |
| 5319 |
| 5320 /** |
| 5321 * Get the type parameter context enclosing this one, if any. |
| 5322 */ |
| 5323 TypeParameterizedElementMixin get enclosingTypeParameterContext; |
| 5324 |
| 5325 /** |
| 5326 * The context in which this element is resynthesized. |
| 5327 */ |
| 5328 ResynthesizerContext get resynthesizerContext; |
| 5329 |
| 5330 /** |
| 5331 * Find out how many type parameters are in scope in this context. |
| 5332 */ |
| 5333 int get typeParameterNestingLevel => |
| 5334 _nestingLevel ??= unlinkedTypeParams.length + |
| 5335 (enclosingTypeParameterContext?.typeParameterNestingLevel ?? 0); |
| 5336 |
| 5337 List<TypeParameterElement> get typeParameters { |
| 5338 if (_typeParameterElements == null) { |
| 5339 int enclosingNestingLevel = |
| 5340 enclosingTypeParameterContext?.typeParameterNestingLevel ?? 0; |
| 5341 int numTypeParameters = unlinkedTypeParams.length; |
| 5342 _typeParameterElements = |
| 5343 new List<TypeParameterElement>(numTypeParameters); |
| 5344 for (int i = 0; i < numTypeParameters; i++) { |
| 5345 _typeParameterElements[i] = new TypeParameterElementImpl.forSerialized( |
| 5346 resynthesizerContext, |
| 5347 unlinkedTypeParams[i], |
| 5348 this, |
| 5349 enclosingNestingLevel + i); |
| 5350 } |
| 5351 } |
| 5352 return _typeParameterElements; |
| 5353 } |
| 5354 |
| 5355 /** |
| 5356 * Get a list of [TypeParameterType] objects corresponding to the |
| 5357 * element's type parameters. |
| 5358 */ |
| 5359 List<TypeParameterType> get typeParameterTypes { |
| 5360 if (_typeParameterTypes == null) { |
| 5361 _typeParameterTypes = |
| 5362 typeParameters.map((TypeParameterElement e) => e.type).toList(); |
| 5363 } |
| 5364 return _typeParameterTypes; |
| 5365 } |
| 5366 |
| 5367 /** |
| 5368 * Get the [UnlinkedTypeParam]s representing the type parameters declared by |
| 5369 * this element. |
| 5370 * |
| 5371 * TODO(scheglov) make private after switching linker to Impl |
| 5372 */ |
| 5373 List<UnlinkedTypeParam> get unlinkedTypeParams; |
| 5374 |
| 5375 /** |
| 5376 * Convert the given [index] into a type parameter type. |
| 5377 */ |
| 5378 TypeParameterType getTypeParameterType(int index) { |
| 5379 List<TypeParameterType> types = typeParameterTypes; |
| 5380 if (index <= types.length) { |
| 5381 return types[types.length - index]; |
| 5382 } else if (enclosingTypeParameterContext != null) { |
| 5383 return enclosingTypeParameterContext |
| 5384 .getTypeParameterType(index - types.length); |
| 5385 } else { |
| 5386 // If we get here, it means that a summary contained a type parameter inde
x |
| 5387 // that was out of range. |
| 5388 throw new RangeError('Invalid type parameter index'); |
| 5389 } |
| 5390 } |
| 5391 |
| 5392 /** |
| 5393 * Find out if the given [typeParameter] is in scope in this context. |
| 5394 */ |
| 5395 bool isTypeParameterInScope(TypeParameterElement typeParameter) { |
| 5396 if (typeParameter.enclosingElement == this) { |
| 5397 return true; |
| 5398 } else if (enclosingTypeParameterContext != null) { |
| 5399 return enclosingTypeParameterContext |
| 5400 .isTypeParameterInScope(typeParameter); |
| 5401 } else { |
| 5402 return false; |
| 5403 } |
| 5404 } |
| 5405 } |
| 5406 |
| 5407 /** |
| 5160 * A concrete implementation of a [UriReferencedElement]. | 5408 * A concrete implementation of a [UriReferencedElement]. |
| 5161 */ | 5409 */ |
| 5162 abstract class UriReferencedElementImpl extends ElementImpl | 5410 abstract class UriReferencedElementImpl extends ElementImpl |
| 5163 implements UriReferencedElement { | 5411 implements UriReferencedElement { |
| 5164 /** | 5412 /** |
| 5165 * The offset of the URI in the file, may be `-1` if synthetic. | 5413 * The offset of the URI in the file, may be `-1` if synthetic. |
| 5166 */ | 5414 */ |
| 5167 int uriOffset = -1; | 5415 int uriOffset = -1; |
| 5168 | 5416 |
| 5169 /** | 5417 /** |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5322 | 5570 |
| 5323 @override | 5571 @override |
| 5324 void visitElement(Element element) { | 5572 void visitElement(Element element) { |
| 5325 int offset = element.nameOffset; | 5573 int offset = element.nameOffset; |
| 5326 if (offset != -1) { | 5574 if (offset != -1) { |
| 5327 map[offset] = element; | 5575 map[offset] = element; |
| 5328 } | 5576 } |
| 5329 super.visitElement(element); | 5577 super.visitElement(element); |
| 5330 } | 5578 } |
| 5331 } | 5579 } |
| OLD | NEW |