| 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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 return true; | 301 return true; |
| 302 } | 302 } |
| 303 return hasLibrarySummary(uri); | 303 return hasLibrarySummary(uri); |
| 304 } | 304 } |
| 305 } | 305 } |
| 306 | 306 |
| 307 /** | 307 /** |
| 308 * Builder of [Expression]s from [UnlinkedExpr]s. | 308 * Builder of [Expression]s from [UnlinkedExpr]s. |
| 309 */ | 309 */ |
| 310 class _ConstExprBuilder { | 310 class _ConstExprBuilder { |
| 311 static const ARGUMENT_LIST = 'ARGUMENT_LIST'; |
| 312 |
| 311 final _UnitResynthesizer resynthesizer; | 313 final _UnitResynthesizer resynthesizer; |
| 312 final ElementImpl context; | 314 final ElementImpl context; |
| 313 final UnlinkedExpr uc; | 315 final UnlinkedExpr uc; |
| 314 | 316 |
| 315 int intPtr = 0; | 317 int intPtr = 0; |
| 316 int doublePtr = 0; | 318 int doublePtr = 0; |
| 317 int stringPtr = 0; | 319 int stringPtr = 0; |
| 318 int refPtr = 0; | 320 int refPtr = 0; |
| 319 final List<Expression> stack = <Expression>[]; | 321 final List<Expression> stack = <Expression>[]; |
| 320 | 322 |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 // prepare ConstructorElement | 646 // prepare ConstructorElement |
| 645 TypeName typeNode; | 647 TypeName typeNode; |
| 646 String constructorName; | 648 String constructorName; |
| 647 ConstructorElement constructorElement; | 649 ConstructorElement constructorElement; |
| 648 if (info.element != null) { | 650 if (info.element != null) { |
| 649 if (info.element is ConstructorElement) { | 651 if (info.element is ConstructorElement) { |
| 650 constructorName = info.name; | 652 constructorName = info.name; |
| 651 } else if (info.element is ClassElement) { | 653 } else if (info.element is ClassElement) { |
| 652 constructorName = null; | 654 constructorName = null; |
| 653 } else { | 655 } else { |
| 654 throw new StateError('Unsupported element for invokeConstructor ' | 656 List<Expression> arguments = _buildArguments(); |
| 655 '${info.element?.runtimeType}'); | 657 SimpleIdentifier name = AstTestFactory.identifier3(info.name); |
| 658 name.staticElement = info.element; |
| 659 name.setProperty(ARGUMENT_LIST, AstTestFactory.argumentList(arguments)); |
| 660 _push(name); |
| 661 return; |
| 656 } | 662 } |
| 657 InterfaceType definingType = resynthesizer._createConstructorDefiningType( | 663 InterfaceType definingType = resynthesizer._createConstructorDefiningType( |
| 658 context?.typeParameterContext, info, ref.typeArguments); | 664 context?.typeParameterContext, info, ref.typeArguments); |
| 659 constructorElement = | 665 constructorElement = |
| 660 resynthesizer._getConstructorForInfo(definingType, info); | 666 resynthesizer._getConstructorForInfo(definingType, info); |
| 661 typeNode = _buildTypeAst(definingType); | 667 typeNode = _buildTypeAst(definingType); |
| 662 } else { | 668 } else { |
| 663 if (info.enclosing != null) { | 669 if (info.enclosing != null) { |
| 664 if (info.enclosing.enclosing != null) { | 670 if (info.enclosing.enclosing != null) { |
| 665 PrefixedIdentifier typeName = AstTestFactory.identifier5( | 671 PrefixedIdentifier typeName = AstTestFactory.identifier5( |
| (...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1523 | 1529 |
| 1524 TypeProvider get typeProvider => summaryResynthesizer.typeProvider; | 1530 TypeProvider get typeProvider => summaryResynthesizer.typeProvider; |
| 1525 | 1531 |
| 1526 /** | 1532 /** |
| 1527 * Build [ElementAnnotationImpl] for the given [UnlinkedExpr]. | 1533 * Build [ElementAnnotationImpl] for the given [UnlinkedExpr]. |
| 1528 */ | 1534 */ |
| 1529 ElementAnnotationImpl buildAnnotation(ElementImpl context, UnlinkedExpr uc) { | 1535 ElementAnnotationImpl buildAnnotation(ElementImpl context, UnlinkedExpr uc) { |
| 1530 ElementAnnotationImpl elementAnnotation = new ElementAnnotationImpl(unit); | 1536 ElementAnnotationImpl elementAnnotation = new ElementAnnotationImpl(unit); |
| 1531 Expression constExpr = _buildConstExpression(context, uc); | 1537 Expression constExpr = _buildConstExpression(context, uc); |
| 1532 if (constExpr is Identifier) { | 1538 if (constExpr is Identifier) { |
| 1539 ArgumentList arguments = |
| 1540 constExpr.getProperty(_ConstExprBuilder.ARGUMENT_LIST); |
| 1533 elementAnnotation.element = constExpr.staticElement; | 1541 elementAnnotation.element = constExpr.staticElement; |
| 1534 elementAnnotation.annotationAst = AstTestFactory.annotation(constExpr); | 1542 elementAnnotation.annotationAst = |
| 1543 AstTestFactory.annotation2(constExpr, null, arguments); |
| 1535 } else if (constExpr is InstanceCreationExpression) { | 1544 } else if (constExpr is InstanceCreationExpression) { |
| 1536 elementAnnotation.element = constExpr.staticElement; | 1545 elementAnnotation.element = constExpr.staticElement; |
| 1537 Identifier typeName = constExpr.constructorName.type.name; | 1546 Identifier typeName = constExpr.constructorName.type.name; |
| 1538 SimpleIdentifier constructorName = constExpr.constructorName.name; | 1547 SimpleIdentifier constructorName = constExpr.constructorName.name; |
| 1539 if (typeName is SimpleIdentifier && constructorName != null) { | 1548 if (typeName is SimpleIdentifier && constructorName != null) { |
| 1540 // E.g. `@cls.ctor()`. Since `cls.ctor` would have been parsed as | 1549 // E.g. `@cls.ctor()`. Since `cls.ctor` would have been parsed as |
| 1541 // a PrefixedIdentifier, we need to resynthesize it as one. | 1550 // a PrefixedIdentifier, we need to resynthesize it as one. |
| 1542 typeName = AstTestFactory.identifier(typeName, constructorName); | 1551 typeName = AstTestFactory.identifier(typeName, constructorName); |
| 1543 constructorName = null; | 1552 constructorName = null; |
| 1544 } | 1553 } |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1894 static String _getElementIdentifier(String name, ReferenceKind kind) { | 1903 static String _getElementIdentifier(String name, ReferenceKind kind) { |
| 1895 if (kind == ReferenceKind.topLevelPropertyAccessor || | 1904 if (kind == ReferenceKind.topLevelPropertyAccessor || |
| 1896 kind == ReferenceKind.propertyAccessor) { | 1905 kind == ReferenceKind.propertyAccessor) { |
| 1897 if (!name.endsWith('=')) { | 1906 if (!name.endsWith('=')) { |
| 1898 return name + '?'; | 1907 return name + '?'; |
| 1899 } | 1908 } |
| 1900 } | 1909 } |
| 1901 return name; | 1910 return name; |
| 1902 } | 1911 } |
| 1903 } | 1912 } |
| OLD | NEW |