| 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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 * Resynthesize a [ClassElement] and place it in [unitHolder]. | 226 * Resynthesize a [ClassElement] and place it in [unitHolder]. |
| 227 */ | 227 */ |
| 228 void buildClass(UnlinkedClass serializedClass) { | 228 void buildClass(UnlinkedClass serializedClass) { |
| 229 try { | 229 try { |
| 230 currentTypeParameters = | 230 currentTypeParameters = |
| 231 serializedClass.typeParameters.map(buildTypeParameter).toList(); | 231 serializedClass.typeParameters.map(buildTypeParameter).toList(); |
| 232 for (int i = 0; i < serializedClass.typeParameters.length; i++) { | 232 for (int i = 0; i < serializedClass.typeParameters.length; i++) { |
| 233 finishTypeParameter( | 233 finishTypeParameter( |
| 234 serializedClass.typeParameters[i], currentTypeParameters[i]); | 234 serializedClass.typeParameters[i], currentTypeParameters[i]); |
| 235 } | 235 } |
| 236 ClassElementImpl classElement = | 236 ClassElementImpl classElement = new ClassElementImpl( |
| 237 new ClassElementImpl(serializedClass.name, -1); | 237 serializedClass.name, serializedClass.nameOffset); |
| 238 classElement.mixinApplication = serializedClass.isMixinApplication; | 238 classElement.mixinApplication = serializedClass.isMixinApplication; |
| 239 InterfaceTypeImpl correspondingType = new InterfaceTypeImpl(classElement); | 239 InterfaceTypeImpl correspondingType = new InterfaceTypeImpl(classElement); |
| 240 if (serializedClass.supertype != null) { | 240 if (serializedClass.supertype != null) { |
| 241 classElement.supertype = buildType(serializedClass.supertype); | 241 classElement.supertype = buildType(serializedClass.supertype); |
| 242 } else if (!serializedClass.hasNoSupertype) { | 242 } else if (!serializedClass.hasNoSupertype) { |
| 243 if (isCoreLibrary) { | 243 if (isCoreLibrary) { |
| 244 delayedObjectSubclasses.add(classElement); | 244 delayedObjectSubclasses.add(classElement); |
| 245 } else { | 245 } else { |
| 246 classElement.supertype = summaryResynthesizer.typeProvider.objectType; | 246 classElement.supertype = summaryResynthesizer.typeProvider.objectType; |
| 247 } | 247 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 } | 314 } |
| 315 | 315 |
| 316 /** | 316 /** |
| 317 * Resynthesize a [ConstructorElement] and place it in the given [holder]. | 317 * Resynthesize a [ConstructorElement] and place it in the given [holder]. |
| 318 * [classType] is the type of the class for which this element is a | 318 * [classType] is the type of the class for which this element is a |
| 319 * constructor. | 319 * constructor. |
| 320 */ | 320 */ |
| 321 void buildConstructor(UnlinkedExecutable serializedExecutable, | 321 void buildConstructor(UnlinkedExecutable serializedExecutable, |
| 322 ElementHolder holder, InterfaceType classType) { | 322 ElementHolder holder, InterfaceType classType) { |
| 323 assert(serializedExecutable.kind == UnlinkedExecutableKind.constructor); | 323 assert(serializedExecutable.kind == UnlinkedExecutableKind.constructor); |
| 324 ConstructorElementImpl constructorElement = | 324 ConstructorElementImpl constructorElement = new ConstructorElementImpl( |
| 325 new ConstructorElementImpl(serializedExecutable.name, -1); | 325 serializedExecutable.name, serializedExecutable.nameOffset); |
| 326 constructorElement.returnType = classType; | 326 constructorElement.returnType = classType; |
| 327 buildExecutableCommonParts(constructorElement, serializedExecutable); | 327 buildExecutableCommonParts(constructorElement, serializedExecutable); |
| 328 constructorElement.factory = serializedExecutable.isFactory; | 328 constructorElement.factory = serializedExecutable.isFactory; |
| 329 constructorElement.const2 = serializedExecutable.isConst; | 329 constructorElement.const2 = serializedExecutable.isConst; |
| 330 holder.addConstructor(constructorElement); | 330 holder.addConstructor(constructorElement); |
| 331 } | 331 } |
| 332 | 332 |
| 333 /** | 333 /** |
| 334 * Resynthesize the [ClassElement] corresponding to an enum, along with the | 334 * Resynthesize the [ClassElement] corresponding to an enum, along with the |
| 335 * associated fields and implicit accessors. | 335 * associated fields and implicit accessors. |
| 336 */ | 336 */ |
| 337 void buildEnum(UnlinkedEnum serializedEnum) { | 337 void buildEnum(UnlinkedEnum serializedEnum) { |
| 338 assert(!isCoreLibrary); | 338 assert(!isCoreLibrary); |
| 339 // TODO(paulberry): add offset support (for this element type and others) | 339 // TODO(paulberry): add offset support (for this element type and others) |
| 340 ClassElementImpl classElement = | 340 ClassElementImpl classElement = |
| 341 new ClassElementImpl(serializedEnum.name, -1); | 341 new ClassElementImpl(serializedEnum.name, serializedEnum.nameOffset); |
| 342 classElement.enum2 = true; | 342 classElement.enum2 = true; |
| 343 InterfaceType enumType = new InterfaceTypeImpl(classElement); | 343 InterfaceType enumType = new InterfaceTypeImpl(classElement); |
| 344 classElement.type = enumType; | 344 classElement.type = enumType; |
| 345 classElement.supertype = summaryResynthesizer.typeProvider.objectType; | 345 classElement.supertype = summaryResynthesizer.typeProvider.objectType; |
| 346 ElementHolder memberHolder = new ElementHolder(); | 346 ElementHolder memberHolder = new ElementHolder(); |
| 347 FieldElementImpl indexField = new FieldElementImpl('index', -1); | 347 FieldElementImpl indexField = new FieldElementImpl('index', -1); |
| 348 indexField.final2 = true; | 348 indexField.final2 = true; |
| 349 indexField.synthetic = true; | 349 indexField.synthetic = true; |
| 350 indexField.type = summaryResynthesizer.typeProvider.intType; | 350 indexField.type = summaryResynthesizer.typeProvider.intType; |
| 351 memberHolder.addField(indexField); | 351 memberHolder.addField(indexField); |
| 352 buildImplicitAccessors(indexField, memberHolder); | 352 buildImplicitAccessors(indexField, memberHolder); |
| 353 FieldElementImpl valuesField = new ConstFieldElementImpl('values', -1); | 353 FieldElementImpl valuesField = new ConstFieldElementImpl('values', -1); |
| 354 valuesField.synthetic = true; | 354 valuesField.synthetic = true; |
| 355 valuesField.const3 = true; | 355 valuesField.const3 = true; |
| 356 valuesField.static = true; | 356 valuesField.static = true; |
| 357 valuesField.type = summaryResynthesizer.typeProvider.listType | 357 valuesField.type = summaryResynthesizer.typeProvider.listType |
| 358 .substitute4(<DartType>[enumType]); | 358 .substitute4(<DartType>[enumType]); |
| 359 memberHolder.addField(valuesField); | 359 memberHolder.addField(valuesField); |
| 360 buildImplicitAccessors(valuesField, memberHolder); | 360 buildImplicitAccessors(valuesField, memberHolder); |
| 361 for (UnlinkedEnumValue serializedEnumValue in serializedEnum.values) { | 361 for (UnlinkedEnumValue serializedEnumValue in serializedEnum.values) { |
| 362 ConstFieldElementImpl valueField = | 362 ConstFieldElementImpl valueField = new ConstFieldElementImpl( |
| 363 new ConstFieldElementImpl(serializedEnumValue.name, -1); | 363 serializedEnumValue.name, serializedEnumValue.nameOffset); |
| 364 valueField.const3 = true; | 364 valueField.const3 = true; |
| 365 valueField.static = true; | 365 valueField.static = true; |
| 366 valueField.type = enumType; | 366 valueField.type = enumType; |
| 367 memberHolder.addField(valueField); | 367 memberHolder.addField(valueField); |
| 368 buildImplicitAccessors(valueField, memberHolder); | 368 buildImplicitAccessors(valueField, memberHolder); |
| 369 } | 369 } |
| 370 classElement.fields = memberHolder.fields; | 370 classElement.fields = memberHolder.fields; |
| 371 classElement.accessors = memberHolder.accessors; | 371 classElement.accessors = memberHolder.accessors; |
| 372 classElement.constructors = <ConstructorElement>[]; | 372 classElement.constructors = <ConstructorElement>[]; |
| 373 unitHolder.addEnum(classElement); | 373 unitHolder.addEnum(classElement); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 385 UnlinkedExecutableKind kind = serializedExecutable.kind; | 385 UnlinkedExecutableKind kind = serializedExecutable.kind; |
| 386 String name = serializedExecutable.name; | 386 String name = serializedExecutable.name; |
| 387 if (kind == UnlinkedExecutableKind.setter) { | 387 if (kind == UnlinkedExecutableKind.setter) { |
| 388 assert(name.endsWith('=')); | 388 assert(name.endsWith('=')); |
| 389 name = name.substring(0, name.length - 1); | 389 name = name.substring(0, name.length - 1); |
| 390 } | 390 } |
| 391 switch (kind) { | 391 switch (kind) { |
| 392 case UnlinkedExecutableKind.functionOrMethod: | 392 case UnlinkedExecutableKind.functionOrMethod: |
| 393 if (isTopLevel) { | 393 if (isTopLevel) { |
| 394 FunctionElementImpl executableElement = | 394 FunctionElementImpl executableElement = |
| 395 new FunctionElementImpl(name, -1); | 395 new FunctionElementImpl(name, serializedExecutable.nameOffset); |
| 396 buildExecutableCommonParts(executableElement, serializedExecutable); | 396 buildExecutableCommonParts(executableElement, serializedExecutable); |
| 397 holder.addFunction(executableElement); | 397 holder.addFunction(executableElement); |
| 398 } else { | 398 } else { |
| 399 MethodElementImpl executableElement = new MethodElementImpl(name, -1); | 399 MethodElementImpl executableElement = |
| 400 new MethodElementImpl(name, serializedExecutable.nameOffset); |
| 400 buildExecutableCommonParts(executableElement, serializedExecutable); | 401 buildExecutableCommonParts(executableElement, serializedExecutable); |
| 401 executableElement.static = serializedExecutable.isStatic; | 402 executableElement.static = serializedExecutable.isStatic; |
| 402 holder.addMethod(executableElement); | 403 holder.addMethod(executableElement); |
| 403 } | 404 } |
| 404 break; | 405 break; |
| 405 case UnlinkedExecutableKind.getter: | 406 case UnlinkedExecutableKind.getter: |
| 406 case UnlinkedExecutableKind.setter: | 407 case UnlinkedExecutableKind.setter: |
| 407 PropertyAccessorElementImpl executableElement = | 408 PropertyAccessorElementImpl executableElement = |
| 408 new PropertyAccessorElementImpl(name, -1); | 409 new PropertyAccessorElementImpl( |
| 410 name, serializedExecutable.nameOffset); |
| 409 if (isTopLevel) { | 411 if (isTopLevel) { |
| 410 executableElement.static = true; | 412 executableElement.static = true; |
| 411 } else { | 413 } else { |
| 412 executableElement.static = serializedExecutable.isStatic; | 414 executableElement.static = serializedExecutable.isStatic; |
| 413 } | 415 } |
| 414 buildExecutableCommonParts(executableElement, serializedExecutable); | 416 buildExecutableCommonParts(executableElement, serializedExecutable); |
| 415 DartType type; | 417 DartType type; |
| 416 if (kind == UnlinkedExecutableKind.getter) { | 418 if (kind == UnlinkedExecutableKind.getter) { |
| 417 executableElement.getter = true; | 419 executableElement.getter = true; |
| 418 type = executableElement.returnType; | 420 type = executableElement.returnType; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 executableElement.external = serializedExecutable.isExternal; | 481 executableElement.external = serializedExecutable.isExternal; |
| 480 currentTypeParameters.removeRange( | 482 currentTypeParameters.removeRange( |
| 481 oldTypeParametersLength, currentTypeParameters.length); | 483 oldTypeParametersLength, currentTypeParameters.length); |
| 482 } | 484 } |
| 483 | 485 |
| 484 /** | 486 /** |
| 485 * Resynthesize an [ExportElement], | 487 * Resynthesize an [ExportElement], |
| 486 */ | 488 */ |
| 487 ExportElement buildExport(UnlinkedExportPublic serializedExportPublic, | 489 ExportElement buildExport(UnlinkedExportPublic serializedExportPublic, |
| 488 UnlinkedExportNonPublic serializedExportNonPublic) { | 490 UnlinkedExportNonPublic serializedExportNonPublic) { |
| 489 ExportElementImpl exportElement = new ExportElementImpl(0); | 491 ExportElementImpl exportElement = |
| 492 new ExportElementImpl(serializedExportNonPublic.offset); |
| 490 String exportedLibraryUri = summaryResynthesizer.sourceFactory | 493 String exportedLibraryUri = summaryResynthesizer.sourceFactory |
| 491 .resolveUri(librarySource, serializedExportPublic.uri) | 494 .resolveUri(librarySource, serializedExportPublic.uri) |
| 492 .uri | 495 .uri |
| 493 .toString(); | 496 .toString(); |
| 494 exportElement.exportedLibrary = new LibraryElementHandle( | 497 exportElement.exportedLibrary = new LibraryElementHandle( |
| 495 summaryResynthesizer, | 498 summaryResynthesizer, |
| 496 new ElementLocationImpl.con3(<String>[exportedLibraryUri])); | 499 new ElementLocationImpl.con3(<String>[exportedLibraryUri])); |
| 497 exportElement.uri = serializedExportPublic.uri; | 500 exportElement.uri = serializedExportPublic.uri; |
| 498 exportElement.combinators = | 501 exportElement.combinators = |
| 499 serializedExportPublic.combinators.map(buildCombinator).toList(); | 502 serializedExportPublic.combinators.map(buildCombinator).toList(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 515 | 518 |
| 516 /** | 519 /** |
| 517 * Build the implicit getter and setter associated with [element], and place | 520 * Build the implicit getter and setter associated with [element], and place |
| 518 * them in [holder]. | 521 * them in [holder]. |
| 519 */ | 522 */ |
| 520 void buildImplicitAccessors( | 523 void buildImplicitAccessors( |
| 521 PropertyInducingElementImpl element, ElementHolder holder) { | 524 PropertyInducingElementImpl element, ElementHolder holder) { |
| 522 String name = element.name; | 525 String name = element.name; |
| 523 DartType type = element.type; | 526 DartType type = element.type; |
| 524 PropertyAccessorElementImpl getter = | 527 PropertyAccessorElementImpl getter = |
| 525 new PropertyAccessorElementImpl(name, -1); | 528 new PropertyAccessorElementImpl(name, element.nameOffset); |
| 526 getter.getter = true; | 529 getter.getter = true; |
| 527 getter.static = element.isStatic; | 530 getter.static = element.isStatic; |
| 528 getter.synthetic = true; | 531 getter.synthetic = true; |
| 529 getter.returnType = type; | 532 getter.returnType = type; |
| 530 getter.type = new FunctionTypeImpl(getter); | 533 getter.type = new FunctionTypeImpl(getter); |
| 531 getter.variable = element; | 534 getter.variable = element; |
| 532 getter.hasImplicitReturnType = element.hasImplicitType; | 535 getter.hasImplicitReturnType = element.hasImplicitType; |
| 533 holder.addAccessor(getter); | 536 holder.addAccessor(getter); |
| 534 element.getter = getter; | 537 element.getter = getter; |
| 535 if (!(element.isConst || element.isFinal)) { | 538 if (!(element.isConst || element.isFinal)) { |
| 536 PropertyAccessorElementImpl setter = | 539 PropertyAccessorElementImpl setter = |
| 537 new PropertyAccessorElementImpl(name, -1); | 540 new PropertyAccessorElementImpl(name, element.nameOffset); |
| 538 setter.setter = true; | 541 setter.setter = true; |
| 539 setter.static = element.isStatic; | 542 setter.static = element.isStatic; |
| 540 setter.synthetic = true; | 543 setter.synthetic = true; |
| 541 setter.parameters = <ParameterElement>[ | 544 setter.parameters = <ParameterElement>[ |
| 542 new ParameterElementImpl('_$name', -1) | 545 new ParameterElementImpl('_$name', element.nameOffset) |
| 543 ..synthetic = true | 546 ..synthetic = true |
| 544 ..type = type | 547 ..type = type |
| 545 ..parameterKind = ParameterKind.REQUIRED | 548 ..parameterKind = ParameterKind.REQUIRED |
| 546 ]; | 549 ]; |
| 547 setter.returnType = VoidTypeImpl.instance; | 550 setter.returnType = VoidTypeImpl.instance; |
| 548 setter.type = new FunctionTypeImpl(setter); | 551 setter.type = new FunctionTypeImpl(setter); |
| 549 setter.variable = element; | 552 setter.variable = element; |
| 550 holder.addAccessor(setter); | 553 holder.addAccessor(setter); |
| 551 element.setter = setter; | 554 element.setter = setter; |
| 552 } | 555 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 if (isSynthetic) { | 617 if (isSynthetic) { |
| 615 importElement.synthetic = true; | 618 importElement.synthetic = true; |
| 616 } else { | 619 } else { |
| 617 importElement.uri = serializedImport.uri; | 620 importElement.uri = serializedImport.uri; |
| 618 importElement.uriOffset = serializedImport.uriOffset; | 621 importElement.uriOffset = serializedImport.uriOffset; |
| 619 importElement.uriEnd = serializedImport.uriEnd; | 622 importElement.uriEnd = serializedImport.uriEnd; |
| 620 } | 623 } |
| 621 if (serializedImport.prefixReference != 0) { | 624 if (serializedImport.prefixReference != 0) { |
| 622 UnlinkedReference serializedPrefix = | 625 UnlinkedReference serializedPrefix = |
| 623 unlinkedUnits[0].references[serializedImport.prefixReference]; | 626 unlinkedUnits[0].references[serializedImport.prefixReference]; |
| 624 importElement.prefix = new PrefixElementImpl(serializedPrefix.name, -1); | 627 importElement.prefix = new PrefixElementImpl( |
| 628 serializedPrefix.name, serializedImport.prefixOffset); |
| 625 } | 629 } |
| 626 importElement.combinators = | 630 importElement.combinators = |
| 627 serializedImport.combinators.map(buildCombinator).toList(); | 631 serializedImport.combinators.map(buildCombinator).toList(); |
| 628 return importElement; | 632 return importElement; |
| 629 } | 633 } |
| 630 | 634 |
| 631 /** | 635 /** |
| 632 * Main entry point. Resynthesize the [LibraryElement] and return it. | 636 * Main entry point. Resynthesize the [LibraryElement] and return it. |
| 633 */ | 637 */ |
| 634 LibraryElement buildLibrary() { | 638 LibraryElement buildLibrary() { |
| 635 // TODO(paulberry): is it ok to pass -1 for offset and nameLength? | 639 bool hasName = unlinkedUnits[0].libraryName.isNotEmpty; |
| 636 LibraryElementImpl libraryElement = new LibraryElementImpl( | 640 LibraryElementImpl libraryElement = new LibraryElementImpl( |
| 637 summaryResynthesizer.context, unlinkedUnits[0].libraryName, -1, -1); | 641 summaryResynthesizer.context, |
| 642 unlinkedUnits[0].libraryName, |
| 643 hasName ? unlinkedUnits[0].libraryNameOffset : -1, |
| 644 unlinkedUnits[0].libraryNameLength); |
| 638 CompilationUnitElementImpl definingCompilationUnit = | 645 CompilationUnitElementImpl definingCompilationUnit = |
| 639 new CompilationUnitElementImpl(librarySource.shortName); | 646 new CompilationUnitElementImpl(librarySource.shortName); |
| 640 libraryElement.definingCompilationUnit = definingCompilationUnit; | 647 libraryElement.definingCompilationUnit = definingCompilationUnit; |
| 641 definingCompilationUnit.source = librarySource; | 648 definingCompilationUnit.source = librarySource; |
| 642 definingCompilationUnit.librarySource = librarySource; | 649 definingCompilationUnit.librarySource = librarySource; |
| 643 List<CompilationUnitElement> parts = <CompilationUnitElement>[]; | 650 List<CompilationUnitElement> parts = <CompilationUnitElement>[]; |
| 644 UnlinkedUnit unlinkedDefiningUnit = unlinkedUnits[0]; | 651 UnlinkedUnit unlinkedDefiningUnit = unlinkedUnits[0]; |
| 645 assert(unlinkedDefiningUnit.publicNamespace.parts.length + 1 == | 652 assert(unlinkedDefiningUnit.publicNamespace.parts.length + 1 == |
| 646 prelinkedLibrary.units.length); | 653 prelinkedLibrary.units.length); |
| 647 for (int i = 1; i < prelinkedLibrary.units.length; i++) { | 654 for (int i = 1; i < prelinkedLibrary.units.length; i++) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 677 classElement.supertype = objectElement.type; | 684 classElement.supertype = objectElement.type; |
| 678 } | 685 } |
| 679 } | 686 } |
| 680 return libraryElement; | 687 return libraryElement; |
| 681 } | 688 } |
| 682 | 689 |
| 683 /** | 690 /** |
| 684 * Resynthesize a [ParameterElement]. | 691 * Resynthesize a [ParameterElement]. |
| 685 */ | 692 */ |
| 686 ParameterElement buildParameter(UnlinkedParam serializedParameter) { | 693 ParameterElement buildParameter(UnlinkedParam serializedParameter) { |
| 687 ParameterElementImpl parameterElement = | 694 ParameterElementImpl parameterElement = new ParameterElementImpl( |
| 688 new ParameterElementImpl(serializedParameter.name, -1); | 695 serializedParameter.name, serializedParameter.nameOffset); |
| 689 if (serializedParameter.isFunctionTyped) { | 696 if (serializedParameter.isFunctionTyped) { |
| 690 FunctionElementImpl parameterTypeElement = | 697 FunctionElementImpl parameterTypeElement = |
| 691 new FunctionElementImpl('', -1); | 698 new FunctionElementImpl('', -1); |
| 692 parameterTypeElement.synthetic = true; | 699 parameterTypeElement.synthetic = true; |
| 693 parameterElement.parameters = | 700 parameterElement.parameters = |
| 694 serializedParameter.parameters.map(buildParameter).toList(); | 701 serializedParameter.parameters.map(buildParameter).toList(); |
| 695 parameterTypeElement.enclosingElement = parameterElement; | 702 parameterTypeElement.enclosingElement = parameterElement; |
| 696 parameterTypeElement.shareParameters(parameterElement.parameters); | 703 parameterTypeElement.shareParameters(parameterElement.parameters); |
| 697 if (serializedParameter.type != null) { | 704 if (serializedParameter.type != null) { |
| 698 parameterTypeElement.returnType = buildType(serializedParameter.type); | 705 parameterTypeElement.returnType = buildType(serializedParameter.type); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 */ | 843 */ |
| 837 void buildTypedef(UnlinkedTypedef serializedTypedef) { | 844 void buildTypedef(UnlinkedTypedef serializedTypedef) { |
| 838 try { | 845 try { |
| 839 currentTypeParameters = | 846 currentTypeParameters = |
| 840 serializedTypedef.typeParameters.map(buildTypeParameter).toList(); | 847 serializedTypedef.typeParameters.map(buildTypeParameter).toList(); |
| 841 for (int i = 0; i < serializedTypedef.typeParameters.length; i++) { | 848 for (int i = 0; i < serializedTypedef.typeParameters.length; i++) { |
| 842 finishTypeParameter( | 849 finishTypeParameter( |
| 843 serializedTypedef.typeParameters[i], currentTypeParameters[i]); | 850 serializedTypedef.typeParameters[i], currentTypeParameters[i]); |
| 844 } | 851 } |
| 845 FunctionTypeAliasElementImpl functionTypeAliasElement = | 852 FunctionTypeAliasElementImpl functionTypeAliasElement = |
| 846 new FunctionTypeAliasElementImpl(serializedTypedef.name, -1); | 853 new FunctionTypeAliasElementImpl( |
| 854 serializedTypedef.name, serializedTypedef.nameOffset); |
| 847 functionTypeAliasElement.parameters = | 855 functionTypeAliasElement.parameters = |
| 848 serializedTypedef.parameters.map(buildParameter).toList(); | 856 serializedTypedef.parameters.map(buildParameter).toList(); |
| 849 if (serializedTypedef.returnType != null) { | 857 if (serializedTypedef.returnType != null) { |
| 850 functionTypeAliasElement.returnType = | 858 functionTypeAliasElement.returnType = |
| 851 buildType(serializedTypedef.returnType); | 859 buildType(serializedTypedef.returnType); |
| 852 } else { | 860 } else { |
| 853 functionTypeAliasElement.returnType = VoidTypeImpl.instance; | 861 functionTypeAliasElement.returnType = VoidTypeImpl.instance; |
| 854 } | 862 } |
| 855 functionTypeAliasElement.type = | 863 functionTypeAliasElement.type = |
| 856 new FunctionTypeImpl.forTypedef(functionTypeAliasElement); | 864 new FunctionTypeImpl.forTypedef(functionTypeAliasElement); |
| 857 functionTypeAliasElement.typeParameters = currentTypeParameters; | 865 functionTypeAliasElement.typeParameters = currentTypeParameters; |
| 858 unitHolder.addTypeAlias(functionTypeAliasElement); | 866 unitHolder.addTypeAlias(functionTypeAliasElement); |
| 859 } finally { | 867 } finally { |
| 860 currentTypeParameters = <TypeParameterElement>[]; | 868 currentTypeParameters = <TypeParameterElement>[]; |
| 861 } | 869 } |
| 862 } | 870 } |
| 863 | 871 |
| 864 /** | 872 /** |
| 865 * Resynthesize a [TypeParameterElement], handling all parts of its except | 873 * Resynthesize a [TypeParameterElement], handling all parts of its except |
| 866 * its bound. | 874 * its bound. |
| 867 * | 875 * |
| 868 * The bound is deferred until later since it may refer to other type | 876 * The bound is deferred until later since it may refer to other type |
| 869 * parameters that have not been resynthesized yet. To handle the bound, | 877 * parameters that have not been resynthesized yet. To handle the bound, |
| 870 * call [finishTypeParameter]. | 878 * call [finishTypeParameter]. |
| 871 */ | 879 */ |
| 872 TypeParameterElement buildTypeParameter( | 880 TypeParameterElement buildTypeParameter( |
| 873 UnlinkedTypeParam serializedTypeParameter) { | 881 UnlinkedTypeParam serializedTypeParameter) { |
| 874 TypeParameterElementImpl typeParameterElement = | 882 TypeParameterElementImpl typeParameterElement = |
| 875 new TypeParameterElementImpl(serializedTypeParameter.name, -1); | 883 new TypeParameterElementImpl( |
| 884 serializedTypeParameter.name, serializedTypeParameter.nameOffset); |
| 876 typeParameterElement.type = new TypeParameterTypeImpl(typeParameterElement); | 885 typeParameterElement.type = new TypeParameterTypeImpl(typeParameterElement); |
| 877 return typeParameterElement; | 886 return typeParameterElement; |
| 878 } | 887 } |
| 879 | 888 |
| 880 /** | 889 /** |
| 881 * Resynthesize a [TopLevelVariableElement] or [FieldElement]. | 890 * Resynthesize a [TopLevelVariableElement] or [FieldElement]. |
| 882 */ | 891 */ |
| 883 void buildVariable(UnlinkedVariable serializedVariable, | 892 void buildVariable(UnlinkedVariable serializedVariable, |
| 884 [ElementHolder holder]) { | 893 [ElementHolder holder]) { |
| 885 if (holder == null) { | 894 if (holder == null) { |
| 886 TopLevelVariableElementImpl element = | 895 TopLevelVariableElementImpl element = new TopLevelVariableElementImpl( |
| 887 new TopLevelVariableElementImpl(serializedVariable.name, -1); | 896 serializedVariable.name, serializedVariable.nameOffset); |
| 888 buildVariableCommonParts(element, serializedVariable); | 897 buildVariableCommonParts(element, serializedVariable); |
| 889 unitHolder.addTopLevelVariable(element); | 898 unitHolder.addTopLevelVariable(element); |
| 890 buildImplicitAccessors(element, unitHolder); | 899 buildImplicitAccessors(element, unitHolder); |
| 891 } else { | 900 } else { |
| 892 FieldElementImpl element = | 901 FieldElementImpl element = new FieldElementImpl( |
| 893 new FieldElementImpl(serializedVariable.name, -1); | 902 serializedVariable.name, serializedVariable.nameOffset); |
| 894 buildVariableCommonParts(element, serializedVariable); | 903 buildVariableCommonParts(element, serializedVariable); |
| 895 element.static = serializedVariable.isStatic; | 904 element.static = serializedVariable.isStatic; |
| 896 holder.addField(element); | 905 holder.addField(element); |
| 897 buildImplicitAccessors(element, holder); | 906 buildImplicitAccessors(element, holder); |
| 898 } | 907 } |
| 899 } | 908 } |
| 900 | 909 |
| 901 /** | 910 /** |
| 902 * Handle the parts that are common to top level variables and fields. | 911 * Handle the parts that are common to top level variables and fields. |
| 903 */ | 912 */ |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 953 } | 962 } |
| 954 for (FunctionTypeAliasElement typeAlias in unit.functionTypeAliases) { | 963 for (FunctionTypeAliasElement typeAlias in unit.functionTypeAliases) { |
| 955 elementMap[typeAlias.name] = typeAlias; | 964 elementMap[typeAlias.name] = typeAlias; |
| 956 } | 965 } |
| 957 resummarizedElements[absoluteUri] = elementMap; | 966 resummarizedElements[absoluteUri] = elementMap; |
| 958 unitHolder = null; | 967 unitHolder = null; |
| 959 prelinkedUnit = null; | 968 prelinkedUnit = null; |
| 960 unlinkedUnit = null; | 969 unlinkedUnit = null; |
| 961 } | 970 } |
| 962 } | 971 } |
| OLD | NEW |