| 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/type.dart'; | 9 import 'package:analyzer/src/dart/element/type.dart'; |
| 10 import 'package:analyzer/src/generated/resolver.dart'; | 10 import 'package:analyzer/src/generated/resolver.dart'; |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 kind: PrelinkedReferenceKind.typedef, | 200 kind: PrelinkedReferenceKind.typedef, |
| 201 name: typedef.name, | 201 name: typedef.name, |
| 202 numTypeParameters: typedef.typeParameters.length)); | 202 numTypeParameters: typedef.typeParameters.length)); |
| 203 } | 203 } |
| 204 } | 204 } |
| 205 if (unitNum == 0) { | 205 if (unitNum == 0) { |
| 206 if (libraryElement.name.isNotEmpty) { | 206 if (libraryElement.name.isNotEmpty) { |
| 207 b.libraryName = libraryElement.name; | 207 b.libraryName = libraryElement.name; |
| 208 b.libraryNameOffset = libraryElement.nameOffset; | 208 b.libraryNameOffset = libraryElement.nameOffset; |
| 209 b.libraryNameLength = libraryElement.nameLength; | 209 b.libraryNameLength = libraryElement.nameLength; |
| 210 b.libraryDocumentationComment = serializeDocumentation(libraryElement); |
| 210 } | 211 } |
| 211 b.publicNamespace = encodeUnlinkedPublicNamespace(ctx, | 212 b.publicNamespace = encodeUnlinkedPublicNamespace(ctx, |
| 212 exports: libraryElement.exports.map(serializeExportPublic).toList(), | 213 exports: libraryElement.exports.map(serializeExportPublic).toList(), |
| 213 parts: libraryElement.parts | 214 parts: libraryElement.parts |
| 214 .map((CompilationUnitElement e) => e.uri) | 215 .map((CompilationUnitElement e) => e.uri) |
| 215 .toList(), | 216 .toList(), |
| 216 names: names); | 217 names: names); |
| 217 b.exports = libraryElement.exports.map(serializeExportNonPublic).toList(); | 218 b.exports = libraryElement.exports.map(serializeExportNonPublic).toList(); |
| 218 b.imports = libraryElement.imports.map(serializeImport).toList(); | 219 b.imports = libraryElement.imports.map(serializeImport).toList(); |
| 219 b.parts = libraryElement.parts | 220 b.parts = libraryElement.parts |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 PropertyInducingElement field = accessor.variable; | 341 PropertyInducingElement field = accessor.variable; |
| 341 if (field != null && !field.isSynthetic) { | 342 if (field != null && !field.isSynthetic) { |
| 342 fields.add(serializeVariable(field)); | 343 fields.add(serializeVariable(field)); |
| 343 } | 344 } |
| 344 } | 345 } |
| 345 } | 346 } |
| 346 b.fields = fields; | 347 b.fields = fields; |
| 347 b.executables = executables; | 348 b.executables = executables; |
| 348 b.isAbstract = classElement.isAbstract; | 349 b.isAbstract = classElement.isAbstract; |
| 349 b.isMixinApplication = classElement.isMixinApplication; | 350 b.isMixinApplication = classElement.isMixinApplication; |
| 351 b.documentationComment = serializeDocumentation(classElement); |
| 350 return b; | 352 return b; |
| 351 } | 353 } |
| 352 | 354 |
| 353 /** | 355 /** |
| 354 * Serialize the given [combinator] into an [UnlinkedCombinator]. | 356 * Serialize the given [combinator] into an [UnlinkedCombinator]. |
| 355 */ | 357 */ |
| 356 UnlinkedCombinatorBuilder serializeCombinator( | 358 UnlinkedCombinatorBuilder serializeCombinator( |
| 357 NamespaceCombinator combinator) { | 359 NamespaceCombinator combinator) { |
| 358 UnlinkedCombinatorBuilder b = new UnlinkedCombinatorBuilder(ctx); | 360 UnlinkedCombinatorBuilder b = new UnlinkedCombinatorBuilder(ctx); |
| 359 if (combinator is ShowElementCombinator) { | 361 if (combinator is ShowElementCombinator) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 372 int serializeDependency(LibraryElement dependentLibrary) { | 374 int serializeDependency(LibraryElement dependentLibrary) { |
| 373 return dependencyMap.putIfAbsent(dependentLibrary, () { | 375 return dependencyMap.putIfAbsent(dependentLibrary, () { |
| 374 int index = dependencies.length; | 376 int index = dependencies.length; |
| 375 dependencies.add(encodePrelinkedDependency(ctx, | 377 dependencies.add(encodePrelinkedDependency(ctx, |
| 376 uri: dependentLibrary.source.uri.toString())); | 378 uri: dependentLibrary.source.uri.toString())); |
| 377 return index; | 379 return index; |
| 378 }); | 380 }); |
| 379 } | 381 } |
| 380 | 382 |
| 381 /** | 383 /** |
| 384 * Serialize documentation from the given [element], creating an |
| 385 * [UnlinkedDocumentationComment]. |
| 386 * |
| 387 * If [element] has no documentation, `null` is returned. |
| 388 */ |
| 389 UnlinkedDocumentationCommentBuilder serializeDocumentation(Element element) { |
| 390 if (element.documentationComment == null) { |
| 391 return null; |
| 392 } |
| 393 return encodeUnlinkedDocumentationComment(ctx, |
| 394 text: element.documentationComment); |
| 395 } |
| 396 |
| 397 /** |
| 382 * Return the index of the entry in the references table | 398 * Return the index of the entry in the references table |
| 383 * ([UnlinkedLibrary.references] and [PrelinkedLibrary.references]) | 399 * ([UnlinkedLibrary.references] and [PrelinkedLibrary.references]) |
| 384 * representing the pseudo-type `dynamic`. | 400 * representing the pseudo-type `dynamic`. |
| 385 */ | 401 */ |
| 386 int serializeDynamicReference() => 0; | 402 int serializeDynamicReference() => 0; |
| 387 | 403 |
| 388 /** | 404 /** |
| 389 * Serialize the given [enumElement], creating an [UnlinkedEnum]. | 405 * Serialize the given [enumElement], creating an [UnlinkedEnum]. |
| 390 */ | 406 */ |
| 391 UnlinkedEnumBuilder serializeEnum(ClassElement enumElement) { | 407 UnlinkedEnumBuilder serializeEnum(ClassElement enumElement) { |
| 392 UnlinkedEnumBuilder b = new UnlinkedEnumBuilder(ctx); | 408 UnlinkedEnumBuilder b = new UnlinkedEnumBuilder(ctx); |
| 393 b.name = enumElement.name; | 409 b.name = enumElement.name; |
| 394 b.nameOffset = enumElement.nameOffset; | 410 b.nameOffset = enumElement.nameOffset; |
| 395 List<UnlinkedEnumValueBuilder> values = <UnlinkedEnumValueBuilder>[]; | 411 List<UnlinkedEnumValueBuilder> values = <UnlinkedEnumValueBuilder>[]; |
| 396 for (FieldElement field in enumElement.fields) { | 412 for (FieldElement field in enumElement.fields) { |
| 397 if (field.isConst && field.type.element == enumElement) { | 413 if (field.isConst && field.type.element == enumElement) { |
| 398 values.add(encodeUnlinkedEnumValue(ctx, | 414 values.add(encodeUnlinkedEnumValue(ctx, |
| 399 name: field.name, nameOffset: field.nameOffset)); | 415 name: field.name, |
| 416 nameOffset: field.nameOffset, |
| 417 documentationComment: serializeDocumentation(field))); |
| 400 } | 418 } |
| 401 } | 419 } |
| 402 b.values = values; | 420 b.values = values; |
| 421 b.documentationComment = serializeDocumentation(enumElement); |
| 403 return b; | 422 return b; |
| 404 } | 423 } |
| 405 | 424 |
| 406 /** | 425 /** |
| 407 * Serialize the given [executableElement], creating an [UnlinkedExecutable]. | 426 * Serialize the given [executableElement], creating an [UnlinkedExecutable]. |
| 408 */ | 427 */ |
| 409 UnlinkedExecutableBuilder serializeExecutable( | 428 UnlinkedExecutableBuilder serializeExecutable( |
| 410 ExecutableElement executableElement) { | 429 ExecutableElement executableElement) { |
| 411 UnlinkedExecutableBuilder b = new UnlinkedExecutableBuilder(ctx); | 430 UnlinkedExecutableBuilder b = new UnlinkedExecutableBuilder(ctx); |
| 412 b.name = executableElement.name; | 431 b.name = executableElement.name; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 431 b.isConst = executableElement.isConst; | 450 b.isConst = executableElement.isConst; |
| 432 b.isFactory = executableElement.isFactory; | 451 b.isFactory = executableElement.isFactory; |
| 433 } else { | 452 } else { |
| 434 b.kind = UnlinkedExecutableKind.functionOrMethod; | 453 b.kind = UnlinkedExecutableKind.functionOrMethod; |
| 435 } | 454 } |
| 436 b.isAbstract = executableElement.isAbstract; | 455 b.isAbstract = executableElement.isAbstract; |
| 437 b.isStatic = executableElement.isStatic && | 456 b.isStatic = executableElement.isStatic && |
| 438 executableElement.enclosingElement is ClassElement; | 457 executableElement.enclosingElement is ClassElement; |
| 439 b.hasImplicitReturnType = executableElement.hasImplicitReturnType; | 458 b.hasImplicitReturnType = executableElement.hasImplicitReturnType; |
| 440 b.isExternal = executableElement.isExternal; | 459 b.isExternal = executableElement.isExternal; |
| 460 b.documentationComment = serializeDocumentation(executableElement); |
| 441 return b; | 461 return b; |
| 442 } | 462 } |
| 443 | 463 |
| 444 /** | 464 /** |
| 445 * Serialize the given [exportElement] into an [UnlinkedExportNonPublic]. | 465 * Serialize the given [exportElement] into an [UnlinkedExportNonPublic]. |
| 446 */ | 466 */ |
| 447 UnlinkedExportNonPublicBuilder serializeExportNonPublic( | 467 UnlinkedExportNonPublicBuilder serializeExportNonPublic( |
| 448 ExportElement exportElement) { | 468 ExportElement exportElement) { |
| 449 UnlinkedExportNonPublicBuilder b = new UnlinkedExportNonPublicBuilder(ctx); | 469 UnlinkedExportNonPublicBuilder b = new UnlinkedExportNonPublicBuilder(ctx); |
| 450 b.offset = exportElement.nameOffset; | 470 b.offset = exportElement.nameOffset; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 UnlinkedTypedefBuilder b = new UnlinkedTypedefBuilder(ctx); | 587 UnlinkedTypedefBuilder b = new UnlinkedTypedefBuilder(ctx); |
| 568 b.name = typedefElement.name; | 588 b.name = typedefElement.name; |
| 569 b.nameOffset = typedefElement.nameOffset; | 589 b.nameOffset = typedefElement.nameOffset; |
| 570 b.typeParameters = | 590 b.typeParameters = |
| 571 typedefElement.typeParameters.map(serializeTypeParam).toList(); | 591 typedefElement.typeParameters.map(serializeTypeParam).toList(); |
| 572 if (!typedefElement.returnType.isVoid) { | 592 if (!typedefElement.returnType.isVoid) { |
| 573 b.returnType = | 593 b.returnType = |
| 574 serializeTypeRef(typedefElement.returnType, typedefElement); | 594 serializeTypeRef(typedefElement.returnType, typedefElement); |
| 575 } | 595 } |
| 576 b.parameters = typedefElement.parameters.map(serializeParam).toList(); | 596 b.parameters = typedefElement.parameters.map(serializeParam).toList(); |
| 597 b.documentationComment = serializeDocumentation(typedefElement); |
| 577 return b; | 598 return b; |
| 578 } | 599 } |
| 579 | 600 |
| 580 /** | 601 /** |
| 581 * Serialize the given [typeParameter] into an [UnlinkedTypeParam]. | 602 * Serialize the given [typeParameter] into an [UnlinkedTypeParam]. |
| 582 */ | 603 */ |
| 583 UnlinkedTypeParamBuilder serializeTypeParam( | 604 UnlinkedTypeParamBuilder serializeTypeParam( |
| 584 TypeParameterElement typeParameter) { | 605 TypeParameterElement typeParameter) { |
| 585 UnlinkedTypeParamBuilder b = new UnlinkedTypeParamBuilder(ctx); | 606 UnlinkedTypeParamBuilder b = new UnlinkedTypeParamBuilder(ctx); |
| 586 b.name = typeParameter.name; | 607 b.name = typeParameter.name; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 */ | 695 */ |
| 675 UnlinkedVariableBuilder serializeVariable(PropertyInducingElement variable) { | 696 UnlinkedVariableBuilder serializeVariable(PropertyInducingElement variable) { |
| 676 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder(ctx); | 697 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder(ctx); |
| 677 b.name = variable.name; | 698 b.name = variable.name; |
| 678 b.nameOffset = variable.nameOffset; | 699 b.nameOffset = variable.nameOffset; |
| 679 b.type = serializeTypeRef(variable.type, variable); | 700 b.type = serializeTypeRef(variable.type, variable); |
| 680 b.isStatic = variable.isStatic && variable.enclosingElement is ClassElement; | 701 b.isStatic = variable.isStatic && variable.enclosingElement is ClassElement; |
| 681 b.isFinal = variable.isFinal; | 702 b.isFinal = variable.isFinal; |
| 682 b.isConst = variable.isConst; | 703 b.isConst = variable.isConst; |
| 683 b.hasImplicitType = variable.hasImplicitType; | 704 b.hasImplicitType = variable.hasImplicitType; |
| 705 b.documentationComment = serializeDocumentation(variable); |
| 684 return b; | 706 return b; |
| 685 } | 707 } |
| 686 } | 708 } |
| OLD | NEW |