| OLD | NEW |
| 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 10 matching lines...) Expand all Loading... |
| 21 */ | 21 */ |
| 22 LibrarySerializationResult serializeLibrary( | 22 LibrarySerializationResult serializeLibrary( |
| 23 LibraryElement lib, TypeProvider typeProvider, bool strongMode) { | 23 LibraryElement lib, TypeProvider typeProvider, bool strongMode) { |
| 24 var serializer = new _LibrarySerializer(lib, typeProvider, strongMode); | 24 var serializer = new _LibrarySerializer(lib, typeProvider, strongMode); |
| 25 LinkedLibraryBuilder linked = serializer.serializeLibrary(); | 25 LinkedLibraryBuilder linked = serializer.serializeLibrary(); |
| 26 return new LibrarySerializationResult( | 26 return new LibrarySerializationResult( |
| 27 linked, serializer.unlinkedUnits, serializer.unitUris); | 27 linked, serializer.unlinkedUnits, serializer.unitUris); |
| 28 } | 28 } |
| 29 | 29 |
| 30 ReferenceKind _getReferenceKind(Element element) { | 30 ReferenceKind _getReferenceKind(Element element) { |
| 31 ReferenceKind kind; | |
| 32 if (element == null || | 31 if (element == null || |
| 33 element is ClassElement || | 32 element is ClassElement || |
| 34 element is DynamicElementImpl) { | 33 element is DynamicElementImpl) { |
| 35 kind = ReferenceKind.classOrEnum; | 34 return ReferenceKind.classOrEnum; |
| 36 } else if (element is ConstructorElement) { | 35 } else if (element is ConstructorElement) { |
| 37 kind = ReferenceKind.constructor; | 36 return ReferenceKind.constructor; |
| 38 } else if (element is FunctionElement) { | 37 } else if (element is FunctionElement) { |
| 39 kind = ReferenceKind.topLevelFunction; | 38 return ReferenceKind.topLevelFunction; |
| 40 } else if (element is FunctionTypeAliasElement) { | 39 } else if (element is FunctionTypeAliasElement) { |
| 41 kind = ReferenceKind.typedef; | 40 return ReferenceKind.typedef; |
| 42 } else if (element is PropertyAccessorElement) { | 41 } else if (element is PropertyAccessorElement) { |
| 43 kind = ReferenceKind.topLevelPropertyAccessor; | 42 if (element.enclosingElement is ClassElement) { |
| 43 return ReferenceKind.constField; |
| 44 } |
| 45 return ReferenceKind.topLevelPropertyAccessor; |
| 44 } else { | 46 } else { |
| 45 throw new Exception('Unexpected element kind: ${element.runtimeType}'); | 47 throw new Exception('Unexpected element kind: ${element.runtimeType}'); |
| 46 } | 48 } |
| 47 return kind; | |
| 48 } | 49 } |
| 49 | 50 |
| 50 /** | 51 /** |
| 51 * Type of closures used by [_LibrarySerializer] to defer generation of | 52 * Type of closures used by [_LibrarySerializer] to defer generation of |
| 52 * [EntityRefBuilder] objects until the end of serialization of a | 53 * [EntityRefBuilder] objects until the end of serialization of a |
| 53 * compilation unit. | 54 * compilation unit. |
| 54 */ | 55 */ |
| 55 typedef EntityRefBuilder _SerializeTypeRef(); | 56 typedef EntityRefBuilder _SerializeTypeRef(); |
| 56 | 57 |
| 57 /** | 58 /** |
| (...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 EntityRefBuilder serializeConstructorName(ConstructorName constructor) { | 864 EntityRefBuilder serializeConstructorName(ConstructorName constructor) { |
| 864 ConstructorElement element = constructor.staticElement; | 865 ConstructorElement element = constructor.staticElement; |
| 865 assert(element != null); | 866 assert(element != null); |
| 866 int referenceId = serializer._getElementReferenceId(element); | 867 int referenceId = serializer._getElementReferenceId(element); |
| 867 return new EntityRefBuilder(reference: referenceId); | 868 return new EntityRefBuilder(reference: referenceId); |
| 868 } | 869 } |
| 869 | 870 |
| 870 EntityRefBuilder serializeIdentifier(Identifier identifier) { | 871 EntityRefBuilder serializeIdentifier(Identifier identifier) { |
| 871 Element element = identifier.staticElement; | 872 Element element = identifier.staticElement; |
| 872 assert(element != null); | 873 assert(element != null); |
| 873 // TODO(scheglov) how to serialize element references? | |
| 874 return new EntityRefBuilder( | 874 return new EntityRefBuilder( |
| 875 reference: serializer._getElementReferenceId(element)); | 875 reference: serializer._getElementReferenceId(element)); |
| 876 } | 876 } |
| 877 |
| 878 @override |
| 879 EntityRefBuilder serializePropertyAccess(PropertyAccess access) { |
| 880 Element element = access.propertyName.staticElement; |
| 881 assert(element != null); |
| 882 return new EntityRefBuilder( |
| 883 reference: serializer._getElementReferenceId(element)); |
| 884 } |
| 877 | 885 |
| 878 @override | 886 @override |
| 879 EntityRefBuilder serializeType(TypeName typeName) { | 887 EntityRefBuilder serializeType(TypeName typeName) { |
| 880 DartType type = typeName != null ? typeName.type : DynamicTypeImpl.instance; | 888 DartType type = typeName != null ? typeName.type : DynamicTypeImpl.instance; |
| 881 return serializer.serializeTypeRef(type, null); | 889 return serializer.serializeTypeRef(type, null); |
| 882 } | 890 } |
| 883 } | 891 } |
| 884 | 892 |
| 885 /** | 893 /** |
| 886 * Instances of this class keep track of intermediate state during | 894 * Instances of this class keep track of intermediate state during |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1065 exportNames.add(new LinkedExportNameBuilder( | 1073 exportNames.add(new LinkedExportNameBuilder( |
| 1066 name: name, | 1074 name: name, |
| 1067 dependency: serializeDependency(dependentLibrary), | 1075 dependency: serializeDependency(dependentLibrary), |
| 1068 unit: unit, | 1076 unit: unit, |
| 1069 kind: kind)); | 1077 kind: kind)); |
| 1070 } | 1078 } |
| 1071 pb.exportNames = exportNames; | 1079 pb.exportNames = exportNames; |
| 1072 return pb; | 1080 return pb; |
| 1073 } | 1081 } |
| 1074 } | 1082 } |
| OLD | NEW |