| 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 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/src/generated/element.dart'; | 8 import 'package:analyzer/src/generated/element.dart'; |
| 9 import 'package:analyzer/src/generated/element_handle.dart'; | 9 import 'package:analyzer/src/generated/element_handle.dart'; |
| 10 import 'package:analyzer/src/generated/engine.dart'; | 10 import 'package:analyzer/src/generated/engine.dart'; |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 * TODO(paulberry): extend this to do the right thing for generic methods. | 205 * TODO(paulberry): extend this to do the right thing for generic methods. |
| 206 */ | 206 */ |
| 207 List<TypeParameterElement> currentTypeParameters; | 207 List<TypeParameterElement> currentTypeParameters; |
| 208 | 208 |
| 209 _LibraryResynthesizer(this.summaryResynthesizer, this.prelinkedLibrary, | 209 _LibraryResynthesizer(this.summaryResynthesizer, this.prelinkedLibrary, |
| 210 this.unlinkedUnits, this.librarySource) { | 210 this.unlinkedUnits, this.librarySource) { |
| 211 isCoreLibrary = librarySource.uri.toString() == 'dart:core'; | 211 isCoreLibrary = librarySource.uri.toString() == 'dart:core'; |
| 212 } | 212 } |
| 213 | 213 |
| 214 /** | 214 /** |
| 215 * Return a list of type arguments corresponding to [currentTypeParameters]. |
| 216 */ |
| 217 List<TypeParameterType> get currentTypeArguments => currentTypeParameters |
| 218 ?.map((TypeParameterElement param) => param.type) |
| 219 ?.toList(); |
| 220 |
| 221 /** |
| 215 * Resynthesize a [ClassElement] and place it in [unitHolder]. | 222 * Resynthesize a [ClassElement] and place it in [unitHolder]. |
| 216 */ | 223 */ |
| 217 void buildClass(UnlinkedClass serializedClass) { | 224 void buildClass(UnlinkedClass serializedClass) { |
| 218 try { | 225 try { |
| 219 currentTypeParameters = | 226 currentTypeParameters = |
| 220 serializedClass.typeParameters.map(buildTypeParameter).toList(); | 227 serializedClass.typeParameters.map(buildTypeParameter).toList(); |
| 221 for (int i = 0; i < serializedClass.typeParameters.length; i++) { | 228 for (int i = 0; i < serializedClass.typeParameters.length; i++) { |
| 222 finishTypeParameter( | 229 finishTypeParameter( |
| 223 serializedClass.typeParameters[i], currentTypeParameters[i]); | 230 serializedClass.typeParameters[i], currentTypeParameters[i]); |
| 224 } | 231 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 buildVariable(serializedVariable, memberHolder); | 266 buildVariable(serializedVariable, memberHolder); |
| 260 } | 267 } |
| 261 if (!serializedClass.isMixinApplication) { | 268 if (!serializedClass.isMixinApplication) { |
| 262 if (!constructorFound) { | 269 if (!constructorFound) { |
| 263 // Synthesize implicit constructors. | 270 // Synthesize implicit constructors. |
| 264 ConstructorElementImpl constructor = | 271 ConstructorElementImpl constructor = |
| 265 new ConstructorElementImpl('', -1); | 272 new ConstructorElementImpl('', -1); |
| 266 constructor.synthetic = true; | 273 constructor.synthetic = true; |
| 267 constructor.returnType = correspondingType; | 274 constructor.returnType = correspondingType; |
| 268 constructor.type = new FunctionTypeImpl.elementWithNameAndArgs( | 275 constructor.type = new FunctionTypeImpl.elementWithNameAndArgs( |
| 269 constructor, | 276 constructor, null, currentTypeArguments); |
| 270 null, | |
| 271 currentTypeParameters | |
| 272 .map((TypeParameterElement e) => e.type) | |
| 273 .toList()); | |
| 274 memberHolder.addConstructor(constructor); | 277 memberHolder.addConstructor(constructor); |
| 275 } | 278 } |
| 276 classElement.constructors = memberHolder.constructors; | 279 classElement.constructors = memberHolder.constructors; |
| 277 } | 280 } |
| 278 classElement.accessors = memberHolder.accessors; | 281 classElement.accessors = memberHolder.accessors; |
| 279 classElement.fields = memberHolder.fields; | 282 classElement.fields = memberHolder.fields; |
| 280 classElement.methods = memberHolder.methods; | 283 classElement.methods = memberHolder.methods; |
| 281 correspondingType.typeArguments = | 284 correspondingType.typeArguments = currentTypeArguments; |
| 282 currentTypeParameters.map((param) => param.type).toList(); | |
| 283 classElement.type = correspondingType; | 285 classElement.type = correspondingType; |
| 284 unitHolder.addType(classElement); | 286 unitHolder.addType(classElement); |
| 285 } finally { | 287 } finally { |
| 286 currentTypeParameters = null; | 288 currentTypeParameters = null; |
| 287 } | 289 } |
| 288 } | 290 } |
| 289 | 291 |
| 290 /** | 292 /** |
| 291 * Resynthesize a [NamespaceCombinator]. | 293 * Resynthesize a [NamespaceCombinator]. |
| 292 */ | 294 */ |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 void buildExecutableCommonParts(ExecutableElementImpl executableElement, | 448 void buildExecutableCommonParts(ExecutableElementImpl executableElement, |
| 447 UnlinkedExecutable serializedExecutable) { | 449 UnlinkedExecutable serializedExecutable) { |
| 448 executableElement.parameters = | 450 executableElement.parameters = |
| 449 serializedExecutable.parameters.map(buildParameter).toList(); | 451 serializedExecutable.parameters.map(buildParameter).toList(); |
| 450 if (serializedExecutable.returnType != null) { | 452 if (serializedExecutable.returnType != null) { |
| 451 executableElement.returnType = buildType(serializedExecutable.returnType); | 453 executableElement.returnType = buildType(serializedExecutable.returnType); |
| 452 } else { | 454 } else { |
| 453 executableElement.returnType = VoidTypeImpl.instance; | 455 executableElement.returnType = VoidTypeImpl.instance; |
| 454 } | 456 } |
| 455 executableElement.type = new FunctionTypeImpl.elementWithNameAndArgs( | 457 executableElement.type = new FunctionTypeImpl.elementWithNameAndArgs( |
| 456 executableElement, | 458 executableElement, null, currentTypeArguments); |
| 457 null, | |
| 458 currentTypeParameters | |
| 459 ?.map((TypeParameterElement e) => e.type) | |
| 460 ?.toList()); | |
| 461 executableElement.hasImplicitReturnType = | 459 executableElement.hasImplicitReturnType = |
| 462 serializedExecutable.hasImplicitReturnType; | 460 serializedExecutable.hasImplicitReturnType; |
| 463 executableElement.external = serializedExecutable.isExternal; | 461 executableElement.external = serializedExecutable.isExternal; |
| 464 } | 462 } |
| 465 | 463 |
| 466 /** | 464 /** |
| 467 * Resynthesize an [ExportElement], | 465 * Resynthesize an [ExportElement], |
| 468 */ | 466 */ |
| 469 ExportElement buildExport(UnlinkedExport serializedExport) { | 467 ExportElement buildExport(UnlinkedExport serializedExport) { |
| 470 ExportElementImpl exportElement = new ExportElementImpl(0); | 468 ExportElementImpl exportElement = new ExportElementImpl(0); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 parameterTypeElement.synthetic = true; | 659 parameterTypeElement.synthetic = true; |
| 662 parameterElement.parameters = | 660 parameterElement.parameters = |
| 663 serializedParameter.parameters.map(buildParameter).toList(); | 661 serializedParameter.parameters.map(buildParameter).toList(); |
| 664 parameterTypeElement.enclosingElement = parameterElement; | 662 parameterTypeElement.enclosingElement = parameterElement; |
| 665 parameterTypeElement.shareParameters(parameterElement.parameters); | 663 parameterTypeElement.shareParameters(parameterElement.parameters); |
| 666 if (serializedParameter.type != null) { | 664 if (serializedParameter.type != null) { |
| 667 parameterTypeElement.returnType = buildType(serializedParameter.type); | 665 parameterTypeElement.returnType = buildType(serializedParameter.type); |
| 668 } else { | 666 } else { |
| 669 parameterTypeElement.returnType = VoidTypeImpl.instance; | 667 parameterTypeElement.returnType = VoidTypeImpl.instance; |
| 670 } | 668 } |
| 671 parameterElement.type = new FunctionTypeImpl(parameterTypeElement); | 669 parameterElement.type = new FunctionTypeImpl.elementWithNameAndArgs( |
| 670 parameterTypeElement, null, currentTypeArguments); |
| 672 } else { | 671 } else { |
| 673 parameterElement.type = buildType(serializedParameter.type); | 672 parameterElement.type = buildType(serializedParameter.type); |
| 674 parameterElement.hasImplicitType = serializedParameter.hasImplicitType; | 673 parameterElement.hasImplicitType = serializedParameter.hasImplicitType; |
| 675 } | 674 } |
| 676 switch (serializedParameter.kind) { | 675 switch (serializedParameter.kind) { |
| 677 case UnlinkedParamKind.named: | 676 case UnlinkedParamKind.named: |
| 678 parameterElement.parameterKind = ParameterKind.NAMED; | 677 parameterElement.parameterKind = ParameterKind.NAMED; |
| 679 break; | 678 break; |
| 680 case UnlinkedParamKind.positional: | 679 case UnlinkedParamKind.positional: |
| 681 parameterElement.parameterKind = ParameterKind.POSITIONAL; | 680 parameterElement.parameterKind = ParameterKind.POSITIONAL; |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 } | 916 } |
| 918 for (FunctionTypeAliasElement typeAlias in unit.functionTypeAliases) { | 917 for (FunctionTypeAliasElement typeAlias in unit.functionTypeAliases) { |
| 919 elementMap[typeAlias.name] = typeAlias; | 918 elementMap[typeAlias.name] = typeAlias; |
| 920 } | 919 } |
| 921 resummarizedElements[absoluteUri] = elementMap; | 920 resummarizedElements[absoluteUri] = elementMap; |
| 922 unitHolder = null; | 921 unitHolder = null; |
| 923 prelinkedUnit = null; | 922 prelinkedUnit = null; |
| 924 unlinkedUnit = null; | 923 unlinkedUnit = null; |
| 925 } | 924 } |
| 926 } | 925 } |
| OLD | NEW |