| 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 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 int slot = ++numSlots; | 831 int slot = ++numSlots; |
| 832 if (type != null) { | 832 if (type != null) { |
| 833 deferredLinkedTypes | 833 deferredLinkedTypes |
| 834 .add(() => serializeTypeRef(type, context, linked: true, slot: slot)); | 834 .add(() => serializeTypeRef(type, context, linked: true, slot: slot)); |
| 835 } | 835 } |
| 836 return slot; | 836 return slot; |
| 837 } | 837 } |
| 838 | 838 |
| 839 int _getElementReferenceId(Element element, {bool linked: false}) { | 839 int _getElementReferenceId(Element element, {bool linked: false}) { |
| 840 return referenceMap.putIfAbsent(element, () { | 840 return referenceMap.putIfAbsent(element, () { |
| 841 LibraryElement dependentLibrary = element?.library; | 841 LibraryElement dependentLibrary; |
| 842 if (element != null) { |
| 843 Element enclosingElement = element.enclosingElement; |
| 844 if (enclosingElement is CompilationUnitElement) { |
| 845 dependentLibrary = enclosingElement.library; |
| 846 } |
| 847 } |
| 842 int unit; | 848 int unit; |
| 843 if (dependentLibrary == null) { | 849 if (dependentLibrary == null) { |
| 844 assert(element == librarySerializer.typeProvider.dynamicType.element || | |
| 845 element == null); | |
| 846 unit = 0; | 850 unit = 0; |
| 847 dependentLibrary = librarySerializer.libraryElement; | 851 dependentLibrary = librarySerializer.libraryElement; |
| 848 } else { | 852 } else { |
| 849 CompilationUnitElement unitElement = | 853 CompilationUnitElement unitElement = |
| 850 element.getAncestor((Element e) => e is CompilationUnitElement); | 854 element.getAncestor((Element e) => e is CompilationUnitElement); |
| 851 unit = dependentLibrary.units.indexOf(unitElement); | 855 unit = dependentLibrary.units.indexOf(unitElement); |
| 852 assert(unit != -1); | 856 assert(unit != -1); |
| 853 } | 857 } |
| 854 LinkedReferenceBuilder linkedReference = new LinkedReferenceBuilder( | 858 LinkedReferenceBuilder linkedReference = new LinkedReferenceBuilder( |
| 855 dependency: librarySerializer.serializeDependency(dependentLibrary), | 859 dependency: librarySerializer.serializeDependency(dependentLibrary), |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 921 if (constructor.name == null) { | 925 if (constructor.name == null) { |
| 922 return typeRef; | 926 return typeRef; |
| 923 } else { | 927 } else { |
| 924 int typeId = typeRef.reference; | 928 int typeId = typeRef.reference; |
| 925 LinkedReference typeLinkedRef = serializer.linkedReferences[typeId]; | 929 LinkedReference typeLinkedRef = serializer.linkedReferences[typeId]; |
| 926 serializer.unlinkedReferences.add(new UnlinkedReferenceBuilder( | 930 serializer.unlinkedReferences.add(new UnlinkedReferenceBuilder( |
| 927 name: constructor.name.name, prefixReference: typeId)); | 931 name: constructor.name.name, prefixReference: typeId)); |
| 928 int refId = serializer.linkedReferences.length; | 932 int refId = serializer.linkedReferences.length; |
| 929 serializer.linkedReferences.add(new LinkedReferenceBuilder( | 933 serializer.linkedReferences.add(new LinkedReferenceBuilder( |
| 930 kind: ReferenceKind.constructor, | 934 kind: ReferenceKind.constructor, |
| 931 dependency: typeLinkedRef.dependency, | |
| 932 unit: typeLinkedRef.unit)); | 935 unit: typeLinkedRef.unit)); |
| 933 return new EntityRefBuilder( | 936 return new EntityRefBuilder( |
| 934 reference: refId, typeArguments: typeRef.typeArguments); | 937 reference: refId, typeArguments: typeRef.typeArguments); |
| 935 } | 938 } |
| 936 } | 939 } |
| 937 | 940 |
| 938 EntityRefBuilder serializeIdentifier(Identifier identifier) { | 941 EntityRefBuilder serializeIdentifier(Identifier identifier) { |
| 939 Element element = identifier.staticElement; | 942 Element element = identifier.staticElement; |
| 940 assert(element != null); | 943 assert(element != null); |
| 941 // The only supported instance property accessor - `length`. | 944 // The only supported instance property accessor - `length`. |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1161 exportNames.add(new LinkedExportNameBuilder( | 1164 exportNames.add(new LinkedExportNameBuilder( |
| 1162 name: name, | 1165 name: name, |
| 1163 dependency: serializeDependency(dependentLibrary), | 1166 dependency: serializeDependency(dependentLibrary), |
| 1164 unit: unit, | 1167 unit: unit, |
| 1165 kind: kind)); | 1168 kind: kind)); |
| 1166 } | 1169 } |
| 1167 pb.exportNames = exportNames; | 1170 pb.exportNames = exportNames; |
| 1168 return pb; | 1171 return pb; |
| 1169 } | 1172 } |
| 1170 } | 1173 } |
| OLD | NEW |