| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.summarize_ast; | 5 library serialization.summarize_ast; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/visitor.dart'; | 8 import 'package:analyzer/dart/ast/visitor.dart'; |
| 9 import 'package:analyzer/src/generated/scanner.dart'; | 9 import 'package:analyzer/src/generated/scanner.dart'; |
| 10 import 'package:analyzer/src/generated/utilities_dart.dart'; | 10 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 } | 505 } |
| 506 } else if (identifier is PrefixedIdentifier) { | 506 } else if (identifier is PrefixedIdentifier) { |
| 507 int prefixIndex = prefixIndices.putIfAbsent(identifier.prefix.name, | 507 int prefixIndex = prefixIndices.putIfAbsent(identifier.prefix.name, |
| 508 () => serializeReference(null, identifier.prefix.name)); | 508 () => serializeReference(null, identifier.prefix.name)); |
| 509 b.reference = | 509 b.reference = |
| 510 serializeReference(prefixIndex, identifier.identifier.name); | 510 serializeReference(prefixIndex, identifier.identifier.name); |
| 511 } else { | 511 } else { |
| 512 throw new StateError( | 512 throw new StateError( |
| 513 'Unexpected identifier type: ${identifier.runtimeType}'); | 513 'Unexpected identifier type: ${identifier.runtimeType}'); |
| 514 } | 514 } |
| 515 if (node.typeArguments != null && | 515 if (node.typeArguments != null) { |
| 516 node.typeArguments.arguments.any(isNotDynamic)) { | 516 // Trailing type arguments of type 'dynamic' should be omitted. |
| 517 b.typeArguments = | 517 NodeList<TypeName> args = node.typeArguments.arguments; |
| 518 node.typeArguments.arguments.map(serializeTypeName).toList(); | 518 int numArgsToSerialize = args.length; |
| 519 while (numArgsToSerialize > 0 && isDynamic(args[numArgsToSerialize - 1])
) { |
| 520 --numArgsToSerialize; |
| 521 } |
| 522 if (numArgsToSerialize > 0) { |
| 523 List<UnlinkedTypeRefBuilder> serializedArguments = <UnlinkedTypeRefBui
lder>[]; |
| 524 for (int i = 0; i < numArgsToSerialize; i++) { |
| 525 serializedArguments.add(serializeTypeName(args[i])); |
| 526 } |
| 527 b.typeArguments = serializedArguments; |
| 528 } |
| 519 } | 529 } |
| 520 } | 530 } |
| 521 return b; | 531 return b; |
| 522 } | 532 } |
| 523 | 533 |
| 524 /** | 534 /** |
| 525 * Serialize the given [typeParameters] into a list of [UnlinkedTypeParam]s, | 535 * Serialize the given [typeParameters] into a list of [UnlinkedTypeParam]s, |
| 526 * and also store them in [typeParameterScope]. | 536 * and also store them in [typeParameterScope]. |
| 527 */ | 537 */ |
| 528 List<UnlinkedTypeParamBuilder> serializeTypeParameters( | 538 List<UnlinkedTypeParamBuilder> serializeTypeParameters( |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 b.nameOffset = node.name.offset; | 799 b.nameOffset = node.name.offset; |
| 790 if (node.bound != null) { | 800 if (node.bound != null) { |
| 791 b.bound = serializeTypeName(node.bound); | 801 b.bound = serializeTypeName(node.bound); |
| 792 } | 802 } |
| 793 return b; | 803 return b; |
| 794 } | 804 } |
| 795 | 805 |
| 796 /** | 806 /** |
| 797 * Helper method to determine if a given [typeName] refers to `dynamic`. | 807 * Helper method to determine if a given [typeName] refers to `dynamic`. |
| 798 */ | 808 */ |
| 799 static bool isNotDynamic(TypeName typeName) { | 809 static bool isDynamic(TypeName typeName) { |
| 800 Identifier name = typeName.name; | 810 Identifier name = typeName.name; |
| 801 return !(name is SimpleIdentifier && name.name == 'dynamic'); | 811 return name is SimpleIdentifier && name.name == 'dynamic'; |
| 802 } | 812 } |
| 803 } | 813 } |
| 804 | 814 |
| 805 /** | 815 /** |
| 806 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s. | 816 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s. |
| 807 */ | 817 */ |
| 808 class _TypeParameterScope extends _Scope { | 818 class _TypeParameterScope extends _Scope { |
| 809 /** | 819 /** |
| 810 * Get the number of [_ScopedTypeParameter]s defined in this | 820 * Get the number of [_ScopedTypeParameter]s defined in this |
| 811 * [_TypeParameterScope]. | 821 * [_TypeParameterScope]. |
| 812 */ | 822 */ |
| 813 int get length => _definedNames.length; | 823 int get length => _definedNames.length; |
| 814 } | 824 } |
| OLD | NEW |