| 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 engine.declaration_resolver_test; | 5 library engine.declaration_resolver_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
| 9 import 'package:analyzer/src/dart/ast/ast.dart'; | 9 import 'package:analyzer/src/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/src/dart/ast/utilities.dart'; | 10 import 'package:analyzer/src/dart/ast/utilities.dart'; |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 '''; | 295 '''; |
| 296 CompilationUnit unit = resolveSource(code); | 296 CompilationUnit unit = resolveSource(code); |
| 297 FunctionElement setterElement = | 297 FunctionElement setterElement = |
| 298 _findSimpleIdentifier(unit, code, 'zzz(x)').staticElement; | 298 _findSimpleIdentifier(unit, code, 'zzz(x)').staticElement; |
| 299 // re-resolve | 299 // re-resolve |
| 300 CompilationUnit unit2 = _cloneResolveUnit(unit); | 300 CompilationUnit unit2 = _cloneResolveUnit(unit); |
| 301 SimpleIdentifier setterName = _findSimpleIdentifier(unit2, code, 'zzz(x)'); | 301 SimpleIdentifier setterName = _findSimpleIdentifier(unit2, code, 'zzz(x)'); |
| 302 expect(setterName.staticElement, same(setterElement)); | 302 expect(setterName.staticElement, same(setterElement)); |
| 303 } | 303 } |
| 304 | 304 |
| 305 void test_visitExportDirective_notExistingSource() { |
| 306 String code = r''' |
| 307 export 'foo.dart'; |
| 308 '''; |
| 309 CompilationUnit unit = resolveSource(code); |
| 310 // re-resolve |
| 311 _cloneResolveUnit(unit); |
| 312 // no other validations than built into DeclarationResolver |
| 313 } |
| 314 |
| 315 void test_visitExportDirective_unresolvedUri() { |
| 316 String code = r''' |
| 317 export 'package:foo/bar.dart'; |
| 318 '''; |
| 319 CompilationUnit unit = resolveSource(code); |
| 320 // re-resolve |
| 321 _cloneResolveUnit(unit); |
| 322 // no other validations than built into DeclarationResolver |
| 323 } |
| 324 |
| 305 void test_visitFunctionExpression() { | 325 void test_visitFunctionExpression() { |
| 306 String code = r''' | 326 String code = r''' |
| 307 main(List<String> items) { | 327 main(List<String> items) { |
| 308 items.forEach((item) {}); | 328 items.forEach((item) {}); |
| 309 } | 329 } |
| 310 '''; | 330 '''; |
| 311 CompilationUnit unit = resolveSource(code); | 331 CompilationUnit unit = resolveSource(code); |
| 312 // re-resolve | 332 // re-resolve |
| 313 _cloneResolveUnit(unit); | 333 _cloneResolveUnit(unit); |
| 314 // no other validations than built into DeclarationResolver | 334 // no other validations than built into DeclarationResolver |
| 315 } | 335 } |
| 316 | 336 |
| 317 void test_visitMethodDeclaration_unaryMinus() { | 337 void test_visitImportDirective_notExistingSource() { |
| 318 String code = r''' | 338 String code = r''' |
| 319 class C { | 339 import 'foo.dart'; |
| 320 C operator -() => null; | |
| 321 C operator -(C other) => null; | |
| 322 } | |
| 323 '''; | 340 '''; |
| 324 CompilationUnit unit = resolveSource(code); | 341 CompilationUnit unit = resolveSource(code); |
| 325 // re-resolve | 342 // re-resolve |
| 343 _cloneResolveUnit(unit); |
| 344 // no other validations than built into DeclarationResolver |
| 345 } |
| 346 |
| 347 void test_visitImportDirective_unresolvedUri() { |
| 348 String code = r''' |
| 349 import 'package:foo/bar.dart'; |
| 350 '''; |
| 351 CompilationUnit unit = resolveSource(code); |
| 352 // re-resolve |
| 326 _cloneResolveUnit(unit); | 353 _cloneResolveUnit(unit); |
| 327 // no other validations than built into DeclarationResolver | 354 // no other validations than built into DeclarationResolver |
| 328 } | 355 } |
| 329 | 356 |
| 330 void test_visitMethodDeclaration_getter_duplicate() { | 357 void test_visitMethodDeclaration_getter_duplicate() { |
| 331 String code = r''' | 358 String code = r''' |
| 332 class C { | 359 class C { |
| 333 int get zzz => 1; | 360 int get zzz => 1; |
| 334 String get zzz => null; | 361 String get zzz => null; |
| 335 } | 362 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 _findSimpleIdentifier(unit, code, 'zzz(x)').staticElement; | 429 _findSimpleIdentifier(unit, code, 'zzz(x)').staticElement; |
| 403 PropertyAccessorElement secondElement = | 430 PropertyAccessorElement secondElement = |
| 404 _findSimpleIdentifier(unit, code, 'zzz(y)').staticElement; | 431 _findSimpleIdentifier(unit, code, 'zzz(y)').staticElement; |
| 405 // re-resolve | 432 // re-resolve |
| 406 CompilationUnit unit2 = _cloneResolveUnit(unit); | 433 CompilationUnit unit2 = _cloneResolveUnit(unit); |
| 407 SimpleIdentifier firstName = _findSimpleIdentifier(unit2, code, 'zzz(x)'); | 434 SimpleIdentifier firstName = _findSimpleIdentifier(unit2, code, 'zzz(x)'); |
| 408 SimpleIdentifier secondName = _findSimpleIdentifier(unit2, code, 'zzz(y)'); | 435 SimpleIdentifier secondName = _findSimpleIdentifier(unit2, code, 'zzz(y)'); |
| 409 expect(firstName.staticElement, same(firstElement)); | 436 expect(firstName.staticElement, same(firstElement)); |
| 410 expect(secondName.staticElement, same(secondElement)); | 437 expect(secondName.staticElement, same(secondElement)); |
| 411 } | 438 } |
| 439 |
| 440 void test_visitMethodDeclaration_unaryMinus() { |
| 441 String code = r''' |
| 442 class C { |
| 443 C operator -() => null; |
| 444 C operator -(C other) => null; |
| 445 } |
| 446 '''; |
| 447 CompilationUnit unit = resolveSource(code); |
| 448 // re-resolve |
| 449 _cloneResolveUnit(unit); |
| 450 // no other validations than built into DeclarationResolver |
| 451 } |
| 452 |
| 453 void test_visitPartDirective_notExistingSource() { |
| 454 String code = r''' |
| 455 part 'foo.bar'; |
| 456 '''; |
| 457 CompilationUnit unit = resolveSource(code); |
| 458 // re-resolve |
| 459 _cloneResolveUnit(unit); |
| 460 // no other validations than built into DeclarationResolver |
| 461 } |
| 412 } | 462 } |
| 413 | 463 |
| 414 /** | 464 /** |
| 415 * Strong mode DeclarationResolver tests | 465 * Strong mode DeclarationResolver tests |
| 416 */ | 466 */ |
| 417 @reflectiveTest | 467 @reflectiveTest |
| 418 class StrongModeDeclarationResolverTest extends ResolverTestCase { | 468 class StrongModeDeclarationResolverTest extends ResolverTestCase { |
| 419 @override | 469 @override |
| 420 void setUp() { | 470 void setUp() { |
| 421 resetWithOptions(new AnalysisOptionsImpl()..strongMode = true); | 471 resetWithOptions(new AnalysisOptionsImpl()..strongMode = true); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 expect(element.type.toString(), "<T>(T, T) → T"); | 510 expect(element.type.toString(), "<T>(T, T) → T"); |
| 461 expect(t.element, same(tElement)); | 511 expect(t.element, same(tElement)); |
| 462 | 512 |
| 463 // re-resolve | 513 // re-resolve |
| 464 CompilationUnit unit2 = _cloneResolveUnit(unit); | 514 CompilationUnit unit2 = _cloneResolveUnit(unit); |
| 465 node = _findSimpleIdentifier(unit2, code, 'max').parent; | 515 node = _findSimpleIdentifier(unit2, code, 'max').parent; |
| 466 t = node.typeParameters.typeParameters[0]; | 516 t = node.typeParameters.typeParameters[0]; |
| 467 expect(t.element, same(tElement)); | 517 expect(t.element, same(tElement)); |
| 468 } | 518 } |
| 469 } | 519 } |
| OLD | NEW |