| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.generated.resolver_test; | 5 library analyzer.test.generated.resolver_test; |
| 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/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| (...skipping 3314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3325 main() { | 3325 main() { |
| 3326 var p1 = new Point(0, 0); | 3326 var p1 = new Point(0, 0); |
| 3327 var p2 = new Point(10, 10); | 3327 var p2 = new Point(10, 10); |
| 3328 int n = p1 + p2; | 3328 int n = p1 + p2; |
| 3329 }'''); | 3329 }'''); |
| 3330 computeLibrarySourceErrors(source); | 3330 computeLibrarySourceErrors(source); |
| 3331 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); | 3331 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); |
| 3332 verify([source]); | 3332 verify([source]); |
| 3333 } | 3333 } |
| 3334 | 3334 |
| 3335 void test_invalidUseOfProtectedMember_1() { | 3335 void test_invalidUseOfProtectedMember_field() { |
| 3336 Source source = addSource(r''' | 3336 Source source = addSource(r''' |
| 3337 import 'package:meta/meta.dart'; | 3337 import 'package:meta/meta.dart'; |
| 3338 class A { | 3338 class A { |
| 3339 @protected |
| 3340 int a; |
| 3341 } |
| 3342 abstract class B implements A { |
| 3343 int b() => a; |
| 3344 }'''); |
| 3345 computeLibrarySourceErrors(source); |
| 3346 assertErrors(source, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]); |
| 3347 verify([source]); |
| 3348 } |
| 3349 |
| 3350 void test_invalidUseOfProtectedMember_function() { |
| 3351 Source source = addSource(r''' |
| 3352 import 'package:meta/meta.dart'; |
| 3353 class A { |
| 3339 @protected | 3354 @protected |
| 3340 void a(){ } | 3355 void a(){ } |
| 3341 } | 3356 } |
| 3342 main() { | 3357 main() { |
| 3343 new A().a(); | 3358 new A().a(); |
| 3344 }'''); | 3359 }'''); |
| 3345 computeLibrarySourceErrors(source); | 3360 computeLibrarySourceErrors(source); |
| 3346 assertErrors(source, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]); | 3361 assertErrors(source, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]); |
| 3347 verify([source]); | 3362 verify([source]); |
| 3348 } | 3363 } |
| 3349 | 3364 |
| 3350 void test_invalidUseOfProtectedMember_2() { | 3365 void test_invalidUseOfProtectedMember_getter() { |
| 3351 Source source = addSource(r''' | 3366 Source source = addSource(r''' |
| 3352 import 'package:meta/meta.dart'; | 3367 import 'package:meta/meta.dart'; |
| 3353 class A { | 3368 class A { |
| 3369 @protected |
| 3370 int get a => 42; |
| 3371 } |
| 3372 abstract class B implements A { |
| 3373 int b() => a; |
| 3374 }'''); |
| 3375 computeLibrarySourceErrors(source); |
| 3376 assertErrors(source, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]); |
| 3377 verify([source]); |
| 3378 } |
| 3379 |
| 3380 void test_invalidUseOfProtectedMember_message() { |
| 3381 Source source = addSource(r''' |
| 3382 import 'package:meta/meta.dart'; |
| 3383 class A { |
| 3384 @protected |
| 3385 void a(){ } |
| 3386 } |
| 3387 class B { |
| 3388 void b() => new A().a(); |
| 3389 }'''); |
| 3390 List<AnalysisError> errors = analysisContext2.computeErrors(source); |
| 3391 expect(errors, hasLength(1)); |
| 3392 expect(errors[0].message, |
| 3393 "The member 'a' can only be used within instance members of subclasses o
f 'A'"); |
| 3394 } |
| 3395 |
| 3396 void test_invalidUseOfProtectedMember_method_1() { |
| 3397 Source source = addSource(r''' |
| 3398 import 'package:meta/meta.dart'; |
| 3399 class A { |
| 3354 @protected | 3400 @protected |
| 3355 void a(){ } | 3401 void a(){ } |
| 3356 } | 3402 } |
| 3357 class B { | 3403 class B { |
| 3358 void b() => new A().a(); | 3404 void b() => new A().a(); |
| 3359 }'''); | 3405 }'''); |
| 3360 computeLibrarySourceErrors(source); | 3406 computeLibrarySourceErrors(source); |
| 3361 assertErrors(source, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]); | 3407 assertErrors(source, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]); |
| 3362 verify([source]); | 3408 verify([source]); |
| 3363 } | 3409 } |
| 3364 | 3410 |
| 3365 void test_invalidUseOfProtectedMember_3() { | 3411 void test_invalidUseOfProtectedMember_method_2() { |
| 3366 Source source = addSource(r''' | 3412 Source source = addSource(r''' |
| 3367 import 'package:meta/meta.dart'; | 3413 import 'package:meta/meta.dart'; |
| 3368 class A { | 3414 class A { |
| 3369 @protected | 3415 @protected |
| 3370 void a(){ } | 3416 void a(){ } |
| 3371 } | 3417 } |
| 3372 abstract class B implements A { | 3418 abstract class B implements A { |
| 3373 void b() => a(); | 3419 void b() => a(); |
| 3374 }'''); | 3420 }'''); |
| 3375 computeLibrarySourceErrors(source); | 3421 computeLibrarySourceErrors(source); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3414 @protected m1() {} | 3460 @protected m1() {} |
| 3415 } | 3461 } |
| 3416 class B extends A { | 3462 class B extends A { |
| 3417 static m2(A a) => a.m1(); | 3463 static m2(A a) => a.m1(); |
| 3418 }'''); | 3464 }'''); |
| 3419 computeLibrarySourceErrors(source); | 3465 computeLibrarySourceErrors(source); |
| 3420 assertErrors(source, []); | 3466 assertErrors(source, []); |
| 3421 verify([source]); | 3467 verify([source]); |
| 3422 } | 3468 } |
| 3423 | 3469 |
| 3470 void test_invalidUseOfProtectedMember_OK_4() { |
| 3471 Source source = addSource(r''' |
| 3472 import 'package:meta/meta.dart'; |
| 3473 class A { |
| 3474 @protected |
| 3475 void a(){ } |
| 3476 } |
| 3477 class B extends A { |
| 3478 void a() => a(); |
| 3479 } |
| 3480 main() { |
| 3481 new B().a(); |
| 3482 }'''); |
| 3483 computeLibrarySourceErrors(source); |
| 3484 assertErrors(source, []); |
| 3485 verify([source]); |
| 3486 } |
| 3487 |
| 3488 void test_invalidUseOfProtectedMember_OK_field() { |
| 3489 Source source = addSource(r''' |
| 3490 import 'package:meta/meta.dart'; |
| 3491 class A { |
| 3492 @protected |
| 3493 int a = 42; |
| 3494 } |
| 3495 class B extends A { |
| 3496 int b() => a; |
| 3497 } |
| 3498 '''); |
| 3499 computeLibrarySourceErrors(source); |
| 3500 assertErrors(source, []); |
| 3501 verify([source]); |
| 3502 } |
| 3503 |
| 3504 void test_invalidUseOfProtectedMember_OK_getter() { |
| 3505 Source source = addSource(r''' |
| 3506 import 'package:meta/meta.dart'; |
| 3507 class A { |
| 3508 @protected |
| 3509 int get a => 42; |
| 3510 } |
| 3511 class B extends A { |
| 3512 int b() => a; |
| 3513 } |
| 3514 '''); |
| 3515 computeLibrarySourceErrors(source); |
| 3516 assertErrors(source, []); |
| 3517 verify([source]); |
| 3518 } |
| 3519 |
| 3520 void test_invalidUseOfProtectedMember_OK_setter() { |
| 3521 Source source = addSource(r''' |
| 3522 import 'package:meta/meta.dart'; |
| 3523 class A { |
| 3524 @protected |
| 3525 void set a(int i) { } |
| 3526 } |
| 3527 class B extends A { |
| 3528 void b(int i) { |
| 3529 a = i; |
| 3530 } |
| 3531 } |
| 3532 '''); |
| 3533 computeLibrarySourceErrors(source); |
| 3534 assertErrors(source, []); |
| 3535 verify([source]); |
| 3536 } |
| 3537 |
| 3538 void test_invalidUseOfProtectedMember_setter() { |
| 3539 Source source = addSource(r''' |
| 3540 import 'package:meta/meta.dart'; |
| 3541 class A { |
| 3542 @protected |
| 3543 void set a(int i) { } |
| 3544 } |
| 3545 abstract class B implements A { |
| 3546 b(int i) { |
| 3547 a = i; |
| 3548 } |
| 3549 }'''); |
| 3550 computeLibrarySourceErrors(source); |
| 3551 assertErrors(source, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]); |
| 3552 verify([source]); |
| 3553 } |
| 3554 |
| 3424 void test_isDouble() { | 3555 void test_isDouble() { |
| 3425 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 3556 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 3426 options.dart2jsHint = true; | 3557 options.dart2jsHint = true; |
| 3427 resetWithOptions(options); | 3558 resetWithOptions(options); |
| 3428 Source source = addSource("var v = 1 is double;"); | 3559 Source source = addSource("var v = 1 is double;"); |
| 3429 computeLibrarySourceErrors(source); | 3560 computeLibrarySourceErrors(source); |
| 3430 assertErrors(source, [HintCode.IS_DOUBLE]); | 3561 assertErrors(source, [HintCode.IS_DOUBLE]); |
| 3431 verify([source]); | 3562 verify([source]); |
| 3432 } | 3563 } |
| 3433 | 3564 |
| (...skipping 13744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17178 | 17309 |
| 17179 void _resolveTestUnit(String code) { | 17310 void _resolveTestUnit(String code) { |
| 17180 testCode = code; | 17311 testCode = code; |
| 17181 testSource = addSource(testCode); | 17312 testSource = addSource(testCode); |
| 17182 LibraryElement library = resolve2(testSource); | 17313 LibraryElement library = resolve2(testSource); |
| 17183 assertNoErrors(testSource); | 17314 assertNoErrors(testSource); |
| 17184 verify([testSource]); | 17315 verify([testSource]); |
| 17185 testUnit = resolveCompilationUnit(testSource, library); | 17316 testUnit = resolveCompilationUnit(testSource, library); |
| 17186 } | 17317 } |
| 17187 } | 17318 } |
| OLD | NEW |