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

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

Issue 2976263002: Resynthesize methods from Kernel. (Closed)
Patch Set: Fix for sync* and test. 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_common.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 821 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 List<ElementAnnotation> get metadata { 832 List<ElementAnnotation> get metadata {
833 if (_unlinkedClass != null) { 833 if (_unlinkedClass != null) {
834 return _metadata ??= 834 return _metadata ??=
835 _buildAnnotations(enclosingUnit, _unlinkedClass.annotations); 835 _buildAnnotations(enclosingUnit, _unlinkedClass.annotations);
836 } 836 }
837 return super.metadata; 837 return super.metadata;
838 } 838 }
839 839
840 @override 840 @override
841 List<MethodElement> get methods { 841 List<MethodElement> get methods {
842 if (_kernel != null) {
843 _methods ??= _kernel.procedures
844 .where((k) =>
845 k.kind == kernel.ProcedureKind.Method ||
846 k.kind == kernel.ProcedureKind.Operator)
847 .map((k) => new MethodElementImpl.forKernel(this, k))
848 .toList(growable: false);
849 }
842 if (_unlinkedClass != null) { 850 if (_unlinkedClass != null) {
843 _methods ??= _unlinkedClass.executables 851 _methods ??= _unlinkedClass.executables
844 .where((e) => e.kind == UnlinkedExecutableKind.functionOrMethod) 852 .where((e) => e.kind == UnlinkedExecutableKind.functionOrMethod)
845 .map((e) => new MethodElementImpl.forSerialized(e, this)) 853 .map((e) => new MethodElementImpl.forSerialized(e, this))
846 .toList(growable: false); 854 .toList(growable: false);
847 } 855 }
848 return _methods ?? const <MethodElement>[]; 856 return _methods ?? const <MethodElement>[];
849 } 857 }
850 858
851 /** 859 /**
(...skipping 2979 matching lines...) Expand 10 before | Expand all | Expand 10 after
3831 /** 3839 /**
3832 * Set whether this executable element has an implicit return type. 3840 * Set whether this executable element has an implicit return type.
3833 */ 3841 */
3834 void set hasImplicitReturnType(bool hasImplicitReturnType) { 3842 void set hasImplicitReturnType(bool hasImplicitReturnType) {
3835 _assertNotResynthesized(serializedExecutable); 3843 _assertNotResynthesized(serializedExecutable);
3836 setModifier(Modifier.IMPLICIT_TYPE, hasImplicitReturnType); 3844 setModifier(Modifier.IMPLICIT_TYPE, hasImplicitReturnType);
3837 } 3845 }
3838 3846
3839 @override 3847 @override
3840 bool get isAbstract { 3848 bool get isAbstract {
3849 if (_kernel != null) {
3850 return _kernel.isAbstract;
3851 }
3841 if (serializedExecutable != null) { 3852 if (serializedExecutable != null) {
3842 return serializedExecutable.isAbstract; 3853 return serializedExecutable.isAbstract;
3843 } 3854 }
3844 return hasModifier(Modifier.ABSTRACT); 3855 return hasModifier(Modifier.ABSTRACT);
3845 } 3856 }
3846 3857
3847 @override 3858 @override
3848 bool get isAsynchronous { 3859 bool get isAsynchronous {
3860 if (_kernel != null) {
3861 kernel.AsyncMarker marker = _kernel.function.asyncMarker;
3862 return marker == kernel.AsyncMarker.Async ||
3863 marker == kernel.AsyncMarker.AsyncStar;
3864 }
3849 if (serializedExecutable != null) { 3865 if (serializedExecutable != null) {
3850 return serializedExecutable.isAsynchronous; 3866 return serializedExecutable.isAsynchronous;
3851 } 3867 }
3852 return hasModifier(Modifier.ASYNCHRONOUS); 3868 return hasModifier(Modifier.ASYNCHRONOUS);
3853 } 3869 }
3854 3870
3855 @override 3871 @override
3856 bool get isExternal { 3872 bool get isExternal {
3857 if (_kernel != null) { 3873 if (_kernel != null) {
3858 return _kernel.isExternal; 3874 return _kernel.isExternal;
3859 } 3875 }
3860 if (serializedExecutable != null) { 3876 if (serializedExecutable != null) {
3861 return serializedExecutable.isExternal; 3877 return serializedExecutable.isExternal;
3862 } 3878 }
3863 return hasModifier(Modifier.EXTERNAL); 3879 return hasModifier(Modifier.EXTERNAL);
3864 } 3880 }
3865 3881
3866 @override 3882 @override
3867 bool get isGenerator { 3883 bool get isGenerator {
3884 if (_kernel != null) {
3885 kernel.AsyncMarker marker = _kernel.function.asyncMarker;
3886 return marker == kernel.AsyncMarker.AsyncStar ||
3887 marker == kernel.AsyncMarker.SyncStar;
3888 }
3868 if (serializedExecutable != null) { 3889 if (serializedExecutable != null) {
3869 return serializedExecutable.isGenerator; 3890 return serializedExecutable.isGenerator;
3870 } 3891 }
3871 return hasModifier(Modifier.GENERATOR); 3892 return hasModifier(Modifier.GENERATOR);
3872 } 3893 }
3873 3894
3874 @override 3895 @override
3875 bool get isOperator => false; 3896 bool get isOperator => false;
3876 3897
3877 @override 3898 @override
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3925 void set parameters(List<ParameterElement> parameters) { 3946 void set parameters(List<ParameterElement> parameters) {
3926 _assertNotResynthesized(serializedExecutable); 3947 _assertNotResynthesized(serializedExecutable);
3927 for (ParameterElement parameter in parameters) { 3948 for (ParameterElement parameter in parameters) {
3928 (parameter as ParameterElementImpl).enclosingElement = this; 3949 (parameter as ParameterElementImpl).enclosingElement = this;
3929 } 3950 }
3930 this._parameters = parameters; 3951 this._parameters = parameters;
3931 } 3952 }
3932 3953
3933 @override 3954 @override
3934 DartType get returnType { 3955 DartType get returnType {
3956 if (_kernel != null) {
3957 return _returnType ??= enclosingUnit._kernelContext
3958 .getType(this, _kernel.function.returnType);
3959 }
3935 if (serializedExecutable != null && 3960 if (serializedExecutable != null &&
3936 _declaredReturnType == null && 3961 _declaredReturnType == null &&
3937 _returnType == null) { 3962 _returnType == null) {
3938 bool isSetter = 3963 bool isSetter =
3939 serializedExecutable.kind == UnlinkedExecutableKind.setter; 3964 serializedExecutable.kind == UnlinkedExecutableKind.setter;
3940 _returnType = enclosingUnit.resynthesizerContext 3965 _returnType = enclosingUnit.resynthesizerContext
3941 .resolveLinkedType(this, serializedExecutable.inferredReturnTypeSlot); 3966 .resolveLinkedType(this, serializedExecutable.inferredReturnTypeSlot);
3942 _declaredReturnType = enclosingUnit.resynthesizerContext.resolveTypeRef( 3967 _declaredReturnType = enclosingUnit.resynthesizerContext.resolveTypeRef(
3943 this, serializedExecutable.returnType, 3968 this, serializedExecutable.returnType,
3944 defaultVoid: isSetter && context.analysisOptions.strongMode, 3969 defaultVoid: isSetter && context.analysisOptions.strongMode,
(...skipping 2597 matching lines...) Expand 10 before | Expand all | Expand 10 after
6542 _visibleRangeOffset = offset; 6567 _visibleRangeOffset = offset;
6543 _visibleRangeLength = length; 6568 _visibleRangeLength = length;
6544 } 6569 }
6545 } 6570 }
6546 6571
6547 /** 6572 /**
6548 * A concrete implementation of a [MethodElement]. 6573 * A concrete implementation of a [MethodElement].
6549 */ 6574 */
6550 class MethodElementImpl extends ExecutableElementImpl implements MethodElement { 6575 class MethodElementImpl extends ExecutableElementImpl implements MethodElement {
6551 /** 6576 /**
6577 * The kernel of the element.
6578 */
6579 kernel.Procedure _kernelProcedure;
6580
6581 /**
6552 * Initialize a newly created method element to have the given [name] at the 6582 * Initialize a newly created method element to have the given [name] at the
6553 * given [offset]. 6583 * given [offset].
6554 */ 6584 */
6555 MethodElementImpl(String name, int offset) : super(name, offset); 6585 MethodElementImpl(String name, int offset) : super(name, offset);
6556 6586
6557 /** 6587 /**
6588 * Initialize using the given kernel.
6589 */
6590 MethodElementImpl.forKernel(
6591 ClassElementImpl enclosingClass, this._kernelProcedure)
6592 : super.forKernel(enclosingClass, _kernelProcedure);
6593
6594 /**
6558 * Initialize a newly created method element to have the given [name]. 6595 * Initialize a newly created method element to have the given [name].
6559 */ 6596 */
6560 MethodElementImpl.forNode(Identifier name) : super.forNode(name); 6597 MethodElementImpl.forNode(Identifier name) : super.forNode(name);
6561 6598
6562 /** 6599 /**
6563 * Initialize using the given serialized information. 6600 * Initialize using the given serialized information.
6564 */ 6601 */
6565 MethodElementImpl.forSerialized( 6602 MethodElementImpl.forSerialized(
6566 UnlinkedExecutable serializedExecutable, ClassElementImpl enclosingClass) 6603 UnlinkedExecutable serializedExecutable, ClassElementImpl enclosingClass)
6567 : super.forSerialized(serializedExecutable, enclosingClass); 6604 : super.forSerialized(serializedExecutable, enclosingClass);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
6606 } 6643 }
6607 int first = name.codeUnitAt(0); 6644 int first = name.codeUnitAt(0);
6608 return !((0x61 <= first && first <= 0x7A) || 6645 return !((0x61 <= first && first <= 0x7A) ||
6609 (0x41 <= first && first <= 0x5A) || 6646 (0x41 <= first && first <= 0x5A) ||
6610 first == 0x5F || 6647 first == 0x5F ||
6611 first == 0x24); 6648 first == 0x24);
6612 } 6649 }
6613 6650
6614 @override 6651 @override
6615 bool get isStatic { 6652 bool get isStatic {
6653 if (_kernel != null) {
6654 return _kernelProcedure.isStatic;
6655 }
6616 if (serializedExecutable != null) { 6656 if (serializedExecutable != null) {
6617 return serializedExecutable.isStatic; 6657 return serializedExecutable.isStatic;
6618 } 6658 }
6619 return hasModifier(Modifier.STATIC); 6659 return hasModifier(Modifier.STATIC);
6620 } 6660 }
6621 6661
6622 /** 6662 /**
6623 * Set whether this method is static. 6663 * Set whether this method is static.
6624 */ 6664 */
6625 void set isStatic(bool isStatic) { 6665 void set isStatic(bool isStatic) {
(...skipping 2537 matching lines...) Expand 10 before | Expand all | Expand 10 after
9163 9203
9164 @override 9204 @override
9165 DartObject computeConstantValue() => null; 9205 DartObject computeConstantValue() => null;
9166 9206
9167 @override 9207 @override
9168 void visitChildren(ElementVisitor visitor) { 9208 void visitChildren(ElementVisitor visitor) {
9169 super.visitChildren(visitor); 9209 super.visitChildren(visitor);
9170 _initializer?.accept(visitor); 9210 _initializer?.accept(visitor);
9171 } 9211 }
9172 } 9212 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698