Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1087)

Side by Side Diff: pkg/analyzer/lib/src/summary/resynthesize.dart

Issue 1672413002: Add summary support for annotations. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/lib/src/summary/idl.dart ('k') | pkg/analyzer/lib/src/summary/summarize_ast.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 summary_resynthesizer; 5 library summary_resynthesizer;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 */ 674 */
675 UnlinkedUnit unlinkedUnit; 675 UnlinkedUnit unlinkedUnit;
676 676
677 /** 677 /**
678 * Map from slot id to the corresponding [EntityRef] object for linked types 678 * Map from slot id to the corresponding [EntityRef] object for linked types
679 * (i.e. propagated and inferred types). 679 * (i.e. propagated and inferred types).
680 */ 680 */
681 Map<int, EntityRef> linkedTypeMap; 681 Map<int, EntityRef> linkedTypeMap;
682 682
683 /** 683 /**
684 * The [CompilationUnitElementImpl] for the compilation unit currently being
685 * resynthesized.
686 */
687 CompilationUnitElementImpl currentCompilationUnit;
688
689 /**
684 * Map of top level elements that have been resynthesized so far. The first 690 * Map of top level elements that have been resynthesized so far. The first
685 * key is the URI of the compilation unit; the second is the name of the top 691 * key is the URI of the compilation unit; the second is the name of the top
686 * level element. 692 * level element.
687 */ 693 */
688 final Map<String, Map<String, Element>> resummarizedElements = 694 final Map<String, Map<String, Element>> resummarizedElements =
689 <String, Map<String, Element>>{}; 695 <String, Map<String, Element>>{};
690 696
691 /** 697 /**
692 * Type parameters for the generic class, typedef, or executable currently 698 * Type parameters for the generic class, typedef, or executable currently
693 * being resynthesized, if any. If multiple entities with type parameters 699 * being resynthesized, if any. If multiple entities with type parameters
(...skipping 24 matching lines...) Expand all
718 } 724 }
719 725
720 /** 726 /**
721 * Return a list of type arguments corresponding to [currentTypeParameters]. 727 * Return a list of type arguments corresponding to [currentTypeParameters].
722 */ 728 */
723 List<TypeParameterType> get currentTypeArguments => currentTypeParameters 729 List<TypeParameterType> get currentTypeArguments => currentTypeParameters
724 ?.map((TypeParameterElement param) => param.type) 730 ?.map((TypeParameterElement param) => param.type)
725 ?.toList(); 731 ?.toList();
726 732
727 /** 733 /**
734 * Build the annotations for the given [element].
735 */
736 void buildAnnotations(
737 ElementImpl element, List<UnlinkedConst> serializedAnnotations) {
738 if (serializedAnnotations.isNotEmpty) {
739 element.metadata = serializedAnnotations.map((UnlinkedConst a) {
740 ElementAnnotationImpl elementAnnotation =
741 new ElementAnnotationImpl(this.currentCompilationUnit);
742 Expression constExpr = _buildConstExpression(a);
743 if (constExpr is Identifier) {
744 elementAnnotation.element = constExpr.staticElement;
745 elementAnnotation.annotationAst = AstFactory.annotation(constExpr);
746 } else if (constExpr is InstanceCreationExpression) {
747 elementAnnotation.element = constExpr.staticElement;
748 Identifier typeName = constExpr.constructorName.type.name;
749 SimpleIdentifier constructorName = constExpr.constructorName.name;
750 if (typeName is SimpleIdentifier && constructorName != null) {
751 // E.g. `@cls.ctor()`. Since `cls.ctor` would have been parsed as
752 // a PrefixedIdentifier, we need to resynthesize it as one.
753 typeName = AstFactory.identifier(typeName, constructorName);
754 constructorName = null;
755 }
756 elementAnnotation.annotationAst = AstFactory.annotation2(
757 typeName, constructorName, constExpr.argumentList);
758 } else {
759 throw new StateError(
760 'Unexpected annotation type: ${constExpr.runtimeType}');
761 }
762 return elementAnnotation;
763 }).toList();
764 }
765 }
766
767 /**
728 * Resynthesize a [ClassElement] and place it in [unitHolder]. 768 * Resynthesize a [ClassElement] and place it in [unitHolder].
729 */ 769 */
730 void buildClass(UnlinkedClass serializedClass) { 770 void buildClass(UnlinkedClass serializedClass) {
731 try { 771 try {
732 currentTypeParameters = 772 currentTypeParameters =
733 serializedClass.typeParameters.map(buildTypeParameter).toList(); 773 serializedClass.typeParameters.map(buildTypeParameter).toList();
734 for (int i = 0; i < serializedClass.typeParameters.length; i++) { 774 for (int i = 0; i < serializedClass.typeParameters.length; i++) {
735 finishTypeParameter( 775 finishTypeParameter(
736 serializedClass.typeParameters[i], currentTypeParameters[i]); 776 serializedClass.typeParameters[i], currentTypeParameters[i]);
737 } 777 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 memberHolder.addConstructor(constructor); 826 memberHolder.addConstructor(constructor);
787 } 827 }
788 classElement.constructors = memberHolder.constructors; 828 classElement.constructors = memberHolder.constructors;
789 } 829 }
790 classElement.accessors = memberHolder.accessors; 830 classElement.accessors = memberHolder.accessors;
791 classElement.fields = memberHolder.fields; 831 classElement.fields = memberHolder.fields;
792 classElement.methods = memberHolder.methods; 832 classElement.methods = memberHolder.methods;
793 correspondingType.typeArguments = currentTypeArguments; 833 correspondingType.typeArguments = currentTypeArguments;
794 classElement.type = correspondingType; 834 classElement.type = correspondingType;
795 buildDocumentation(classElement, serializedClass.documentationComment); 835 buildDocumentation(classElement, serializedClass.documentationComment);
836 buildAnnotations(classElement, serializedClass.annotations);
796 unitHolder.addType(classElement); 837 unitHolder.addType(classElement);
797 } finally { 838 } finally {
798 currentTypeParameters = <TypeParameterElement>[]; 839 currentTypeParameters = <TypeParameterElement>[];
799 fields = null; 840 fields = null;
800 } 841 }
801 } 842 }
802 843
803 /** 844 /**
804 * Resynthesize a [NamespaceCombinator]. 845 * Resynthesize a [NamespaceCombinator].
805 */ 846 */
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 */ 896 */
856 void buildEnum(UnlinkedEnum serializedEnum) { 897 void buildEnum(UnlinkedEnum serializedEnum) {
857 assert(!isCoreLibrary); 898 assert(!isCoreLibrary);
858 ClassElementImpl classElement = 899 ClassElementImpl classElement =
859 new ClassElementImpl(serializedEnum.name, serializedEnum.nameOffset); 900 new ClassElementImpl(serializedEnum.name, serializedEnum.nameOffset);
860 classElement.enum2 = true; 901 classElement.enum2 = true;
861 InterfaceType enumType = new InterfaceTypeImpl(classElement); 902 InterfaceType enumType = new InterfaceTypeImpl(classElement);
862 classElement.type = enumType; 903 classElement.type = enumType;
863 classElement.supertype = summaryResynthesizer.typeProvider.objectType; 904 classElement.supertype = summaryResynthesizer.typeProvider.objectType;
864 buildDocumentation(classElement, serializedEnum.documentationComment); 905 buildDocumentation(classElement, serializedEnum.documentationComment);
906 buildAnnotations(classElement, serializedEnum.annotations);
865 ElementHolder memberHolder = new ElementHolder(); 907 ElementHolder memberHolder = new ElementHolder();
866 FieldElementImpl indexField = new FieldElementImpl('index', -1); 908 FieldElementImpl indexField = new FieldElementImpl('index', -1);
867 indexField.final2 = true; 909 indexField.final2 = true;
868 indexField.synthetic = true; 910 indexField.synthetic = true;
869 indexField.type = summaryResynthesizer.typeProvider.intType; 911 indexField.type = summaryResynthesizer.typeProvider.intType;
870 memberHolder.addField(indexField); 912 memberHolder.addField(indexField);
871 buildImplicitAccessors(indexField, memberHolder); 913 buildImplicitAccessors(indexField, memberHolder);
872 FieldElementImpl valuesField = new ConstFieldElementImpl('values', -1); 914 FieldElementImpl valuesField = new ConstFieldElementImpl('values', -1);
873 valuesField.synthetic = true; 915 valuesField.synthetic = true;
874 valuesField.const3 = true; 916 valuesField.const3 = true;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 executableElement.hasImplicitReturnType = 1040 executableElement.hasImplicitReturnType =
999 serializedExecutable.returnType == null; 1041 serializedExecutable.returnType == null;
1000 } 1042 }
1001 executableElement.type = new FunctionTypeImpl.elementWithNameAndArgs( 1043 executableElement.type = new FunctionTypeImpl.elementWithNameAndArgs(
1002 executableElement, null, oldTypeArguments, false); 1044 executableElement, null, oldTypeArguments, false);
1003 executableElement.external = serializedExecutable.isExternal; 1045 executableElement.external = serializedExecutable.isExternal;
1004 currentTypeParameters.removeRange( 1046 currentTypeParameters.removeRange(
1005 oldTypeParametersLength, currentTypeParameters.length); 1047 oldTypeParametersLength, currentTypeParameters.length);
1006 buildDocumentation( 1048 buildDocumentation(
1007 executableElement, serializedExecutable.documentationComment); 1049 executableElement, serializedExecutable.documentationComment);
1050 buildAnnotations(executableElement, serializedExecutable.annotations);
1008 } 1051 }
1009 1052
1010 /** 1053 /**
1011 * Resynthesize an [ExportElement], 1054 * Resynthesize an [ExportElement],
1012 */ 1055 */
1013 ExportElement buildExport(UnlinkedExportPublic serializedExportPublic, 1056 ExportElement buildExport(UnlinkedExportPublic serializedExportPublic,
1014 UnlinkedExportNonPublic serializedExportNonPublic) { 1057 UnlinkedExportNonPublic serializedExportNonPublic) {
1015 ExportElementImpl exportElement = 1058 ExportElementImpl exportElement =
1016 new ExportElementImpl(serializedExportNonPublic.offset); 1059 new ExportElementImpl(serializedExportNonPublic.offset);
1017 String exportedLibraryUri = summaryResynthesizer.sourceFactory 1060 String exportedLibraryUri = summaryResynthesizer.sourceFactory
1018 .resolveUri(librarySource, serializedExportPublic.uri) 1061 .resolveUri(librarySource, serializedExportPublic.uri)
1019 .uri 1062 .uri
1020 .toString(); 1063 .toString();
1021 exportElement.exportedLibrary = new LibraryElementHandle( 1064 exportElement.exportedLibrary = new LibraryElementHandle(
1022 summaryResynthesizer, 1065 summaryResynthesizer,
1023 new ElementLocationImpl.con3(<String>[exportedLibraryUri])); 1066 new ElementLocationImpl.con3(<String>[exportedLibraryUri]));
1024 exportElement.uri = serializedExportPublic.uri; 1067 exportElement.uri = serializedExportPublic.uri;
1025 exportElement.combinators = 1068 exportElement.combinators =
1026 serializedExportPublic.combinators.map(buildCombinator).toList(); 1069 serializedExportPublic.combinators.map(buildCombinator).toList();
1027 exportElement.uriOffset = serializedExportNonPublic.uriOffset; 1070 exportElement.uriOffset = serializedExportNonPublic.uriOffset;
1028 exportElement.uriEnd = serializedExportNonPublic.uriEnd; 1071 exportElement.uriEnd = serializedExportNonPublic.uriEnd;
1072 buildAnnotations(exportElement, serializedExportNonPublic.annotations);
1029 return exportElement; 1073 return exportElement;
1030 } 1074 }
1031 1075
1032 /** 1076 /**
1033 * Build an [ElementHandle] referring to the entity referred to by the given 1077 * Build an [ElementHandle] referring to the entity referred to by the given
1034 * [exportName]. 1078 * [exportName].
1035 */ 1079 */
1036 ElementHandle buildExportName(LinkedExportName exportName) { 1080 ElementHandle buildExportName(LinkedExportName exportName) {
1037 String name = exportName.name; 1081 String name = exportName.name;
1038 if (exportName.kind == ReferenceKind.topLevelPropertyAccessor && 1082 if (exportName.kind == ReferenceKind.topLevelPropertyAccessor &&
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 }); 1122 });
1079 // Add all the names from [exportNames]. 1123 // Add all the names from [exportNames].
1080 for (LinkedExportName exportName in exportNames) { 1124 for (LinkedExportName exportName in exportNames) {
1081 definedNames.putIfAbsent( 1125 definedNames.putIfAbsent(
1082 exportName.name, () => buildExportName(exportName)); 1126 exportName.name, () => buildExportName(exportName));
1083 } 1127 }
1084 return new Namespace(definedNames); 1128 return new Namespace(definedNames);
1085 } 1129 }
1086 1130
1087 /** 1131 /**
1088 * Resynthesize a [FieldElement].
1089 */
1090 FieldElement buildField(UnlinkedVariable serializedField) {
1091 FieldElementImpl fieldElement =
1092 new FieldElementImpl(serializedField.name, -1);
1093 fieldElement.type = buildType(serializedField.type);
1094 fieldElement.const3 = serializedField.isConst;
1095 return fieldElement;
1096 }
1097
1098 /**
1099 * Build the implicit getter and setter associated with [element], and place 1132 * Build the implicit getter and setter associated with [element], and place
1100 * them in [holder]. 1133 * them in [holder].
1101 */ 1134 */
1102 void buildImplicitAccessors( 1135 void buildImplicitAccessors(
1103 PropertyInducingElementImpl element, ElementHolder holder) { 1136 PropertyInducingElementImpl element, ElementHolder holder) {
1104 String name = element.name; 1137 String name = element.name;
1105 DartType type = element.type; 1138 DartType type = element.type;
1106 PropertyAccessorElementImpl getter = 1139 PropertyAccessorElementImpl getter =
1107 new PropertyAccessorElementImpl(name, element.nameOffset); 1140 new PropertyAccessorElementImpl(name, element.nameOffset);
1108 getter.getter = true; 1141 getter.getter = true;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 importElement.importedLibrary = new LibraryElementHandle( 1222 importElement.importedLibrary = new LibraryElementHandle(
1190 summaryResynthesizer, 1223 summaryResynthesizer,
1191 new ElementLocationImpl.con3(<String>[absoluteUri])); 1224 new ElementLocationImpl.con3(<String>[absoluteUri]));
1192 if (isSynthetic) { 1225 if (isSynthetic) {
1193 importElement.synthetic = true; 1226 importElement.synthetic = true;
1194 } else { 1227 } else {
1195 importElement.uri = serializedImport.uri; 1228 importElement.uri = serializedImport.uri;
1196 importElement.uriOffset = serializedImport.uriOffset; 1229 importElement.uriOffset = serializedImport.uriOffset;
1197 importElement.uriEnd = serializedImport.uriEnd; 1230 importElement.uriEnd = serializedImport.uriEnd;
1198 importElement.deferred = serializedImport.isDeferred; 1231 importElement.deferred = serializedImport.isDeferred;
1232 buildAnnotations(importElement, serializedImport.annotations);
1199 } 1233 }
1200 importElement.prefixOffset = serializedImport.prefixOffset; 1234 importElement.prefixOffset = serializedImport.prefixOffset;
1201 if (serializedImport.prefixReference != 0) { 1235 if (serializedImport.prefixReference != 0) {
1202 UnlinkedReference serializedPrefix = 1236 UnlinkedReference serializedPrefix =
1203 unlinkedUnits[0].references[serializedImport.prefixReference]; 1237 unlinkedUnits[0].references[serializedImport.prefixReference];
1204 importElement.prefix = new PrefixElementImpl( 1238 importElement.prefix = new PrefixElementImpl(
1205 serializedPrefix.name, serializedImport.prefixOffset); 1239 serializedPrefix.name, serializedImport.prefixOffset);
1206 } 1240 }
1207 importElement.combinators = 1241 importElement.combinators =
1208 serializedImport.combinators.map(buildCombinator).toList(); 1242 serializedImport.combinators.map(buildCombinator).toList();
1209 return importElement; 1243 return importElement;
1210 } 1244 }
1211 1245
1212 /** 1246 /**
1213 * Main entry point. Resynthesize the [LibraryElement] and return it. 1247 * Main entry point. Resynthesize the [LibraryElement] and return it.
1214 */ 1248 */
1215 LibraryElement buildLibrary() { 1249 LibraryElement buildLibrary() {
1250 CompilationUnitElementImpl definingCompilationUnit =
1251 new CompilationUnitElementImpl(librarySource.shortName);
1252 prepareUnit(definingCompilationUnit, 0);
1216 bool hasName = unlinkedUnits[0].libraryName.isNotEmpty; 1253 bool hasName = unlinkedUnits[0].libraryName.isNotEmpty;
1217 LibraryElementImpl library = new LibraryElementImpl( 1254 LibraryElementImpl library = new LibraryElementImpl(
1218 summaryResynthesizer.context, 1255 summaryResynthesizer.context,
1219 unlinkedUnits[0].libraryName, 1256 unlinkedUnits[0].libraryName,
1220 hasName ? unlinkedUnits[0].libraryNameOffset : -1, 1257 hasName ? unlinkedUnits[0].libraryNameOffset : -1,
1221 unlinkedUnits[0].libraryNameLength); 1258 unlinkedUnits[0].libraryNameLength);
1222 buildDocumentation(library, unlinkedUnits[0].libraryDocumentationComment); 1259 buildDocumentation(library, unlinkedUnits[0].libraryDocumentationComment);
1223 CompilationUnitElementImpl definingCompilationUnit = 1260 buildAnnotations(library, unlinkedUnits[0].libraryAnnotations);
1224 new CompilationUnitElementImpl(librarySource.shortName);
1225 library.definingCompilationUnit = definingCompilationUnit; 1261 library.definingCompilationUnit = definingCompilationUnit;
1226 definingCompilationUnit.source = librarySource; 1262 definingCompilationUnit.source = librarySource;
1227 definingCompilationUnit.librarySource = librarySource; 1263 definingCompilationUnit.librarySource = librarySource;
1228 List<CompilationUnitElement> parts = <CompilationUnitElement>[]; 1264 List<CompilationUnitElement> parts = <CompilationUnitElement>[];
1229 UnlinkedUnit unlinkedDefiningUnit = unlinkedUnits[0]; 1265 UnlinkedUnit unlinkedDefiningUnit = unlinkedUnits[0];
1230 assert(unlinkedDefiningUnit.publicNamespace.parts.length + 1 == 1266 assert(unlinkedDefiningUnit.publicNamespace.parts.length + 1 ==
1231 linkedLibrary.units.length); 1267 linkedLibrary.units.length);
1232 for (int i = 1; i < linkedLibrary.units.length; i++) { 1268 for (int i = 1; i < linkedLibrary.units.length; i++) {
1233 CompilationUnitElementImpl part = buildPart( 1269 CompilationUnitElementImpl part = buildPart(
1234 unlinkedDefiningUnit.publicNamespace.parts[i - 1], 1270 unlinkedDefiningUnit.publicNamespace.parts[i - 1],
(...skipping 10 matching lines...) Expand all
1245 library.imports = imports; 1281 library.imports = imports;
1246 List<ExportElement> exports = <ExportElement>[]; 1282 List<ExportElement> exports = <ExportElement>[];
1247 assert(unlinkedDefiningUnit.exports.length == 1283 assert(unlinkedDefiningUnit.exports.length ==
1248 unlinkedDefiningUnit.publicNamespace.exports.length); 1284 unlinkedDefiningUnit.publicNamespace.exports.length);
1249 for (int i = 0; i < unlinkedDefiningUnit.exports.length; i++) { 1285 for (int i = 0; i < unlinkedDefiningUnit.exports.length; i++) {
1250 exports.add(buildExport(unlinkedDefiningUnit.publicNamespace.exports[i], 1286 exports.add(buildExport(unlinkedDefiningUnit.publicNamespace.exports[i],
1251 unlinkedDefiningUnit.exports[i])); 1287 unlinkedDefiningUnit.exports[i]));
1252 } 1288 }
1253 library.exports = exports; 1289 library.exports = exports;
1254 populateUnit(definingCompilationUnit, 0); 1290 populateUnit(definingCompilationUnit, 0);
1291 finishUnit();
1255 for (int i = 0; i < parts.length; i++) { 1292 for (int i = 0; i < parts.length; i++) {
1293 prepareUnit(parts[i], i + 1);
1256 populateUnit(parts[i], i + 1); 1294 populateUnit(parts[i], i + 1);
1295 finishUnit();
1257 } 1296 }
1258 BuildLibraryElementUtils.patchTopLevelAccessors(library); 1297 BuildLibraryElementUtils.patchTopLevelAccessors(library);
1259 // Update delayed Object class references. 1298 // Update delayed Object class references.
1260 if (isCoreLibrary) { 1299 if (isCoreLibrary) {
1261 ClassElement objectElement = library.getType('Object'); 1300 ClassElement objectElement = library.getType('Object');
1262 assert(objectElement != null); 1301 assert(objectElement != null);
1263 for (ClassElementImpl classElement in delayedObjectSubclasses) { 1302 for (ClassElementImpl classElement in delayedObjectSubclasses) {
1264 classElement.supertype = objectElement.type; 1303 classElement.supertype = objectElement.type;
1265 } 1304 }
1266 } 1305 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 new DefaultParameterElementImpl( 1371 new DefaultParameterElementImpl(
1333 serializedParameter.name, serializedParameter.nameOffset); 1372 serializedParameter.name, serializedParameter.nameOffset);
1334 parameterElement = defaultParameter; 1373 parameterElement = defaultParameter;
1335 defaultParameter.constantInitializer = 1374 defaultParameter.constantInitializer =
1336 _buildConstExpression(serializedParameter.defaultValue); 1375 _buildConstExpression(serializedParameter.defaultValue);
1337 } else { 1376 } else {
1338 parameterElement = new ParameterElementImpl( 1377 parameterElement = new ParameterElementImpl(
1339 serializedParameter.name, serializedParameter.nameOffset); 1378 serializedParameter.name, serializedParameter.nameOffset);
1340 } 1379 }
1341 } 1380 }
1381 buildAnnotations(parameterElement, serializedParameter.annotations);
1342 if (serializedParameter.isFunctionTyped) { 1382 if (serializedParameter.isFunctionTyped) {
1343 FunctionElementImpl parameterTypeElement = 1383 FunctionElementImpl parameterTypeElement =
1344 new FunctionElementImpl('', -1); 1384 new FunctionElementImpl('', -1);
1345 parameterTypeElement.synthetic = true; 1385 parameterTypeElement.synthetic = true;
1346 parameterElement.parameters = 1386 parameterElement.parameters =
1347 serializedParameter.parameters.map(buildParameter).toList(); 1387 serializedParameter.parameters.map(buildParameter).toList();
1348 parameterTypeElement.enclosingElement = parameterElement; 1388 parameterTypeElement.enclosingElement = parameterElement;
1349 parameterTypeElement.shareParameters(parameterElement.parameters); 1389 parameterTypeElement.shareParameters(parameterElement.parameters);
1350 parameterTypeElement.returnType = buildType(serializedParameter.type); 1390 parameterTypeElement.returnType = buildType(serializedParameter.type);
1351 parameterElement.type = new FunctionTypeImpl.elementWithNameAndArgs( 1391 parameterElement.type = new FunctionTypeImpl.elementWithNameAndArgs(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 String uri, UnlinkedPart partDecl, UnlinkedUnit serializedPart) { 1425 String uri, UnlinkedPart partDecl, UnlinkedUnit serializedPart) {
1386 Source unitSource = 1426 Source unitSource =
1387 summaryResynthesizer.sourceFactory.resolveUri(librarySource, uri); 1427 summaryResynthesizer.sourceFactory.resolveUri(librarySource, uri);
1388 CompilationUnitElementImpl partUnit = 1428 CompilationUnitElementImpl partUnit =
1389 new CompilationUnitElementImpl(unitSource.shortName); 1429 new CompilationUnitElementImpl(unitSource.shortName);
1390 partUnit.uriOffset = partDecl.uriOffset; 1430 partUnit.uriOffset = partDecl.uriOffset;
1391 partUnit.uriEnd = partDecl.uriEnd; 1431 partUnit.uriEnd = partDecl.uriEnd;
1392 partUnit.source = unitSource; 1432 partUnit.source = unitSource;
1393 partUnit.librarySource = librarySource; 1433 partUnit.librarySource = librarySource;
1394 partUnit.uri = uri; 1434 partUnit.uri = uri;
1435 buildAnnotations(partUnit, partDecl.annotations);
1395 return partUnit; 1436 return partUnit;
1396 } 1437 }
1397 1438
1398 /** 1439 /**
1399 * Build a [DartType] object based on a [EntityRef]. This [DartType] 1440 * Build a [DartType] object based on a [EntityRef]. This [DartType]
1400 * may refer to elements in other libraries than the library being 1441 * may refer to elements in other libraries than the library being
1401 * deserialized, so handles are used to avoid having to deserialize other 1442 * deserialized, so handles are used to avoid having to deserialize other
1402 * libraries in the process. 1443 * libraries in the process.
1403 */ 1444 */
1404 DartType buildType(EntityRef type, {bool defaultVoid: false}) { 1445 DartType buildType(EntityRef type, {bool defaultVoid: false}) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 serializedTypedef.name, serializedTypedef.nameOffset); 1486 serializedTypedef.name, serializedTypedef.nameOffset);
1446 functionTypeAliasElement.parameters = 1487 functionTypeAliasElement.parameters =
1447 serializedTypedef.parameters.map(buildParameter).toList(); 1488 serializedTypedef.parameters.map(buildParameter).toList();
1448 functionTypeAliasElement.returnType = 1489 functionTypeAliasElement.returnType =
1449 buildType(serializedTypedef.returnType); 1490 buildType(serializedTypedef.returnType);
1450 functionTypeAliasElement.type = 1491 functionTypeAliasElement.type =
1451 new FunctionTypeImpl.forTypedef(functionTypeAliasElement); 1492 new FunctionTypeImpl.forTypedef(functionTypeAliasElement);
1452 functionTypeAliasElement.typeParameters = currentTypeParameters; 1493 functionTypeAliasElement.typeParameters = currentTypeParameters;
1453 buildDocumentation( 1494 buildDocumentation(
1454 functionTypeAliasElement, serializedTypedef.documentationComment); 1495 functionTypeAliasElement, serializedTypedef.documentationComment);
1496 buildAnnotations(functionTypeAliasElement, serializedTypedef.annotations);
1455 unitHolder.addTypeAlias(functionTypeAliasElement); 1497 unitHolder.addTypeAlias(functionTypeAliasElement);
1456 } finally { 1498 } finally {
1457 currentTypeParameters = <TypeParameterElement>[]; 1499 currentTypeParameters = <TypeParameterElement>[];
1458 } 1500 }
1459 } 1501 }
1460 1502
1461 /** 1503 /**
1462 * Resynthesize a [TypeParameterElement], handling all parts of its except 1504 * Resynthesize a [TypeParameterElement], handling all parts of its except
1463 * its bound. 1505 * its bound.
1464 * 1506 *
1465 * The bound is deferred until later since it may refer to other type 1507 * The bound is deferred until later since it may refer to other type
1466 * parameters that have not been resynthesized yet. To handle the bound, 1508 * parameters that have not been resynthesized yet. To handle the bound,
1467 * call [finishTypeParameter]. 1509 * call [finishTypeParameter].
1468 */ 1510 */
1469 TypeParameterElement buildTypeParameter( 1511 TypeParameterElement buildTypeParameter(
1470 UnlinkedTypeParam serializedTypeParameter) { 1512 UnlinkedTypeParam serializedTypeParameter) {
1471 TypeParameterElementImpl typeParameterElement = 1513 TypeParameterElementImpl typeParameterElement =
1472 new TypeParameterElementImpl( 1514 new TypeParameterElementImpl(
1473 serializedTypeParameter.name, serializedTypeParameter.nameOffset); 1515 serializedTypeParameter.name, serializedTypeParameter.nameOffset);
1474 typeParameterElement.type = new TypeParameterTypeImpl(typeParameterElement); 1516 typeParameterElement.type = new TypeParameterTypeImpl(typeParameterElement);
1517 buildAnnotations(typeParameterElement, serializedTypeParameter.annotations);
1475 return typeParameterElement; 1518 return typeParameterElement;
1476 } 1519 }
1477 1520
1478 /** 1521 /**
1479 * Resynthesize a [TopLevelVariableElement] or [FieldElement]. 1522 * Resynthesize a [TopLevelVariableElement] or [FieldElement].
1480 */ 1523 */
1481 void buildVariable(UnlinkedVariable serializedVariable, 1524 void buildVariable(UnlinkedVariable serializedVariable,
1482 [ElementHolder holder]) { 1525 [ElementHolder holder]) {
1483 if (holder == null) { 1526 if (holder == null) {
1484 TopLevelVariableElementImpl element; 1527 TopLevelVariableElementImpl element;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1522 void buildVariableCommonParts(PropertyInducingElementImpl element, 1565 void buildVariableCommonParts(PropertyInducingElementImpl element,
1523 UnlinkedVariable serializedVariable) { 1566 UnlinkedVariable serializedVariable) {
1524 element.type = buildLinkedType(serializedVariable.inferredTypeSlot) ?? 1567 element.type = buildLinkedType(serializedVariable.inferredTypeSlot) ??
1525 buildType(serializedVariable.type); 1568 buildType(serializedVariable.type);
1526 element.const3 = serializedVariable.isConst; 1569 element.const3 = serializedVariable.isConst;
1527 element.final2 = serializedVariable.isFinal; 1570 element.final2 = serializedVariable.isFinal;
1528 element.hasImplicitType = serializedVariable.type == null; 1571 element.hasImplicitType = serializedVariable.type == null;
1529 element.propagatedType = 1572 element.propagatedType =
1530 buildLinkedType(serializedVariable.propagatedTypeSlot); 1573 buildLinkedType(serializedVariable.propagatedTypeSlot);
1531 buildDocumentation(element, serializedVariable.documentationComment); 1574 buildDocumentation(element, serializedVariable.documentationComment);
1575 buildAnnotations(element, serializedVariable.annotations);
1532 } 1576 }
1533 1577
1534 /** 1578 /**
1535 * Finish creating a [TypeParameterElement] by deserializing its bound. 1579 * Finish creating a [TypeParameterElement] by deserializing its bound.
1536 */ 1580 */
1537 void finishTypeParameter(UnlinkedTypeParam serializedTypeParameter, 1581 void finishTypeParameter(UnlinkedTypeParam serializedTypeParameter,
1538 TypeParameterElementImpl typeParameterElement) { 1582 TypeParameterElementImpl typeParameterElement) {
1539 if (serializedTypeParameter.bound != null) { 1583 if (serializedTypeParameter.bound != null) {
1540 typeParameterElement.bound = buildType(serializedTypeParameter.bound); 1584 typeParameterElement.bound = buildType(serializedTypeParameter.bound);
1541 } 1585 }
1542 } 1586 }
1543 1587
1544 /** 1588 /**
1589 * Tear down data structures used during deserialization of a compilation
1590 * unit.
1591 */
1592 void finishUnit() {
1593 unitHolder = null;
1594 linkedUnit = null;
1595 unlinkedUnit = null;
1596 linkedTypeMap = null;
1597 referenceInfos = null;
1598 currentCompilationUnit = null;
1599 }
1600
1601 /**
1545 * Build the components of an [ElementLocationImpl] for the entity in the 1602 * Build the components of an [ElementLocationImpl] for the entity in the
1546 * given [unit] of the dependency located at [dependencyIndex], and having 1603 * given [unit] of the dependency located at [dependencyIndex], and having
1547 * the given [name]. 1604 * the given [name].
1548 */ 1605 */
1549 List<String> getReferencedLocationComponents( 1606 List<String> getReferencedLocationComponents(
1550 int dependencyIndex, int unit, String name) { 1607 int dependencyIndex, int unit, String name) {
1551 if (dependencyIndex == 0) { 1608 if (dependencyIndex == 0) {
1552 String referencedLibraryUri = librarySource.uri.toString(); 1609 String referencedLibraryUri = librarySource.uri.toString();
1553 String partUri; 1610 String partUri;
1554 if (unit != 0) { 1611 if (unit != 0) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1667 referenceInfos[i] = new _ReferenceInfo( 1724 referenceInfos[i] = new _ReferenceInfo(
1668 enclosingInfo, name, element, type, numTypeParameters); 1725 enclosingInfo, name, element, type, numTypeParameters);
1669 } 1726 }
1670 } 1727 }
1671 1728
1672 /** 1729 /**
1673 * Populate a [CompilationUnitElement] by deserializing all the elements 1730 * Populate a [CompilationUnitElement] by deserializing all the elements
1674 * contained in it. 1731 * contained in it.
1675 */ 1732 */
1676 void populateUnit(CompilationUnitElementImpl unit, int unitNum) { 1733 void populateUnit(CompilationUnitElementImpl unit, int unitNum) {
1677 linkedUnit = linkedLibrary.units[unitNum];
1678 unlinkedUnit = unlinkedUnits[unitNum];
1679 linkedTypeMap = <int, EntityRef>{};
1680 for (EntityRef t in linkedUnit.types) {
1681 linkedTypeMap[t.slot] = t;
1682 }
1683 populateReferenceInfos();
1684 unitHolder = new ElementHolder();
1685 unlinkedUnit.classes.forEach(buildClass); 1734 unlinkedUnit.classes.forEach(buildClass);
1686 unlinkedUnit.enums.forEach(buildEnum); 1735 unlinkedUnit.enums.forEach(buildEnum);
1687 unlinkedUnit.executables.forEach(buildExecutable); 1736 unlinkedUnit.executables.forEach(buildExecutable);
1688 unlinkedUnit.typedefs.forEach(buildTypedef); 1737 unlinkedUnit.typedefs.forEach(buildTypedef);
1689 unlinkedUnit.variables.forEach(buildVariable); 1738 unlinkedUnit.variables.forEach(buildVariable);
1690 String absoluteUri = unit.source.uri.toString(); 1739 String absoluteUri = unit.source.uri.toString();
1691 unit.accessors = unitHolder.accessors; 1740 unit.accessors = unitHolder.accessors;
1692 unit.enums = unitHolder.enums; 1741 unit.enums = unitHolder.enums;
1693 unit.functions = unitHolder.functions; 1742 unit.functions = unitHolder.functions;
1694 List<FunctionTypeAliasElement> typeAliases = unitHolder.typeAliases; 1743 List<FunctionTypeAliasElement> typeAliases = unitHolder.typeAliases;
(...skipping 15 matching lines...) Expand all
1710 for (FunctionTypeAliasElement typeAlias in unit.functionTypeAliases) { 1759 for (FunctionTypeAliasElement typeAlias in unit.functionTypeAliases) {
1711 elementMap[typeAlias.name] = typeAlias; 1760 elementMap[typeAlias.name] = typeAlias;
1712 } 1761 }
1713 for (FunctionElement function in unit.functions) { 1762 for (FunctionElement function in unit.functions) {
1714 elementMap[function.name] = function; 1763 elementMap[function.name] = function;
1715 } 1764 }
1716 for (PropertyAccessorElementImpl accessor in unit.accessors) { 1765 for (PropertyAccessorElementImpl accessor in unit.accessors) {
1717 elementMap[accessor.identifier] = accessor; 1766 elementMap[accessor.identifier] = accessor;
1718 } 1767 }
1719 resummarizedElements[absoluteUri] = elementMap; 1768 resummarizedElements[absoluteUri] = elementMap;
1720 unitHolder = null; 1769 }
1721 linkedUnit = null; 1770
1722 unlinkedUnit = null; 1771 /**
1723 linkedTypeMap = null; 1772 * Set up data structures for deserializing a compilation unit.
1724 referenceInfos = null; 1773 */
1774 void prepareUnit(CompilationUnitElementImpl unit, int unitNum) {
1775 linkedUnit = linkedLibrary.units[unitNum];
1776 unlinkedUnit = unlinkedUnits[unitNum];
1777 linkedTypeMap = <int, EntityRef>{};
1778 currentCompilationUnit = unit;
1779 for (EntityRef t in linkedUnit.types) {
1780 linkedTypeMap[t.slot] = t;
1781 }
1782 populateReferenceInfos();
1783 unitHolder = new ElementHolder();
1725 } 1784 }
1726 1785
1727 Expression _buildConstExpression(UnlinkedConst uc) { 1786 Expression _buildConstExpression(UnlinkedConst uc) {
1728 return new _ConstExprBuilder(this, uc).build(); 1787 return new _ConstExprBuilder(this, uc).build();
1729 } 1788 }
1730 1789
1731 /** 1790 /**
1732 * Return the new handle of the `String.length` getter element. 1791 * Return the new handle of the `String.length` getter element.
1733 */ 1792 */
1734 PropertyAccessorElementHandle _buildStringLengthPropertyAccessorElement() => 1793 PropertyAccessorElementHandle _buildStringLengthPropertyAccessorElement() =>
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1871 } 1930 }
1872 : () => this.element; 1931 : () => this.element;
1873 // TODO(paulberry): Is it a bug that we have to pass `false` for 1932 // TODO(paulberry): Is it a bug that we have to pass `false` for
1874 // isInstantiated? 1933 // isInstantiated?
1875 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); 1934 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false);
1876 } else { 1935 } else {
1877 return null; 1936 return null;
1878 } 1937 }
1879 } 1938 }
1880 } 1939 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/idl.dart ('k') | pkg/analyzer/lib/src/summary/summarize_ast.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698