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 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 } | 1013 } |
1014 classElement.constructors = memberHolder.constructors; | 1014 classElement.constructors = memberHolder.constructors; |
1015 } | 1015 } |
1016 classElement.accessors = memberHolder.accessors; | 1016 classElement.accessors = memberHolder.accessors; |
1017 classElement.fields = memberHolder.fields; | 1017 classElement.fields = memberHolder.fields; |
1018 classElement.methods = memberHolder.methods; | 1018 classElement.methods = memberHolder.methods; |
1019 correspondingType.typeArguments = getCurrentTypeArguments(); | 1019 correspondingType.typeArguments = getCurrentTypeArguments(); |
1020 classElement.type = correspondingType; | 1020 classElement.type = correspondingType; |
1021 buildDocumentation(classElement, serializedClass.documentationComment); | 1021 buildDocumentation(classElement, serializedClass.documentationComment); |
1022 buildAnnotations(classElement, serializedClass.annotations); | 1022 buildAnnotations(classElement, serializedClass.annotations); |
| 1023 buildCodeRange(classElement, serializedClass.codeRange); |
1023 resolveConstructorInitializers(classElement); | 1024 resolveConstructorInitializers(classElement); |
1024 unitHolder.addType(classElement); | 1025 unitHolder.addType(classElement); |
1025 currentTypeParameters.removeLast(); | 1026 currentTypeParameters.removeLast(); |
1026 assert(currentTypeParameters.isEmpty); | 1027 assert(currentTypeParameters.isEmpty); |
1027 fields = null; | 1028 fields = null; |
1028 constructors = null; | 1029 constructors = null; |
1029 } | 1030 } |
1030 | 1031 |
| 1032 void buildCodeRange(ElementImpl element, CodeRange codeRange) { |
| 1033 if (codeRange != null) { |
| 1034 element.setCodeRange(codeRange.offset, codeRange.length); |
| 1035 } |
| 1036 } |
| 1037 |
1031 /** | 1038 /** |
1032 * Resynthesize a [NamespaceCombinator]. | 1039 * Resynthesize a [NamespaceCombinator]. |
1033 */ | 1040 */ |
1034 NamespaceCombinator buildCombinator(UnlinkedCombinator serializedCombinator) { | 1041 NamespaceCombinator buildCombinator(UnlinkedCombinator serializedCombinator) { |
1035 if (serializedCombinator.shows.isNotEmpty) { | 1042 if (serializedCombinator.shows.isNotEmpty) { |
1036 ShowElementCombinatorImpl combinator = new ShowElementCombinatorImpl(); | 1043 ShowElementCombinatorImpl combinator = new ShowElementCombinatorImpl(); |
1037 // Note: we call toList() so that we don't retain a reference to the | 1044 // Note: we call toList() so that we don't retain a reference to the |
1038 // deserialized data structure. | 1045 // deserialized data structure. |
1039 combinator.shownNames = serializedCombinator.shows.toList(); | 1046 combinator.shownNames = serializedCombinator.shows.toList(); |
1040 combinator.offset = serializedCombinator.offset; | 1047 combinator.offset = serializedCombinator.offset; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1144 void buildEnum(UnlinkedEnum serializedEnum) { | 1151 void buildEnum(UnlinkedEnum serializedEnum) { |
1145 assert(!isCoreLibrary); | 1152 assert(!isCoreLibrary); |
1146 ClassElementImpl classElement = | 1153 ClassElementImpl classElement = |
1147 new ClassElementImpl(serializedEnum.name, serializedEnum.nameOffset); | 1154 new ClassElementImpl(serializedEnum.name, serializedEnum.nameOffset); |
1148 classElement.enum2 = true; | 1155 classElement.enum2 = true; |
1149 InterfaceType enumType = new InterfaceTypeImpl(classElement); | 1156 InterfaceType enumType = new InterfaceTypeImpl(classElement); |
1150 classElement.type = enumType; | 1157 classElement.type = enumType; |
1151 classElement.supertype = summaryResynthesizer.typeProvider.objectType; | 1158 classElement.supertype = summaryResynthesizer.typeProvider.objectType; |
1152 buildDocumentation(classElement, serializedEnum.documentationComment); | 1159 buildDocumentation(classElement, serializedEnum.documentationComment); |
1153 buildAnnotations(classElement, serializedEnum.annotations); | 1160 buildAnnotations(classElement, serializedEnum.annotations); |
| 1161 buildCodeRange(classElement, serializedEnum.codeRange); |
1154 ElementHolder memberHolder = new ElementHolder(); | 1162 ElementHolder memberHolder = new ElementHolder(); |
1155 // Build the 'index' field. | 1163 // Build the 'index' field. |
1156 FieldElementImpl indexField = new FieldElementImpl('index', -1); | 1164 FieldElementImpl indexField = new FieldElementImpl('index', -1); |
1157 indexField.final2 = true; | 1165 indexField.final2 = true; |
1158 indexField.synthetic = true; | 1166 indexField.synthetic = true; |
1159 indexField.type = summaryResynthesizer.typeProvider.intType; | 1167 indexField.type = summaryResynthesizer.typeProvider.intType; |
1160 memberHolder.addField(indexField); | 1168 memberHolder.addField(indexField); |
1161 buildImplicitAccessors(indexField, memberHolder); | 1169 buildImplicitAccessors(indexField, memberHolder); |
1162 // Build the 'values' field. | 1170 // Build the 'values' field. |
1163 FieldElementImpl valuesField = new ConstFieldElementImpl('values', -1); | 1171 FieldElementImpl valuesField = new ConstFieldElementImpl('values', -1); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1299 defaultVoid: isSetter && summaryResynthesizer.strongMode); | 1307 defaultVoid: isSetter && summaryResynthesizer.strongMode); |
1300 executableElement.hasImplicitReturnType = | 1308 executableElement.hasImplicitReturnType = |
1301 serializedExecutable.returnType == null; | 1309 serializedExecutable.returnType == null; |
1302 } | 1310 } |
1303 executableElement.type = new FunctionTypeImpl.elementWithNameAndArgs( | 1311 executableElement.type = new FunctionTypeImpl.elementWithNameAndArgs( |
1304 executableElement, null, getCurrentTypeArguments(skipLevels: 1), false); | 1312 executableElement, null, getCurrentTypeArguments(skipLevels: 1), false); |
1305 executableElement.external = serializedExecutable.isExternal; | 1313 executableElement.external = serializedExecutable.isExternal; |
1306 buildDocumentation( | 1314 buildDocumentation( |
1307 executableElement, serializedExecutable.documentationComment); | 1315 executableElement, serializedExecutable.documentationComment); |
1308 buildAnnotations(executableElement, serializedExecutable.annotations); | 1316 buildAnnotations(executableElement, serializedExecutable.annotations); |
| 1317 buildCodeRange(executableElement, serializedExecutable.codeRange); |
1309 executableElement.functions = | 1318 executableElement.functions = |
1310 serializedExecutable.localFunctions.map(buildLocalFunction).toList(); | 1319 serializedExecutable.localFunctions.map(buildLocalFunction).toList(); |
1311 executableElement.labels = | 1320 executableElement.labels = |
1312 serializedExecutable.localLabels.map(buildLocalLabel).toList(); | 1321 serializedExecutable.localLabels.map(buildLocalLabel).toList(); |
1313 executableElement.localVariables = | 1322 executableElement.localVariables = |
1314 serializedExecutable.localVariables.map(buildLocalVariable).toList(); | 1323 serializedExecutable.localVariables.map(buildLocalVariable).toList(); |
1315 currentTypeParameters.removeLast(); | 1324 currentTypeParameters.removeLast(); |
1316 } | 1325 } |
1317 | 1326 |
1318 /** | 1327 /** |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1700 if (serializedParameter.defaultValue != null) { | 1709 if (serializedParameter.defaultValue != null) { |
1701 defaultParameter.constantInitializer = | 1710 defaultParameter.constantInitializer = |
1702 _buildConstExpression(serializedParameter.defaultValue); | 1711 _buildConstExpression(serializedParameter.defaultValue); |
1703 defaultParameter.defaultValueCode = | 1712 defaultParameter.defaultValueCode = |
1704 serializedParameter.defaultValueCode; | 1713 serializedParameter.defaultValueCode; |
1705 } | 1714 } |
1706 } | 1715 } |
1707 } | 1716 } |
1708 parameterElement.synthetic = synthetic; | 1717 parameterElement.synthetic = synthetic; |
1709 buildAnnotations(parameterElement, serializedParameter.annotations); | 1718 buildAnnotations(parameterElement, serializedParameter.annotations); |
| 1719 buildCodeRange(parameterElement, serializedParameter.codeRange); |
1710 if (serializedParameter.isFunctionTyped) { | 1720 if (serializedParameter.isFunctionTyped) { |
1711 FunctionElementImpl parameterTypeElement = | 1721 FunctionElementImpl parameterTypeElement = |
1712 new FunctionElementImpl('', -1); | 1722 new FunctionElementImpl('', -1); |
1713 parameterTypeElement.synthetic = true; | 1723 parameterTypeElement.synthetic = true; |
1714 parameterElement.parameters = | 1724 parameterElement.parameters = |
1715 serializedParameter.parameters.map(buildParameter).toList(); | 1725 serializedParameter.parameters.map(buildParameter).toList(); |
1716 parameterTypeElement.enclosingElement = parameterElement; | 1726 parameterTypeElement.enclosingElement = parameterElement; |
1717 parameterTypeElement.shareParameters(parameterElement.parameters); | 1727 parameterTypeElement.shareParameters(parameterElement.parameters); |
1718 parameterTypeElement.returnType = buildType(serializedParameter.type); | 1728 parameterTypeElement.returnType = buildType(serializedParameter.type); |
1719 parameterElement.type = new FunctionTypeImpl.elementWithNameAndArgs( | 1729 parameterElement.type = new FunctionTypeImpl.elementWithNameAndArgs( |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1833 buildTypeParameters(serializedTypedef.typeParameters); | 1843 buildTypeParameters(serializedTypedef.typeParameters); |
1834 functionTypeAliasElement.parameters = | 1844 functionTypeAliasElement.parameters = |
1835 serializedTypedef.parameters.map(buildParameter).toList(); | 1845 serializedTypedef.parameters.map(buildParameter).toList(); |
1836 functionTypeAliasElement.returnType = | 1846 functionTypeAliasElement.returnType = |
1837 buildType(serializedTypedef.returnType); | 1847 buildType(serializedTypedef.returnType); |
1838 functionTypeAliasElement.type = | 1848 functionTypeAliasElement.type = |
1839 new FunctionTypeImpl.forTypedef(functionTypeAliasElement); | 1849 new FunctionTypeImpl.forTypedef(functionTypeAliasElement); |
1840 buildDocumentation( | 1850 buildDocumentation( |
1841 functionTypeAliasElement, serializedTypedef.documentationComment); | 1851 functionTypeAliasElement, serializedTypedef.documentationComment); |
1842 buildAnnotations(functionTypeAliasElement, serializedTypedef.annotations); | 1852 buildAnnotations(functionTypeAliasElement, serializedTypedef.annotations); |
| 1853 buildCodeRange(functionTypeAliasElement, serializedTypedef.codeRange); |
1843 unitHolder.addTypeAlias(functionTypeAliasElement); | 1854 unitHolder.addTypeAlias(functionTypeAliasElement); |
1844 currentTypeParameters.removeLast(); | 1855 currentTypeParameters.removeLast(); |
1845 assert(currentTypeParameters.isEmpty); | 1856 assert(currentTypeParameters.isEmpty); |
1846 } | 1857 } |
1847 | 1858 |
1848 /** | 1859 /** |
1849 * Resynthesize a [TypeParameterElement], handling all parts of its except | 1860 * Resynthesize a [TypeParameterElement], handling all parts of its except |
1850 * its bound. | 1861 * its bound. |
1851 * | 1862 * |
1852 * The bound is deferred until later since it may refer to other type | 1863 * The bound is deferred until later since it may refer to other type |
1853 * parameters that have not been resynthesized yet. To handle the bound, | 1864 * parameters that have not been resynthesized yet. To handle the bound, |
1854 * call [finishTypeParameter]. | 1865 * call [finishTypeParameter]. |
1855 */ | 1866 */ |
1856 TypeParameterElement buildTypeParameter( | 1867 TypeParameterElement buildTypeParameter( |
1857 UnlinkedTypeParam serializedTypeParameter) { | 1868 UnlinkedTypeParam serializedTypeParameter) { |
1858 TypeParameterElementImpl typeParameterElement = | 1869 TypeParameterElementImpl typeParameterElement = |
1859 new TypeParameterElementImpl( | 1870 new TypeParameterElementImpl( |
1860 serializedTypeParameter.name, serializedTypeParameter.nameOffset); | 1871 serializedTypeParameter.name, serializedTypeParameter.nameOffset); |
1861 typeParameterElement.type = new TypeParameterTypeImpl(typeParameterElement); | 1872 typeParameterElement.type = new TypeParameterTypeImpl(typeParameterElement); |
1862 buildAnnotations(typeParameterElement, serializedTypeParameter.annotations); | 1873 buildAnnotations(typeParameterElement, serializedTypeParameter.annotations); |
| 1874 buildCodeRange(typeParameterElement, serializedTypeParameter.codeRange); |
1863 return typeParameterElement; | 1875 return typeParameterElement; |
1864 } | 1876 } |
1865 | 1877 |
1866 /** | 1878 /** |
1867 * Build [TypeParameterElement]s corresponding to the type parameters in | 1879 * Build [TypeParameterElement]s corresponding to the type parameters in |
1868 * [serializedTypeParameters] and store them in [currentTypeParameters]. | 1880 * [serializedTypeParameters] and store them in [currentTypeParameters]. |
1869 * Also return them. | 1881 * Also return them. |
1870 */ | 1882 */ |
1871 List<TypeParameterElement> buildTypeParameters( | 1883 List<TypeParameterElement> buildTypeParameters( |
1872 List<UnlinkedTypeParam> serializedTypeParameters) { | 1884 List<UnlinkedTypeParam> serializedTypeParameters) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1926 void buildVariableCommonParts( | 1938 void buildVariableCommonParts( |
1927 VariableElementImpl element, UnlinkedVariable serializedVariable) { | 1939 VariableElementImpl element, UnlinkedVariable serializedVariable) { |
1928 element.type = buildLinkedType(serializedVariable.inferredTypeSlot) ?? | 1940 element.type = buildLinkedType(serializedVariable.inferredTypeSlot) ?? |
1929 buildType(serializedVariable.type); | 1941 buildType(serializedVariable.type); |
1930 element.const3 = serializedVariable.isConst; | 1942 element.const3 = serializedVariable.isConst; |
1931 element.final2 = serializedVariable.isFinal; | 1943 element.final2 = serializedVariable.isFinal; |
1932 element.hasImplicitType = serializedVariable.type == null; | 1944 element.hasImplicitType = serializedVariable.type == null; |
1933 buildVariableInitializer(element, serializedVariable.initializer); | 1945 buildVariableInitializer(element, serializedVariable.initializer); |
1934 buildDocumentation(element, serializedVariable.documentationComment); | 1946 buildDocumentation(element, serializedVariable.documentationComment); |
1935 buildAnnotations(element, serializedVariable.annotations); | 1947 buildAnnotations(element, serializedVariable.annotations); |
| 1948 buildCodeRange(element, serializedVariable.codeRange); |
1936 } | 1949 } |
1937 | 1950 |
1938 /** | 1951 /** |
1939 * If the given [serializedInitializer] is not `null`, create the | 1952 * If the given [serializedInitializer] is not `null`, create the |
1940 * corresponding [FunctionElementImpl] and set it for the [variable]. | 1953 * corresponding [FunctionElementImpl] and set it for the [variable]. |
1941 */ | 1954 */ |
1942 void buildVariableInitializer( | 1955 void buildVariableInitializer( |
1943 VariableElementImpl variable, UnlinkedExecutable serializedInitializer) { | 1956 VariableElementImpl variable, UnlinkedExecutable serializedInitializer) { |
1944 if (serializedInitializer == null) { | 1957 if (serializedInitializer == null) { |
1945 return null; | 1958 return null; |
1946 } | 1959 } |
1947 FunctionElementImpl initializerElement = | 1960 FunctionElementImpl initializerElement = |
1948 buildLocalFunction(serializedInitializer); | 1961 buildLocalFunction(serializedInitializer); |
1949 initializerElement.synthetic = true; | 1962 initializerElement.synthetic = true; |
| 1963 initializerElement.setCodeRange(null, null); |
1950 variable.initializer = initializerElement; | 1964 variable.initializer = initializerElement; |
1951 } | 1965 } |
1952 | 1966 |
1953 /** | 1967 /** |
1954 * Finish creating a [TypeParameterElement] by deserializing its bound. | 1968 * Finish creating a [TypeParameterElement] by deserializing its bound. |
1955 */ | 1969 */ |
1956 void finishTypeParameter(UnlinkedTypeParam serializedTypeParameter, | 1970 void finishTypeParameter(UnlinkedTypeParam serializedTypeParameter, |
1957 TypeParameterElementImpl typeParameterElement) { | 1971 TypeParameterElementImpl typeParameterElement) { |
1958 if (serializedTypeParameter.bound != null) { | 1972 if (serializedTypeParameter.bound != null) { |
1959 typeParameterElement.bound = buildType(serializedTypeParameter.bound); | 1973 typeParameterElement.bound = buildType(serializedTypeParameter.bound); |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2197 } | 2211 } |
2198 for (FunctionTypeAliasElement typeAlias in unit.functionTypeAliases) { | 2212 for (FunctionTypeAliasElement typeAlias in unit.functionTypeAliases) { |
2199 elementMap[typeAlias.name] = typeAlias; | 2213 elementMap[typeAlias.name] = typeAlias; |
2200 } | 2214 } |
2201 for (FunctionElement function in unit.functions) { | 2215 for (FunctionElement function in unit.functions) { |
2202 elementMap[function.name] = function; | 2216 elementMap[function.name] = function; |
2203 } | 2217 } |
2204 for (PropertyAccessorElementImpl accessor in unit.accessors) { | 2218 for (PropertyAccessorElementImpl accessor in unit.accessors) { |
2205 elementMap[accessor.identifier] = accessor; | 2219 elementMap[accessor.identifier] = accessor; |
2206 } | 2220 } |
| 2221 buildCodeRange(unit, unlinkedUnit.codeRange); |
2207 resynthesizedUnits[absoluteUri] = unit; | 2222 resynthesizedUnits[absoluteUri] = unit; |
2208 resynthesizedElements[absoluteUri] = elementMap; | 2223 resynthesizedElements[absoluteUri] = elementMap; |
2209 assert(currentTypeParameters.isEmpty); | 2224 assert(currentTypeParameters.isEmpty); |
2210 } | 2225 } |
2211 | 2226 |
2212 /** | 2227 /** |
2213 * Set up data structures for deserializing a compilation unit. | 2228 * Set up data structures for deserializing a compilation unit. |
2214 */ | 2229 */ |
2215 void prepareUnit(CompilationUnitElementImpl unit, int unitNum) { | 2230 void prepareUnit(CompilationUnitElementImpl unit, int unitNum) { |
2216 linkedUnit = linkedLibrary.units[unitNum]; | 2231 linkedUnit = linkedLibrary.units[unitNum]; |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2457 List<DartType> typeArguments = const <DartType>[]; | 2472 List<DartType> typeArguments = const <DartType>[]; |
2458 if (numTypeArguments != 0) { | 2473 if (numTypeArguments != 0) { |
2459 typeArguments = <DartType>[]; | 2474 typeArguments = <DartType>[]; |
2460 for (int i = 0; i < numTypeArguments; i++) { | 2475 for (int i = 0; i < numTypeArguments; i++) { |
2461 typeArguments.add(getTypeArgument(i)); | 2476 typeArguments.add(getTypeArgument(i)); |
2462 } | 2477 } |
2463 } | 2478 } |
2464 return typeArguments; | 2479 return typeArguments; |
2465 } | 2480 } |
2466 } | 2481 } |
OLD | NEW |