| 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 name: accessor.name, | 176 name: accessor.name, |
| 177 numTypeParameters: accessor.typeParameters.length)); | 177 numTypeParameters: accessor.typeParameters.length)); |
| 178 } | 178 } |
| 179 } | 179 } |
| 180 for (ClassElement cls in compilationUnit.types) { | 180 for (ClassElement cls in compilationUnit.types) { |
| 181 if (cls.isPublic) { | 181 if (cls.isPublic) { |
| 182 names.add(new UnlinkedPublicNameBuilder( | 182 names.add(new UnlinkedPublicNameBuilder( |
| 183 kind: ReferenceKind.classOrEnum, | 183 kind: ReferenceKind.classOrEnum, |
| 184 name: cls.name, | 184 name: cls.name, |
| 185 numTypeParameters: cls.typeParameters.length, | 185 numTypeParameters: cls.typeParameters.length, |
| 186 executables: serializePublicStaticMethodsAndConstructors(cls))); | 186 constMembers: serializeClassConstMembers(cls))); |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 for (ClassElement enm in compilationUnit.enums) { | 189 for (ClassElement enm in compilationUnit.enums) { |
| 190 if (enm.isPublic) { | 190 if (enm.isPublic) { |
| 191 names.add(new UnlinkedPublicNameBuilder( | 191 names.add(new UnlinkedPublicNameBuilder( |
| 192 kind: ReferenceKind.classOrEnum, name: enm.name)); | 192 kind: ReferenceKind.classOrEnum, name: enm.name)); |
| 193 } | 193 } |
| 194 } | 194 } |
| 195 for (FunctionElement function in compilationUnit.functions) { | 195 for (FunctionElement function in compilationUnit.functions) { |
| 196 if (function.isPublic) { | 196 if (function.isPublic) { |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 } | 369 } |
| 370 b.fields = fields; | 370 b.fields = fields; |
| 371 b.executables = executables; | 371 b.executables = executables; |
| 372 b.isAbstract = classElement.isAbstract; | 372 b.isAbstract = classElement.isAbstract; |
| 373 b.isMixinApplication = classElement.isMixinApplication; | 373 b.isMixinApplication = classElement.isMixinApplication; |
| 374 b.documentationComment = serializeDocumentation(classElement); | 374 b.documentationComment = serializeDocumentation(classElement); |
| 375 return b; | 375 return b; |
| 376 } | 376 } |
| 377 | 377 |
| 378 /** | 378 /** |
| 379 * If [cls] is a class, return the list of its members available for |
| 380 * constants - static constant fields, static methods and constructors. |
| 381 * Otherwise return `null`. |
| 382 */ |
| 383 List<UnlinkedPublicNameBuilder> serializeClassConstMembers(ClassElement cls) { |
| 384 if (cls.kind == ElementKind.CLASS) { |
| 385 List<UnlinkedPublicNameBuilder> bs = <UnlinkedPublicNameBuilder>[]; |
| 386 for (FieldElement field in cls.fields) { |
| 387 if (field.isStatic && field.isConst && field.isPublic) { |
| 388 bs.add(new UnlinkedPublicNameBuilder( |
| 389 name: field.name, |
| 390 kind: ReferenceKind.constField, |
| 391 numTypeParameters: 0)); |
| 392 } |
| 393 } |
| 394 for (MethodElement method in cls.methods) { |
| 395 if (method.isStatic && method.isPublic) { |
| 396 bs.add(new UnlinkedPublicNameBuilder( |
| 397 name: method.name, |
| 398 kind: ReferenceKind.staticMethod, |
| 399 numTypeParameters: method.typeParameters.length)); |
| 400 } |
| 401 } |
| 402 for (ConstructorElement constructor in cls.constructors) { |
| 403 if (constructor.isConst && constructor.isPublic) { |
| 404 bs.add(new UnlinkedPublicNameBuilder( |
| 405 name: constructor.name, |
| 406 kind: ReferenceKind.constructor, |
| 407 numTypeParameters: 0)); |
| 408 } |
| 409 } |
| 410 return bs; |
| 411 } |
| 412 return null; |
| 413 } |
| 414 |
| 415 /** |
| 379 * Serialize the given [combinator] into an [UnlinkedCombinator]. | 416 * Serialize the given [combinator] into an [UnlinkedCombinator]. |
| 380 */ | 417 */ |
| 381 UnlinkedCombinatorBuilder serializeCombinator( | 418 UnlinkedCombinatorBuilder serializeCombinator( |
| 382 NamespaceCombinator combinator) { | 419 NamespaceCombinator combinator) { |
| 383 UnlinkedCombinatorBuilder b = new UnlinkedCombinatorBuilder(); | 420 UnlinkedCombinatorBuilder b = new UnlinkedCombinatorBuilder(); |
| 384 if (combinator is ShowElementCombinator) { | 421 if (combinator is ShowElementCombinator) { |
| 385 b.shows = combinator.shownNames; | 422 b.shows = combinator.shownNames; |
| 386 } else if (combinator is HideElementCombinator) { | 423 } else if (combinator is HideElementCombinator) { |
| 387 b.hides = combinator.hiddenNames; | 424 b.hides = combinator.hiddenNames; |
| 388 } | 425 } |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 assert(unlinkedReferences.length == linkedReferences.length); | 612 assert(unlinkedReferences.length == linkedReferences.length); |
| 576 int index = unlinkedReferences.length; | 613 int index = unlinkedReferences.length; |
| 577 unlinkedReferences.add(new UnlinkedReferenceBuilder(name: element.name)); | 614 unlinkedReferences.add(new UnlinkedReferenceBuilder(name: element.name)); |
| 578 linkedReferences | 615 linkedReferences |
| 579 .add(new LinkedReferenceBuilder(kind: ReferenceKind.prefix)); | 616 .add(new LinkedReferenceBuilder(kind: ReferenceKind.prefix)); |
| 580 return index; | 617 return index; |
| 581 }); | 618 }); |
| 582 } | 619 } |
| 583 | 620 |
| 584 /** | 621 /** |
| 585 * If [cls] is a class, return the list of its public static methods and | |
| 586 * constructors. Otherwise return `null`. | |
| 587 */ | |
| 588 List<UnlinkedPublicNameBuilder> serializePublicStaticMethodsAndConstructors( | |
| 589 ClassElement cls) { | |
| 590 if (cls.kind == ElementKind.CLASS) { | |
| 591 List<UnlinkedPublicNameBuilder> bs = <UnlinkedPublicNameBuilder>[]; | |
| 592 for (MethodElement method in cls.methods) { | |
| 593 if (method.isStatic && method.isPublic) { | |
| 594 bs.add(new UnlinkedPublicNameBuilder( | |
| 595 name: method.name, | |
| 596 kind: ReferenceKind.staticMethod, | |
| 597 numTypeParameters: method.typeParameters.length)); | |
| 598 } | |
| 599 } | |
| 600 for (ConstructorElement constructor in cls.constructors) { | |
| 601 if (constructor.isPublic && !constructor.isSynthetic) { | |
| 602 bs.add(new UnlinkedPublicNameBuilder( | |
| 603 name: constructor.name, | |
| 604 kind: ReferenceKind.constructor, | |
| 605 numTypeParameters: 0)); | |
| 606 } | |
| 607 } | |
| 608 return bs; | |
| 609 } | |
| 610 return null; | |
| 611 } | |
| 612 | |
| 613 /** | |
| 614 * Compute the reference index which should be stored in a [EntityRef]. | 622 * Compute the reference index which should be stored in a [EntityRef]. |
| 615 * | 623 * |
| 616 * If [linked] is true, and a new reference has to be created, the reference | 624 * If [linked] is true, and a new reference has to be created, the reference |
| 617 * will only be stored in [linkedReferences]. | 625 * will only be stored in [linkedReferences]. |
| 618 */ | 626 */ |
| 619 int serializeReferenceForType(DartType type, bool linked) { | 627 int serializeReferenceForType(DartType type, bool linked) { |
| 620 Element element = type.element; | 628 Element element = type.element; |
| 621 LibraryElement dependentLibrary = element?.library; | 629 LibraryElement dependentLibrary = element?.library; |
| 622 if (dependentLibrary == null) { | 630 if (dependentLibrary == null) { |
| 623 assert(type.isDynamic || type.isVoid); | 631 assert(type.isDynamic || type.isVoid); |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1057 exportNames.add(new LinkedExportNameBuilder( | 1065 exportNames.add(new LinkedExportNameBuilder( |
| 1058 name: name, | 1066 name: name, |
| 1059 dependency: serializeDependency(dependentLibrary), | 1067 dependency: serializeDependency(dependentLibrary), |
| 1060 unit: unit, | 1068 unit: unit, |
| 1061 kind: kind)); | 1069 kind: kind)); |
| 1062 } | 1070 } |
| 1063 pb.exportNames = exportNames; | 1071 pb.exportNames = exportNames; |
| 1064 return pb; | 1072 return pb; |
| 1065 } | 1073 } |
| 1066 } | 1074 } |
| OLD | NEW |