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

Side by Side Diff: pkg/analyzer/test/src/task/dart_test.dart

Issue 1055573003: Report unused elements in GenerateHintsTask. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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/task/dart.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) 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 test.src.task.dart_test; 5 library test.src.task.dart_test;
6 6
7 import 'package:analyzer/file_system/file_system.dart'; 7 import 'package:analyzer/file_system/file_system.dart';
8 import 'package:analyzer/file_system/memory_file_system.dart'; 8 import 'package:analyzer/file_system/memory_file_system.dart';
9 import 'package:analyzer/src/context/cache.dart'; 9 import 'package:analyzer/src/context/cache.dart';
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
(...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 _m2() {} 1146 _m2() {}
1147 } 1147 }
1148 1148
1149 main(A a, p) { 1149 main(A a, p) {
1150 a._m2(); 1150 a._m2();
1151 p._m3(); 1151 p._m3();
1152 } 1152 }
1153 '''); 1153 ''');
1154 _computeUsedElements(source); 1154 _computeUsedElements(source);
1155 // validate 1155 // validate
1156 print(usedElementNames);
1157 print(usedElements.members);
1158 expect(usedElementNames, unorderedEquals(['A', 'a', 'p', '_m2'])); 1156 expect(usedElementNames, unorderedEquals(['A', 'a', 'p', '_m2']));
1159 expect(usedElements.members, unorderedEquals(['_m2', '_m3'])); 1157 expect(usedElements.members, unorderedEquals(['_m2', '_m3']));
1160 } 1158 }
1161 1159
1162 void _computeUsedElements(Source source) { 1160 void _computeUsedElements(Source source) {
1163 LibraryUnitTarget target = new LibraryUnitTarget(source, source); 1161 LibraryUnitTarget target = new LibraryUnitTarget(source, source);
1164 _computeResult(target, USED_ELEMENTS); 1162 _computeResult(target, USED_ELEMENTS);
1165 expect(task, new isInstanceOf<GatherUsedElementsTask>()); 1163 expect(task, new isInstanceOf<GatherUsedElementsTask>());
1166 usedElements = outputs[USED_ELEMENTS]; 1164 usedElements = outputs[USED_ELEMENTS];
1167 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); 1165 usedElementNames = usedElements.elements.map((e) => e.name).toSet();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 // TODO(developer) foo bar 1236 // TODO(developer) foo bar
1239 } 1237 }
1240 '''); 1238 ''');
1241 LibraryUnitTarget target = new LibraryUnitTarget(source, source); 1239 LibraryUnitTarget target = new LibraryUnitTarget(source, source);
1242 _computeResult(target, HINTS); 1240 _computeResult(target, HINTS);
1243 expect(task, new isInstanceOf<GenerateHintsTask>()); 1241 expect(task, new isInstanceOf<GenerateHintsTask>());
1244 // validate 1242 // validate
1245 _fillErrorListener(HINTS); 1243 _fillErrorListener(HINTS);
1246 errorListener.assertErrorsWithCodes(<ErrorCode>[TodoCode.TODO]); 1244 errorListener.assertErrorsWithCodes(<ErrorCode>[TodoCode.TODO]);
1247 } 1245 }
1246
1247 test_perform_unusedElements_class() {
1248 Source source = _newSource('/test.dart', '''
1249 class _A {}
1250 class _B {}
1251 main() {
1252 new _A();
1253 }
1254 ''');
1255 LibraryUnitTarget target = new LibraryUnitTarget(source, source);
1256 _computeResult(target, HINTS);
1257 expect(task, new isInstanceOf<GenerateHintsTask>());
1258 // validate
1259 _fillErrorListener(HINTS);
1260 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_ELEMENT]);
1261 }
1262
1263 test_perform_unusedElements_localVariable() {
1264 Source source = _newSource('/test.dart', '''
1265 main() {
1266 var v = 42;
1267 }
1268 ''');
1269 LibraryUnitTarget target = new LibraryUnitTarget(source, source);
1270 _computeResult(target, HINTS);
1271 expect(task, new isInstanceOf<GenerateHintsTask>());
1272 // validate
1273 _fillErrorListener(HINTS);
1274 errorListener
1275 .assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_LOCAL_VARIABLE]);
1276 }
1277
1278 test_perform_unusedElements_method() {
1279 Source source = _newSource('/my_lib.dart', '''
1280 library my_lib;
1281 part 'my_part.dart';
1282 class A {
1283 _ma() {}
1284 _mb() {}
1285 _mc() {}
1286 }
1287 ''');
1288 _newSource('/my_part.dart', '''
1289 part of my_lib;
1290
1291 f(A a) {
1292 a._mb();
1293 }
1294 ''');
1295 LibraryUnitTarget target = new LibraryUnitTarget(source, source);
1296 _computeResult(target, HINTS);
1297 expect(task, new isInstanceOf<GenerateHintsTask>());
1298 // validate
1299 _fillErrorListener(HINTS);
1300 errorListener.assertErrorsWithCodes(
1301 <ErrorCode>[HintCode.UNUSED_ELEMENT, HintCode.UNUSED_ELEMENT]);
1302 }
1248 } 1303 }
1249 1304
1250 @reflectiveTest 1305 @reflectiveTest
1251 class ParseDartTaskTest extends _AbstractDartTaskTest { 1306 class ParseDartTaskTest extends _AbstractDartTaskTest {
1252 test_buildInputs() { 1307 test_buildInputs() {
1253 Map<String, TaskInput> inputs = ParseDartTask.buildInputs(emptySource); 1308 Map<String, TaskInput> inputs = ParseDartTask.buildInputs(emptySource);
1254 expect(inputs, isNotNull); 1309 expect(inputs, isNotNull);
1255 expect(inputs.keys, unorderedEquals([ 1310 expect(inputs.keys, unorderedEquals([
1256 ParseDartTask.LINE_INFO_INPUT_NAME, 1311 ParseDartTask.LINE_INFO_INPUT_NAME,
1257 ParseDartTask.TOKEN_STREAM_INPUT_NAME 1312 ParseDartTask.TOKEN_STREAM_INPUT_NAME
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
1769 return entryMap.putIfAbsent(target, () => new CacheEntry()); 1824 return entryMap.putIfAbsent(target, () => new CacheEntry());
1770 } 1825 }
1771 1826
1772 TimestampedData<String> getContents(Source source) => source.contents; 1827 TimestampedData<String> getContents(Source source) => source.contents;
1773 1828
1774 noSuchMethod(Invocation invocation) { 1829 noSuchMethod(Invocation invocation) {
1775 print('noSuchMethod: ${invocation.memberName}'); 1830 print('noSuchMethod: ${invocation.memberName}');
1776 return super.noSuchMethod(invocation); 1831 return super.noSuchMethod(invocation);
1777 } 1832 }
1778 } 1833 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/task/dart.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698