| 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 summary_resynthesizer; | 5 library summary_resynthesizer; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 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 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 return stack.single; | 448 return stack.single; |
| 449 } | 449 } |
| 450 | 450 |
| 451 TypeName _buildTypeAst(DartType type) { | 451 TypeName _buildTypeAst(DartType type) { |
| 452 if (type is DynamicTypeImpl) { | 452 if (type is DynamicTypeImpl) { |
| 453 TypeName node = AstFactory.typeName4('dynamic'); | 453 TypeName node = AstFactory.typeName4('dynamic'); |
| 454 node.type = type; | 454 node.type = type; |
| 455 (node.name as SimpleIdentifier).staticElement = type.element; | 455 (node.name as SimpleIdentifier).staticElement = type.element; |
| 456 return node; | 456 return node; |
| 457 } else if (type is InterfaceType) { | 457 } else if (type is InterfaceType) { |
| 458 List<TypeName> argumentNodes = | 458 List<DartType> typeArguments = type.typeArguments; |
| 459 type.typeArguments.map(_buildTypeAst).toList(); | 459 List<TypeName> argumentNodes = typeArguments.every((a) => a.isDynamic) |
| 460 ? null |
| 461 : typeArguments.map(_buildTypeAst).toList(); |
| 460 TypeName node = AstFactory.typeName4(type.name, argumentNodes); | 462 TypeName node = AstFactory.typeName4(type.name, argumentNodes); |
| 461 node.type = type; | 463 node.type = type; |
| 462 (node.name as SimpleIdentifier).staticElement = type.element; | 464 (node.name as SimpleIdentifier).staticElement = type.element; |
| 463 return node; | 465 return node; |
| 464 } | 466 } |
| 465 throw new StateError('Unsupported type $type'); | 467 throw new StateError('Unsupported type $type'); |
| 466 } | 468 } |
| 467 | 469 |
| 468 /** | 470 /** |
| 469 * Return the [ConstructorElement] by applying [typeArgumentRefs] to the | 471 * Return the [ConstructorElement] by applying [typeArgumentRefs] to the |
| 470 * given linked [info]. Both cases when [info] is a [ClassElement] and | 472 * given linked [info]. Both cases when [info] is a [ClassElement] and |
| 471 * [ConstructorElement] are supported. | 473 * [ConstructorElement] are supported. |
| 472 */ | 474 */ |
| 473 _DeferredConstructorElement _createConstructorElement( | 475 _DeferredConstructorElement _createConstructorElement( |
| 474 _ReferenceInfo info, List<EntityRef> typeArgumentRefs) { | 476 _ReferenceInfo info, List<EntityRef> typeArgumentRefs) { |
| 475 bool isClass = info.element is ClassElement; | 477 bool isClass = info.element is ClassElement; |
| 476 _ReferenceInfo classInfo = isClass ? info : info.enclosing; | 478 _ReferenceInfo classInfo = isClass ? info : info.enclosing; |
| 477 List<DartType> typeArguments = | 479 List<DartType> typeArguments = |
| 478 typeArgumentRefs.map(resynthesizer.buildType).toList(); | 480 typeArgumentRefs.map(resynthesizer.buildType).toList(); |
| 479 InterfaceType classType = | 481 InterfaceType classType = classInfo.buildType((i) { |
| 480 classInfo.buildType((i) => typeArguments[i], const <int>[]); | 482 if (i < typeArguments.length) { |
| 483 return typeArguments[i]; |
| 484 } else { |
| 485 return DynamicTypeImpl.instance; |
| 486 } |
| 487 }, const <int>[]); |
| 481 String name = isClass ? '' : info.name; | 488 String name = isClass ? '' : info.name; |
| 482 return new _DeferredConstructorElement(classType, name); | 489 return new _DeferredConstructorElement(classType, name); |
| 483 } | 490 } |
| 484 | 491 |
| 485 InterpolationElement _newInterpolationElement(Expression expr) { | 492 InterpolationElement _newInterpolationElement(Expression expr) { |
| 486 if (expr is SimpleStringLiteral) { | 493 if (expr is SimpleStringLiteral) { |
| 487 return new InterpolationString(expr.literal, expr.value); | 494 return new InterpolationString(expr.literal, expr.value); |
| 488 } else { | 495 } else { |
| 489 return new InterpolationExpression( | 496 return new InterpolationExpression( |
| 490 TokenFactory.tokenFromType(TokenType.STRING_INTERPOLATION_EXPRESSION), | 497 TokenFactory.tokenFromType(TokenType.STRING_INTERPOLATION_EXPRESSION), |
| (...skipping 1526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2017 } | 2024 } |
| 2018 : () => this.element; | 2025 : () => this.element; |
| 2019 // TODO(paulberry): Is it a bug that we have to pass `false` for | 2026 // TODO(paulberry): Is it a bug that we have to pass `false` for |
| 2020 // isInstantiated? | 2027 // isInstantiated? |
| 2021 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); | 2028 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); |
| 2022 } else { | 2029 } else { |
| 2023 return null; | 2030 return null; |
| 2024 } | 2031 } |
| 2025 } | 2032 } |
| 2026 } | 2033 } |
| OLD | NEW |