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 2197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2208 UnlinkedExecutable serializedExecutable, ClassElementImpl enclosingClass) | 2208 UnlinkedExecutable serializedExecutable, ClassElementImpl enclosingClass) |
2209 : _kernelConstructor = null, | 2209 : _kernelConstructor = null, |
2210 _kernelFactory = null, | 2210 _kernelFactory = null, |
2211 super.forSerialized(serializedExecutable, enclosingClass); | 2211 super.forSerialized(serializedExecutable, enclosingClass); |
2212 | 2212 |
2213 /** | 2213 /** |
2214 * Return the constant initializers for this element, which will be empty if | 2214 * Return the constant initializers for this element, which will be empty if |
2215 * there are no initializers, or `null` if there was an error in the source. | 2215 * there are no initializers, or `null` if there was an error in the source. |
2216 */ | 2216 */ |
2217 List<ConstructorInitializer> get constantInitializers { | 2217 List<ConstructorInitializer> get constantInitializers { |
2218 if (serializedExecutable != null && _constantInitializers == null) { | 2218 if (_constantInitializers == null) { |
2219 _constantInitializers ??= serializedExecutable.constantInitializers | 2219 if (_kernelConstructor != null) { |
2220 .map((i) => _buildConstructorInitializer(i)) | 2220 var context = enclosingUnit._kernelContext; |
2221 .toList(growable: false); | 2221 _constantInitializers = _kernelConstructor.initializers |
| 2222 .map((k) => context.getConstructorInitializer(this, k)) |
| 2223 .where((i) => i != null) |
| 2224 .toList(); |
| 2225 } |
| 2226 if (serializedExecutable != null) { |
| 2227 _constantInitializers = serializedExecutable.constantInitializers |
| 2228 .map((i) => _buildConstructorInitializer(i)) |
| 2229 .toList(growable: false); |
| 2230 } |
2222 } | 2231 } |
2223 return _constantInitializers; | 2232 return _constantInitializers; |
2224 } | 2233 } |
2225 | 2234 |
2226 void set constantInitializers( | 2235 void set constantInitializers( |
2227 List<ConstructorInitializer> constantInitializers) { | 2236 List<ConstructorInitializer> constantInitializers) { |
2228 _assertNotResynthesized(serializedExecutable); | 2237 _assertNotResynthesized(serializedExecutable); |
2229 _constantInitializers = constantInitializers; | 2238 _constantInitializers = constantInitializers; |
2230 } | 2239 } |
2231 | 2240 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2342 return _periodOffset; | 2351 return _periodOffset; |
2343 } | 2352 } |
2344 | 2353 |
2345 void set periodOffset(int periodOffset) { | 2354 void set periodOffset(int periodOffset) { |
2346 _assertNotResynthesized(serializedExecutable); | 2355 _assertNotResynthesized(serializedExecutable); |
2347 _periodOffset = periodOffset; | 2356 _periodOffset = periodOffset; |
2348 } | 2357 } |
2349 | 2358 |
2350 @override | 2359 @override |
2351 ConstructorElement get redirectedConstructor { | 2360 ConstructorElement get redirectedConstructor { |
2352 if (serializedExecutable != null && _redirectedConstructor == null) { | 2361 if (_redirectedConstructor == null) { |
2353 if (serializedExecutable.isRedirectedConstructor) { | 2362 if (_kernelConstructor != null) { |
2354 if (serializedExecutable.isFactory) { | 2363 for (var initializer in _kernelConstructor.initializers) { |
2355 _redirectedConstructor = enclosingUnit.resynthesizerContext | 2364 if (initializer is kernel.RedirectingInitializer) { |
2356 .resolveConstructorRef( | 2365 return _redirectedConstructor = enclosingUnit._kernelContext |
2357 enclosingElement, serializedExecutable.redirectedConstructor); | 2366 .getElement(initializer.targetReference) |
| 2367 as ConstructorElementImpl; |
| 2368 } |
| 2369 } |
| 2370 } |
| 2371 if (serializedExecutable != null) { |
| 2372 if (serializedExecutable.isRedirectedConstructor) { |
| 2373 if (serializedExecutable.isFactory) { |
| 2374 _redirectedConstructor = enclosingUnit.resynthesizerContext |
| 2375 .resolveConstructorRef(enclosingElement, |
| 2376 serializedExecutable.redirectedConstructor); |
| 2377 } else { |
| 2378 _redirectedConstructor = enclosingElement.getNamedConstructor( |
| 2379 serializedExecutable.redirectedConstructorName); |
| 2380 } |
2358 } else { | 2381 } else { |
2359 _redirectedConstructor = enclosingElement.getNamedConstructor( | 2382 return null; |
2360 serializedExecutable.redirectedConstructorName); | |
2361 } | 2383 } |
2362 } else { | |
2363 return null; | |
2364 } | 2384 } |
2365 } | 2385 } |
2366 return _redirectedConstructor; | 2386 return _redirectedConstructor; |
2367 } | 2387 } |
2368 | 2388 |
2369 void set redirectedConstructor(ConstructorElement redirectedConstructor) { | 2389 void set redirectedConstructor(ConstructorElement redirectedConstructor) { |
2370 _assertNotResynthesized(serializedExecutable); | 2390 _assertNotResynthesized(serializedExecutable); |
2371 _redirectedConstructor = redirectedConstructor; | 2391 _redirectedConstructor = redirectedConstructor; |
2372 } | 2392 } |
2373 | 2393 |
(...skipping 3484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5858 } | 5878 } |
5859 } | 5879 } |
5860 | 5880 |
5861 /** | 5881 /** |
5862 * The kernel context in which a library is resynthesized. | 5882 * The kernel context in which a library is resynthesized. |
5863 */ | 5883 */ |
5864 abstract class KernelLibraryResynthesizerContext { | 5884 abstract class KernelLibraryResynthesizerContext { |
5865 kernel.Library get library; | 5885 kernel.Library get library; |
5866 | 5886 |
5867 /** | 5887 /** |
| 5888 * Return the resynthesized [ConstructorInitializer] for the given Kernel |
| 5889 * [initializer], or `null` if synthetic. |
| 5890 */ |
| 5891 ConstructorInitializer getConstructorInitializer( |
| 5892 ConstructorElementImpl constructor, kernel.Initializer initializer); |
| 5893 |
| 5894 /** |
| 5895 * Return the [Element] referenced by the given [reference]. |
| 5896 */ |
| 5897 ElementImpl getElement(kernel.Reference reference); |
| 5898 |
| 5899 /** |
5868 * Return the [Expression] for the given kernel. | 5900 * Return the [Expression] for the given kernel. |
5869 */ | 5901 */ |
5870 Expression getExpression(kernel.Expression expression); | 5902 Expression getExpression(kernel.Expression expression); |
5871 | 5903 |
5872 /** | 5904 /** |
5873 * Return the [InterfaceType] for the given Kernel [type], or `null` if the | 5905 * Return the [InterfaceType] for the given Kernel [type], or `null` if the |
5874 * [type] does not correspond to an [InterfaceType]. | 5906 * [type] does not correspond to an [InterfaceType]. |
5875 */ | 5907 */ |
5876 InterfaceType getInterfaceType(ElementImpl context, kernel.Supertype type); | 5908 InterfaceType getInterfaceType(ElementImpl context, kernel.Supertype type); |
5877 | 5909 |
(...skipping 3676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9554 | 9586 |
9555 @override | 9587 @override |
9556 DartObject computeConstantValue() => null; | 9588 DartObject computeConstantValue() => null; |
9557 | 9589 |
9558 @override | 9590 @override |
9559 void visitChildren(ElementVisitor visitor) { | 9591 void visitChildren(ElementVisitor visitor) { |
9560 super.visitChildren(visitor); | 9592 super.visitChildren(visitor); |
9561 _initializer?.accept(visitor); | 9593 _initializer?.accept(visitor); |
9562 } | 9594 } |
9563 } | 9595 } |
OLD | NEW |