OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 analyzer.test.src.summary.resynthesize_ast_test; | 5 library analyzer.test.src.summary.resynthesize_ast_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 // So, we should not compare them. | 264 // So, we should not compare them. |
265 } | 265 } |
266 | 266 |
267 @override | 267 @override |
268 DartSdk createDartSdk() => AbstractContextTest.SHARED_MOCK_SDK; | 268 DartSdk createDartSdk() => AbstractContextTest.SHARED_MOCK_SDK; |
269 | 269 |
270 @override | 270 @override |
271 AnalysisOptionsImpl createOptions() => | 271 AnalysisOptionsImpl createOptions() => |
272 super.createOptions()..strongMode = isStrongMode; | 272 super.createOptions()..strongMode = isStrongMode; |
273 | 273 |
274 @override | 274 test_getElement_constructor_named() async { |
275 TestSummaryResynthesizer encodeDecodeLibrarySource(Source source) { | 275 String text = 'class C { C.named(); }'; |
| 276 Source source = addLibrarySource('/test.dart', text); |
| 277 ConstructorElement original = context |
| 278 .computeLibraryElement(source) |
| 279 .getType('C') |
| 280 .getNamedConstructor('named'); |
| 281 expect(original, isNotNull); |
| 282 ConstructorElement resynthesized = _validateGetElement(text, original); |
| 283 compareConstructorElements(resynthesized, original, 'C.constructor named'); |
| 284 } |
| 285 |
| 286 test_getElement_constructor_unnamed() async { |
| 287 String text = 'class C { C(); }'; |
| 288 Source source = addLibrarySource('/test.dart', text); |
| 289 ConstructorElement original = |
| 290 context.computeLibraryElement(source).getType('C').unnamedConstructor; |
| 291 expect(original, isNotNull); |
| 292 ConstructorElement resynthesized = _validateGetElement(text, original); |
| 293 compareConstructorElements(resynthesized, original, 'C.constructor'); |
| 294 } |
| 295 |
| 296 test_getElement_field() async { |
| 297 String text = 'class C { var f; }'; |
| 298 Source source = addLibrarySource('/test.dart', text); |
| 299 FieldElement original = |
| 300 context.computeLibraryElement(source).getType('C').getField('f'); |
| 301 expect(original, isNotNull); |
| 302 FieldElement resynthesized = _validateGetElement(text, original); |
| 303 compareFieldElements(resynthesized, original, 'C.field f'); |
| 304 } |
| 305 |
| 306 test_getElement_getter() async { |
| 307 String text = 'class C { get f => null; }'; |
| 308 Source source = addLibrarySource('/test.dart', text); |
| 309 PropertyAccessorElement original = |
| 310 context.computeLibraryElement(source).getType('C').getGetter('f'); |
| 311 expect(original, isNotNull); |
| 312 PropertyAccessorElement resynthesized = _validateGetElement(text, original); |
| 313 comparePropertyAccessorElements(resynthesized, original, 'C.getter f'); |
| 314 } |
| 315 |
| 316 test_getElement_method() async { |
| 317 String text = 'class C { f() {} }'; |
| 318 Source source = addLibrarySource('/test.dart', text); |
| 319 MethodElement original = |
| 320 context.computeLibraryElement(source).getType('C').getMethod('f'); |
| 321 expect(original, isNotNull); |
| 322 MethodElement resynthesized = _validateGetElement(text, original); |
| 323 compareMethodElements(resynthesized, original, 'C.method f'); |
| 324 } |
| 325 |
| 326 test_getElement_operator() async { |
| 327 String text = 'class C { operator+(x) => null; }'; |
| 328 Source source = addLibrarySource('/test.dart', text); |
| 329 MethodElement original = |
| 330 context.computeLibraryElement(source).getType('C').getMethod('+'); |
| 331 expect(original, isNotNull); |
| 332 MethodElement resynthesized = _validateGetElement(text, original); |
| 333 compareMethodElements(resynthesized, original, 'C.operator+'); |
| 334 } |
| 335 |
| 336 test_getElement_setter() async { |
| 337 String text = 'class C { void set f(value) {} }'; |
| 338 Source source = addLibrarySource('/test.dart', text); |
| 339 PropertyAccessorElement original = |
| 340 context.computeLibraryElement(source).getType('C').getSetter('f'); |
| 341 expect(original, isNotNull); |
| 342 PropertyAccessorElement resynthesized = _validateGetElement(text, original); |
| 343 comparePropertyAccessorElements(resynthesized, original, 'C.setter f'); |
| 344 } |
| 345 |
| 346 test_getElement_unit() async { |
| 347 String text = 'class C { f() {} }'; |
| 348 Source source = addLibrarySource('/test.dart', text); |
| 349 CompilationUnitElement original = |
| 350 context.computeLibraryElement(source).definingCompilationUnit; |
| 351 expect(original, isNotNull); |
| 352 CompilationUnitElement resynthesized = _validateGetElement(text, original); |
| 353 compareCompilationUnitElements(resynthesized, original); |
| 354 } |
| 355 |
| 356 /** |
| 357 * Return a [SummaryResynthesizer] to resynthesize the library with the |
| 358 * given [Source]. |
| 359 */ |
| 360 TestSummaryResynthesizer _encodeDecodeLibrarySource(Source source) { |
276 return _encodeLibrary(source); | 361 return _encodeLibrary(source); |
277 } | 362 } |
| 363 |
| 364 /** |
| 365 * Encode the library containing [original] into a summary and then use |
| 366 * [TestSummaryResynthesizer.getElement] to retrieve just the original |
| 367 * element from the resynthesized summary. |
| 368 */ |
| 369 Element _validateGetElement(String text, Element original) { |
| 370 SummaryResynthesizer resynthesizer = |
| 371 _encodeDecodeLibrarySource(original.library.source); |
| 372 ElementLocationImpl location = original.location; |
| 373 Element result = resynthesizer.getElement(location); |
| 374 checkMinimalResynthesisWork(resynthesizer, original.library); |
| 375 // Check that no other summaries needed to be resynthesized to resynthesize |
| 376 // the library element. |
| 377 expect(resynthesizer.resynthesisCount, 3); |
| 378 expect(result.location, location); |
| 379 return result; |
| 380 } |
278 } | 381 } |
OLD | NEW |