OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, the Dart project authors. | 2 * Copyright (c) 2013, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
11 * or implied. See the License for the specific language governing permissions a
nd limitations under | 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
12 * the License. | 12 * the License. |
13 */ | 13 */ |
14 package com.google.dart.engine.resolver; | 14 package com.google.dart.engine.resolver; |
15 | 15 |
16 import com.google.dart.engine.error.HintCode; | 16 import com.google.dart.engine.error.HintCode; |
17 import com.google.dart.engine.error.StaticTypeWarningCode; | 17 import com.google.dart.engine.error.StaticTypeWarningCode; |
18 import com.google.dart.engine.error.StaticWarningCode; | 18 import com.google.dart.engine.error.StaticWarningCode; |
19 import com.google.dart.engine.source.Source; | 19 import com.google.dart.engine.source.Source; |
20 | 20 |
21 public class HintCodeTest extends ResolverTestCase { | 21 public class HintCodeTest extends ResolverTestCase { |
| 22 |
22 public void fail_isInt() throws Exception { | 23 public void fail_isInt() throws Exception { |
23 Source source = addSource(createSource(// | 24 Source source = addSource(createSource(// |
24 "var v = 1 is int;")); | 25 "var v = 1 is int;")); |
25 resolve(source); | 26 resolve(source); |
26 assertErrors(source, HintCode.IS_INT); | 27 assertErrors(source, HintCode.IS_INT); |
27 verify(source); | 28 verify(source); |
28 } | 29 } |
29 | 30 |
30 public void fail_isNotInt() throws Exception { | 31 public void fail_isNotInt() throws Exception { |
31 Source source = addSource(createSource(// | 32 Source source = addSource(createSource(// |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 " return;", | 319 " return;", |
319 " var two = 2;", | 320 " var two = 2;", |
320 " return;", | 321 " return;", |
321 " var three = 3;", | 322 " var three = 3;", |
322 "}")); | 323 "}")); |
323 resolve(source); | 324 resolve(source); |
324 assertErrors(source, HintCode.DEAD_CODE); | 325 assertErrors(source, HintCode.DEAD_CODE); |
325 verify(source); | 326 verify(source); |
326 } | 327 } |
327 | 328 |
| 329 public void test_deprecatedAnnotationUse_assignment() throws Exception { |
| 330 Source source = addSource(createSource(// |
| 331 "class A {", |
| 332 " @deprecated", |
| 333 " A operator+(A a) {}", |
| 334 "}", |
| 335 "f(A a) {", |
| 336 " A b;", |
| 337 " a += b;", |
| 338 "}")); |
| 339 resolve(source); |
| 340 assertErrors(source, HintCode.DEPRECATED_MEMBER_USE); |
| 341 verify(source); |
| 342 } |
| 343 |
| 344 public void test_deprecatedAnnotationUse_deprecated() throws Exception { |
| 345 Source source = addSource(createSource(// |
| 346 "class A {", |
| 347 " @deprecated", |
| 348 " m() {}", |
| 349 " n() {m();}", |
| 350 "}")); |
| 351 resolve(source); |
| 352 assertErrors(source, HintCode.DEPRECATED_MEMBER_USE); |
| 353 verify(source); |
| 354 } |
| 355 |
| 356 public void test_deprecatedAnnotationUse_Deprecated() throws Exception { |
| 357 Source source = addSource(createSource(// |
| 358 "class A {", |
| 359 " @Deprecated('0.9')", |
| 360 " m() {}", |
| 361 " n() {m();}", |
| 362 "}")); |
| 363 resolve(source); |
| 364 assertErrors(source, HintCode.DEPRECATED_MEMBER_USE); |
| 365 verify(source); |
| 366 } |
| 367 |
| 368 public void test_deprecatedAnnotationUse_export() throws Exception { |
| 369 Source source = addSource(createSource(// |
| 370 "export 'deprecated_library.dart';")); |
| 371 addSource("/deprecated_library.dart", createSource(// |
| 372 "@deprecated", |
| 373 "library deprecated_library;", |
| 374 "class A {}")); |
| 375 resolve(source); |
| 376 assertErrors(source, HintCode.DEPRECATED_MEMBER_USE); |
| 377 verify(source); |
| 378 } |
| 379 |
| 380 public void test_deprecatedAnnotationUse_getter() throws Exception { |
| 381 Source source = addSource(createSource(// |
| 382 "class A {", |
| 383 " @deprecated", |
| 384 " get m => 1;", |
| 385 "}", |
| 386 "f(A a) {", |
| 387 " return a.m;", |
| 388 "}")); |
| 389 resolve(source); |
| 390 assertErrors(source, HintCode.DEPRECATED_MEMBER_USE); |
| 391 verify(source); |
| 392 } |
| 393 |
| 394 public void test_deprecatedAnnotationUse_import() throws Exception { |
| 395 Source source = addSource(createSource(// |
| 396 "import 'deprecated_library.dart';", |
| 397 "f(A a) {}")); |
| 398 addSource("/deprecated_library.dart", createSource(// |
| 399 "@deprecated", |
| 400 "library deprecated_library;", |
| 401 "class A {}")); |
| 402 resolve(source); |
| 403 assertErrors(source, HintCode.DEPRECATED_MEMBER_USE); |
| 404 verify(source); |
| 405 } |
| 406 |
| 407 public void test_deprecatedAnnotationUse_indexExpression() throws Exception { |
| 408 Source source = addSource(createSource(// |
| 409 "class A {", |
| 410 " @deprecated", |
| 411 " operator[](int i) {}", |
| 412 "}", |
| 413 "f(A a) {", |
| 414 " return a[1];", |
| 415 "}")); |
| 416 resolve(source); |
| 417 assertErrors(source, HintCode.DEPRECATED_MEMBER_USE); |
| 418 verify(source); |
| 419 } |
| 420 |
| 421 public void test_deprecatedAnnotationUse_instanceCreation() throws Exception { |
| 422 Source source = addSource(createSource(// |
| 423 "class A {", |
| 424 " @deprecated", |
| 425 " A(int i) {}", |
| 426 "}", |
| 427 "f() {", |
| 428 " A a = new A(1);", |
| 429 "}")); |
| 430 resolve(source); |
| 431 assertErrors(source, HintCode.DEPRECATED_MEMBER_USE); |
| 432 verify(source); |
| 433 } |
| 434 |
| 435 public void test_deprecatedAnnotationUse_instanceCreation_namedConstructor() t
hrows Exception { |
| 436 Source source = addSource(createSource(// |
| 437 "class A {", |
| 438 " @deprecated", |
| 439 " A.named(int i) {}", |
| 440 "}", |
| 441 "f() {", |
| 442 " A a = new A.named(1);", |
| 443 "}")); |
| 444 resolve(source); |
| 445 assertErrors(source, HintCode.DEPRECATED_MEMBER_USE); |
| 446 verify(source); |
| 447 } |
| 448 |
| 449 public void test_deprecatedAnnotationUse_operator() throws Exception { |
| 450 Source source = addSource(createSource(// |
| 451 "class A {", |
| 452 " @deprecated", |
| 453 " operator+(A a) {}", |
| 454 "}", |
| 455 "f(A a) {", |
| 456 " A b;", |
| 457 " return a + b;", |
| 458 "}")); |
| 459 resolve(source); |
| 460 assertErrors(source, HintCode.DEPRECATED_MEMBER_USE); |
| 461 verify(source); |
| 462 } |
| 463 |
| 464 public void test_deprecatedAnnotationUse_setter() throws Exception { |
| 465 Source source = addSource(createSource(// |
| 466 "class A {", |
| 467 " @deprecated", |
| 468 " set s(v) {}", |
| 469 "}", |
| 470 "f(A a) {", |
| 471 " return a.s = 1;", |
| 472 "}")); |
| 473 resolve(source); |
| 474 assertErrors(source, HintCode.DEPRECATED_MEMBER_USE); |
| 475 verify(source); |
| 476 } |
| 477 |
| 478 public void test_deprecatedAnnotationUse_superConstructor() throws Exception { |
| 479 Source source = addSource(createSource(// |
| 480 "class A {", |
| 481 " @deprecated", |
| 482 " A() {}", |
| 483 "}", |
| 484 "class B extends A {", |
| 485 " B() : super() {}", |
| 486 "}")); |
| 487 resolve(source); |
| 488 assertErrors(source, HintCode.DEPRECATED_MEMBER_USE); |
| 489 verify(source); |
| 490 } |
| 491 |
| 492 public void test_deprecatedAnnotationUse_superConstructor_namedConstructor() t
hrows Exception { |
| 493 Source source = addSource(createSource(// |
| 494 "class A {", |
| 495 " @deprecated", |
| 496 " A.named() {}", |
| 497 "}", |
| 498 "class B extends A {", |
| 499 " B() : super.named() {}", |
| 500 "}")); |
| 501 resolve(source); |
| 502 assertErrors(source, HintCode.DEPRECATED_MEMBER_USE); |
| 503 verify(source); |
| 504 } |
| 505 |
328 public void test_divisionOptimization_double() throws Exception { | 506 public void test_divisionOptimization_double() throws Exception { |
329 Source source = addSource(createSource(// | 507 Source source = addSource(createSource(// |
330 "f(double x, double y) {", | 508 "f(double x, double y) {", |
331 " var v = (x / y).toInt();", | 509 " var v = (x / y).toInt();", |
332 "}")); | 510 "}")); |
333 resolve(source); | 511 resolve(source); |
334 assertErrors(source, HintCode.DIVISION_OPTIMIZATION); | 512 assertErrors(source, HintCode.DIVISION_OPTIMIZATION); |
335 verify(source); | 513 verify(source); |
336 } | 514 } |
337 | 515 |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 "library lib1;", | 955 "library lib1;", |
778 "class A {}", | 956 "class A {}", |
779 "class B {}")); | 957 "class B {}")); |
780 resolve(source); | 958 resolve(source); |
781 assertErrors(source, HintCode.UNUSED_IMPORT); | 959 assertErrors(source, HintCode.UNUSED_IMPORT); |
782 assertNoErrors(source2); | 960 assertNoErrors(source2); |
783 verify(source, source2); | 961 verify(source, source2); |
784 } | 962 } |
785 | 963 |
786 } | 964 } |
OLD | NEW |