| 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 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 /** | 381 /** |
| 382 * If [cls] is a class, return the list of its members available for | 382 * If [cls] is a class, return the list of its members available for |
| 383 * constants - static constant fields, static methods and constructors. | 383 * constants - static constant fields, static methods and constructors. |
| 384 * Otherwise return `null`. | 384 * Otherwise return `null`. |
| 385 */ | 385 */ |
| 386 List<UnlinkedPublicNameBuilder> serializeClassConstMembers(ClassElement cls) { | 386 List<UnlinkedPublicNameBuilder> serializeClassConstMembers(ClassElement cls) { |
| 387 if (cls.kind == ElementKind.CLASS) { | 387 if (cls.kind == ElementKind.CLASS) { |
| 388 List<UnlinkedPublicNameBuilder> bs = <UnlinkedPublicNameBuilder>[]; | 388 List<UnlinkedPublicNameBuilder> bs = <UnlinkedPublicNameBuilder>[]; |
| 389 for (FieldElement field in cls.fields) { | 389 for (FieldElement field in cls.fields) { |
| 390 if (field.isStatic && field.isConst && field.isPublic) { | 390 if (field.isStatic && field.isConst && field.isPublic) { |
| 391 // TODO(paulberry): should numTypeParameters include class params? |
| 391 bs.add(new UnlinkedPublicNameBuilder( | 392 bs.add(new UnlinkedPublicNameBuilder( |
| 392 name: field.name, | 393 name: field.name, |
| 393 kind: ReferenceKind.propertyAccessor, | 394 kind: ReferenceKind.propertyAccessor, |
| 394 numTypeParameters: 0)); | 395 numTypeParameters: 0)); |
| 395 } | 396 } |
| 396 } | 397 } |
| 397 for (MethodElement method in cls.methods) { | 398 for (MethodElement method in cls.methods) { |
| 398 if (method.isStatic && method.isPublic) { | 399 if (method.isStatic && method.isPublic) { |
| 400 // TODO(paulberry): should numTypeParameters include class params? |
| 399 bs.add(new UnlinkedPublicNameBuilder( | 401 bs.add(new UnlinkedPublicNameBuilder( |
| 400 name: method.name, | 402 name: method.name, |
| 401 kind: ReferenceKind.method, | 403 kind: ReferenceKind.method, |
| 402 numTypeParameters: method.typeParameters.length)); | 404 numTypeParameters: method.typeParameters.length)); |
| 403 } | 405 } |
| 404 } | 406 } |
| 405 for (ConstructorElement constructor in cls.constructors) { | 407 for (ConstructorElement constructor in cls.constructors) { |
| 406 if (constructor.isConst && constructor.isPublic) { | 408 if (constructor.isConst && constructor.isPublic) { |
| 409 // TODO(paulberry): should numTypeParameters include class params? |
| 407 bs.add(new UnlinkedPublicNameBuilder( | 410 bs.add(new UnlinkedPublicNameBuilder( |
| 408 name: constructor.name, | 411 name: constructor.name, |
| 409 kind: ReferenceKind.constructor, | 412 kind: ReferenceKind.constructor, |
| 410 numTypeParameters: 0)); | 413 numTypeParameters: 0)); |
| 411 } | 414 } |
| 412 } | 415 } |
| 413 return bs; | 416 return bs; |
| 414 } | 417 } |
| 415 return null; | 418 return null; |
| 416 } | 419 } |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 assert(element == librarySerializer.typeProvider.dynamicType.element || | 839 assert(element == librarySerializer.typeProvider.dynamicType.element || |
| 837 element == null); | 840 element == null); |
| 838 unit = 0; | 841 unit = 0; |
| 839 dependentLibrary = librarySerializer.libraryElement; | 842 dependentLibrary = librarySerializer.libraryElement; |
| 840 } else { | 843 } else { |
| 841 CompilationUnitElement unitElement = | 844 CompilationUnitElement unitElement = |
| 842 element.getAncestor((Element e) => e is CompilationUnitElement); | 845 element.getAncestor((Element e) => e is CompilationUnitElement); |
| 843 unit = dependentLibrary.units.indexOf(unitElement); | 846 unit = dependentLibrary.units.indexOf(unitElement); |
| 844 assert(unit != -1); | 847 assert(unit != -1); |
| 845 } | 848 } |
| 846 int numTypeParameters = 0; | |
| 847 if (element is TypeParameterizedElement) { | |
| 848 numTypeParameters = element.typeParameters.length; | |
| 849 } | |
| 850 LinkedReferenceBuilder linkedReference = new LinkedReferenceBuilder( | 849 LinkedReferenceBuilder linkedReference = new LinkedReferenceBuilder( |
| 851 dependency: librarySerializer.serializeDependency(dependentLibrary), | 850 dependency: librarySerializer.serializeDependency(dependentLibrary), |
| 852 kind: _getReferenceKind(element), | 851 kind: _getReferenceKind(element), |
| 853 unit: unit, | 852 unit: unit); |
| 854 numTypeParameters: numTypeParameters); | 853 if (element is TypeParameterizedElement) { |
| 854 linkedReference.numTypeParameters = element.typeParameters.length; |
| 855 } |
| 855 String name = element == null ? 'void' : element.name; | 856 String name = element == null ? 'void' : element.name; |
| 856 if (linked) { | 857 if (linked) { |
| 857 linkedReference.name = name; | 858 linkedReference.name = name; |
| 858 Element enclosing = element?.enclosingElement; | 859 Element enclosing = element?.enclosingElement; |
| 859 if (enclosing is ClassElement) { | 860 if (enclosing is ClassElement) { |
| 860 linkedReference.containingReference = | 861 linkedReference.containingReference = |
| 861 _getElementReferenceId(enclosing, linked: linked); | 862 _getElementReferenceId(enclosing, linked: linked); |
| 863 linkedReference.numTypeParameters += enclosing.typeParameters.length; |
| 862 } | 864 } |
| 863 } else { | 865 } else { |
| 864 assert(unlinkedReferences.length == linkedReferences.length); | 866 assert(unlinkedReferences.length == linkedReferences.length); |
| 865 int prefixReference = 0; | 867 int prefixReference = 0; |
| 866 Element enclosing = element?.enclosingElement; | 868 Element enclosing = element?.enclosingElement; |
| 867 if (enclosing == null || enclosing is CompilationUnitElement) { | 869 if (enclosing == null || enclosing is CompilationUnitElement) { |
| 868 // Figure out a prefix that may be used to refer to the given element. | 870 // Figure out a prefix that may be used to refer to the given element. |
| 869 // TODO(paulberry): to avoid subtle relinking inconsistencies we | 871 // TODO(paulberry): to avoid subtle relinking inconsistencies we |
| 870 // should use the actual prefix from the AST (a given type may be | 872 // should use the actual prefix from the AST (a given type may be |
| 871 // reachable via multiple prefixes), but sadly, this information is | 873 // reachable via multiple prefixes), but sadly, this information is |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1141 exportNames.add(new LinkedExportNameBuilder( | 1143 exportNames.add(new LinkedExportNameBuilder( |
| 1142 name: name, | 1144 name: name, |
| 1143 dependency: serializeDependency(dependentLibrary), | 1145 dependency: serializeDependency(dependentLibrary), |
| 1144 unit: unit, | 1146 unit: unit, |
| 1145 kind: kind)); | 1147 kind: kind)); |
| 1146 } | 1148 } |
| 1147 pb.exportNames = exportNames; | 1149 pb.exportNames = exportNames; |
| 1148 return pb; | 1150 return pb; |
| 1149 } | 1151 } |
| 1150 } | 1152 } |
| OLD | NEW |