| 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/member.dart'; | 10 import 'package:analyzer/src/dart/element/member.dart'; |
| (...skipping 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1074 LinkedReference typeLinkedRef = | 1074 LinkedReference typeLinkedRef = |
| 1075 serializer.linkedReferences[typeRef.reference]; | 1075 serializer.linkedReferences[typeRef.reference]; |
| 1076 int refId = serializer.serializeUnlinkedReference( | 1076 int refId = serializer.serializeUnlinkedReference( |
| 1077 name.name, ReferenceKind.constructor, | 1077 name.name, ReferenceKind.constructor, |
| 1078 prefixReference: typeRef.reference, unit: typeLinkedRef.unit); | 1078 prefixReference: typeRef.reference, unit: typeLinkedRef.unit); |
| 1079 return new EntityRefBuilder( | 1079 return new EntityRefBuilder( |
| 1080 reference: refId, typeArguments: typeRef.typeArguments); | 1080 reference: refId, typeArguments: typeRef.typeArguments); |
| 1081 } | 1081 } |
| 1082 } | 1082 } |
| 1083 | 1083 |
| 1084 EntityRefBuilder serializeIdentifier(Identifier identifier) { | 1084 EntityRefBuilder serializeIdentifier(Identifier identifier, |
| 1085 {int prefixReference: 0}) { |
| 1085 Element element = identifier.staticElement; | 1086 Element element = identifier.staticElement; |
| 1086 assert(element != null); | 1087 // Unresolved identifier. |
| 1088 if (element == null) { |
| 1089 int reference; |
| 1090 if (identifier is PrefixedIdentifier) { |
| 1091 int prefix = serializeIdentifier(identifier.prefix).reference; |
| 1092 reference = serializer.serializeUnlinkedReference( |
| 1093 identifier.identifier.name, ReferenceKind.unresolved, |
| 1094 prefixReference: prefix); |
| 1095 } else { |
| 1096 reference = serializer.serializeUnlinkedReference( |
| 1097 identifier.name, ReferenceKind.unresolved, |
| 1098 prefixReference: prefixReference); |
| 1099 } |
| 1100 return new EntityRefBuilder(reference: reference); |
| 1101 } |
| 1087 // The only supported instance property accessor - `length`. | 1102 // The only supported instance property accessor - `length`. |
| 1088 if (identifier is PrefixedIdentifier && | 1103 if (identifier is PrefixedIdentifier && |
| 1089 element is PropertyAccessorElement && | 1104 element is PropertyAccessorElement && |
| 1090 !element.isStatic) { | 1105 !element.isStatic) { |
| 1091 if (element.name != 'length') { | 1106 if (element.name != 'length') { |
| 1092 throw new StateError('Only "length" property is allowed in constants.'); | 1107 throw new StateError('Only "length" property is allowed in constants.'); |
| 1093 } | 1108 } |
| 1094 Element prefixElement = identifier.prefix.staticElement; | 1109 Element prefixElement = identifier.prefix.staticElement; |
| 1095 int prefixRef = serializer._getElementReferenceId(prefixElement); | 1110 int prefixRef = serializer._getElementReferenceId(prefixElement); |
| 1096 int lengthRef = serializer._getLengthPropertyReference(prefixRef); | 1111 int lengthRef = serializer._getLengthPropertyReference(prefixRef); |
| 1097 return new EntityRefBuilder(reference: lengthRef); | 1112 return new EntityRefBuilder(reference: lengthRef); |
| 1098 } | 1113 } |
| 1099 if (element is TypeParameterElement) { | 1114 if (element is TypeParameterElement) { |
| 1100 throw new StateError('Constants may not refer to type parameters.'); | 1115 throw new StateError('Constants may not refer to type parameters.'); |
| 1101 } | 1116 } |
| 1102 return new EntityRefBuilder( | 1117 return new EntityRefBuilder( |
| 1103 reference: serializer._getElementReferenceId(element)); | 1118 reference: serializer._getElementReferenceId(element)); |
| 1104 } | 1119 } |
| 1105 | 1120 |
| 1106 @override | 1121 @override |
| 1107 EntityRefBuilder serializePropertyAccess(PropertyAccess access) { | 1122 EntityRefBuilder serializePropertyAccess(PropertyAccess access) { |
| 1108 Element element = access.propertyName.staticElement; | 1123 Element element = access.propertyName.staticElement; |
| 1109 assert(element != null); | 1124 // Unresolved property access. |
| 1125 if (element == null) { |
| 1126 Expression target = access.target; |
| 1127 if (target is Identifier) { |
| 1128 EntityRefBuilder targetRef = serializeIdentifier(target); |
| 1129 EntityRefBuilder propertyRef = serializeIdentifier(access.propertyName, |
| 1130 prefixReference: targetRef.reference); |
| 1131 return new EntityRefBuilder(reference: propertyRef.reference); |
| 1132 } else { |
| 1133 // TODO(scheglov) should we handle other targets in malformed constants? |
| 1134 throw new StateError('Unexpected target type: ${target.runtimeType}'); |
| 1135 } |
| 1136 } |
| 1110 // The only supported instance property accessor - `length`. | 1137 // The only supported instance property accessor - `length`. |
| 1111 Expression target = access.target; | 1138 Expression target = access.target; |
| 1112 if (target is Identifier && | 1139 if (target is Identifier && |
| 1113 element is PropertyAccessorElement && | 1140 element is PropertyAccessorElement && |
| 1114 !element.isStatic) { | 1141 !element.isStatic) { |
| 1115 assert(element.name == 'length'); | 1142 assert(element.name == 'length'); |
| 1116 Element prefixElement = target.staticElement; | 1143 Element prefixElement = target.staticElement; |
| 1117 int prefixRef = serializer._getElementReferenceId(prefixElement); | 1144 int prefixRef = serializer._getElementReferenceId(prefixElement); |
| 1118 int lengthRef = serializer._getLengthPropertyReference(prefixRef); | 1145 int lengthRef = serializer._getLengthPropertyReference(prefixRef); |
| 1119 return new EntityRefBuilder(reference: lengthRef); | 1146 return new EntityRefBuilder(reference: lengthRef); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1312 exportNames.add(new LinkedExportNameBuilder( | 1339 exportNames.add(new LinkedExportNameBuilder( |
| 1313 name: name, | 1340 name: name, |
| 1314 dependency: serializeDependency(dependentLibrary), | 1341 dependency: serializeDependency(dependentLibrary), |
| 1315 unit: unit, | 1342 unit: unit, |
| 1316 kind: kind)); | 1343 kind: kind)); |
| 1317 } | 1344 } |
| 1318 pb.exportNames = exportNames; | 1345 pb.exportNames = exportNames; |
| 1319 return pb; | 1346 return pb; |
| 1320 } | 1347 } |
| 1321 } | 1348 } |
| OLD | NEW |