Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: pkg/analyzer/test/generated/resolver_test.dart

Issue 1020243004: Report separate UNUSED_CATCH_CLAUSE and UNUSED_CATCH_STACK hints. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: tweak Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 8
9 import 'package:analyzer/src/generated/ast.dart'; 9 import 'package:analyzer/src/generated/ast.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
(...skipping 4137 matching lines...) Expand 10 before | Expand all | Expand 10 after
4148 assertErrors(source, [HintCode.UNUSED_IMPORT]); 4148 assertErrors(source, [HintCode.UNUSED_IMPORT]);
4149 assertNoErrors(source2); 4149 assertNoErrors(source2);
4150 verify([source, source2]); 4150 verify([source, source2]);
4151 } 4151 }
4152 4152
4153 void test_unusedLocalVariable_inCatch_exception() { 4153 void test_unusedLocalVariable_inCatch_exception() {
4154 enableUnusedLocalVariable = true; 4154 enableUnusedLocalVariable = true;
4155 Source source = addSource(r''' 4155 Source source = addSource(r'''
4156 main() { 4156 main() {
4157 try { 4157 try {
4158 } on String catch (exception) {
4159 }
4160 }''');
4161 resolve(source);
4162 assertErrors(source, [HintCode.UNUSED_CATCH_CLAUSE]);
4163 verify([source]);
4164 }
4165
4166 void test_unusedLocalVariable_inCatch_exception_hasStack() {
4167 enableUnusedLocalVariable = true;
4168 Source source = addSource(r'''
4169 main() {
4170 try {
4171 } catch (exception, stack) {
4172 print(stack);
4173 }
4174 }''');
4175 resolve(source);
4176 assertNoErrors(source);
4177 verify([source]);
4178 }
4179
4180 void test_unusedLocalVariable_inCatch_exception_noOnClause() {
4181 enableUnusedLocalVariable = true;
4182 Source source = addSource(r'''
4183 main() {
4184 try {
4158 } catch (exception) { 4185 } catch (exception) {
4159 } 4186 }
4160 }'''); 4187 }''');
4161 resolve(source); 4188 resolve(source);
4162 assertErrors(source); 4189 assertNoErrors(source);
4163 verify([source]); 4190 verify([source]);
4164 } 4191 }
4165 4192
4166 void test_unusedLocalVariable_inCatch_stackTrace() { 4193 void test_unusedLocalVariable_inCatch_stackTrace() {
4167 enableUnusedLocalVariable = true; 4194 enableUnusedLocalVariable = true;
4168 Source source = addSource(r''' 4195 Source source = addSource(r'''
4169 main() { 4196 main() {
4170 try { 4197 try {
4171 } catch (exception, stackTrace) { 4198 } catch (exception, stackTrace) {
4172 } 4199 }
4173 }'''); 4200 }''');
4174 resolve(source); 4201 resolve(source);
4175 assertErrors(source, [HintCode.UNUSED_LOCAL_VARIABLE]); 4202 assertErrors(source, [HintCode.UNUSED_CATCH_STACK]);
4176 verify([source]); 4203 verify([source]);
4177 } 4204 }
4178 4205
4179 void test_unusedLocalVariable_inCatch_stackTrace_used() { 4206 void test_unusedLocalVariable_inCatch_stackTrace_used() {
4180 enableUnusedLocalVariable = true; 4207 enableUnusedLocalVariable = true;
4181 Source source = addSource(r''' 4208 Source source = addSource(r'''
4182 main() { 4209 main() {
4183 try { 4210 try {
4184 } catch (exception, stackTrace) { 4211 } catch (exception, stackTrace) {
4185 print('exception at $stackTrace'); 4212 print('exception at $stackTrace');
(...skipping 3428 matching lines...) Expand 10 before | Expand all | Expand 10 after
7614 [List<ErrorCode> expectedErrorCodes = ErrorCode.EMPTY_LIST]) { 7641 [List<ErrorCode> expectedErrorCodes = ErrorCode.EMPTY_LIST]) {
7615 GatheringErrorListener errorListener = new GatheringErrorListener(); 7642 GatheringErrorListener errorListener = new GatheringErrorListener();
7616 for (AnalysisError error in analysisContext2.computeErrors(source)) { 7643 for (AnalysisError error in analysisContext2.computeErrors(source)) {
7617 ErrorCode errorCode = error.errorCode; 7644 ErrorCode errorCode = error.errorCode;
7618 if (!enableUnusedElement && 7645 if (!enableUnusedElement &&
7619 (errorCode == HintCode.UNUSED_ELEMENT || 7646 (errorCode == HintCode.UNUSED_ELEMENT ||
7620 errorCode == HintCode.UNUSED_FIELD)) { 7647 errorCode == HintCode.UNUSED_FIELD)) {
7621 continue; 7648 continue;
7622 } 7649 }
7623 if (!enableUnusedLocalVariable && 7650 if (!enableUnusedLocalVariable &&
7624 errorCode == HintCode.UNUSED_LOCAL_VARIABLE) { 7651 (errorCode == HintCode.UNUSED_CATCH_CLAUSE ||
7652 errorCode == HintCode.UNUSED_CATCH_STACK ||
7653 errorCode == HintCode.UNUSED_LOCAL_VARIABLE)) {
7625 continue; 7654 continue;
7626 } 7655 }
7627 errorListener.onError(error); 7656 errorListener.onError(error);
7628 } 7657 }
7629 errorListener.assertErrorsWithCodes(expectedErrorCodes); 7658 errorListener.assertErrorsWithCodes(expectedErrorCodes);
7630 } 7659 }
7631 7660
7632 /** 7661 /**
7633 * Assert that no errors have been reported against the given source. 7662 * Assert that no errors have been reported against the given source.
7634 * 7663 *
(...skipping 6024 matching lines...) Expand 10 before | Expand all | Expand 10 after
13659 // check propagated type 13688 // check propagated type
13660 FunctionType propagatedType = node.propagatedType as FunctionType; 13689 FunctionType propagatedType = node.propagatedType as FunctionType;
13661 expect(propagatedType.returnType, test.typeProvider.stringType); 13690 expect(propagatedType.returnType, test.typeProvider.stringType);
13662 } on AnalysisException catch (e, stackTrace) { 13691 } on AnalysisException catch (e, stackTrace) {
13663 thrownException[0] = new CaughtException(e, stackTrace); 13692 thrownException[0] = new CaughtException(e, stackTrace);
13664 } 13693 }
13665 } 13694 }
13666 return null; 13695 return null;
13667 } 13696 }
13668 } 13697 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698