| 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 serialization.elements; | 5 library serialization.elements; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/element/element.dart'; | 7 import 'package:analyzer/dart/element/element.dart'; |
| 8 import 'package:analyzer/dart/element/type.dart'; | 8 import 'package:analyzer/dart/element/type.dart'; |
| 9 import 'package:analyzer/src/dart/element/element.dart'; | 9 import 'package:analyzer/src/dart/element/element.dart'; |
| 10 import 'package:analyzer/src/dart/element/type.dart'; | 10 import 'package:analyzer/src/dart/element/type.dart'; |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 } | 215 } |
| 216 if (unitNum == 0) { | 216 if (unitNum == 0) { |
| 217 LibraryElement libraryElement = librarySerializer.libraryElement; | 217 LibraryElement libraryElement = librarySerializer.libraryElement; |
| 218 if (libraryElement.name.isNotEmpty) { | 218 if (libraryElement.name.isNotEmpty) { |
| 219 LibraryElement libraryElement = librarySerializer.libraryElement; | 219 LibraryElement libraryElement = librarySerializer.libraryElement; |
| 220 unlinkedUnit.libraryName = libraryElement.name; | 220 unlinkedUnit.libraryName = libraryElement.name; |
| 221 unlinkedUnit.libraryNameOffset = libraryElement.nameOffset; | 221 unlinkedUnit.libraryNameOffset = libraryElement.nameOffset; |
| 222 unlinkedUnit.libraryNameLength = libraryElement.nameLength; | 222 unlinkedUnit.libraryNameLength = libraryElement.nameLength; |
| 223 unlinkedUnit.libraryDocumentationComment = | 223 unlinkedUnit.libraryDocumentationComment = |
| 224 serializeDocumentation(libraryElement); | 224 serializeDocumentation(libraryElement); |
| 225 unlinkedUnit.libraryAnnotations = serializeAnnotations(libraryElement); |
| 225 } | 226 } |
| 226 unlinkedUnit.publicNamespace = new UnlinkedPublicNamespaceBuilder( | 227 unlinkedUnit.publicNamespace = new UnlinkedPublicNamespaceBuilder( |
| 227 exports: libraryElement.exports.map(serializeExportPublic).toList(), | 228 exports: libraryElement.exports.map(serializeExportPublic).toList(), |
| 228 parts: libraryElement.parts | 229 parts: libraryElement.parts |
| 229 .map((CompilationUnitElement e) => e.uri) | 230 .map((CompilationUnitElement e) => e.uri) |
| 230 .toList(), | 231 .toList(), |
| 231 names: names); | 232 names: names); |
| 232 unlinkedUnit.exports = | 233 unlinkedUnit.exports = |
| 233 libraryElement.exports.map(serializeExportNonPublic).toList(); | 234 libraryElement.exports.map(serializeExportNonPublic).toList(); |
| 234 unlinkedUnit.imports = | 235 unlinkedUnit.imports = |
| 235 libraryElement.imports.map(serializeImport).toList(); | 236 libraryElement.imports.map(serializeImport).toList(); |
| 236 unlinkedUnit.parts = libraryElement.parts | 237 unlinkedUnit.parts = libraryElement.parts |
| 237 .map((CompilationUnitElement e) => | 238 .map((CompilationUnitElement e) => new UnlinkedPartBuilder( |
| 238 new UnlinkedPartBuilder(uriOffset: e.uriOffset, uriEnd: e.uriEnd)) | 239 uriOffset: e.uriOffset, |
| 240 uriEnd: e.uriEnd, |
| 241 annotations: serializeAnnotations(e))) |
| 239 .toList(); | 242 .toList(); |
| 240 } else { | 243 } else { |
| 241 // TODO(paulberry): we need to figure out a way to record library, part, | 244 // TODO(paulberry): we need to figure out a way to record library, part, |
| 242 // import, and export declarations that appear in non-defining | 245 // import, and export declarations that appear in non-defining |
| 243 // compilation units (even though such declarations are prohibited by the | 246 // compilation units (even though such declarations are prohibited by the |
| 244 // language), so that if the user makes code changes that cause a | 247 // language), so that if the user makes code changes that cause a |
| 245 // non-defining compilation unit to become a defining compilation unit, | 248 // non-defining compilation unit to become a defining compilation unit, |
| 246 // we can create a correct summary by simply re-linking. | 249 // we can create a correct summary by simply re-linking. |
| 247 unlinkedUnit.publicNamespace = | 250 unlinkedUnit.publicNamespace = |
| 248 new UnlinkedPublicNamespaceBuilder(names: names); | 251 new UnlinkedPublicNamespaceBuilder(names: names); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 if (type is InterfaceType) { | 328 if (type is InterfaceType) { |
| 326 return type.typeArguments; | 329 return type.typeArguments; |
| 327 } else if (type is FunctionType) { | 330 } else if (type is FunctionType) { |
| 328 return type.typeArguments; | 331 return type.typeArguments; |
| 329 } else { | 332 } else { |
| 330 return null; | 333 return null; |
| 331 } | 334 } |
| 332 } | 335 } |
| 333 | 336 |
| 334 /** | 337 /** |
| 338 * Serialize annotations from the given [element]. If [element] has no |
| 339 * annotations, the empty list is returned. |
| 340 */ |
| 341 List<UnlinkedConstBuilder> serializeAnnotations(Element element) { |
| 342 if (element.metadata.isEmpty) { |
| 343 return const <UnlinkedConstBuilder>[]; |
| 344 } |
| 345 return element.metadata.map((ElementAnnotationImpl a) { |
| 346 _ConstExprSerializer serializer = new _ConstExprSerializer(this); |
| 347 serializer.serializeAnnotation(a.annotationAst); |
| 348 return serializer.toBuilder(); |
| 349 }).toList(); |
| 350 } |
| 351 |
| 352 /** |
| 335 * Serialize the given [classElement], creating an [UnlinkedClass]. | 353 * Serialize the given [classElement], creating an [UnlinkedClass]. |
| 336 */ | 354 */ |
| 337 UnlinkedClassBuilder serializeClass(ClassElement classElement) { | 355 UnlinkedClassBuilder serializeClass(ClassElement classElement) { |
| 338 UnlinkedClassBuilder b = new UnlinkedClassBuilder(); | 356 UnlinkedClassBuilder b = new UnlinkedClassBuilder(); |
| 339 b.name = classElement.name; | 357 b.name = classElement.name; |
| 340 b.nameOffset = classElement.nameOffset; | 358 b.nameOffset = classElement.nameOffset; |
| 341 b.typeParameters = | 359 b.typeParameters = |
| 342 classElement.typeParameters.map(serializeTypeParam).toList(); | 360 classElement.typeParameters.map(serializeTypeParam).toList(); |
| 343 if (classElement.supertype == null) { | 361 if (classElement.supertype == null) { |
| 344 b.hasNoSupertype = true; | 362 b.hasNoSupertype = true; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 369 if (field != null && !field.isSynthetic) { | 387 if (field != null && !field.isSynthetic) { |
| 370 fields.add(serializeVariable(field)); | 388 fields.add(serializeVariable(field)); |
| 371 } | 389 } |
| 372 } | 390 } |
| 373 } | 391 } |
| 374 b.fields = fields; | 392 b.fields = fields; |
| 375 b.executables = executables; | 393 b.executables = executables; |
| 376 b.isAbstract = classElement.isAbstract; | 394 b.isAbstract = classElement.isAbstract; |
| 377 b.isMixinApplication = classElement.isMixinApplication; | 395 b.isMixinApplication = classElement.isMixinApplication; |
| 378 b.documentationComment = serializeDocumentation(classElement); | 396 b.documentationComment = serializeDocumentation(classElement); |
| 397 b.annotations = serializeAnnotations(classElement); |
| 379 return b; | 398 return b; |
| 380 } | 399 } |
| 381 | 400 |
| 382 /** | 401 /** |
| 383 * If [cls] is a class, return the list of its members available for | 402 * If [cls] is a class, return the list of its members available for |
| 384 * constants - static constant fields, static methods and constructors. | 403 * constants - static constant fields, static methods and constructors. |
| 385 * Otherwise return `null`. | 404 * Otherwise return `null`. |
| 386 */ | 405 */ |
| 387 List<UnlinkedPublicNameBuilder> serializeClassConstMembers(ClassElement cls) { | 406 List<UnlinkedPublicNameBuilder> serializeClassConstMembers(ClassElement cls) { |
| 388 if (cls.kind == ElementKind.CLASS) { | 407 if (cls.kind == ElementKind.CLASS) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 for (FieldElement field in enumElement.fields) { | 488 for (FieldElement field in enumElement.fields) { |
| 470 if (field.isConst && field.type.element == enumElement) { | 489 if (field.isConst && field.type.element == enumElement) { |
| 471 values.add(new UnlinkedEnumValueBuilder( | 490 values.add(new UnlinkedEnumValueBuilder( |
| 472 name: field.name, | 491 name: field.name, |
| 473 nameOffset: field.nameOffset, | 492 nameOffset: field.nameOffset, |
| 474 documentationComment: serializeDocumentation(field))); | 493 documentationComment: serializeDocumentation(field))); |
| 475 } | 494 } |
| 476 } | 495 } |
| 477 b.values = values; | 496 b.values = values; |
| 478 b.documentationComment = serializeDocumentation(enumElement); | 497 b.documentationComment = serializeDocumentation(enumElement); |
| 498 b.annotations = serializeAnnotations(enumElement); |
| 479 return b; | 499 return b; |
| 480 } | 500 } |
| 481 | 501 |
| 482 /** | 502 /** |
| 483 * Serialize the given [executableElement], creating an [UnlinkedExecutable]. | 503 * Serialize the given [executableElement], creating an [UnlinkedExecutable]. |
| 484 */ | 504 */ |
| 485 UnlinkedExecutableBuilder serializeExecutable( | 505 UnlinkedExecutableBuilder serializeExecutable( |
| 486 ExecutableElement executableElement) { | 506 ExecutableElement executableElement) { |
| 487 UnlinkedExecutableBuilder b = new UnlinkedExecutableBuilder(); | 507 UnlinkedExecutableBuilder b = new UnlinkedExecutableBuilder(); |
| 488 b.name = executableElement.name; | 508 b.name = executableElement.name; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 511 b.isConst = executableElement.isConst; | 531 b.isConst = executableElement.isConst; |
| 512 b.isFactory = executableElement.isFactory; | 532 b.isFactory = executableElement.isFactory; |
| 513 } else { | 533 } else { |
| 514 b.kind = UnlinkedExecutableKind.functionOrMethod; | 534 b.kind = UnlinkedExecutableKind.functionOrMethod; |
| 515 } | 535 } |
| 516 b.isAbstract = executableElement.isAbstract; | 536 b.isAbstract = executableElement.isAbstract; |
| 517 b.isStatic = executableElement.isStatic && | 537 b.isStatic = executableElement.isStatic && |
| 518 executableElement.enclosingElement is ClassElement; | 538 executableElement.enclosingElement is ClassElement; |
| 519 b.isExternal = executableElement.isExternal; | 539 b.isExternal = executableElement.isExternal; |
| 520 b.documentationComment = serializeDocumentation(executableElement); | 540 b.documentationComment = serializeDocumentation(executableElement); |
| 541 b.annotations = serializeAnnotations(executableElement); |
| 521 return b; | 542 return b; |
| 522 } | 543 } |
| 523 | 544 |
| 524 /** | 545 /** |
| 525 * Serialize the given [exportElement] into an [UnlinkedExportNonPublic]. | 546 * Serialize the given [exportElement] into an [UnlinkedExportNonPublic]. |
| 526 */ | 547 */ |
| 527 UnlinkedExportNonPublicBuilder serializeExportNonPublic( | 548 UnlinkedExportNonPublicBuilder serializeExportNonPublic( |
| 528 ExportElement exportElement) { | 549 ExportElement exportElement) { |
| 529 UnlinkedExportNonPublicBuilder b = new UnlinkedExportNonPublicBuilder(); | 550 UnlinkedExportNonPublicBuilder b = new UnlinkedExportNonPublicBuilder(); |
| 530 b.offset = exportElement.nameOffset; | 551 b.offset = exportElement.nameOffset; |
| 531 b.uriOffset = exportElement.uriOffset; | 552 b.uriOffset = exportElement.uriOffset; |
| 532 b.uriEnd = exportElement.uriEnd; | 553 b.uriEnd = exportElement.uriEnd; |
| 554 b.annotations = serializeAnnotations(exportElement); |
| 533 return b; | 555 return b; |
| 534 } | 556 } |
| 535 | 557 |
| 536 /** | 558 /** |
| 537 * Serialize the given [exportElement] into an [UnlinkedExportPublic]. | 559 * Serialize the given [exportElement] into an [UnlinkedExportPublic]. |
| 538 */ | 560 */ |
| 539 UnlinkedExportPublicBuilder serializeExportPublic( | 561 UnlinkedExportPublicBuilder serializeExportPublic( |
| 540 ExportElement exportElement) { | 562 ExportElement exportElement) { |
| 541 UnlinkedExportPublicBuilder b = new UnlinkedExportPublicBuilder(); | 563 UnlinkedExportPublicBuilder b = new UnlinkedExportPublicBuilder(); |
| 542 b.uri = exportElement.uri; | 564 b.uri = exportElement.uri; |
| 543 b.combinators = exportElement.combinators.map(serializeCombinator).toList(); | 565 b.combinators = exportElement.combinators.map(serializeCombinator).toList(); |
| 544 return b; | 566 return b; |
| 545 } | 567 } |
| 546 | 568 |
| 547 /** | 569 /** |
| 548 * Serialize the given [importElement] yielding an [UnlinkedImportBuilder]. | 570 * Serialize the given [importElement] yielding an [UnlinkedImportBuilder]. |
| 549 * Also, add linked information about it to the [linkedImports] list. | 571 * Also, add linked information about it to the [linkedImports] list. |
| 550 */ | 572 */ |
| 551 UnlinkedImportBuilder serializeImport(ImportElement importElement) { | 573 UnlinkedImportBuilder serializeImport(ImportElement importElement) { |
| 552 UnlinkedImportBuilder b = new UnlinkedImportBuilder(); | 574 UnlinkedImportBuilder b = new UnlinkedImportBuilder(); |
| 575 b.annotations = serializeAnnotations(importElement); |
| 553 b.isDeferred = importElement.isDeferred; | 576 b.isDeferred = importElement.isDeferred; |
| 554 b.combinators = importElement.combinators.map(serializeCombinator).toList(); | 577 b.combinators = importElement.combinators.map(serializeCombinator).toList(); |
| 555 if (importElement.prefix != null) { | 578 if (importElement.prefix != null) { |
| 556 b.prefixReference = serializePrefix(importElement.prefix); | 579 b.prefixReference = serializePrefix(importElement.prefix); |
| 557 b.prefixOffset = importElement.prefix.nameOffset; | 580 b.prefixOffset = importElement.prefix.nameOffset; |
| 558 } | 581 } |
| 559 if (importElement.isSynthetic) { | 582 if (importElement.isSynthetic) { |
| 560 b.isImplicit = true; | 583 b.isImplicit = true; |
| 561 } else { | 584 } else { |
| 562 b.offset = importElement.nameOffset; | 585 b.offset = importElement.nameOffset; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 580 case ParameterKind.REQUIRED: | 603 case ParameterKind.REQUIRED: |
| 581 b.kind = UnlinkedParamKind.required; | 604 b.kind = UnlinkedParamKind.required; |
| 582 break; | 605 break; |
| 583 case ParameterKind.POSITIONAL: | 606 case ParameterKind.POSITIONAL: |
| 584 b.kind = UnlinkedParamKind.positional; | 607 b.kind = UnlinkedParamKind.positional; |
| 585 break; | 608 break; |
| 586 case ParameterKind.NAMED: | 609 case ParameterKind.NAMED: |
| 587 b.kind = UnlinkedParamKind.named; | 610 b.kind = UnlinkedParamKind.named; |
| 588 break; | 611 break; |
| 589 } | 612 } |
| 613 b.annotations = serializeAnnotations(parameter); |
| 590 b.isInitializingFormal = parameter.isInitializingFormal; | 614 b.isInitializingFormal = parameter.isInitializingFormal; |
| 591 DartType type = parameter.type; | 615 DartType type = parameter.type; |
| 592 if (parameter.hasImplicitType) { | 616 if (parameter.hasImplicitType) { |
| 593 Element contextParent = context.enclosingElement; | 617 Element contextParent = context.enclosingElement; |
| 594 if (!parameter.isInitializingFormal && | 618 if (!parameter.isInitializingFormal && |
| 595 contextParent is ExecutableElement && | 619 contextParent is ExecutableElement && |
| 596 !contextParent.isStatic && | 620 !contextParent.isStatic && |
| 597 contextParent is! ConstructorElement) { | 621 contextParent is! ConstructorElement) { |
| 598 b.inferredTypeSlot = storeInferredType(type, context); | 622 b.inferredTypeSlot = storeInferredType(type, context); |
| 599 } | 623 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 UnlinkedTypedefBuilder serializeTypedef( | 682 UnlinkedTypedefBuilder serializeTypedef( |
| 659 FunctionTypeAliasElement typedefElement) { | 683 FunctionTypeAliasElement typedefElement) { |
| 660 UnlinkedTypedefBuilder b = new UnlinkedTypedefBuilder(); | 684 UnlinkedTypedefBuilder b = new UnlinkedTypedefBuilder(); |
| 661 b.name = typedefElement.name; | 685 b.name = typedefElement.name; |
| 662 b.nameOffset = typedefElement.nameOffset; | 686 b.nameOffset = typedefElement.nameOffset; |
| 663 b.typeParameters = | 687 b.typeParameters = |
| 664 typedefElement.typeParameters.map(serializeTypeParam).toList(); | 688 typedefElement.typeParameters.map(serializeTypeParam).toList(); |
| 665 b.returnType = serializeTypeRef(typedefElement.returnType, typedefElement); | 689 b.returnType = serializeTypeRef(typedefElement.returnType, typedefElement); |
| 666 b.parameters = typedefElement.parameters.map(serializeParam).toList(); | 690 b.parameters = typedefElement.parameters.map(serializeParam).toList(); |
| 667 b.documentationComment = serializeDocumentation(typedefElement); | 691 b.documentationComment = serializeDocumentation(typedefElement); |
| 692 b.annotations = serializeAnnotations(typedefElement); |
| 668 return b; | 693 return b; |
| 669 } | 694 } |
| 670 | 695 |
| 671 /** | 696 /** |
| 672 * Serialize the given [typeParameter] into an [UnlinkedTypeParam]. | 697 * Serialize the given [typeParameter] into an [UnlinkedTypeParam]. |
| 673 */ | 698 */ |
| 674 UnlinkedTypeParamBuilder serializeTypeParam( | 699 UnlinkedTypeParamBuilder serializeTypeParam( |
| 675 TypeParameterElement typeParameter) { | 700 TypeParameterElement typeParameter) { |
| 676 UnlinkedTypeParamBuilder b = new UnlinkedTypeParamBuilder(); | 701 UnlinkedTypeParamBuilder b = new UnlinkedTypeParamBuilder(); |
| 677 b.name = typeParameter.name; | 702 b.name = typeParameter.name; |
| 678 b.nameOffset = typeParameter.nameOffset; | 703 b.nameOffset = typeParameter.nameOffset; |
| 679 if (typeParameter.bound != null) { | 704 if (typeParameter.bound != null) { |
| 680 b.bound = serializeTypeRef(typeParameter.bound, typeParameter); | 705 b.bound = serializeTypeRef(typeParameter.bound, typeParameter); |
| 681 } | 706 } |
| 707 b.annotations = serializeAnnotations(typeParameter); |
| 682 return b; | 708 return b; |
| 683 } | 709 } |
| 684 | 710 |
| 685 /** | 711 /** |
| 686 * Serialize the given [type] into a [EntityRef]. If [slot] is provided, | 712 * Serialize the given [type] into a [EntityRef]. If [slot] is provided, |
| 687 * it should be included in the [EntityRef]. If [linked] is true, any | 713 * it should be included in the [EntityRef]. If [linked] is true, any |
| 688 * references that are created will be populated into [linkedReferences] but | 714 * references that are created will be populated into [linkedReferences] but |
| 689 * not [unlinkedReferences]. | 715 * not [unlinkedReferences]. |
| 690 * | 716 * |
| 691 * [context] is the element within which the [EntityRef] will be | 717 * [context] is the element within which the [EntityRef] will be |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder(); | 803 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder(); |
| 778 b.name = variable.name; | 804 b.name = variable.name; |
| 779 b.nameOffset = variable.nameOffset; | 805 b.nameOffset = variable.nameOffset; |
| 780 if (!variable.hasImplicitType) { | 806 if (!variable.hasImplicitType) { |
| 781 b.type = serializeTypeRef(variable.type, variable); | 807 b.type = serializeTypeRef(variable.type, variable); |
| 782 } | 808 } |
| 783 b.isStatic = variable.isStatic && variable.enclosingElement is ClassElement; | 809 b.isStatic = variable.isStatic && variable.enclosingElement is ClassElement; |
| 784 b.isFinal = variable.isFinal; | 810 b.isFinal = variable.isFinal; |
| 785 b.isConst = variable.isConst; | 811 b.isConst = variable.isConst; |
| 786 b.documentationComment = serializeDocumentation(variable); | 812 b.documentationComment = serializeDocumentation(variable); |
| 813 b.annotations = serializeAnnotations(variable); |
| 787 if (variable is ConstVariableElement) { | 814 if (variable is ConstVariableElement) { |
| 788 ConstVariableElement constVariable = variable as ConstVariableElement; | 815 ConstVariableElement constVariable = variable as ConstVariableElement; |
| 789 Expression initializer = constVariable.constantInitializer; | 816 Expression initializer = constVariable.constantInitializer; |
| 790 if (initializer != null) { | 817 if (initializer != null) { |
| 791 b.constExpr = serializeConstExpr(initializer); | 818 b.constExpr = serializeConstExpr(initializer); |
| 792 } | 819 } |
| 793 } | 820 } |
| 794 if (b.isFinal || b.isConst) { | 821 if (b.isFinal || b.isConst) { |
| 795 b.propagatedTypeSlot = storeLinkedType(variable.propagatedType, variable); | 822 b.propagatedTypeSlot = storeLinkedType(variable.propagatedType, variable); |
| 796 } else { | 823 } else { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 /** | 939 /** |
| 913 * Instances of this class keep track of intermediate state during | 940 * Instances of this class keep track of intermediate state during |
| 914 * serialization of a single constant [Expression]. | 941 * serialization of a single constant [Expression]. |
| 915 */ | 942 */ |
| 916 class _ConstExprSerializer extends AbstractConstExprSerializer { | 943 class _ConstExprSerializer extends AbstractConstExprSerializer { |
| 917 final _CompilationUnitSerializer serializer; | 944 final _CompilationUnitSerializer serializer; |
| 918 | 945 |
| 919 _ConstExprSerializer(this.serializer); | 946 _ConstExprSerializer(this.serializer); |
| 920 | 947 |
| 921 @override | 948 @override |
| 922 EntityRefBuilder serializeConstructorName(ConstructorName constructor) { | 949 void serializeAnnotation(Annotation annotation) { |
| 923 DartType type = constructor.type.type; | 950 if (annotation.arguments == null) { |
| 924 EntityRefBuilder typeRef = serializer.serializeTypeRef(type, null); | 951 assert(annotation.constructorName == null); |
| 925 if (constructor.name == null) { | 952 serialize(annotation.name); |
| 953 } else { |
| 954 Identifier name = annotation.name; |
| 955 Element nameElement = name.staticElement; |
| 956 EntityRefBuilder constructor; |
| 957 if (nameElement is ConstructorElement && name is PrefixedIdentifier) { |
| 958 assert(annotation.constructorName == null); |
| 959 constructor = serializeConstructorName( |
| 960 new TypeName(name.prefix, null)..type = nameElement.returnType, |
| 961 name.identifier); |
| 962 } else if (nameElement is TypeDefiningElement) { |
| 963 constructor = serializeConstructorName( |
| 964 new TypeName(annotation.name, null)..type = nameElement.type, |
| 965 annotation.constructorName); |
| 966 } else { |
| 967 throw new StateError('Unexpected annotation nameElement type:' |
| 968 ' ${nameElement.runtimeType}'); |
| 969 } |
| 970 serializeInstanceCreation(constructor, annotation.arguments); |
| 971 } |
| 972 } |
| 973 |
| 974 @override |
| 975 EntityRefBuilder serializeConstructorName( |
| 976 TypeName type, SimpleIdentifier name) { |
| 977 EntityRefBuilder typeRef = serializer.serializeTypeRef(type.type, null); |
| 978 if (name == null) { |
| 926 return typeRef; | 979 return typeRef; |
| 927 } else { | 980 } else { |
| 928 int typeId = typeRef.reference; | 981 int typeId = typeRef.reference; |
| 929 LinkedReference typeLinkedRef = serializer.linkedReferences[typeId]; | 982 LinkedReference typeLinkedRef = serializer.linkedReferences[typeId]; |
| 930 serializer.unlinkedReferences.add(new UnlinkedReferenceBuilder( | 983 serializer.unlinkedReferences.add(new UnlinkedReferenceBuilder( |
| 931 name: constructor.name.name, prefixReference: typeId)); | 984 name: name.name, prefixReference: typeId)); |
| 932 int refId = serializer.linkedReferences.length; | 985 int refId = serializer.linkedReferences.length; |
| 933 serializer.linkedReferences.add(new LinkedReferenceBuilder( | 986 serializer.linkedReferences.add(new LinkedReferenceBuilder( |
| 934 kind: ReferenceKind.constructor, | 987 kind: ReferenceKind.constructor, unit: typeLinkedRef.unit)); |
| 935 unit: typeLinkedRef.unit)); | |
| 936 return new EntityRefBuilder( | 988 return new EntityRefBuilder( |
| 937 reference: refId, typeArguments: typeRef.typeArguments); | 989 reference: refId, typeArguments: typeRef.typeArguments); |
| 938 } | 990 } |
| 939 } | 991 } |
| 940 | 992 |
| 941 EntityRefBuilder serializeIdentifier(Identifier identifier) { | 993 EntityRefBuilder serializeIdentifier(Identifier identifier) { |
| 942 Element element = identifier.staticElement; | 994 Element element = identifier.staticElement; |
| 943 assert(element != null); | 995 assert(element != null); |
| 944 // The only supported instance property accessor - `length`. | 996 // The only supported instance property accessor - `length`. |
| 945 if (identifier is PrefixedIdentifier && | 997 if (identifier is PrefixedIdentifier && |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1164 exportNames.add(new LinkedExportNameBuilder( | 1216 exportNames.add(new LinkedExportNameBuilder( |
| 1165 name: name, | 1217 name: name, |
| 1166 dependency: serializeDependency(dependentLibrary), | 1218 dependency: serializeDependency(dependentLibrary), |
| 1167 unit: unit, | 1219 unit: unit, |
| 1168 kind: kind)); | 1220 kind: kind)); |
| 1169 } | 1221 } |
| 1170 pb.exportNames = exportNames; | 1222 pb.exportNames = exportNames; |
| 1171 return pb; | 1223 return pb; |
| 1172 } | 1224 } |
| 1173 } | 1225 } |
| OLD | NEW |