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 engine.resolver_test; | 5 library engine.resolver_test; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 import 'package:analyzer/src/generated/java_core.dart'; | 8 import 'package:analyzer/src/generated/java_core.dart'; |
9 import 'package:analyzer/src/generated/java_engine.dart'; | 9 import 'package:analyzer/src/generated/java_engine.dart'; |
10 import 'package:analyzer/src/generated/java_engine_io.dart'; | 10 import 'package:analyzer/src/generated/java_engine_io.dart'; |
(...skipping 3190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3201 Source source2 = addNamedSource("/lib1.dart", r''' | 3201 Source source2 = addNamedSource("/lib1.dart", r''' |
3202 library lib1; | 3202 library lib1; |
3203 class A {} | 3203 class A {} |
3204 class B {}'''); | 3204 class B {}'''); |
3205 resolve(source); | 3205 resolve(source); |
3206 assertErrors(source, [HintCode.UNUSED_IMPORT]); | 3206 assertErrors(source, [HintCode.UNUSED_IMPORT]); |
3207 assertNoErrors(source2); | 3207 assertNoErrors(source2); |
3208 verify([source, source2]); | 3208 verify([source, source2]); |
3209 } | 3209 } |
3210 | 3210 |
| 3211 void test_unusedElement_class_noReference() { |
| 3212 enableUnusedElement = true; |
| 3213 Source source = addSource(r''' |
| 3214 class _A {} |
| 3215 main() { |
| 3216 }'''); |
| 3217 resolve(source); |
| 3218 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 3219 verify([source]); |
| 3220 } |
| 3221 |
| 3222 void test_unusedElement_class_inConstructorName() { |
| 3223 enableUnusedElement = true; |
| 3224 Source source = addSource(r''' |
| 3225 class _A { |
| 3226 _A() {} |
| 3227 _A.named() {} |
| 3228 } |
| 3229 '''); |
| 3230 resolve(source); |
| 3231 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 3232 verify([source]); |
| 3233 } |
| 3234 |
| 3235 void test_unusedElement_class_inClassMember() { |
| 3236 enableUnusedElement = true; |
| 3237 Source source = addSource(r''' |
| 3238 class _A { |
| 3239 static staticMethod() { |
| 3240 new _A(); |
| 3241 } |
| 3242 instanceMethod() { |
| 3243 new _A(); |
| 3244 } |
| 3245 } |
| 3246 '''); |
| 3247 resolve(source); |
| 3248 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 3249 verify([source]); |
| 3250 } |
| 3251 |
| 3252 void test_unusedElement_class_isExpression() { |
| 3253 enableUnusedElement = true; |
| 3254 Source source = addSource(r''' |
| 3255 class _A {} |
| 3256 main(p) { |
| 3257 if (p is _A) { |
| 3258 } |
| 3259 } |
| 3260 '''); |
| 3261 resolve(source); |
| 3262 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 3263 verify([source]); |
| 3264 } |
| 3265 |
| 3266 void test_unusedElement_class_variableDeclaration() { |
| 3267 enableUnusedElement = true; |
| 3268 Source source = addSource(r''' |
| 3269 class _A {} |
| 3270 main() { |
| 3271 _A v; |
| 3272 print(v); |
| 3273 } |
| 3274 print(x) {} |
| 3275 '''); |
| 3276 resolve(source); |
| 3277 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 3278 verify([source]); |
| 3279 } |
| 3280 |
| 3281 void test_unusedElement_class_isUsed_extends() { |
| 3282 enableUnusedElement = true; |
| 3283 Source source = addSource(r''' |
| 3284 class _A {} |
| 3285 class B extends _A {} |
| 3286 '''); |
| 3287 resolve(source); |
| 3288 assertNoErrors(source); |
| 3289 verify([source]); |
| 3290 } |
| 3291 |
| 3292 void test_unusedElement_class_isUsed_implements() { |
| 3293 enableUnusedElement = true; |
| 3294 Source source = addSource(r''' |
| 3295 class _A {} |
| 3296 class B implements _A {} |
| 3297 '''); |
| 3298 resolve(source); |
| 3299 assertNoErrors(source); |
| 3300 verify([source]); |
| 3301 } |
| 3302 |
| 3303 void test_unusedElement_class_isUsed_instanceCreation() { |
| 3304 enableUnusedElement = true; |
| 3305 Source source = addSource(r''' |
| 3306 class _A {} |
| 3307 main() { |
| 3308 new _A(); |
| 3309 }'''); |
| 3310 resolve(source); |
| 3311 assertNoErrors(source); |
| 3312 verify([source]); |
| 3313 } |
| 3314 |
| 3315 void test_unusedElement_class_isUsed_staticFieldAccess() { |
| 3316 enableUnusedElement = true; |
| 3317 Source source = addSource(r''' |
| 3318 class _A { |
| 3319 static const F = 42; |
| 3320 } |
| 3321 main() { |
| 3322 _A.F; |
| 3323 }'''); |
| 3324 resolve(source); |
| 3325 assertNoErrors(source); |
| 3326 verify([source]); |
| 3327 } |
| 3328 |
| 3329 void test_unusedElement_class_isUsed_staticMethodInvocation() { |
| 3330 enableUnusedElement = true; |
| 3331 Source source = addSource(r''' |
| 3332 class _A { |
| 3333 static m() {} |
| 3334 } |
| 3335 main() { |
| 3336 _A.m(); |
| 3337 }'''); |
| 3338 resolve(source); |
| 3339 assertNoErrors(source); |
| 3340 verify([source]); |
| 3341 } |
| 3342 |
3211 void test_unusedLocalVariable() { | 3343 void test_unusedLocalVariable() { |
3212 enableUnusedLocalVariable = true; | 3344 enableUnusedLocalVariable = true; |
3213 Source source = addSource(r''' | 3345 Source source = addSource(r''' |
3214 main() { | 3346 main() { |
3215 var v = 1; | 3347 var v = 1; |
3216 v = 2; | 3348 v = 2; |
3217 }'''); | 3349 }'''); |
3218 resolve(source); | 3350 resolve(source); |
3219 assertErrors(source, [HintCode.UNUSED_LOCAL_VARIABLE]); | 3351 assertErrors(source, [HintCode.UNUSED_LOCAL_VARIABLE]); |
3220 verify([source]); | 3352 verify([source]); |
(...skipping 3106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6327 } | 6459 } |
6328 } | 6460 } |
6329 | 6461 |
6330 class ResolverTestCase extends EngineTestCase { | 6462 class ResolverTestCase extends EngineTestCase { |
6331 /** | 6463 /** |
6332 * The analysis context used to parse the compilation units being resolved. | 6464 * The analysis context used to parse the compilation units being resolved. |
6333 */ | 6465 */ |
6334 AnalysisContextImpl analysisContext2; | 6466 AnalysisContextImpl analysisContext2; |
6335 | 6467 |
6336 /** | 6468 /** |
| 6469 * Specifies if [assertErrors] should check for [HintCode.UNUSED_ELEMENT]. |
| 6470 */ |
| 6471 bool enableUnusedElement = false; |
| 6472 |
| 6473 /** |
6337 * Specifies if [assertErrors] should check for [HintCode.UNUSED_LOCAL_VARIABL
E]. | 6474 * Specifies if [assertErrors] should check for [HintCode.UNUSED_LOCAL_VARIABL
E]. |
6338 */ | 6475 */ |
6339 bool enableUnusedLocalVariable = false; | 6476 bool enableUnusedLocalVariable = false; |
6340 | 6477 |
6341 @override | 6478 @override |
6342 void setUp() { | 6479 void setUp() { |
6343 reset(); | 6480 reset(); |
6344 } | 6481 } |
6345 | 6482 |
6346 /** | 6483 /** |
(...skipping 26 matching lines...) Expand all Loading... |
6373 * | 6510 * |
6374 * @param source the source against which the errors should have been reported | 6511 * @param source the source against which the errors should have been reported |
6375 * @param expectedErrorCodes the error codes of the errors that should have be
en reported | 6512 * @param expectedErrorCodes the error codes of the errors that should have be
en reported |
6376 * @throws AnalysisException if the reported errors could not be computed | 6513 * @throws AnalysisException if the reported errors could not be computed |
6377 * @throws AssertionFailedError if a different number of errors have been repo
rted than were | 6514 * @throws AssertionFailedError if a different number of errors have been repo
rted than were |
6378 * expected | 6515 * expected |
6379 */ | 6516 */ |
6380 void assertErrors(Source source, [List<ErrorCode> expectedErrorCodes = ErrorCo
de.EMPTY_LIST]) { | 6517 void assertErrors(Source source, [List<ErrorCode> expectedErrorCodes = ErrorCo
de.EMPTY_LIST]) { |
6381 GatheringErrorListener errorListener = new GatheringErrorListener(); | 6518 GatheringErrorListener errorListener = new GatheringErrorListener(); |
6382 for (AnalysisError error in analysisContext2.computeErrors(source)) { | 6519 for (AnalysisError error in analysisContext2.computeErrors(source)) { |
| 6520 if (error.errorCode == HintCode.UNUSED_ELEMENT && |
| 6521 !enableUnusedElement) { |
| 6522 continue; |
| 6523 } |
6383 if (error.errorCode == HintCode.UNUSED_LOCAL_VARIABLE && | 6524 if (error.errorCode == HintCode.UNUSED_LOCAL_VARIABLE && |
6384 !enableUnusedLocalVariable) { | 6525 !enableUnusedLocalVariable) { |
6385 continue; | 6526 continue; |
6386 } | 6527 } |
6387 errorListener.onError(error); | 6528 errorListener.onError(error); |
6388 } | 6529 } |
6389 errorListener.assertErrorsWithCodes(expectedErrorCodes); | 6530 errorListener.assertErrorsWithCodes(expectedErrorCodes); |
6390 } | 6531 } |
6391 | 6532 |
6392 /** | 6533 /** |
(...skipping 5362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11755 runReflectiveTests(TypeResolverVisitorTest); | 11896 runReflectiveTests(TypeResolverVisitorTest); |
11756 runReflectiveTests(CheckedModeCompileTimeErrorCodeTest); | 11897 runReflectiveTests(CheckedModeCompileTimeErrorCodeTest); |
11757 runReflectiveTests(ErrorResolverTest); | 11898 runReflectiveTests(ErrorResolverTest); |
11758 runReflectiveTests(HintCodeTest); | 11899 runReflectiveTests(HintCodeTest); |
11759 runReflectiveTests(MemberMapTest); | 11900 runReflectiveTests(MemberMapTest); |
11760 runReflectiveTests(NonHintCodeTest); | 11901 runReflectiveTests(NonHintCodeTest); |
11761 runReflectiveTests(SimpleResolverTest); | 11902 runReflectiveTests(SimpleResolverTest); |
11762 runReflectiveTests(StrictModeTest); | 11903 runReflectiveTests(StrictModeTest); |
11763 runReflectiveTests(TypePropagationTest); | 11904 runReflectiveTests(TypePropagationTest); |
11764 } | 11905 } |
OLD | NEW |