| 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 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 int slot = ++numSlots; | 984 int slot = ++numSlots; |
| 985 if (type != null) { | 985 if (type != null) { |
| 986 deferredLinkedTypes | 986 deferredLinkedTypes |
| 987 .add(() => serializeTypeRef(type, context, linked: true, slot: slot)); | 987 .add(() => serializeTypeRef(type, context, linked: true, slot: slot)); |
| 988 } | 988 } |
| 989 return slot; | 989 return slot; |
| 990 } | 990 } |
| 991 | 991 |
| 992 int _getElementReferenceId(Element element, {bool linked: false}) { | 992 int _getElementReferenceId(Element element, {bool linked: false}) { |
| 993 return referenceMap.putIfAbsent(element, () { | 993 return referenceMap.putIfAbsent(element, () { |
| 994 LibraryElement dependentLibrary; | 994 LibraryElement dependentLibrary = librarySerializer.libraryElement; |
| 995 int unit = 0; |
| 995 if (element != null) { | 996 if (element != null) { |
| 996 Element enclosingElement = element.enclosingElement; | 997 Element enclosingElement = element.enclosingElement; |
| 997 if (enclosingElement is CompilationUnitElement) { | 998 if (enclosingElement is CompilationUnitElement) { |
| 998 dependentLibrary = enclosingElement.library; | 999 dependentLibrary = enclosingElement.library; |
| 1000 unit = dependentLibrary.units.indexOf(enclosingElement); |
| 1001 assert(unit != -1); |
| 999 } | 1002 } |
| 1000 } | 1003 } |
| 1001 int unit; | |
| 1002 if (dependentLibrary == null) { | |
| 1003 unit = 0; | |
| 1004 dependentLibrary = librarySerializer.libraryElement; | |
| 1005 } else { | |
| 1006 CompilationUnitElement unitElement = | |
| 1007 element.getAncestor((Element e) => e is CompilationUnitElement); | |
| 1008 unit = dependentLibrary.units.indexOf(unitElement); | |
| 1009 assert(unit != -1); | |
| 1010 } | |
| 1011 ReferenceKind kind = _getReferenceKind(element); | 1004 ReferenceKind kind = _getReferenceKind(element); |
| 1012 String name = element == null ? 'void' : element.name; | 1005 String name = element == null ? 'void' : element.name; |
| 1013 int index; | 1006 int index; |
| 1014 LinkedReferenceBuilder linkedReference; | 1007 LinkedReferenceBuilder linkedReference; |
| 1015 if (linked) { | 1008 if (linked) { |
| 1016 linkedReference = | 1009 linkedReference = |
| 1017 new LinkedReferenceBuilder(kind: kind, unit: unit, name: name); | 1010 new LinkedReferenceBuilder(kind: kind, unit: unit, name: name); |
| 1018 Element enclosing = element?.enclosingElement; | 1011 Element enclosing = element?.enclosingElement; |
| 1019 if (enclosing is ClassElement) { | 1012 if (enclosing is ClassElement) { |
| 1020 linkedReference.containingReference = | 1013 linkedReference.containingReference = |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1390 exportNames.add(new LinkedExportNameBuilder( | 1383 exportNames.add(new LinkedExportNameBuilder( |
| 1391 name: name, | 1384 name: name, |
| 1392 dependency: serializeDependency(dependentLibrary), | 1385 dependency: serializeDependency(dependentLibrary), |
| 1393 unit: unit, | 1386 unit: unit, |
| 1394 kind: kind)); | 1387 kind: kind)); |
| 1395 } | 1388 } |
| 1396 pb.exportNames = exportNames; | 1389 pb.exportNames = exportNames; |
| 1397 return pb; | 1390 return pb; |
| 1398 } | 1391 } |
| 1399 } | 1392 } |
| OLD | NEW |