| 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/ast/standard_ast_factory.dart'; | 10 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 break; | 470 break; |
| 471 // invokeMethodRef | 471 // invokeMethodRef |
| 472 case UnlinkedExprOperation.invokeMethodRef: | 472 case UnlinkedExprOperation.invokeMethodRef: |
| 473 _pushInvokeMethodRef(); | 473 _pushInvokeMethodRef(); |
| 474 break; | 474 break; |
| 475 // containers | 475 // containers |
| 476 case UnlinkedExprOperation.makeUntypedList: | 476 case UnlinkedExprOperation.makeUntypedList: |
| 477 _pushList(null); | 477 _pushList(null); |
| 478 break; | 478 break; |
| 479 case UnlinkedExprOperation.makeTypedList: | 479 case UnlinkedExprOperation.makeTypedList: |
| 480 TypeName itemType = _newTypeName(); | 480 TypeAnnotation itemType = _newTypeName(); |
| 481 _pushList(AstTestFactory.typeArgumentList(<TypeName>[itemType])); | 481 _pushList( |
| 482 AstTestFactory.typeArgumentList(<TypeAnnotation>[itemType])); |
| 482 break; | 483 break; |
| 483 case UnlinkedExprOperation.makeUntypedMap: | 484 case UnlinkedExprOperation.makeUntypedMap: |
| 484 _pushMap(null); | 485 _pushMap(null); |
| 485 break; | 486 break; |
| 486 case UnlinkedExprOperation.makeTypedMap: | 487 case UnlinkedExprOperation.makeTypedMap: |
| 487 TypeName keyType = _newTypeName(); | 488 TypeAnnotation keyType = _newTypeName(); |
| 488 TypeName valueType = _newTypeName(); | 489 TypeAnnotation valueType = _newTypeName(); |
| 489 _pushMap( | 490 _pushMap(AstTestFactory |
| 490 AstTestFactory.typeArgumentList(<TypeName>[keyType, valueType])); | 491 .typeArgumentList(<TypeAnnotation>[keyType, valueType])); |
| 491 break; | 492 break; |
| 492 case UnlinkedExprOperation.pushReference: | 493 case UnlinkedExprOperation.pushReference: |
| 493 _pushReference(); | 494 _pushReference(); |
| 494 break; | 495 break; |
| 495 case UnlinkedExprOperation.extractProperty: | 496 case UnlinkedExprOperation.extractProperty: |
| 496 _pushExtractProperty(); | 497 _pushExtractProperty(); |
| 497 break; | 498 break; |
| 498 case UnlinkedExprOperation.invokeConstructor: | 499 case UnlinkedExprOperation.invokeConstructor: |
| 499 _pushInstanceCreation(); | 500 _pushInstanceCreation(); |
| 500 break; | 501 break; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 if (enclosing is SimpleIdentifier) { | 573 if (enclosing is SimpleIdentifier) { |
| 573 SimpleIdentifier identifier = AstTestFactory.identifier3(info.name) | 574 SimpleIdentifier identifier = AstTestFactory.identifier3(info.name) |
| 574 ..staticElement = element; | 575 ..staticElement = element; |
| 575 return AstTestFactory.identifier(enclosing, identifier); | 576 return AstTestFactory.identifier(enclosing, identifier); |
| 576 } | 577 } |
| 577 SimpleIdentifier property = AstTestFactory.identifier3(info.name) | 578 SimpleIdentifier property = AstTestFactory.identifier3(info.name) |
| 578 ..staticElement = element; | 579 ..staticElement = element; |
| 579 return AstTestFactory.propertyAccess(enclosing, property); | 580 return AstTestFactory.propertyAccess(enclosing, property); |
| 580 } | 581 } |
| 581 | 582 |
| 582 TypeName _buildTypeAst(DartType type) { | 583 TypeAnnotation _buildTypeAst(DartType type) { |
| 583 List<TypeName> argumentNodes; | 584 List<TypeAnnotation> argumentNodes; |
| 584 if (type is ParameterizedType) { | 585 if (type is ParameterizedType) { |
| 585 if (!resynthesizer.libraryResynthesizer.typesWithImplicitTypeArguments | 586 if (!resynthesizer.libraryResynthesizer.typesWithImplicitTypeArguments |
| 586 .contains(type)) { | 587 .contains(type)) { |
| 587 List<DartType> typeArguments = type.typeArguments; | 588 List<DartType> typeArguments = type.typeArguments; |
| 588 argumentNodes = typeArguments.every((a) => a.isDynamic) | 589 argumentNodes = typeArguments.every((a) => a.isDynamic) |
| 589 ? null | 590 ? null |
| 590 : typeArguments.map(_buildTypeAst).toList(); | 591 : typeArguments.map(_buildTypeAst).toList(); |
| 591 } | 592 } |
| 592 } | 593 } |
| 593 TypeName node = AstTestFactory.typeName4(type.name, argumentNodes); | 594 TypeName node = AstTestFactory.typeName4(type.name, argumentNodes); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 607 TokenFactory.tokenFromType(TokenType.STRING_INTERPOLATION_EXPRESSION), | 608 TokenFactory.tokenFromType(TokenType.STRING_INTERPOLATION_EXPRESSION), |
| 608 expr, | 609 expr, |
| 609 TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET)); | 610 TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET)); |
| 610 } | 611 } |
| 611 } | 612 } |
| 612 | 613 |
| 613 /** | 614 /** |
| 614 * Convert the next reference to the [DartType] and return the AST | 615 * Convert the next reference to the [DartType] and return the AST |
| 615 * corresponding to this type. | 616 * corresponding to this type. |
| 616 */ | 617 */ |
| 617 TypeName _newTypeName() { | 618 TypeAnnotation _newTypeName() { |
| 618 EntityRef typeRef = uc.references[refPtr++]; | 619 EntityRef typeRef = uc.references[refPtr++]; |
| 619 DartType type = | 620 DartType type = |
| 620 resynthesizer.buildType(typeRef, context?.typeParameterContext); | 621 resynthesizer.buildType(typeRef, context?.typeParameterContext); |
| 621 return _buildTypeAst(type); | 622 return _buildTypeAst(type); |
| 622 } | 623 } |
| 623 | 624 |
| 624 Expression _pop() => stack.removeLast(); | 625 Expression _pop() => stack.removeLast(); |
| 625 | 626 |
| 626 void _push(Expression expr) { | 627 void _push(Expression expr) { |
| 627 stack.add(expr); | 628 stack.add(expr); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 } | 718 } |
| 718 | 719 |
| 719 void _pushInvokeMethodRef() { | 720 void _pushInvokeMethodRef() { |
| 720 List<Expression> arguments = _buildArguments(); | 721 List<Expression> arguments = _buildArguments(); |
| 721 EntityRef ref = uc.references[refPtr++]; | 722 EntityRef ref = uc.references[refPtr++]; |
| 722 _ReferenceInfo info = resynthesizer.getReferenceInfo(ref.reference); | 723 _ReferenceInfo info = resynthesizer.getReferenceInfo(ref.reference); |
| 723 Expression node = _buildIdentifierSequence(info); | 724 Expression node = _buildIdentifierSequence(info); |
| 724 TypeArgumentList typeArguments; | 725 TypeArgumentList typeArguments; |
| 725 int numTypeArguments = uc.ints[intPtr++]; | 726 int numTypeArguments = uc.ints[intPtr++]; |
| 726 if (numTypeArguments > 0) { | 727 if (numTypeArguments > 0) { |
| 727 List<TypeName> typeNames = new List<TypeName>(numTypeArguments); | 728 List<TypeAnnotation> typeNames = |
| 729 new List<TypeAnnotation>(numTypeArguments); |
| 728 for (int i = 0; i < numTypeArguments; i++) { | 730 for (int i = 0; i < numTypeArguments; i++) { |
| 729 typeNames[i] = _newTypeName(); | 731 typeNames[i] = _newTypeName(); |
| 730 } | 732 } |
| 731 typeArguments = AstTestFactory.typeArgumentList(typeNames); | 733 typeArguments = AstTestFactory.typeArgumentList(typeNames); |
| 732 } | 734 } |
| 733 if (node is SimpleIdentifier) { | 735 if (node is SimpleIdentifier) { |
| 734 _push(astFactory.methodInvocation( | 736 _push(astFactory.methodInvocation( |
| 735 null, | 737 null, |
| 736 TokenFactory.tokenFromType(TokenType.PERIOD), | 738 TokenFactory.tokenFromType(TokenType.PERIOD), |
| 737 node, | 739 node, |
| (...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1912 static String _getElementIdentifier(String name, ReferenceKind kind) { | 1914 static String _getElementIdentifier(String name, ReferenceKind kind) { |
| 1913 if (kind == ReferenceKind.topLevelPropertyAccessor || | 1915 if (kind == ReferenceKind.topLevelPropertyAccessor || |
| 1914 kind == ReferenceKind.propertyAccessor) { | 1916 kind == ReferenceKind.propertyAccessor) { |
| 1915 if (!name.endsWith('=')) { | 1917 if (!name.endsWith('=')) { |
| 1916 return name + '?'; | 1918 return name + '?'; |
| 1917 } | 1919 } |
| 1918 } | 1920 } |
| 1919 return name; | 1921 return name; |
| 1920 } | 1922 } |
| 1921 } | 1923 } |
| OLD | NEW |