| 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/member.dart'; | 10 import 'package:analyzer/src/dart/element/member.dart'; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 return ReferenceKind.function; | 44 return ReferenceKind.function; |
| 45 } else if (element is FunctionTypeAliasElement) { | 45 } else if (element is FunctionTypeAliasElement) { |
| 46 return ReferenceKind.typedef; | 46 return ReferenceKind.typedef; |
| 47 } else if (element is PropertyAccessorElement) { | 47 } else if (element is PropertyAccessorElement) { |
| 48 if (element.enclosingElement is ClassElement) { | 48 if (element.enclosingElement is ClassElement) { |
| 49 return ReferenceKind.propertyAccessor; | 49 return ReferenceKind.propertyAccessor; |
| 50 } | 50 } |
| 51 return ReferenceKind.topLevelPropertyAccessor; | 51 return ReferenceKind.topLevelPropertyAccessor; |
| 52 } else if (element is MethodElement) { | 52 } else if (element is MethodElement) { |
| 53 return ReferenceKind.method; | 53 return ReferenceKind.method; |
| 54 } else if (element is TopLevelVariableElement) { |
| 55 // Summaries don't need to distinguish between references to a variable and |
| 56 // references to its getter. |
| 57 return ReferenceKind.topLevelPropertyAccessor; |
| 58 } else if (element is LocalVariableElement) { |
| 59 return ReferenceKind.variable; |
| 60 } else if (element is FieldElement) { |
| 61 // Summaries don't need to distinguish between references to a field and |
| 62 // references to its getter. |
| 63 return ReferenceKind.propertyAccessor; |
| 54 } else { | 64 } else { |
| 55 throw new Exception('Unexpected element kind: ${element.runtimeType}'); | 65 throw new Exception('Unexpected element kind: ${element.runtimeType}'); |
| 56 } | 66 } |
| 57 } | 67 } |
| 58 | 68 |
| 59 /** | 69 /** |
| 60 * Type of closures used by [_LibrarySerializer] to defer generation of | 70 * Type of closures used by [_LibrarySerializer] to defer generation of |
| 61 * [EntityRefBuilder] objects until the end of serialization of a | 71 * [EntityRefBuilder] objects until the end of serialization of a |
| 62 * compilation unit. | 72 * compilation unit. |
| 63 */ | 73 */ |
| (...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 } | 1012 } |
| 1003 } | 1013 } |
| 1004 ReferenceKind kind = _getReferenceKind(element); | 1014 ReferenceKind kind = _getReferenceKind(element); |
| 1005 String name = element == null ? 'void' : element.name; | 1015 String name = element == null ? 'void' : element.name; |
| 1006 int index; | 1016 int index; |
| 1007 LinkedReferenceBuilder linkedReference; | 1017 LinkedReferenceBuilder linkedReference; |
| 1008 if (linked) { | 1018 if (linked) { |
| 1009 linkedReference = | 1019 linkedReference = |
| 1010 new LinkedReferenceBuilder(kind: kind, unit: unit, name: name); | 1020 new LinkedReferenceBuilder(kind: kind, unit: unit, name: name); |
| 1011 Element enclosing = element?.enclosingElement; | 1021 Element enclosing = element?.enclosingElement; |
| 1012 if (enclosing is ClassElement) { | 1022 if (enclosing != null && enclosing is! CompilationUnitElement) { |
| 1013 linkedReference.containingReference = | 1023 linkedReference.containingReference = |
| 1014 _getElementReferenceId(enclosing, linked: linked); | 1024 _getElementReferenceId(enclosing, linked: linked); |
| 1015 linkedReference.numTypeParameters = enclosing.typeParameters.length; | 1025 if (enclosing is ClassElement) { |
| 1026 linkedReference.numTypeParameters = enclosing.typeParameters.length; |
| 1027 } else if (enclosing is ExecutableElement) { |
| 1028 if (element is FunctionElement) { |
| 1029 assert(enclosing.functions.contains(element)); |
| 1030 linkedReference.localIndex = enclosing.functions.indexOf(element); |
| 1031 } else if (element is LocalVariableElement) { |
| 1032 assert(enclosing.localVariables.contains(element)); |
| 1033 linkedReference.localIndex = |
| 1034 enclosing.localVariables.indexOf(element); |
| 1035 } else { |
| 1036 throw new StateError( |
| 1037 'Unexpected enclosed element type: ${element.runtimeType}'); |
| 1038 } |
| 1039 } else if (enclosing is VariableElement) { |
| 1040 assert(identical(enclosing.initializer, element)); |
| 1041 } else { |
| 1042 throw new StateError( |
| 1043 'Unexpected enclosing element type: ${enclosing.runtimeType}'); |
| 1044 } |
| 1016 } | 1045 } |
| 1017 index = linkedReferences.length; | 1046 index = linkedReferences.length; |
| 1018 linkedReferences.add(linkedReference); | 1047 linkedReferences.add(linkedReference); |
| 1019 } else { | 1048 } else { |
| 1020 assert(unlinkedReferences.length == linkedReferences.length); | 1049 assert(unlinkedReferences.length == linkedReferences.length); |
| 1021 int prefixReference = 0; | 1050 int prefixReference = 0; |
| 1022 Element enclosing = element?.enclosingElement; | 1051 Element enclosing = element?.enclosingElement; |
| 1023 if (enclosing == null || enclosing is CompilationUnitElement) { | 1052 if (enclosing == null || enclosing is CompilationUnitElement) { |
| 1024 // Figure out a prefix that may be used to refer to the given element. | 1053 // Figure out a prefix that may be used to refer to the given element. |
| 1025 // TODO(paulberry): to avoid subtle relinking inconsistencies we | 1054 // TODO(paulberry): to avoid subtle relinking inconsistencies we |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1383 exportNames.add(new LinkedExportNameBuilder( | 1412 exportNames.add(new LinkedExportNameBuilder( |
| 1384 name: name, | 1413 name: name, |
| 1385 dependency: serializeDependency(dependentLibrary), | 1414 dependency: serializeDependency(dependentLibrary), |
| 1386 unit: unit, | 1415 unit: unit, |
| 1387 kind: kind)); | 1416 kind: kind)); |
| 1388 } | 1417 } |
| 1389 pb.exportNames = exportNames; | 1418 pb.exportNames = exportNames; |
| 1390 return pb; | 1419 return pb; |
| 1391 } | 1420 } |
| 1392 } | 1421 } |
| OLD | NEW |