| 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/type.dart'; | 9 import 'package:analyzer/src/dart/element/type.dart'; |
| 10 import 'package:analyzer/src/generated/resolver.dart'; | 10 import 'package:analyzer/src/generated/resolver.dart'; |
| 11 import 'package:analyzer/src/generated/utilities_dart.dart'; | 11 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 12 import 'package:analyzer/src/summary/format.dart'; | 12 import 'package:analyzer/src/summary/format.dart'; |
| 13 import 'package:analyzer/src/summary/name_filter.dart'; |
| 13 | 14 |
| 14 /** | 15 /** |
| 15 * Serialize all the elements in [lib] to a summary using [ctx] as the context | 16 * Serialize all the elements in [lib] to a summary using [ctx] as the context |
| 16 * for building the summary, and using [typeProvider] to find built-in types. | 17 * for building the summary, and using [typeProvider] to find built-in types. |
| 17 */ | 18 */ |
| 18 LibrarySerializationResult serializeLibrary( | 19 LibrarySerializationResult serializeLibrary( |
| 19 LibraryElement lib, TypeProvider typeProvider) { | 20 LibraryElement lib, TypeProvider typeProvider) { |
| 20 var serializer = new _LibrarySerializer(lib, typeProvider); | 21 var serializer = new _LibrarySerializer(lib, typeProvider); |
| 21 PrelinkedLibraryBuilder prelinked = serializer.serializeLibrary(); | 22 PrelinkedLibraryBuilder prelinked = serializer.serializeLibrary(); |
| 22 return new LibrarySerializationResult( | 23 return new LibrarySerializationResult( |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 /** | 276 /** |
| 276 * Fill in [prefixMap] using information from [libraryElement.imports]. | 277 * Fill in [prefixMap] using information from [libraryElement.imports]. |
| 277 */ | 278 */ |
| 278 void computePrefixMap() { | 279 void computePrefixMap() { |
| 279 for (ImportElement import in libraryElement.imports) { | 280 for (ImportElement import in libraryElement.imports) { |
| 280 if (import.prefix == null) { | 281 if (import.prefix == null) { |
| 281 continue; | 282 continue; |
| 282 } | 283 } |
| 283 import.importedLibrary.exportNamespace.definedNames | 284 import.importedLibrary.exportNamespace.definedNames |
| 284 .forEach((String name, Element e) { | 285 .forEach((String name, Element e) { |
| 285 if (import.combinators.any((NamespaceCombinator combinator) => | 286 if (new NameFilter.forNamespaceCombinators(import.combinators) |
| 286 doesCombinatorReject(combinator, name))) { | 287 .accepts(name)) { |
| 287 return; | 288 prefixMap[e] = import.prefix; |
| 288 } | 289 } |
| 289 prefixMap[e] = import.prefix; | |
| 290 }); | 290 }); |
| 291 } | 291 } |
| 292 } | 292 } |
| 293 | 293 |
| 294 /** | 294 /** |
| 295 * Determine if the given [combinator] would reject an element having the | |
| 296 * given [name]. | |
| 297 */ | |
| 298 bool doesCombinatorReject(NamespaceCombinator combinator, String name) { | |
| 299 if (combinator is ShowElementCombinator) { | |
| 300 return !combinator.shownNames.contains(name); | |
| 301 } else if (combinator is HideElementCombinator) { | |
| 302 return combinator.hiddenNames.contains(name); | |
| 303 } else { | |
| 304 throw new StateError( | |
| 305 'Unexpected combinator type ${combinator.runtimeType}'); | |
| 306 } | |
| 307 } | |
| 308 | |
| 309 /** | |
| 310 * Compute the appropriate De Bruijn index to represent the given type | 295 * Compute the appropriate De Bruijn index to represent the given type |
| 311 * parameter [type]. | 296 * parameter [type]. |
| 312 */ | 297 */ |
| 313 int findTypeParameterIndex(TypeParameterType type, Element context) { | 298 int findTypeParameterIndex(TypeParameterType type, Element context) { |
| 314 int index = 0; | 299 int index = 0; |
| 315 while (context != null) { | 300 while (context != null) { |
| 316 List<TypeParameterElement> typeParameters; | 301 List<TypeParameterElement> typeParameters; |
| 317 if (context is ClassElement) { | 302 if (context is ClassElement) { |
| 318 typeParameters = context.typeParameters; | 303 typeParameters = context.typeParameters; |
| 319 } else if (context is FunctionTypeAliasElement) { | 304 } else if (context is FunctionTypeAliasElement) { |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 * satisfy the request. | 705 * satisfy the request. |
| 721 */ | 706 */ |
| 722 int serializeUnresolvedReference() { | 707 int serializeUnresolvedReference() { |
| 723 // TODO(paulberry): in order for relinking to work, we need to record the | 708 // TODO(paulberry): in order for relinking to work, we need to record the |
| 724 // name and prefix of the unresolved symbol. This is not (yet) encoded in | 709 // name and prefix of the unresolved symbol. This is not (yet) encoded in |
| 725 // the element model. For the moment we use a name that can't possibly | 710 // the element model. For the moment we use a name that can't possibly |
| 726 // ever exist. | 711 // ever exist. |
| 727 if (unresolvedReferenceIndex == null) { | 712 if (unresolvedReferenceIndex == null) { |
| 728 assert(unlinkedReferences.length == prelinkedReferences.length); | 713 assert(unlinkedReferences.length == prelinkedReferences.length); |
| 729 unresolvedReferenceIndex = unlinkedReferences.length; | 714 unresolvedReferenceIndex = unlinkedReferences.length; |
| 730 unlinkedReferences | 715 unlinkedReferences.add(encodeUnlinkedReference(name: '*unresolved*')); |
| 731 .add(encodeUnlinkedReference(name: '*unresolved*')); | |
| 732 prelinkedReferences.add( | 716 prelinkedReferences.add( |
| 733 encodePrelinkedReference(kind: PrelinkedReferenceKind.unresolved)); | 717 encodePrelinkedReference(kind: PrelinkedReferenceKind.unresolved)); |
| 734 } | 718 } |
| 735 return unresolvedReferenceIndex; | 719 return unresolvedReferenceIndex; |
| 736 } | 720 } |
| 737 | 721 |
| 738 /** | 722 /** |
| 739 * Serialize the given [variable], creating an [UnlinkedVariable]. | 723 * Serialize the given [variable], creating an [UnlinkedVariable]. |
| 740 */ | 724 */ |
| 741 UnlinkedVariableBuilder serializeVariable(PropertyInducingElement variable) { | 725 UnlinkedVariableBuilder serializeVariable(PropertyInducingElement variable) { |
| 742 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder(); | 726 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder(); |
| 743 b.name = variable.name; | 727 b.name = variable.name; |
| 744 b.nameOffset = variable.nameOffset; | 728 b.nameOffset = variable.nameOffset; |
| 745 b.type = serializeTypeRef(variable.type, variable); | 729 b.type = serializeTypeRef(variable.type, variable); |
| 746 b.isStatic = variable.isStatic && variable.enclosingElement is ClassElement; | 730 b.isStatic = variable.isStatic && variable.enclosingElement is ClassElement; |
| 747 b.isFinal = variable.isFinal; | 731 b.isFinal = variable.isFinal; |
| 748 b.isConst = variable.isConst; | 732 b.isConst = variable.isConst; |
| 749 b.hasImplicitType = variable.hasImplicitType; | 733 b.hasImplicitType = variable.hasImplicitType; |
| 750 b.documentationComment = serializeDocumentation(variable); | 734 b.documentationComment = serializeDocumentation(variable); |
| 751 return b; | 735 return b; |
| 752 } | 736 } |
| 753 } | 737 } |
| OLD | NEW |