| 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 998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1009 deferredLinkedTypes | 1009 deferredLinkedTypes |
| 1010 .add(() => serializeTypeRef(type, context, linked: true, slot: slot)); | 1010 .add(() => serializeTypeRef(type, context, linked: true, slot: slot)); |
| 1011 } | 1011 } |
| 1012 return slot; | 1012 return slot; |
| 1013 } | 1013 } |
| 1014 | 1014 |
| 1015 int _getElementReferenceId(Element element, {bool linked: false}) { | 1015 int _getElementReferenceId(Element element, {bool linked: false}) { |
| 1016 return referenceMap.putIfAbsent(element, () { | 1016 return referenceMap.putIfAbsent(element, () { |
| 1017 LibraryElement dependentLibrary = librarySerializer.libraryElement; | 1017 LibraryElement dependentLibrary = librarySerializer.libraryElement; |
| 1018 int unit = 0; | 1018 int unit = 0; |
| 1019 Element enclosingElement; |
| 1019 if (element != null) { | 1020 if (element != null) { |
| 1020 Element enclosingElement = element.enclosingElement; | 1021 enclosingElement = element.enclosingElement; |
| 1021 if (enclosingElement is CompilationUnitElement) { | 1022 if (enclosingElement is CompilationUnitElement) { |
| 1022 dependentLibrary = enclosingElement.library; | 1023 dependentLibrary = enclosingElement.library; |
| 1023 unit = dependentLibrary.units.indexOf(enclosingElement); | 1024 unit = dependentLibrary.units.indexOf(enclosingElement); |
| 1024 assert(unit != -1); | 1025 assert(unit != -1); |
| 1025 } | 1026 } |
| 1026 } | 1027 } |
| 1027 ReferenceKind kind = _getReferenceKind(element); | 1028 ReferenceKind kind = _getReferenceKind(element); |
| 1028 String name = element == null ? 'void' : element.name; | 1029 String name = element == null ? 'void' : element.name; |
| 1029 int index; | 1030 int index; |
| 1030 LinkedReferenceBuilder linkedReference; | 1031 LinkedReferenceBuilder linkedReference; |
| 1031 if (linked) { | 1032 if (linked) { |
| 1032 linkedReference = | 1033 linkedReference = |
| 1033 new LinkedReferenceBuilder(kind: kind, unit: unit, name: name); | 1034 new LinkedReferenceBuilder(kind: kind, unit: unit, name: name); |
| 1034 Element enclosing = element?.enclosingElement; | 1035 if (enclosingElement != null && |
| 1035 if (enclosing != null && enclosing is! CompilationUnitElement) { | 1036 enclosingElement is! CompilationUnitElement) { |
| 1036 linkedReference.containingReference = | 1037 linkedReference.containingReference = |
| 1037 _getElementReferenceId(enclosing, linked: linked); | 1038 _getElementReferenceId(enclosingElement, linked: linked); |
| 1038 if (enclosing is ClassElement) { | 1039 if (enclosingElement is ClassElement) { |
| 1039 linkedReference.numTypeParameters = enclosing.typeParameters.length; | 1040 linkedReference.numTypeParameters = |
| 1040 } else if (enclosing is ExecutableElement) { | 1041 enclosingElement.typeParameters.length; |
| 1042 } else if (enclosingElement is ExecutableElement) { |
| 1041 if (element is FunctionElement) { | 1043 if (element is FunctionElement) { |
| 1042 assert(enclosing.functions.contains(element)); | 1044 assert(enclosingElement.functions.contains(element)); |
| 1043 linkedReference.localIndex = enclosing.functions.indexOf(element); | 1045 linkedReference.localIndex = |
| 1046 enclosingElement.functions.indexOf(element); |
| 1044 } else if (element is LocalVariableElement) { | 1047 } else if (element is LocalVariableElement) { |
| 1045 assert(enclosing.localVariables.contains(element)); | 1048 assert(enclosingElement.localVariables.contains(element)); |
| 1046 linkedReference.localIndex = | 1049 linkedReference.localIndex = |
| 1047 enclosing.localVariables.indexOf(element); | 1050 enclosingElement.localVariables.indexOf(element); |
| 1048 } else { | 1051 } else { |
| 1049 throw new StateError( | 1052 throw new StateError( |
| 1050 'Unexpected enclosed element type: ${element.runtimeType}'); | 1053 'Unexpected enclosed element type: ${element.runtimeType}'); |
| 1051 } | 1054 } |
| 1052 } else if (enclosing is VariableElement) { | 1055 } else if (enclosingElement is VariableElement) { |
| 1053 assert(identical(enclosing.initializer, element)); | 1056 assert(identical(enclosingElement.initializer, element)); |
| 1054 } else { | 1057 } else { |
| 1055 throw new StateError( | 1058 throw new StateError( |
| 1056 'Unexpected enclosing element type: ${enclosing.runtimeType}'); | 1059 'Unexpected enclosing element type: ${enclosingElement.runtimeTy
pe}'); |
| 1057 } | 1060 } |
| 1058 } | 1061 } |
| 1059 index = linkedReferences.length; | 1062 index = linkedReferences.length; |
| 1060 linkedReferences.add(linkedReference); | 1063 linkedReferences.add(linkedReference); |
| 1061 } else { | 1064 } else { |
| 1062 assert(unlinkedReferences.length == linkedReferences.length); | 1065 assert(unlinkedReferences.length == linkedReferences.length); |
| 1063 int prefixReference = 0; | 1066 int prefixReference = 0; |
| 1064 Element enclosing = element?.enclosingElement; | 1067 Element enclosing = element?.enclosingElement; |
| 1065 if (enclosing == null || enclosing is CompilationUnitElement) { | 1068 if (enclosing == null || enclosing is CompilationUnitElement) { |
| 1066 // Figure out a prefix that may be used to refer to the given element. | 1069 // Figure out a prefix that may be used to refer to the given element. |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1425 exportNames.add(new LinkedExportNameBuilder( | 1428 exportNames.add(new LinkedExportNameBuilder( |
| 1426 name: name, | 1429 name: name, |
| 1427 dependency: serializeDependency(dependentLibrary), | 1430 dependency: serializeDependency(dependentLibrary), |
| 1428 unit: unit, | 1431 unit: unit, |
| 1429 kind: kind)); | 1432 kind: kind)); |
| 1430 } | 1433 } |
| 1431 pb.exportNames = exportNames; | 1434 pb.exportNames = exportNames; |
| 1432 return pb; | 1435 return pb; |
| 1433 } | 1436 } |
| 1434 } | 1437 } |
| OLD | NEW |