| 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 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 959 | 959 |
| 960 /** | 960 /** |
| 961 * If a constructor initializer expression is being serialized, the names of | 961 * If a constructor initializer expression is being serialized, the names of |
| 962 * the constructor parameters. Otherwise `null`. | 962 * the constructor parameters. Otherwise `null`. |
| 963 */ | 963 */ |
| 964 final Set<String> constructorParameterNames; | 964 final Set<String> constructorParameterNames; |
| 965 | 965 |
| 966 _ConstExprSerializer(this.serializer, this.constructorParameterNames); | 966 _ConstExprSerializer(this.serializer, this.constructorParameterNames); |
| 967 | 967 |
| 968 @override | 968 @override |
| 969 bool isConstructorParameterName(String name) { |
| 970 return constructorParameterNames?.contains(name) ?? false; |
| 971 } |
| 972 |
| 973 @override |
| 969 void serializeAnnotation(Annotation annotation) { | 974 void serializeAnnotation(Annotation annotation) { |
| 970 if (annotation.arguments == null) { | 975 if (annotation.arguments == null) { |
| 971 assert(annotation.constructorName == null); | 976 assert(annotation.constructorName == null); |
| 972 serialize(annotation.name); | 977 serialize(annotation.name); |
| 973 } else { | 978 } else { |
| 974 Identifier name = annotation.name; | 979 Identifier name = annotation.name; |
| 975 Element nameElement = name.staticElement; | 980 Element nameElement = name.staticElement; |
| 976 EntityRefBuilder constructor; | 981 EntityRefBuilder constructor; |
| 977 if (nameElement is ConstructorElement && name is PrefixedIdentifier) { | 982 if (nameElement is ConstructorElement && name is PrefixedIdentifier) { |
| 978 assert(annotation.constructorName == null); | 983 assert(annotation.constructorName == null); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1010 } | 1015 } |
| 1011 } | 1016 } |
| 1012 | 1017 |
| 1013 EntityRefBuilder serializeIdentifier(Identifier identifier) { | 1018 EntityRefBuilder serializeIdentifier(Identifier identifier) { |
| 1014 Element element = identifier.staticElement; | 1019 Element element = identifier.staticElement; |
| 1015 assert(element != null); | 1020 assert(element != null); |
| 1016 // The only supported instance property accessor - `length`. | 1021 // The only supported instance property accessor - `length`. |
| 1017 if (identifier is PrefixedIdentifier && | 1022 if (identifier is PrefixedIdentifier && |
| 1018 element is PropertyAccessorElement && | 1023 element is PropertyAccessorElement && |
| 1019 !element.isStatic) { | 1024 !element.isStatic) { |
| 1020 assert(element.name == 'length'); | 1025 if (element.name != 'length') { |
| 1026 throw new StateError('Only "length" property is allowed in constants.'); |
| 1027 } |
| 1021 Element prefixElement = identifier.prefix.staticElement; | 1028 Element prefixElement = identifier.prefix.staticElement; |
| 1022 int prefixRef = serializer._getElementReferenceId(prefixElement); | 1029 int prefixRef = serializer._getElementReferenceId(prefixElement); |
| 1023 int lengthRef = serializer._getLengthPropertyReference(prefixRef); | 1030 int lengthRef = serializer._getLengthPropertyReference(prefixRef); |
| 1024 return new EntityRefBuilder(reference: lengthRef); | 1031 return new EntityRefBuilder(reference: lengthRef); |
| 1025 } | 1032 } |
| 1026 return new EntityRefBuilder( | 1033 return new EntityRefBuilder( |
| 1027 reference: serializer._getElementReferenceId(element)); | 1034 reference: serializer._getElementReferenceId(element)); |
| 1028 } | 1035 } |
| 1029 | 1036 |
| 1030 @override | 1037 @override |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1044 } | 1051 } |
| 1045 return new EntityRefBuilder( | 1052 return new EntityRefBuilder( |
| 1046 reference: serializer._getElementReferenceId(element)); | 1053 reference: serializer._getElementReferenceId(element)); |
| 1047 } | 1054 } |
| 1048 | 1055 |
| 1049 @override | 1056 @override |
| 1050 EntityRefBuilder serializeType(TypeName typeName) { | 1057 EntityRefBuilder serializeType(TypeName typeName) { |
| 1051 DartType type = typeName != null ? typeName.type : DynamicTypeImpl.instance; | 1058 DartType type = typeName != null ? typeName.type : DynamicTypeImpl.instance; |
| 1052 return serializer.serializeTypeRef(type, null); | 1059 return serializer.serializeTypeRef(type, null); |
| 1053 } | 1060 } |
| 1054 | |
| 1055 @override | |
| 1056 bool isConstructorParameterName(String name) { | |
| 1057 return constructorParameterNames?.contains(name) ?? false; | |
| 1058 } | |
| 1059 } | 1061 } |
| 1060 | 1062 |
| 1061 /** | 1063 /** |
| 1062 * Instances of this class keep track of intermediate state during | 1064 * Instances of this class keep track of intermediate state during |
| 1063 * serialization of a single library. | 1065 * serialization of a single library. |
| 1064 */ | 1066 */ |
| 1065 class _LibrarySerializer { | 1067 class _LibrarySerializer { |
| 1066 /** | 1068 /** |
| 1067 * The library to be serialized. | 1069 * The library to be serialized. |
| 1068 */ | 1070 */ |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1241 exportNames.add(new LinkedExportNameBuilder( | 1243 exportNames.add(new LinkedExportNameBuilder( |
| 1242 name: name, | 1244 name: name, |
| 1243 dependency: serializeDependency(dependentLibrary), | 1245 dependency: serializeDependency(dependentLibrary), |
| 1244 unit: unit, | 1246 unit: unit, |
| 1245 kind: kind)); | 1247 kind: kind)); |
| 1246 } | 1248 } |
| 1247 pb.exportNames = exportNames; | 1249 pb.exportNames = exportNames; |
| 1248 return pb; | 1250 return pb; |
| 1249 } | 1251 } |
| 1250 } | 1252 } |
| OLD | NEW |