| 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/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| (...skipping 1659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1670 elementAnnotation.annotationAst = AstFactory.annotation2( | 1670 elementAnnotation.annotationAst = AstFactory.annotation2( |
| 1671 typeName, constructorName, constExpr.argumentList); | 1671 typeName, constructorName, constExpr.argumentList); |
| 1672 } else { | 1672 } else { |
| 1673 throw new StateError( | 1673 throw new StateError( |
| 1674 'Unexpected annotation type: ${constExpr.runtimeType}'); | 1674 'Unexpected annotation type: ${constExpr.runtimeType}'); |
| 1675 } | 1675 } |
| 1676 return elementAnnotation; | 1676 return elementAnnotation; |
| 1677 } | 1677 } |
| 1678 | 1678 |
| 1679 /** | 1679 /** |
| 1680 * Build the annotations for the given [element]. | |
| 1681 */ | |
| 1682 void buildAnnotations( | |
| 1683 ElementImpl element, List<UnlinkedConst> serializedAnnotations) { | |
| 1684 if (serializedAnnotations.isNotEmpty) { | |
| 1685 element.metadata = serializedAnnotations | |
| 1686 .map((a) => buildAnnotation(element, a)) | |
| 1687 .toList(); | |
| 1688 } | |
| 1689 } | |
| 1690 | |
| 1691 /** | |
| 1692 * Resynthesize a [ClassElement] and place it in [unitHolder]. | 1680 * Resynthesize a [ClassElement] and place it in [unitHolder]. |
| 1693 */ | 1681 */ |
| 1694 void buildClass(UnlinkedClass serializedClass) { | 1682 void buildClass(UnlinkedClass serializedClass) { |
| 1695 ClassElement classElement; | 1683 ClassElement classElement; |
| 1696 if (libraryResynthesizer.isCoreLibrary && | 1684 if (libraryResynthesizer.isCoreLibrary && |
| 1697 serializedClass.supertype == null) { | 1685 serializedClass.supertype == null) { |
| 1698 classElement = buildClassImpl(serializedClass, null); | 1686 classElement = buildClassImpl(serializedClass, null); |
| 1699 if (!serializedClass.hasNoSupertype) { | 1687 if (!serializedClass.hasNoSupertype) { |
| 1700 libraryResynthesizer.delayedObjectSubclasses.add(classElement); | 1688 libraryResynthesizer.delayedObjectSubclasses.add(classElement); |
| 1701 } | 1689 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1750 } | 1738 } |
| 1751 | 1739 |
| 1752 /** | 1740 /** |
| 1753 * Resynthesize a [ClassElementImpl]. If [handle] is not `null`, then | 1741 * Resynthesize a [ClassElementImpl]. If [handle] is not `null`, then |
| 1754 * executables are not resynthesized, and [InterfaceTypeImpl] is created | 1742 * executables are not resynthesized, and [InterfaceTypeImpl] is created |
| 1755 * around the [handle], so that executables are resynthesized lazily. | 1743 * around the [handle], so that executables are resynthesized lazily. |
| 1756 */ | 1744 */ |
| 1757 ClassElementImpl buildClassImpl( | 1745 ClassElementImpl buildClassImpl( |
| 1758 UnlinkedClass serializedClass, ClassElementHandle handle) { | 1746 UnlinkedClass serializedClass, ClassElementHandle handle) { |
| 1759 ClassElementImpl classElement = | 1747 ClassElementImpl classElement = |
| 1760 new ClassElementImpl.forSerialized(serializedClass, unit); | 1748 new ClassElementImpl.forSerialized(serializedClass, null, unit); |
| 1761 classElement.hasBeenInferred = summaryResynthesizer.strongMode; | 1749 classElement.hasBeenInferred = summaryResynthesizer.strongMode; |
| 1762 InterfaceTypeImpl correspondingType = | 1750 InterfaceTypeImpl correspondingType = |
| 1763 new InterfaceTypeImpl(handle ?? classElement); | 1751 new InterfaceTypeImpl(handle ?? classElement); |
| 1764 if (serializedClass.supertype != null) { | 1752 if (serializedClass.supertype != null) { |
| 1765 classElement.supertype = | 1753 classElement.supertype = |
| 1766 buildType(serializedClass.supertype, classElement); | 1754 buildType(serializedClass.supertype, classElement); |
| 1767 } else if (!libraryResynthesizer.isCoreLibrary) { | 1755 } else if (!libraryResynthesizer.isCoreLibrary) { |
| 1768 classElement.supertype = typeProvider.objectType; | 1756 classElement.supertype = typeProvider.objectType; |
| 1769 } | 1757 } |
| 1770 // TODO(scheglov) move to ClassElementImpl | 1758 // TODO(scheglov) move to ClassElementImpl |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1884 } | 1872 } |
| 1885 } | 1873 } |
| 1886 | 1874 |
| 1887 /** | 1875 /** |
| 1888 * Resynthesize the [ClassElement] corresponding to an enum, along with the | 1876 * Resynthesize the [ClassElement] corresponding to an enum, along with the |
| 1889 * associated fields and implicit accessors. | 1877 * associated fields and implicit accessors. |
| 1890 */ | 1878 */ |
| 1891 void buildEnum(UnlinkedEnum serializedEnum) { | 1879 void buildEnum(UnlinkedEnum serializedEnum) { |
| 1892 assert(!libraryResynthesizer.isCoreLibrary); | 1880 assert(!libraryResynthesizer.isCoreLibrary); |
| 1893 ClassElementImpl classElement = | 1881 ClassElementImpl classElement = |
| 1894 new ClassElementImpl(serializedEnum.name, serializedEnum.nameOffset); | 1882 new ClassElementImpl.forSerialized(null, serializedEnum, unit); |
| 1895 classElement.enum2 = true; | |
| 1896 InterfaceType enumType = new InterfaceTypeImpl(classElement); | 1883 InterfaceType enumType = new InterfaceTypeImpl(classElement); |
| 1897 classElement.type = enumType; | 1884 classElement.type = enumType; |
| 1898 classElement.supertype = typeProvider.objectType; | 1885 classElement.supertype = typeProvider.objectType; |
| 1899 buildDocumentation(classElement, serializedEnum.documentationComment); | |
| 1900 buildAnnotations(classElement, serializedEnum.annotations); | |
| 1901 buildCodeRange(classElement, serializedEnum.codeRange); | |
| 1902 ElementHolder memberHolder = new ElementHolder(); | 1886 ElementHolder memberHolder = new ElementHolder(); |
| 1903 // Build the 'index' field. | 1887 // Build the 'index' field. |
| 1904 FieldElementImpl indexField = new FieldElementImpl('index', -1); | 1888 FieldElementImpl indexField = new FieldElementImpl('index', -1); |
| 1905 indexField.final2 = true; | 1889 indexField.final2 = true; |
| 1906 indexField.synthetic = true; | 1890 indexField.synthetic = true; |
| 1907 indexField.type = typeProvider.intType; | 1891 indexField.type = typeProvider.intType; |
| 1908 memberHolder.addField(indexField); | 1892 memberHolder.addField(indexField); |
| 1909 buildImplicitAccessors(indexField, memberHolder); | 1893 buildImplicitAccessors(indexField, memberHolder); |
| 1910 // Build the 'values' field. | 1894 // Build the 'values' field. |
| 1911 FieldElementImpl valuesField = new ConstFieldElementImpl('values', -1); | 1895 FieldElementImpl valuesField = new ConstFieldElementImpl('values', -1); |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2434 static String _getElementIdentifier(String name, ReferenceKind kind) { | 2418 static String _getElementIdentifier(String name, ReferenceKind kind) { |
| 2435 if (kind == ReferenceKind.topLevelPropertyAccessor || | 2419 if (kind == ReferenceKind.topLevelPropertyAccessor || |
| 2436 kind == ReferenceKind.propertyAccessor) { | 2420 kind == ReferenceKind.propertyAccessor) { |
| 2437 if (!name.endsWith('=')) { | 2421 if (!name.endsWith('=')) { |
| 2438 return name + '?'; | 2422 return name + '?'; |
| 2439 } | 2423 } |
| 2440 } | 2424 } |
| 2441 return name; | 2425 return name; |
| 2442 } | 2426 } |
| 2443 } | 2427 } |
| OLD | NEW |