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

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

Issue 2980963002: Resynthesize constructor properties. (Closed)
Patch Set: Created 3 years, 5 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
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_kernel_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 /** 469 /**
470 * Initialize a newly created class element to have the given [name] at the 470 * Initialize a newly created class element to have the given [name] at the
471 * given [offset] in the file that contains the declaration of this element. 471 * given [offset] in the file that contains the declaration of this element.
472 */ 472 */
473 ClassElementImpl(String name, int offset) 473 ClassElementImpl(String name, int offset)
474 : _unlinkedClass = null, 474 : _unlinkedClass = null,
475 _kernel = null, 475 _kernel = null,
476 super(name, offset); 476 super(name, offset);
477 477
478 /** 478 /**
479 * Initialize using the given kernel.
480 */
481 ClassElementImpl.forKernel(
482 CompilationUnitElementImpl enclosingUnit, this._kernel)
483 : _unlinkedClass = null,
484 super.forSerialized(enclosingUnit);
485
486 /**
479 * Initialize a newly created class element to have the given [name]. 487 * Initialize a newly created class element to have the given [name].
480 */ 488 */
481 ClassElementImpl.forNode(Identifier name) 489 ClassElementImpl.forNode(Identifier name)
482 : _unlinkedClass = null, 490 : _unlinkedClass = null,
483 _kernel = null, 491 _kernel = null,
484 super.forNode(name); 492 super.forNode(name);
485 493
486 /** 494 /**
487 * Initialize using the given serialized information. 495 * Initialize using the given serialized information.
488 */ 496 */
489 ClassElementImpl.forSerialized( 497 ClassElementImpl.forSerialized(
490 this._unlinkedClass, CompilationUnitElementImpl enclosingUnit) 498 this._unlinkedClass, CompilationUnitElementImpl enclosingUnit)
491 : _kernel = null, 499 : _kernel = null,
492 super.forSerialized(enclosingUnit); 500 super.forSerialized(enclosingUnit);
493 501
494 /** 502 /**
495 * Initialize using the given kernel.
496 */
497 ClassElementImpl.forKernel(
498 CompilationUnitElementImpl enclosingUnit, this._kernel)
499 : _unlinkedClass = null,
500 super.forSerialized(enclosingUnit);
501
502 /**
503 * Set whether this class is abstract. 503 * Set whether this class is abstract.
504 */ 504 */
505 void set abstract(bool isAbstract) { 505 void set abstract(bool isAbstract) {
506 _assertNotResynthesized(_unlinkedClass); 506 _assertNotResynthesized(_unlinkedClass);
507 setModifier(Modifier.ABSTRACT, isAbstract); 507 setModifier(Modifier.ABSTRACT, isAbstract);
508 } 508 }
509 509
510 @override 510 @override
511 List<PropertyAccessorElement> get accessors { 511 List<PropertyAccessorElement> get accessors {
512 if (_unlinkedClass != null && _accessors == null) { 512 if (_unlinkedClass != null && _accessors == null) {
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after
1390 * [name]. 1390 * [name].
1391 */ 1391 */
1392 CompilationUnitElementImpl(String name) 1392 CompilationUnitElementImpl(String name)
1393 : resynthesizerContext = null, 1393 : resynthesizerContext = null,
1394 _unlinkedUnit = null, 1394 _unlinkedUnit = null,
1395 _unlinkedPart = null, 1395 _unlinkedPart = null,
1396 _kernelContext = null, 1396 _kernelContext = null,
1397 super(name, -1); 1397 super(name, -1);
1398 1398
1399 /** 1399 /**
1400 * Initialize using the given serialized information. 1400 * Initialize using the given kernel information.
1401 */ 1401 */
1402 CompilationUnitElementImpl.forSerialized( 1402 CompilationUnitElementImpl.forKernel(
1403 LibraryElementImpl enclosingLibrary, 1403 LibraryElementImpl enclosingLibrary, this._kernelContext, String name)
1404 this.resynthesizerContext, 1404 : resynthesizerContext = null,
1405 this._unlinkedUnit, 1405 _unlinkedUnit = null,
1406 this._unlinkedPart, 1406 _unlinkedPart = null,
1407 String name)
1408 : _kernelContext = null,
1409 super.forSerialized(null) { 1407 super.forSerialized(null) {
1410 _enclosingElement = enclosingLibrary; 1408 _enclosingElement = enclosingLibrary;
1411 _name = name; 1409 _name = name;
1412 _nameOffset = -1; 1410 _nameOffset = -1;
1413 } 1411 }
1414 1412
1415 /** 1413 /**
1416 * Initialize using the given kernel information. 1414 * Initialize using the given serialized information.
1417 */ 1415 */
1418 CompilationUnitElementImpl.forKernel( 1416 CompilationUnitElementImpl.forSerialized(
1419 LibraryElementImpl enclosingLibrary, this._kernelContext, String name) 1417 LibraryElementImpl enclosingLibrary,
1420 : resynthesizerContext = null, 1418 this.resynthesizerContext,
1421 _unlinkedUnit = null, 1419 this._unlinkedUnit,
1422 _unlinkedPart = null, 1420 this._unlinkedPart,
1421 String name)
1422 : _kernelContext = null,
1423 super.forSerialized(null) { 1423 super.forSerialized(null) {
1424 _enclosingElement = enclosingLibrary; 1424 _enclosingElement = enclosingLibrary;
1425 _name = name; 1425 _name = name;
1426 _nameOffset = -1; 1426 _nameOffset = -1;
1427 } 1427 }
1428 1428
1429 @override 1429 @override
1430 List<PropertyAccessorElement> get accessors { 1430 List<PropertyAccessorElement> get accessors {
1431 if (_unlinkedUnit != null) { 1431 if (_unlinkedUnit != null) {
1432 if (_accessors == null) { 1432 if (_accessors == null) {
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
2011 2011
2012 /** 2012 /**
2013 * Initialize a newly created constructor element to have the given [name] and 2013 * Initialize a newly created constructor element to have the given [name] and
2014 * [offset]. 2014 * [offset].
2015 */ 2015 */
2016 ConstructorElementImpl(String name, int offset) 2016 ConstructorElementImpl(String name, int offset)
2017 : _kernel = null, 2017 : _kernel = null,
2018 super(name, offset); 2018 super(name, offset);
2019 2019
2020 /** 2020 /**
2021 * Initialize using the given serialized information.
2022 */
2023 ConstructorElementImpl.forKernel(
2024 ClassElementImpl enclosingClass, this._kernel)
2025 : super.forKernel(enclosingClass, _kernel) {
2026 isSynthetic = _kernel.isSyntheticDefault;
2027 }
2028
2029 /**
2021 * Initialize a newly created constructor element to have the given [name]. 2030 * Initialize a newly created constructor element to have the given [name].
2022 */ 2031 */
2023 ConstructorElementImpl.forNode(Identifier name) 2032 ConstructorElementImpl.forNode(Identifier name)
2024 : _kernel = null, 2033 : _kernel = null,
2025 super.forNode(name); 2034 super.forNode(name);
2026 2035
2027 /** 2036 /**
2028 * Initialize using the given serialized information. 2037 * Initialize using the given serialized information.
2029 */ 2038 */
2030 ConstructorElementImpl.forSerialized( 2039 ConstructorElementImpl.forSerialized(
2031 UnlinkedExecutable serializedExecutable, ClassElementImpl enclosingClass) 2040 UnlinkedExecutable serializedExecutable, ClassElementImpl enclosingClass)
2032 : _kernel = null, 2041 : _kernel = null,
2033 super.forSerialized(serializedExecutable, enclosingClass); 2042 super.forSerialized(serializedExecutable, enclosingClass);
2034 2043
2035 /** 2044 /**
2036 * Initialize using the given serialized information.
2037 */
2038 ConstructorElementImpl.forKernel(
2039 ClassElementImpl enclosingClass, this._kernel)
2040 : super.forSerialized(null, enclosingClass) {
2041 isSynthetic = _kernel.isSyntheticDefault;
2042 }
2043
2044 /**
2045 * Return the constant initializers for this element, which will be empty if 2045 * Return the constant initializers for this element, which will be empty if
2046 * there are no initializers, or `null` if there was an error in the source. 2046 * there are no initializers, or `null` if there was an error in the source.
2047 */ 2047 */
2048 List<ConstructorInitializer> get constantInitializers { 2048 List<ConstructorInitializer> get constantInitializers {
2049 if (serializedExecutable != null && _constantInitializers == null) { 2049 if (serializedExecutable != null && _constantInitializers == null) {
2050 _constantInitializers ??= serializedExecutable.constantInitializers 2050 _constantInitializers ??= serializedExecutable.constantInitializers
2051 .map((i) => _buildConstructorInitializer(i)) 2051 .map((i) => _buildConstructorInitializer(i))
2052 .toList(growable: false); 2052 .toList(growable: false);
2053 } 2053 }
2054 return _constantInitializers; 2054 return _constantInitializers;
(...skipping 16 matching lines...) Expand all
2071 /** 2071 /**
2072 * Set whether this constructor represents a factory method. 2072 * Set whether this constructor represents a factory method.
2073 */ 2073 */
2074 void set factory(bool isFactory) { 2074 void set factory(bool isFactory) {
2075 _assertNotResynthesized(serializedExecutable); 2075 _assertNotResynthesized(serializedExecutable);
2076 setModifier(Modifier.FACTORY, isFactory); 2076 setModifier(Modifier.FACTORY, isFactory);
2077 } 2077 }
2078 2078
2079 @override 2079 @override
2080 bool get isConst { 2080 bool get isConst {
2081 if (_kernel != null) {
2082 return _kernel.isConst;
2083 }
2081 if (serializedExecutable != null) { 2084 if (serializedExecutable != null) {
2082 return serializedExecutable.isConst; 2085 return serializedExecutable.isConst;
2083 } 2086 }
2084 return hasModifier(Modifier.CONST); 2087 return hasModifier(Modifier.CONST);
2085 } 2088 }
2086 2089
2087 /** 2090 /**
2088 * Set whether this constructor represents a 'const' constructor. 2091 * Set whether this constructor represents a 'const' constructor.
2089 */ 2092 */
2090 void set isConst(bool isConst) { 2093 void set isConst(bool isConst) {
(...skipping 1564 matching lines...) Expand 10 before | Expand all | Expand 10 after
3655 /** 3658 /**
3656 * Initialize a newly created executable element to have the given [name] and 3659 * Initialize a newly created executable element to have the given [name] and
3657 * [offset]. 3660 * [offset].
3658 */ 3661 */
3659 ExecutableElementImpl(String name, int offset) 3662 ExecutableElementImpl(String name, int offset)
3660 : serializedExecutable = null, 3663 : serializedExecutable = null,
3661 _kernel = null, 3664 _kernel = null,
3662 super(name, offset); 3665 super(name, offset);
3663 3666
3664 /** 3667 /**
3668 * Initialize using the given kernel.
3669 */
3670 ExecutableElementImpl.forKernel(ElementImpl enclosingElement, this._kernel)
3671 : serializedExecutable = null,
3672 super.forSerialized(enclosingElement);
3673
3674 /**
3665 * Initialize a newly created executable element to have the given [name]. 3675 * Initialize a newly created executable element to have the given [name].
3666 */ 3676 */
3667 ExecutableElementImpl.forNode(Identifier name) 3677 ExecutableElementImpl.forNode(Identifier name)
3668 : serializedExecutable = null, 3678 : serializedExecutable = null,
3669 _kernel = null, 3679 _kernel = null,
3670 super.forNode(name); 3680 super.forNode(name);
3671 3681
3672 /** 3682 /**
3673 * Initialize using the given serialized information. 3683 * Initialize using the given serialized information.
3674 */ 3684 */
3675 ExecutableElementImpl.forSerialized( 3685 ExecutableElementImpl.forSerialized(
3676 this.serializedExecutable, ElementImpl enclosingElement) 3686 this.serializedExecutable, ElementImpl enclosingElement)
3677 : _kernel = null, 3687 : _kernel = null,
3678 super.forSerialized(enclosingElement); 3688 super.forSerialized(enclosingElement);
3679 3689
3680 /** 3690 /**
3681 * Initialize using the given kernel.
3682 */
3683 ExecutableElementImpl.forKernel(ElementImpl enclosingElement, this._kernel)
3684 : serializedExecutable = null,
3685 super.forSerialized(enclosingElement);
3686
3687 /**
3688 * Set whether this executable element's body is asynchronous. 3691 * Set whether this executable element's body is asynchronous.
3689 */ 3692 */
3690 void set asynchronous(bool isAsynchronous) { 3693 void set asynchronous(bool isAsynchronous) {
3691 _assertNotResynthesized(serializedExecutable); 3694 _assertNotResynthesized(serializedExecutable);
3692 setModifier(Modifier.ASYNCHRONOUS, isAsynchronous); 3695 setModifier(Modifier.ASYNCHRONOUS, isAsynchronous);
3693 } 3696 }
3694 3697
3695 @override 3698 @override
3696 int get codeLength { 3699 int get codeLength {
3697 if (serializedExecutable != null) { 3700 if (serializedExecutable != null) {
(...skipping 10 matching lines...) Expand all
3708 return super.codeOffset; 3711 return super.codeOffset;
3709 } 3712 }
3710 3713
3711 void set declaredReturnType(DartType returnType) { 3714 void set declaredReturnType(DartType returnType) {
3712 _assertNotResynthesized(serializedExecutable); 3715 _assertNotResynthesized(serializedExecutable);
3713 _declaredReturnType = _checkElementOfType(returnType); 3716 _declaredReturnType = _checkElementOfType(returnType);
3714 } 3717 }
3715 3718
3716 @override 3719 @override
3717 String get displayName { 3720 String get displayName {
3721 if (_kernel != null) {
3722 return _kernel.name.name;
3723 }
3718 if (serializedExecutable != null) { 3724 if (serializedExecutable != null) {
3719 return serializedExecutable.name; 3725 return serializedExecutable.name;
3720 } 3726 }
3721 return super.displayName; 3727 return super.displayName;
3722 } 3728 }
3723 3729
3724 @override 3730 @override
3725 String get documentationComment { 3731 String get documentationComment {
3726 if (serializedExecutable != null) { 3732 if (serializedExecutable != null) {
3727 return serializedExecutable?.documentationComment?.text; 3733 return serializedExecutable?.documentationComment?.text;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
3794 @override 3800 @override
3795 bool get isAsynchronous { 3801 bool get isAsynchronous {
3796 if (serializedExecutable != null) { 3802 if (serializedExecutable != null) {
3797 return serializedExecutable.isAsynchronous; 3803 return serializedExecutable.isAsynchronous;
3798 } 3804 }
3799 return hasModifier(Modifier.ASYNCHRONOUS); 3805 return hasModifier(Modifier.ASYNCHRONOUS);
3800 } 3806 }
3801 3807
3802 @override 3808 @override
3803 bool get isExternal { 3809 bool get isExternal {
3810 if (_kernel != null) {
3811 return _kernel.isExternal;
3812 }
3804 if (serializedExecutable != null) { 3813 if (serializedExecutable != null) {
3805 return serializedExecutable.isExternal; 3814 return serializedExecutable.isExternal;
3806 } 3815 }
3807 return hasModifier(Modifier.EXTERNAL); 3816 return hasModifier(Modifier.EXTERNAL);
3808 } 3817 }
3809 3818
3810 @override 3819 @override
3811 bool get isGenerator { 3820 bool get isGenerator {
3812 if (serializedExecutable != null) { 3821 if (serializedExecutable != null) {
3813 return serializedExecutable.isGenerator; 3822 return serializedExecutable.isGenerator;
(...skipping 1729 matching lines...) Expand 10 before | Expand all | Expand 10 after
5543 : new HideElementCombinatorImpl.forSerialized(unlinkedCombinator); 5552 : new HideElementCombinatorImpl.forSerialized(unlinkedCombinator);
5544 } 5553 }
5545 return combinators; 5554 return combinators;
5546 } else { 5555 } else {
5547 return const <NamespaceCombinator>[]; 5556 return const <NamespaceCombinator>[];
5548 } 5557 }
5549 } 5558 }
5550 } 5559 }
5551 5560
5552 /** 5561 /**
5562 * The kernel context in which a library is resynthesized.
5563 */
5564 abstract class KernelLibraryResynthesizerContext {
5565 kernel.Library get library;
5566 }
5567
5568 /**
5553 * A concrete implementation of a [LabelElement]. 5569 * A concrete implementation of a [LabelElement].
5554 */ 5570 */
5555 class LabelElementImpl extends ElementImpl implements LabelElement { 5571 class LabelElementImpl extends ElementImpl implements LabelElement {
5556 /** 5572 /**
5557 * A flag indicating whether this label is associated with a `switch` 5573 * A flag indicating whether this label is associated with a `switch`
5558 * statement. 5574 * statement.
5559 */ 5575 */
5560 // TODO(brianwilkerson) Make this a modifier. 5576 // TODO(brianwilkerson) Make this a modifier.
5561 final bool _onSwitchStatement; 5577 final bool _onSwitchStatement;
5562 5578
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
5703 * Initialize a newly created library element in the given [context] to have 5719 * Initialize a newly created library element in the given [context] to have
5704 * the given [name] and [offset]. 5720 * the given [name] and [offset].
5705 */ 5721 */
5706 LibraryElementImpl(this.context, String name, int offset, this.nameLength) 5722 LibraryElementImpl(this.context, String name, int offset, this.nameLength)
5707 : resynthesizerContext = null, 5723 : resynthesizerContext = null,
5708 _kernelContext = null, 5724 _kernelContext = null,
5709 _unlinkedDefiningUnit = null, 5725 _unlinkedDefiningUnit = null,
5710 super(name, offset); 5726 super(name, offset);
5711 5727
5712 /** 5728 /**
5729 * Initialize using the given kernel information.
5730 */
5731 LibraryElementImpl.forKernel(this.context, this._kernelContext)
5732 : resynthesizerContext = null,
5733 _unlinkedDefiningUnit = null,
5734 nameLength = _kernelContext.library.name?.length ?? 0,
5735 super.forSerialized(null) {
5736 _name = _kernelContext.library.name ?? '';
5737 _nameOffset = _kernelContext.library.fileOffset;
5738 setResolutionCapability(
5739 LibraryResolutionCapability.resolvedTypeNames, true);
5740 setResolutionCapability(
5741 LibraryResolutionCapability.constantExpressions, true);
5742
5743 definingCompilationUnit = new CompilationUnitElementImpl.forKernel(
5744 this, _kernelContext, '<no-name>');
5745
5746 // TODO(scheglov) how to support parts?
5747 }
5748
5749 /**
5713 * Initialize a newly created library element in the given [context] to have 5750 * Initialize a newly created library element in the given [context] to have
5714 * the given [name]. 5751 * the given [name].
5715 */ 5752 */
5716 LibraryElementImpl.forNode(this.context, LibraryIdentifier name) 5753 LibraryElementImpl.forNode(this.context, LibraryIdentifier name)
5717 : nameLength = name != null ? name.length : 0, 5754 : nameLength = name != null ? name.length : 0,
5718 resynthesizerContext = null, 5755 resynthesizerContext = null,
5719 _kernelContext = null, 5756 _kernelContext = null,
5720 _unlinkedDefiningUnit = null, 5757 _unlinkedDefiningUnit = null,
5721 super.forNode(name); 5758 super.forNode(name);
5722 5759
5723 /** 5760 /**
5724 * Initialize using the given serialized information. 5761 * Initialize using the given serialized information.
5725 */ 5762 */
5726 LibraryElementImpl.forSerialized(this.context, String name, int offset, 5763 LibraryElementImpl.forSerialized(this.context, String name, int offset,
5727 this.nameLength, this.resynthesizerContext, this._unlinkedDefiningUnit) 5764 this.nameLength, this.resynthesizerContext, this._unlinkedDefiningUnit)
5728 : _kernelContext = null, 5765 : _kernelContext = null,
5729 super.forSerialized(null) { 5766 super.forSerialized(null) {
5730 _name = name; 5767 _name = name;
5731 _nameOffset = offset; 5768 _nameOffset = offset;
5732 setResolutionCapability( 5769 setResolutionCapability(
5733 LibraryResolutionCapability.resolvedTypeNames, true); 5770 LibraryResolutionCapability.resolvedTypeNames, true);
5734 setResolutionCapability( 5771 setResolutionCapability(
5735 LibraryResolutionCapability.constantExpressions, true); 5772 LibraryResolutionCapability.constantExpressions, true);
5736 } 5773 }
5737 5774
5738 /**
5739 * Initialize using the given kernel information.
5740 */
5741 LibraryElementImpl.forKernel(this.context, this._kernelContext)
5742 : resynthesizerContext = null,
5743 _unlinkedDefiningUnit = null,
5744 nameLength = _kernelContext.library.name?.length ?? 0,
5745 super.forSerialized(null) {
5746 _name = _kernelContext.library.name ?? '';
5747 _nameOffset = _kernelContext.library.fileOffset;
5748 setResolutionCapability(
5749 LibraryResolutionCapability.resolvedTypeNames, true);
5750 setResolutionCapability(
5751 LibraryResolutionCapability.constantExpressions, true);
5752
5753 definingCompilationUnit = new CompilationUnitElementImpl.forKernel(
5754 this, _kernelContext, '<no-name>');
5755
5756 // TODO(scheglov) how to support parts?
5757 }
5758
5759 @override 5775 @override
5760 int get codeLength { 5776 int get codeLength {
5761 CompilationUnitElement unit = _definingCompilationUnit; 5777 CompilationUnitElement unit = _definingCompilationUnit;
5762 if (unit is CompilationUnitElementImpl) { 5778 if (unit is CompilationUnitElementImpl) {
5763 return unit.codeLength; 5779 return unit.codeLength;
5764 } 5780 }
5765 return null; 5781 return null;
5766 } 5782 }
5767 5783
5768 @override 5784 @override
(...skipping 3215 matching lines...) Expand 10 before | Expand all | Expand 10 after
8984 9000
8985 @override 9001 @override
8986 DartObject computeConstantValue() => null; 9002 DartObject computeConstantValue() => null;
8987 9003
8988 @override 9004 @override
8989 void visitChildren(ElementVisitor visitor) { 9005 void visitChildren(ElementVisitor visitor) {
8990 super.visitChildren(visitor); 9006 super.visitChildren(visitor);
8991 _initializer?.accept(visitor); 9007 _initializer?.accept(visitor);
8992 } 9008 }
8993 } 9009 }
8994
8995 /**
8996 * The kernel context in which a library is resynthesized.
8997 */
8998 abstract class KernelLibraryResynthesizerContext {
8999 kernel.Library get library;
9000 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_kernel_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698