| 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 'dart:convert'; | 7 import 'dart:convert'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 name: accessor.name, | 348 name: accessor.name, |
| 349 numTypeParameters: accessor.typeParameters.length)); | 349 numTypeParameters: accessor.typeParameters.length)); |
| 350 } | 350 } |
| 351 } | 351 } |
| 352 for (ClassElement cls in compilationUnit.types) { | 352 for (ClassElement cls in compilationUnit.types) { |
| 353 if (cls.isPublic) { | 353 if (cls.isPublic) { |
| 354 names.add(new UnlinkedPublicNameBuilder( | 354 names.add(new UnlinkedPublicNameBuilder( |
| 355 kind: ReferenceKind.classOrEnum, | 355 kind: ReferenceKind.classOrEnum, |
| 356 name: cls.name, | 356 name: cls.name, |
| 357 numTypeParameters: cls.typeParameters.length, | 357 numTypeParameters: cls.typeParameters.length, |
| 358 members: serializeClassConstMembers(cls))); | 358 members: serializeClassStaticMembers(cls))); |
| 359 } | 359 } |
| 360 } | 360 } |
| 361 for (ClassElement enm in compilationUnit.enums) { | 361 for (ClassElement enm in compilationUnit.enums) { |
| 362 if (enm.isPublic) { | 362 if (enm.isPublic) { |
| 363 names.add(new UnlinkedPublicNameBuilder( | 363 names.add(new UnlinkedPublicNameBuilder( |
| 364 kind: ReferenceKind.classOrEnum, | 364 kind: ReferenceKind.classOrEnum, |
| 365 name: enm.name, | 365 name: enm.name, |
| 366 members: serializeClassConstMembers(enm))); | 366 members: serializeClassStaticMembers(enm))); |
| 367 } | 367 } |
| 368 } | 368 } |
| 369 for (FunctionElement function in compilationUnit.functions) { | 369 for (FunctionElement function in compilationUnit.functions) { |
| 370 if (function.isPublic) { | 370 if (function.isPublic) { |
| 371 names.add(new UnlinkedPublicNameBuilder( | 371 names.add(new UnlinkedPublicNameBuilder( |
| 372 kind: ReferenceKind.topLevelFunction, | 372 kind: ReferenceKind.topLevelFunction, |
| 373 name: function.name, | 373 name: function.name, |
| 374 numTypeParameters: function.typeParameters.length)); | 374 numTypeParameters: function.typeParameters.length)); |
| 375 } | 375 } |
| 376 } | 376 } |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 b.executables = executables; | 587 b.executables = executables; |
| 588 b.isAbstract = classElement.isAbstract; | 588 b.isAbstract = classElement.isAbstract; |
| 589 b.isMixinApplication = classElement.isMixinApplication; | 589 b.isMixinApplication = classElement.isMixinApplication; |
| 590 b.documentationComment = serializeDocumentation(classElement); | 590 b.documentationComment = serializeDocumentation(classElement); |
| 591 b.annotations = serializeAnnotations(classElement); | 591 b.annotations = serializeAnnotations(classElement); |
| 592 b.codeRange = serializeCodeRange(classElement); | 592 b.codeRange = serializeCodeRange(classElement); |
| 593 return b; | 593 return b; |
| 594 } | 594 } |
| 595 | 595 |
| 596 /** | 596 /** |
| 597 * If [cls] is a class, return the list of its members available for | 597 * If [cls] is a class, return the list of its static members - static |
| 598 * constants - static constant fields, static methods and constructors. | 598 * constant fields, static methods and constructors. Otherwise return `null`. |
| 599 * Otherwise return `null`. | |
| 600 */ | 599 */ |
| 601 List<UnlinkedPublicNameBuilder> serializeClassConstMembers(ClassElement cls) { | 600 List<UnlinkedPublicNameBuilder> serializeClassStaticMembers( |
| 601 ClassElement cls) { |
| 602 if (cls.isMixinApplication) { | 602 if (cls.isMixinApplication) { |
| 603 // Mixin application members can't be determined directly from the AST so | 603 // Mixin application members can't be determined directly from the AST so |
| 604 // we can't store them in UnlinkedPublicName. | 604 // we can't store them in UnlinkedPublicName. |
| 605 // TODO(paulberry): find somewhere else to store them. | 605 // TODO(paulberry): find somewhere else to store them. |
| 606 return null; | 606 return null; |
| 607 } | 607 } |
| 608 if (cls.kind == ElementKind.CLASS) { | 608 if (cls.kind == ElementKind.CLASS) { |
| 609 List<UnlinkedPublicNameBuilder> bs = <UnlinkedPublicNameBuilder>[]; | 609 List<UnlinkedPublicNameBuilder> bs = <UnlinkedPublicNameBuilder>[]; |
| 610 for (FieldElement field in cls.fields) { | |
| 611 if (field.isStatic && field.isConst && field.isPublic) { | |
| 612 // TODO(paulberry): include non-consts | |
| 613 // TODO(paulberry): should numTypeParameters include class params? | |
| 614 bs.add(new UnlinkedPublicNameBuilder( | |
| 615 name: field.name, | |
| 616 kind: ReferenceKind.propertyAccessor, | |
| 617 numTypeParameters: 0)); | |
| 618 } | |
| 619 } | |
| 620 for (MethodElement method in cls.methods) { | 610 for (MethodElement method in cls.methods) { |
| 621 if (method.isStatic && method.isPublic) { | 611 if (method.isStatic && method.isPublic) { |
| 622 // TODO(paulberry): should numTypeParameters include class params? | 612 // TODO(paulberry): should numTypeParameters include class params? |
| 623 bs.add(new UnlinkedPublicNameBuilder( | 613 bs.add(new UnlinkedPublicNameBuilder( |
| 624 name: method.name, | 614 name: method.name, |
| 625 kind: ReferenceKind.method, | 615 kind: ReferenceKind.method, |
| 626 numTypeParameters: method.typeParameters.length)); | 616 numTypeParameters: method.typeParameters.length)); |
| 627 } | 617 } |
| 628 } | 618 } |
| 629 for (PropertyAccessorElement accessor in cls.accessors) { | 619 for (PropertyAccessorElement accessor in cls.accessors) { |
| 630 if (accessor.isStatic && | 620 if (accessor.isStatic && |
| 631 accessor.isGetter && | 621 accessor.isGetter && |
| 632 accessor.isPublic && | 622 accessor.isPublic) { |
| 633 !accessor.isSynthetic) { | |
| 634 // TODO(paulberry): combine with field code above. | |
| 635 // TODO(paulberry): should numTypeParameters include class params? | 623 // TODO(paulberry): should numTypeParameters include class params? |
| 636 bs.add(new UnlinkedPublicNameBuilder( | 624 bs.add(new UnlinkedPublicNameBuilder( |
| 637 name: accessor.name, kind: ReferenceKind.propertyAccessor)); | 625 name: accessor.name, kind: ReferenceKind.propertyAccessor)); |
| 638 } | 626 } |
| 639 } | 627 } |
| 640 for (ConstructorElement constructor in cls.constructors) { | 628 for (ConstructorElement constructor in cls.constructors) { |
| 641 if (constructor.isPublic && constructor.name.isNotEmpty) { | 629 if (constructor.isPublic && constructor.name.isNotEmpty) { |
| 642 // TODO(paulberry): should numTypeParameters include class params? | 630 // TODO(paulberry): should numTypeParameters include class params? |
| 643 bs.add(new UnlinkedPublicNameBuilder( | 631 bs.add(new UnlinkedPublicNameBuilder( |
| 644 name: constructor.name, | 632 name: constructor.name, |
| (...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1680 exportNames.add(new LinkedExportNameBuilder( | 1668 exportNames.add(new LinkedExportNameBuilder( |
| 1681 name: name, | 1669 name: name, |
| 1682 dependency: serializeDependency(dependentLibrary), | 1670 dependency: serializeDependency(dependentLibrary), |
| 1683 unit: unit, | 1671 unit: unit, |
| 1684 kind: kind)); | 1672 kind: kind)); |
| 1685 } | 1673 } |
| 1686 pb.exportNames = exportNames; | 1674 pb.exportNames = exportNames; |
| 1687 return pb; | 1675 return pb; |
| 1688 } | 1676 } |
| 1689 } | 1677 } |
| OLD | NEW |