| 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 'dart:convert'; | 7 import 'dart:convert'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
| (...skipping 1313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1324 void serializeAnnotation(Annotation annotation) { | 1324 void serializeAnnotation(Annotation annotation) { |
| 1325 if (annotation.arguments == null) { | 1325 if (annotation.arguments == null) { |
| 1326 assert(annotation.constructorName == null); | 1326 assert(annotation.constructorName == null); |
| 1327 serialize(annotation.name); | 1327 serialize(annotation.name); |
| 1328 } else { | 1328 } else { |
| 1329 Identifier name = annotation.name; | 1329 Identifier name = annotation.name; |
| 1330 Element nameElement = name.staticElement; | 1330 Element nameElement = name.staticElement; |
| 1331 EntityRefBuilder constructor; | 1331 EntityRefBuilder constructor; |
| 1332 if (nameElement is ConstructorElement && name is PrefixedIdentifier) { | 1332 if (nameElement is ConstructorElement && name is PrefixedIdentifier) { |
| 1333 assert(annotation.constructorName == null); | 1333 assert(annotation.constructorName == null); |
| 1334 constructor = serializeConstructorName( | 1334 constructor = serializeConstructorRef( |
| 1335 new TypeName(name.prefix, null)..type = nameElement.returnType, | 1335 nameElement.returnType, name.prefix, null, name.identifier); |
| 1336 name.identifier); | |
| 1337 } else if (nameElement is TypeDefiningElement) { | 1336 } else if (nameElement is TypeDefiningElement) { |
| 1338 constructor = serializeConstructorName( | 1337 constructor = serializeConstructorRef(nameElement.type, annotation.name, |
| 1339 new TypeName(annotation.name, null)..type = nameElement.type, | 1338 null, annotation.constructorName); |
| 1340 annotation.constructorName); | |
| 1341 } else if (nameElement == null) { | 1339 } else if (nameElement == null) { |
| 1342 // Unresolved annotation. | 1340 // Unresolved annotation. |
| 1343 if (name is PrefixedIdentifier && annotation.constructorName == null) { | 1341 if (name is PrefixedIdentifier && annotation.constructorName == null) { |
| 1344 constructor = serializeConstructorName( | 1342 constructor = |
| 1345 new TypeName(name.prefix, null), name.identifier); | 1343 serializeConstructorRef(null, name.prefix, null, name.identifier); |
| 1346 } else { | 1344 } else { |
| 1347 constructor = serializeConstructorName( | 1345 constructor = serializeConstructorRef( |
| 1348 new TypeName(annotation.name, null), annotation.constructorName); | 1346 null, annotation.name, null, annotation.constructorName); |
| 1349 } | 1347 } |
| 1350 } else { | 1348 } else { |
| 1351 throw new StateError('Unexpected annotation nameElement type:' | 1349 throw new StateError('Unexpected annotation nameElement type:' |
| 1352 ' ${nameElement.runtimeType}'); | 1350 ' ${nameElement.runtimeType}'); |
| 1353 } | 1351 } |
| 1354 serializeInstanceCreation(constructor, annotation.arguments); | 1352 serializeInstanceCreation(constructor, annotation.arguments); |
| 1355 } | 1353 } |
| 1356 } | 1354 } |
| 1357 | 1355 |
| 1358 @override | 1356 @override |
| 1359 EntityRefBuilder serializeConstructorName( | 1357 EntityRefBuilder serializeConstructorRef(DartType type, Identifier typeName, |
| 1360 TypeName type, SimpleIdentifier name) { | 1358 TypeArgumentList typeArguments, SimpleIdentifier name) { |
| 1361 EntityRefBuilder typeRef = serializeType(type); | 1359 EntityRefBuilder typeRef = serializeType(type, typeName, typeArguments); |
| 1362 if (name == null) { | 1360 if (name == null) { |
| 1363 return typeRef; | 1361 return typeRef; |
| 1364 } else { | 1362 } else { |
| 1365 LinkedReference typeLinkedRef = | 1363 LinkedReference typeLinkedRef = |
| 1366 serializer.linkedReferences[typeRef.reference]; | 1364 serializer.linkedReferences[typeRef.reference]; |
| 1367 int refId = serializer.serializeUnlinkedReference( | 1365 int refId = serializer.serializeUnlinkedReference( |
| 1368 name.name, | 1366 name.name, |
| 1369 name.staticElement != null | 1367 name.staticElement != null |
| 1370 ? ReferenceKind.constructor | 1368 ? ReferenceKind.constructor |
| 1371 : ReferenceKind.unresolved, | 1369 : ReferenceKind.unresolved, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1426 expr.propertyName.name, ReferenceKind.unresolved, | 1424 expr.propertyName.name, ReferenceKind.unresolved, |
| 1427 prefixReference: targetRef); | 1425 prefixReference: targetRef); |
| 1428 return new EntityRefBuilder(reference: ref); | 1426 return new EntityRefBuilder(reference: ref); |
| 1429 } | 1427 } |
| 1430 } else { | 1428 } else { |
| 1431 throw new StateError('Unexpected node type: ${expr.runtimeType}'); | 1429 throw new StateError('Unexpected node type: ${expr.runtimeType}'); |
| 1432 } | 1430 } |
| 1433 } | 1431 } |
| 1434 | 1432 |
| 1435 @override | 1433 @override |
| 1436 EntityRefBuilder serializeType(TypeName typeName) { | 1434 EntityRefBuilder serializeType( |
| 1437 if (typeName != null) { | 1435 DartType type, Identifier name, TypeArgumentList arguments) { |
| 1438 DartType type = typeName.type; | 1436 if (name != null) { |
| 1439 if (type == null || type.isUndefined) { | 1437 if (type == null || type.isUndefined) { |
| 1440 return serializeIdentifier(typeName.name); | 1438 return serializeIdentifier(name); |
| 1441 } | 1439 } |
| 1442 } | 1440 } |
| 1443 DartType type = typeName != null ? typeName.type : DynamicTypeImpl.instance; | 1441 DartType typeOrDynamic = type ?? DynamicTypeImpl.instance; |
| 1444 return serializer.serializeTypeRef(type, context); | 1442 return serializer.serializeTypeRef(typeOrDynamic, context); |
| 1445 } | 1443 } |
| 1446 | 1444 |
| 1447 /** | 1445 /** |
| 1448 * Return `true` if the given [element] can be resolved at prelink step. | 1446 * Return `true` if the given [element] can be resolved at prelink step. |
| 1449 */ | 1447 */ |
| 1450 static bool _isPrelinkResolvableElement(Element element) { | 1448 static bool _isPrelinkResolvableElement(Element element) { |
| 1451 if (element == null) { | 1449 if (element == null) { |
| 1452 return false; | 1450 return false; |
| 1453 } | 1451 } |
| 1454 if (element == DynamicTypeImpl.instance.element) { | 1452 if (element == DynamicTypeImpl.instance.element) { |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1668 exportNames.add(new LinkedExportNameBuilder( | 1666 exportNames.add(new LinkedExportNameBuilder( |
| 1669 name: name, | 1667 name: name, |
| 1670 dependency: serializeDependency(dependentLibrary), | 1668 dependency: serializeDependency(dependentLibrary), |
| 1671 unit: unit, | 1669 unit: unit, |
| 1672 kind: kind)); | 1670 kind: kind)); |
| 1673 } | 1671 } |
| 1674 pb.exportNames = exportNames; | 1672 pb.exportNames = exportNames; |
| 1675 return pb; | 1673 return pb; |
| 1676 } | 1674 } |
| 1677 } | 1675 } |
| OLD | NEW |