| 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 test.src.serialization.elements_test; | 5 library test.src.serialization.elements_test; |
| 6 | 6 |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/constant/value.dart'; | 10 import 'package:analyzer/dart/constant/value.dart'; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 expect(resynthesized.hasExtUri, original.hasExtUri); | 100 expect(resynthesized.hasExtUri, original.hasExtUri); |
| 101 compareCompilationUnitElements(resynthesized.definingCompilationUnit, | 101 compareCompilationUnitElements(resynthesized.definingCompilationUnit, |
| 102 original.definingCompilationUnit); | 102 original.definingCompilationUnit); |
| 103 expect(resynthesized.parts.length, original.parts.length, reason: 'parts'); | 103 expect(resynthesized.parts.length, original.parts.length, reason: 'parts'); |
| 104 for (int i = 0; i < resynthesized.parts.length; i++) { | 104 for (int i = 0; i < resynthesized.parts.length; i++) { |
| 105 compareCompilationUnitElements(resynthesized.parts[i], original.parts[i]); | 105 compareCompilationUnitElements(resynthesized.parts[i], original.parts[i]); |
| 106 } | 106 } |
| 107 expect(resynthesized.imports.length, original.imports.length, | 107 expect(resynthesized.imports.length, original.imports.length, |
| 108 reason: 'imports'); | 108 reason: 'imports'); |
| 109 for (int i = 0; i < resynthesized.imports.length; i++) { | 109 for (int i = 0; i < resynthesized.imports.length; i++) { |
| 110 compareImportElements(resynthesized.imports[i], original.imports[i], | 110 ImportElement originalImport = original.imports[i]; |
| 111 'import ${original.imports[i].uri}'); | 111 compareImportElements( |
| 112 resynthesized.imports[i], originalImport, originalImport.toString()); |
| 112 } | 113 } |
| 113 expect(resynthesized.exports.length, original.exports.length, | 114 expect(resynthesized.exports.length, original.exports.length, |
| 114 reason: 'exports'); | 115 reason: 'exports'); |
| 115 for (int i = 0; i < resynthesized.exports.length; i++) { | 116 for (int i = 0; i < resynthesized.exports.length; i++) { |
| 116 compareExportElements(resynthesized.exports[i], original.exports[i], | 117 ExportElement originalExport = original.exports[i]; |
| 117 'export ${original.exports[i].uri}'); | 118 compareExportElements( |
| 119 resynthesized.exports[i], originalExport, originalExport.toString()); |
| 118 } | 120 } |
| 119 expect(resynthesized.nameLength, original.nameLength); | 121 expect(resynthesized.nameLength, original.nameLength); |
| 120 compareNamespaces(resynthesized.publicNamespace, original.publicNamespace, | 122 compareNamespaces(resynthesized.publicNamespace, original.publicNamespace, |
| 121 '(public namespace)'); | 123 '(public namespace)'); |
| 122 compareNamespaces(resynthesized.exportNamespace, original.exportNamespace, | 124 compareNamespaces(resynthesized.exportNamespace, original.exportNamespace, |
| 123 '(export namespace)'); | 125 '(export namespace)'); |
| 124 if (original.entryPoint == null) { | 126 if (original.entryPoint == null) { |
| 125 expect(resynthesized.entryPoint, isNull); | 127 expect(resynthesized.entryPoint, isNull); |
| 126 } else { | 128 } else { |
| 127 expect(resynthesized.entryPoint, isNotNull); | 129 expect(resynthesized.entryPoint, isNotNull); |
| (...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1157 Map<String, UnlinkedUnit> unlinkedSummaries = <String, UnlinkedUnit>{}; | 1159 Map<String, UnlinkedUnit> unlinkedSummaries = <String, UnlinkedUnit>{}; |
| 1158 LinkedLibrary getLinkedSummaryFor(LibraryElement lib) { | 1160 LinkedLibrary getLinkedSummaryFor(LibraryElement lib) { |
| 1159 LibrarySerializationResult serialized = serializeLibrary( | 1161 LibrarySerializationResult serialized = serializeLibrary( |
| 1160 lib, context.typeProvider, context.analysisOptions.strongMode); | 1162 lib, context.typeProvider, context.analysisOptions.strongMode); |
| 1161 for (int i = 0; i < serialized.unlinkedUnits.length; i++) { | 1163 for (int i = 0; i < serialized.unlinkedUnits.length; i++) { |
| 1162 unlinkedSummaries[serialized.unitUris[i]] = | 1164 unlinkedSummaries[serialized.unitUris[i]] = |
| 1163 new UnlinkedUnit.fromBuffer(serialized.unlinkedUnits[i].toBuffer()); | 1165 new UnlinkedUnit.fromBuffer(serialized.unlinkedUnits[i].toBuffer()); |
| 1164 } | 1166 } |
| 1165 return new LinkedLibrary.fromBuffer(serialized.linked.toBuffer()); | 1167 return new LinkedLibrary.fromBuffer(serialized.linked.toBuffer()); |
| 1166 } | 1168 } |
| 1169 |
| 1167 Map<String, LinkedLibrary> linkedSummaries = <String, LinkedLibrary>{ | 1170 Map<String, LinkedLibrary> linkedSummaries = <String, LinkedLibrary>{ |
| 1168 library.source.uri.toString(): getLinkedSummaryFor(library) | 1171 library.source.uri.toString(): getLinkedSummaryFor(library) |
| 1169 }; | 1172 }; |
| 1170 for (Source source in otherLibrarySources) { | 1173 for (Source source in otherLibrarySources) { |
| 1171 LibraryElement original = context.computeLibraryElement(source); | 1174 LibraryElement original = context.computeLibraryElement(source); |
| 1172 String uri = source.uri.toString(); | 1175 String uri = source.uri.toString(); |
| 1173 linkedSummaries[uri] = getLinkedSummaryFor(original); | 1176 linkedSummaries[uri] = getLinkedSummaryFor(original); |
| 1174 } | 1177 } |
| 1175 if (dumpSummaries) { | 1178 if (dumpSummaries) { |
| 1176 unlinkedSummaries.forEach((String path, UnlinkedUnit unit) { | 1179 unlinkedSummaries.forEach((String path, UnlinkedUnit unit) { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1321 return element.isSetter; | 1324 return element.isSetter; |
| 1322 } | 1325 } |
| 1323 return false; | 1326 return false; |
| 1324 } else if (modifier == Modifier.STATIC) { | 1327 } else if (modifier == Modifier.STATIC) { |
| 1325 if (element is ExecutableElement) { | 1328 if (element is ExecutableElement) { |
| 1326 return element.isStatic; | 1329 return element.isStatic; |
| 1327 } | 1330 } |
| 1328 return false; | 1331 return false; |
| 1329 } else if (modifier == Modifier.SYNTHETIC) { | 1332 } else if (modifier == Modifier.SYNTHETIC) { |
| 1330 return element.isSynthetic; | 1333 return element.isSynthetic; |
| 1334 } else if (modifier == Modifier.URI_EXISTS) { |
| 1335 if (element is ExportElement) { |
| 1336 return element.uriExists; |
| 1337 } else if (element is ImportElement) { |
| 1338 return element.uriExists; |
| 1339 } |
| 1340 return false; |
| 1331 } | 1341 } |
| 1332 throw new UnimplementedError( | 1342 throw new UnimplementedError( |
| 1333 'Modifier $modifier for ${element?.runtimeType}'); | 1343 'Modifier $modifier for ${element?.runtimeType}'); |
| 1334 } | 1344 } |
| 1335 } | 1345 } |
| 1336 | 1346 |
| 1337 @reflectiveTest | 1347 @reflectiveTest |
| 1338 class ResynthesizeElementTest extends ResynthesizeTest { | 1348 class ResynthesizeElementTest extends ResynthesizeTest { |
| 1339 @override | 1349 @override |
| 1340 LibraryElementImpl checkLibrary(String text, | 1350 LibraryElementImpl checkLibrary(String text, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1387 Map<String, UnlinkedUnit> unlinkedSummaries = <String, UnlinkedUnit>{}; | 1397 Map<String, UnlinkedUnit> unlinkedSummaries = <String, UnlinkedUnit>{}; |
| 1388 LinkedLibrary getLinkedSummaryFor(LibraryElement lib) { | 1398 LinkedLibrary getLinkedSummaryFor(LibraryElement lib) { |
| 1389 LibrarySerializationResult serialized = serializeLibrary( | 1399 LibrarySerializationResult serialized = serializeLibrary( |
| 1390 lib, context.typeProvider, context.analysisOptions.strongMode); | 1400 lib, context.typeProvider, context.analysisOptions.strongMode); |
| 1391 for (int i = 0; i < serialized.unlinkedUnits.length; i++) { | 1401 for (int i = 0; i < serialized.unlinkedUnits.length; i++) { |
| 1392 unlinkedSummaries[serialized.unitUris[i]] = | 1402 unlinkedSummaries[serialized.unitUris[i]] = |
| 1393 new UnlinkedUnit.fromBuffer(serialized.unlinkedUnits[i].toBuffer()); | 1403 new UnlinkedUnit.fromBuffer(serialized.unlinkedUnits[i].toBuffer()); |
| 1394 } | 1404 } |
| 1395 return new LinkedLibrary.fromBuffer(serialized.linked.toBuffer()); | 1405 return new LinkedLibrary.fromBuffer(serialized.linked.toBuffer()); |
| 1396 } | 1406 } |
| 1407 |
| 1397 Map<String, LinkedLibrary> linkedSummaries = <String, LinkedLibrary>{ | 1408 Map<String, LinkedLibrary> linkedSummaries = <String, LinkedLibrary>{ |
| 1398 library.source.uri.toString(): getLinkedSummaryFor(library) | 1409 library.source.uri.toString(): getLinkedSummaryFor(library) |
| 1399 }; | 1410 }; |
| 1400 for (Source source in otherLibrarySources) { | 1411 for (Source source in otherLibrarySources) { |
| 1401 LibraryElement original = context.computeLibraryElement(source); | 1412 LibraryElement original = context.computeLibraryElement(source); |
| 1402 String uri = source.uri.toString(); | 1413 String uri = source.uri.toString(); |
| 1403 linkedSummaries[uri] = getLinkedSummaryFor(original); | 1414 linkedSummaries[uri] = getLinkedSummaryFor(original); |
| 1404 } | 1415 } |
| 1405 if (dumpSummaries) { | 1416 if (dumpSummaries) { |
| 1406 unlinkedSummaries.forEach((String path, UnlinkedUnit unit) { | 1417 unlinkedSummaries.forEach((String path, UnlinkedUnit unit) { |
| (...skipping 3206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4613 fail('Unexpectedly tried to get unlinked summary for $uri'); | 4624 fail('Unexpectedly tried to get unlinked summary for $uri'); |
| 4614 } | 4625 } |
| 4615 return serializedUnit; | 4626 return serializedUnit; |
| 4616 } | 4627 } |
| 4617 | 4628 |
| 4618 @override | 4629 @override |
| 4619 bool hasLibrarySummary(String uri) { | 4630 bool hasLibrarySummary(String uri) { |
| 4620 return true; | 4631 return true; |
| 4621 } | 4632 } |
| 4622 } | 4633 } |
| OLD | NEW |