| 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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 constructor, null, currentTypeArguments, false); | 281 constructor, null, currentTypeArguments, false); |
| 282 memberHolder.addConstructor(constructor); | 282 memberHolder.addConstructor(constructor); |
| 283 } | 283 } |
| 284 classElement.constructors = memberHolder.constructors; | 284 classElement.constructors = memberHolder.constructors; |
| 285 } | 285 } |
| 286 classElement.accessors = memberHolder.accessors; | 286 classElement.accessors = memberHolder.accessors; |
| 287 classElement.fields = memberHolder.fields; | 287 classElement.fields = memberHolder.fields; |
| 288 classElement.methods = memberHolder.methods; | 288 classElement.methods = memberHolder.methods; |
| 289 correspondingType.typeArguments = currentTypeArguments; | 289 correspondingType.typeArguments = currentTypeArguments; |
| 290 classElement.type = correspondingType; | 290 classElement.type = correspondingType; |
| 291 buildDocumentation(classElement, serializedClass.documentationComment); |
| 291 unitHolder.addType(classElement); | 292 unitHolder.addType(classElement); |
| 292 } finally { | 293 } finally { |
| 293 currentTypeParameters = <TypeParameterElement>[]; | 294 currentTypeParameters = <TypeParameterElement>[]; |
| 294 } | 295 } |
| 295 } | 296 } |
| 296 | 297 |
| 297 /** | 298 /** |
| 298 * Resynthesize a [NamespaceCombinator]. | 299 * Resynthesize a [NamespaceCombinator]. |
| 299 */ | 300 */ |
| 300 NamespaceCombinator buildCombinator(UnlinkedCombinator serializedCombinator) { | 301 NamespaceCombinator buildCombinator(UnlinkedCombinator serializedCombinator) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 324 ConstructorElementImpl constructorElement = new ConstructorElementImpl( | 325 ConstructorElementImpl constructorElement = new ConstructorElementImpl( |
| 325 serializedExecutable.name, serializedExecutable.nameOffset); | 326 serializedExecutable.name, serializedExecutable.nameOffset); |
| 326 constructorElement.returnType = classType; | 327 constructorElement.returnType = classType; |
| 327 buildExecutableCommonParts(constructorElement, serializedExecutable); | 328 buildExecutableCommonParts(constructorElement, serializedExecutable); |
| 328 constructorElement.factory = serializedExecutable.isFactory; | 329 constructorElement.factory = serializedExecutable.isFactory; |
| 329 constructorElement.const2 = serializedExecutable.isConst; | 330 constructorElement.const2 = serializedExecutable.isConst; |
| 330 holder.addConstructor(constructorElement); | 331 holder.addConstructor(constructorElement); |
| 331 } | 332 } |
| 332 | 333 |
| 333 /** | 334 /** |
| 335 * Build the documentation for the given [element]. Does nothing if |
| 336 * [serializedDocumentationComment] is `null`. |
| 337 */ |
| 338 void buildDocumentation(ElementImpl element, |
| 339 UnlinkedDocumentationComment serializedDocumentationComment) { |
| 340 if (serializedDocumentationComment != null) { |
| 341 element.documentationComment = serializedDocumentationComment.text; |
| 342 } |
| 343 } |
| 344 |
| 345 /** |
| 334 * Resynthesize the [ClassElement] corresponding to an enum, along with the | 346 * Resynthesize the [ClassElement] corresponding to an enum, along with the |
| 335 * associated fields and implicit accessors. | 347 * associated fields and implicit accessors. |
| 336 */ | 348 */ |
| 337 void buildEnum(UnlinkedEnum serializedEnum) { | 349 void buildEnum(UnlinkedEnum serializedEnum) { |
| 338 assert(!isCoreLibrary); | 350 assert(!isCoreLibrary); |
| 339 // TODO(paulberry): add offset support (for this element type and others) | 351 // TODO(paulberry): add offset support (for this element type and others) |
| 340 ClassElementImpl classElement = | 352 ClassElementImpl classElement = |
| 341 new ClassElementImpl(serializedEnum.name, serializedEnum.nameOffset); | 353 new ClassElementImpl(serializedEnum.name, serializedEnum.nameOffset); |
| 342 classElement.enum2 = true; | 354 classElement.enum2 = true; |
| 343 InterfaceType enumType = new InterfaceTypeImpl(classElement); | 355 InterfaceType enumType = new InterfaceTypeImpl(classElement); |
| 344 classElement.type = enumType; | 356 classElement.type = enumType; |
| 345 classElement.supertype = summaryResynthesizer.typeProvider.objectType; | 357 classElement.supertype = summaryResynthesizer.typeProvider.objectType; |
| 358 buildDocumentation(classElement, serializedEnum.documentationComment); |
| 346 ElementHolder memberHolder = new ElementHolder(); | 359 ElementHolder memberHolder = new ElementHolder(); |
| 347 FieldElementImpl indexField = new FieldElementImpl('index', -1); | 360 FieldElementImpl indexField = new FieldElementImpl('index', -1); |
| 348 indexField.final2 = true; | 361 indexField.final2 = true; |
| 349 indexField.synthetic = true; | 362 indexField.synthetic = true; |
| 350 indexField.type = summaryResynthesizer.typeProvider.intType; | 363 indexField.type = summaryResynthesizer.typeProvider.intType; |
| 351 memberHolder.addField(indexField); | 364 memberHolder.addField(indexField); |
| 352 buildImplicitAccessors(indexField, memberHolder); | 365 buildImplicitAccessors(indexField, memberHolder); |
| 353 FieldElementImpl valuesField = new ConstFieldElementImpl('values', -1); | 366 FieldElementImpl valuesField = new ConstFieldElementImpl('values', -1); |
| 354 valuesField.synthetic = true; | 367 valuesField.synthetic = true; |
| 355 valuesField.const3 = true; | 368 valuesField.const3 = true; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 } else { | 487 } else { |
| 475 executableElement.returnType = VoidTypeImpl.instance; | 488 executableElement.returnType = VoidTypeImpl.instance; |
| 476 } | 489 } |
| 477 executableElement.type = new FunctionTypeImpl.elementWithNameAndArgs( | 490 executableElement.type = new FunctionTypeImpl.elementWithNameAndArgs( |
| 478 executableElement, null, oldTypeArguments, false); | 491 executableElement, null, oldTypeArguments, false); |
| 479 executableElement.hasImplicitReturnType = | 492 executableElement.hasImplicitReturnType = |
| 480 serializedExecutable.hasImplicitReturnType; | 493 serializedExecutable.hasImplicitReturnType; |
| 481 executableElement.external = serializedExecutable.isExternal; | 494 executableElement.external = serializedExecutable.isExternal; |
| 482 currentTypeParameters.removeRange( | 495 currentTypeParameters.removeRange( |
| 483 oldTypeParametersLength, currentTypeParameters.length); | 496 oldTypeParametersLength, currentTypeParameters.length); |
| 497 buildDocumentation( |
| 498 executableElement, serializedExecutable.documentationComment); |
| 484 } | 499 } |
| 485 | 500 |
| 486 /** | 501 /** |
| 487 * Resynthesize an [ExportElement], | 502 * Resynthesize an [ExportElement], |
| 488 */ | 503 */ |
| 489 ExportElement buildExport(UnlinkedExportPublic serializedExportPublic, | 504 ExportElement buildExport(UnlinkedExportPublic serializedExportPublic, |
| 490 UnlinkedExportNonPublic serializedExportNonPublic) { | 505 UnlinkedExportNonPublic serializedExportNonPublic) { |
| 491 ExportElementImpl exportElement = | 506 ExportElementImpl exportElement = |
| 492 new ExportElementImpl(serializedExportNonPublic.offset); | 507 new ExportElementImpl(serializedExportNonPublic.offset); |
| 493 String exportedLibraryUri = summaryResynthesizer.sourceFactory | 508 String exportedLibraryUri = summaryResynthesizer.sourceFactory |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 /** | 650 /** |
| 636 * Main entry point. Resynthesize the [LibraryElement] and return it. | 651 * Main entry point. Resynthesize the [LibraryElement] and return it. |
| 637 */ | 652 */ |
| 638 LibraryElement buildLibrary() { | 653 LibraryElement buildLibrary() { |
| 639 bool hasName = unlinkedUnits[0].libraryName.isNotEmpty; | 654 bool hasName = unlinkedUnits[0].libraryName.isNotEmpty; |
| 640 LibraryElementImpl libraryElement = new LibraryElementImpl( | 655 LibraryElementImpl libraryElement = new LibraryElementImpl( |
| 641 summaryResynthesizer.context, | 656 summaryResynthesizer.context, |
| 642 unlinkedUnits[0].libraryName, | 657 unlinkedUnits[0].libraryName, |
| 643 hasName ? unlinkedUnits[0].libraryNameOffset : -1, | 658 hasName ? unlinkedUnits[0].libraryNameOffset : -1, |
| 644 unlinkedUnits[0].libraryNameLength); | 659 unlinkedUnits[0].libraryNameLength); |
| 660 buildDocumentation( |
| 661 libraryElement, unlinkedUnits[0].libraryDocumentationComment); |
| 645 CompilationUnitElementImpl definingCompilationUnit = | 662 CompilationUnitElementImpl definingCompilationUnit = |
| 646 new CompilationUnitElementImpl(librarySource.shortName); | 663 new CompilationUnitElementImpl(librarySource.shortName); |
| 647 libraryElement.definingCompilationUnit = definingCompilationUnit; | 664 libraryElement.definingCompilationUnit = definingCompilationUnit; |
| 648 definingCompilationUnit.source = librarySource; | 665 definingCompilationUnit.source = librarySource; |
| 649 definingCompilationUnit.librarySource = librarySource; | 666 definingCompilationUnit.librarySource = librarySource; |
| 650 List<CompilationUnitElement> parts = <CompilationUnitElement>[]; | 667 List<CompilationUnitElement> parts = <CompilationUnitElement>[]; |
| 651 UnlinkedUnit unlinkedDefiningUnit = unlinkedUnits[0]; | 668 UnlinkedUnit unlinkedDefiningUnit = unlinkedUnits[0]; |
| 652 assert(unlinkedDefiningUnit.publicNamespace.parts.length + 1 == | 669 assert(unlinkedDefiningUnit.publicNamespace.parts.length + 1 == |
| 653 prelinkedLibrary.units.length); | 670 prelinkedLibrary.units.length); |
| 654 for (int i = 1; i < prelinkedLibrary.units.length; i++) { | 671 for (int i = 1; i < prelinkedLibrary.units.length; i++) { |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 serializedTypedef.parameters.map(buildParameter).toList(); | 878 serializedTypedef.parameters.map(buildParameter).toList(); |
| 862 if (serializedTypedef.returnType != null) { | 879 if (serializedTypedef.returnType != null) { |
| 863 functionTypeAliasElement.returnType = | 880 functionTypeAliasElement.returnType = |
| 864 buildType(serializedTypedef.returnType); | 881 buildType(serializedTypedef.returnType); |
| 865 } else { | 882 } else { |
| 866 functionTypeAliasElement.returnType = VoidTypeImpl.instance; | 883 functionTypeAliasElement.returnType = VoidTypeImpl.instance; |
| 867 } | 884 } |
| 868 functionTypeAliasElement.type = | 885 functionTypeAliasElement.type = |
| 869 new FunctionTypeImpl.forTypedef(functionTypeAliasElement); | 886 new FunctionTypeImpl.forTypedef(functionTypeAliasElement); |
| 870 functionTypeAliasElement.typeParameters = currentTypeParameters; | 887 functionTypeAliasElement.typeParameters = currentTypeParameters; |
| 888 buildDocumentation( |
| 889 functionTypeAliasElement, serializedTypedef.documentationComment); |
| 871 unitHolder.addTypeAlias(functionTypeAliasElement); | 890 unitHolder.addTypeAlias(functionTypeAliasElement); |
| 872 } finally { | 891 } finally { |
| 873 currentTypeParameters = <TypeParameterElement>[]; | 892 currentTypeParameters = <TypeParameterElement>[]; |
| 874 } | 893 } |
| 875 } | 894 } |
| 876 | 895 |
| 877 /** | 896 /** |
| 878 * Resynthesize a [TypeParameterElement], handling all parts of its except | 897 * Resynthesize a [TypeParameterElement], handling all parts of its except |
| 879 * its bound. | 898 * its bound. |
| 880 * | 899 * |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 } | 932 } |
| 914 | 933 |
| 915 /** | 934 /** |
| 916 * Handle the parts that are common to top level variables and fields. | 935 * Handle the parts that are common to top level variables and fields. |
| 917 */ | 936 */ |
| 918 void buildVariableCommonParts(PropertyInducingElementImpl element, | 937 void buildVariableCommonParts(PropertyInducingElementImpl element, |
| 919 UnlinkedVariable serializedVariable) { | 938 UnlinkedVariable serializedVariable) { |
| 920 element.type = buildType(serializedVariable.type); | 939 element.type = buildType(serializedVariable.type); |
| 921 element.const3 = serializedVariable.isConst; | 940 element.const3 = serializedVariable.isConst; |
| 922 element.hasImplicitType = serializedVariable.hasImplicitType; | 941 element.hasImplicitType = serializedVariable.hasImplicitType; |
| 942 buildDocumentation(element, serializedVariable.documentationComment); |
| 923 } | 943 } |
| 924 | 944 |
| 925 /** | 945 /** |
| 926 * Finish creating a [TypeParameterElement] by deserializing its bound. | 946 * Finish creating a [TypeParameterElement] by deserializing its bound. |
| 927 */ | 947 */ |
| 928 void finishTypeParameter(UnlinkedTypeParam serializedTypeParameter, | 948 void finishTypeParameter(UnlinkedTypeParam serializedTypeParameter, |
| 929 TypeParameterElementImpl typeParameterElement) { | 949 TypeParameterElementImpl typeParameterElement) { |
| 930 if (serializedTypeParameter.bound != null) { | 950 if (serializedTypeParameter.bound != null) { |
| 931 typeParameterElement.bound = buildType(serializedTypeParameter.bound); | 951 typeParameterElement.bound = buildType(serializedTypeParameter.bound); |
| 932 } | 952 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 977 break; | 997 break; |
| 978 } | 998 } |
| 979 } | 999 } |
| 980 resummarizedElements[absoluteUri] = elementMap; | 1000 resummarizedElements[absoluteUri] = elementMap; |
| 981 unitHolder = null; | 1001 unitHolder = null; |
| 982 prelinkedUnit = null; | 1002 prelinkedUnit = null; |
| 983 unlinkedUnit = null; | 1003 unlinkedUnit = null; |
| 984 return entryPoint; | 1004 return entryPoint; |
| 985 } | 1005 } |
| 986 } | 1006 } |
| OLD | NEW |