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

Side by Side Diff: pkg/analyzer/lib/src/summary/summarize_elements.dart

Issue 1640813002: Support for static method references in constants. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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/summary_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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 serialization.elements; 5 library serialization.elements;
6 6
7 import 'package:analyzer/dart/element/element.dart'; 7 import 'package:analyzer/dart/element/element.dart';
8 import 'package:analyzer/dart/element/type.dart'; 8 import 'package:analyzer/dart/element/type.dart';
9 import 'package:analyzer/src/dart/element/element.dart'; 9 import 'package:analyzer/src/dart/element/element.dart';
10 import 'package:analyzer/src/dart/element/type.dart'; 10 import 'package:analyzer/src/dart/element/type.dart';
(...skipping 25 matching lines...) Expand all
36 return ReferenceKind.constructor; 36 return ReferenceKind.constructor;
37 } else if (element is FunctionElement) { 37 } else if (element is FunctionElement) {
38 return ReferenceKind.topLevelFunction; 38 return ReferenceKind.topLevelFunction;
39 } else if (element is FunctionTypeAliasElement) { 39 } else if (element is FunctionTypeAliasElement) {
40 return ReferenceKind.typedef; 40 return ReferenceKind.typedef;
41 } else if (element is PropertyAccessorElement) { 41 } else if (element is PropertyAccessorElement) {
42 if (element.enclosingElement is ClassElement) { 42 if (element.enclosingElement is ClassElement) {
43 return ReferenceKind.constField; 43 return ReferenceKind.constField;
44 } 44 }
45 return ReferenceKind.topLevelPropertyAccessor; 45 return ReferenceKind.topLevelPropertyAccessor;
46 } else if (element is MethodElement) {
47 return ReferenceKind.staticMethod;
46 } else { 48 } else {
47 throw new Exception('Unexpected element kind: ${element.runtimeType}'); 49 throw new Exception('Unexpected element kind: ${element.runtimeType}');
48 } 50 }
49 } 51 }
50 52
51 /** 53 /**
52 * Type of closures used by [_LibrarySerializer] to defer generation of 54 * Type of closures used by [_LibrarySerializer] to defer generation of
53 * [EntityRefBuilder] objects until the end of serialization of a 55 * [EntityRefBuilder] objects until the end of serialization of a
54 * compilation unit. 56 * compilation unit.
55 */ 57 */
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 .add(() => serializeTypeRef(type, context, linked: true, slot: slot)); 794 .add(() => serializeTypeRef(type, context, linked: true, slot: slot));
793 } 795 }
794 return slot; 796 return slot;
795 } 797 }
796 798
797 int _getElementReferenceId(Element element, {bool linked: false}) { 799 int _getElementReferenceId(Element element, {bool linked: false}) {
798 return referenceMap.putIfAbsent(element, () { 800 return referenceMap.putIfAbsent(element, () {
799 if (element is ConstructorElement && element.displayName.isEmpty) { 801 if (element is ConstructorElement && element.displayName.isEmpty) {
800 return _getElementReferenceId(element.enclosingElement, linked: linked); 802 return _getElementReferenceId(element.enclosingElement, linked: linked);
801 } 803 }
804 if (element is MethodElement && !element.isStatic) {
805 throw new StateError('Only static methods can be serialized.');
806 }
802 if (element is PropertyAccessorElement) { 807 if (element is PropertyAccessorElement) {
803 Element enclosing = element.enclosingElement; 808 Element enclosing = element.enclosingElement;
804 if (!(enclosing is CompilationUnitElement || element.isStatic)) { 809 if (!(enclosing is CompilationUnitElement || element.isStatic)) {
805 throw new StateError( 810 throw new StateError(
806 'Only top-level or static property accessors can be serialized.'); 811 'Only top-level or static property accessors can be serialized.');
807 } 812 }
808 } 813 }
809 LibraryElement dependentLibrary = element?.library; 814 LibraryElement dependentLibrary = element?.library;
810 int unit; 815 int unit;
811 if (dependentLibrary == null) { 816 if (dependentLibrary == null) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 return new EntityRefBuilder( 907 return new EntityRefBuilder(
903 reference: serializer._getElementReferenceId(element)); 908 reference: serializer._getElementReferenceId(element));
904 } 909 }
905 910
906 @override 911 @override
907 EntityRefBuilder serializePropertyAccess(PropertyAccess access) { 912 EntityRefBuilder serializePropertyAccess(PropertyAccess access) {
908 Element element = access.propertyName.staticElement; 913 Element element = access.propertyName.staticElement;
909 assert(element != null); 914 assert(element != null);
910 // The only supported instance property accessor - `length`. 915 // The only supported instance property accessor - `length`.
911 Expression target = access.target; 916 Expression target = access.target;
912 if (target is Identifier && element is PropertyAccessorElement && 917 if (target is Identifier &&
918 element is PropertyAccessorElement &&
913 !element.isStatic) { 919 !element.isStatic) {
914 assert(element.name == 'length'); 920 assert(element.name == 'length');
915 Element prefixElement = target.staticElement; 921 Element prefixElement = target.staticElement;
916 int prefixRef = serializer._getElementReferenceId(prefixElement); 922 int prefixRef = serializer._getElementReferenceId(prefixElement);
917 int lengthRef = serializer._getLengthPropertyReference(prefixRef); 923 int lengthRef = serializer._getLengthPropertyReference(prefixRef);
918 return new EntityRefBuilder(reference: lengthRef); 924 return new EntityRefBuilder(reference: lengthRef);
919 } 925 }
920 return new EntityRefBuilder( 926 return new EntityRefBuilder(
921 reference: serializer._getElementReferenceId(element)); 927 reference: serializer._getElementReferenceId(element));
922 } 928 }
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 exportNames.add(new LinkedExportNameBuilder( 1117 exportNames.add(new LinkedExportNameBuilder(
1112 name: name, 1118 name: name,
1113 dependency: serializeDependency(dependentLibrary), 1119 dependency: serializeDependency(dependentLibrary),
1114 unit: unit, 1120 unit: unit,
1115 kind: kind)); 1121 kind: kind));
1116 } 1122 }
1117 pb.exportNames = exportNames; 1123 pb.exportNames = exportNames;
1118 return pb; 1124 return pb;
1119 } 1125 }
1120 } 1126 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/summary_common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698