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

Side by Side Diff: pkg/analysis_server/test/services/correction/fix_test.dart

Issue 923103004: Return RequestErrorCode.NO_INDEX_GENERATED for search/refactoring requests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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
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 test.services.correction.fix; 5 library test.services.correction.fix;
6 6
7 import 'package:analysis_server/src/protocol.dart' hide AnalysisError; 7 import 'package:analysis_server/src/protocol.dart' hide AnalysisError;
8 import 'package:analysis_server/src/services/correction/fix.dart'; 8 import 'package:analysis_server/src/services/correction/fix.dart';
9 import 'package:analysis_server/src/services/index/index.dart';
10 import 'package:analysis_server/src/services/index/local_memory_index.dart';
11 import 'package:analysis_server/src/services/search/search_engine_internal.dart' ;
12 import 'package:analyzer/file_system/file_system.dart'; 9 import 'package:analyzer/file_system/file_system.dart';
13 import 'package:analyzer/source/package_map_resolver.dart'; 10 import 'package:analyzer/source/package_map_resolver.dart';
14 import 'package:analyzer/src/generated/error.dart'; 11 import 'package:analyzer/src/generated/error.dart';
15 import 'package:analyzer/src/generated/parser.dart'; 12 import 'package:analyzer/src/generated/parser.dart';
16 import 'package:analyzer/src/generated/source.dart'; 13 import 'package:analyzer/src/generated/source.dart';
17 import 'package:unittest/unittest.dart'; 14 import 'package:unittest/unittest.dart';
18 15
19 import '../../abstract_context.dart'; 16 import '../../abstract_context.dart';
20 import '../../abstract_single_unit.dart'; 17 import '../../abstract_single_unit.dart';
21 import '../../reflective_tests.dart'; 18 import '../../reflective_tests.dart';
22 19
23 20
24 main() { 21 main() {
25 groupSep = ' | '; 22 groupSep = ' | ';
26 runReflectiveTests(FixProcessorTest); 23 runReflectiveTests(FixProcessorTest);
27 } 24 }
28 25
29 26
30 typedef bool AnalysisErrorFilter(AnalysisError error); 27 typedef bool AnalysisErrorFilter(AnalysisError error);
31 28
32 29
33 @reflectiveTest 30 @reflectiveTest
34 class FixProcessorTest extends AbstractSingleUnitTest { 31 class FixProcessorTest extends AbstractSingleUnitTest {
35 Index index;
36 SearchEngineImpl searchEngine;
37
38 AnalysisErrorFilter errorFilter = null; 32 AnalysisErrorFilter errorFilter = null;
39 33
40 Fix fix; 34 Fix fix;
41 SourceChange change; 35 SourceChange change;
42 String resultCode; 36 String resultCode;
43 37
44 void assert_undefinedFunction_create_returnType_bool(String lineWithTest) { 38 void assert_undefinedFunction_create_returnType_bool(String lineWithTest) {
45 _indexTestUnit(''' 39 resolveTestUnit('''
46 main() { 40 main() {
47 bool b = true; 41 bool b = true;
48 $lineWithTest 42 $lineWithTest
49 } 43 }
50 '''); 44 ''');
51 assertHasFix(FixKind.CREATE_FUNCTION, ''' 45 assertHasFix(FixKind.CREATE_FUNCTION, '''
52 main() { 46 main() {
53 bool b = true; 47 bool b = true;
54 $lineWithTest 48 $lineWithTest
55 } 49 }
(...skipping 10 matching lines...) Expand all
66 // apply to "file" 60 // apply to "file"
67 List<SourceFileEdit> fileEdits = change.edits; 61 List<SourceFileEdit> fileEdits = change.edits;
68 expect(fileEdits, hasLength(1)); 62 expect(fileEdits, hasLength(1));
69 resultCode = SourceEdit.applySequence(testCode, change.edits[0].edits); 63 resultCode = SourceEdit.applySequence(testCode, change.edits[0].edits);
70 // verify 64 // verify
71 expect(resultCode, expected); 65 expect(resultCode, expected);
72 } 66 }
73 67
74 void assertNoFix(FixKind kind) { 68 void assertNoFix(FixKind kind) {
75 AnalysisError error = _findErrorToFix(); 69 AnalysisError error = _findErrorToFix();
76 List<Fix> fixes = computeFixes(searchEngine, testUnit, error); 70 List<Fix> fixes = computeFixes(testUnit, error);
77 for (Fix fix in fixes) { 71 for (Fix fix in fixes) {
78 if (fix.kind == kind) { 72 if (fix.kind == kind) {
79 throw fail('Unexpected fix $kind in\n${fixes.join('\n')}'); 73 throw fail('Unexpected fix $kind in\n${fixes.join('\n')}');
80 } 74 }
81 } 75 }
82 } 76 }
83 77
84 Position expectedPosition(String search) { 78 Position expectedPosition(String search) {
85 int offset = resultCode.indexOf(search); 79 int offset = resultCode.indexOf(search);
86 return new Position(testFile, offset); 80 return new Position(testFile, offset);
87 } 81 }
88 82
89 List<Position> expectedPositions(List<String> patterns) { 83 List<Position> expectedPositions(List<String> patterns) {
90 List<Position> positions = <Position>[]; 84 List<Position> positions = <Position>[];
91 patterns.forEach((String search) { 85 patterns.forEach((String search) {
92 positions.add(expectedPosition(search)); 86 positions.add(expectedPosition(search));
93 }); 87 });
94 return positions; 88 return positions;
95 } 89 }
96 90
97 List<LinkedEditSuggestion> expectedSuggestions(LinkedEditSuggestionKind kind, 91 List<LinkedEditSuggestion> expectedSuggestions(LinkedEditSuggestionKind kind,
98 List<String> values) { 92 List<String> values) {
99 return values.map((value) { 93 return values.map((value) {
100 return new LinkedEditSuggestion(value, kind); 94 return new LinkedEditSuggestion(value, kind);
101 }).toList(); 95 }).toList();
102 } 96 }
103 97
104 void setUp() { 98 void setUp() {
105 super.setUp(); 99 super.setUp();
106 index = createLocalMemoryIndex();
107 searchEngine = new SearchEngineImpl(index);
108 verifyNoTestUnitErrors = false; 100 verifyNoTestUnitErrors = false;
109 } 101 }
110 102
111 void test_addSync_blockFunctionBody() { 103 void test_addSync_blockFunctionBody() {
112 _indexTestUnit(''' 104 resolveTestUnit('''
113 foo() {} 105 foo() {}
114 main() { 106 main() {
115 await foo(); 107 await foo();
116 } 108 }
117 '''); 109 ''');
118 List<AnalysisError> errors = context.computeErrors(testSource); 110 List<AnalysisError> errors = context.computeErrors(testSource);
119 expect(errors, hasLength(2)); 111 expect(errors, hasLength(2));
120 // ParserError: Expected to find ';' 112 // ParserError: Expected to find ';'
121 { 113 {
122 AnalysisError error = errors[0]; 114 AnalysisError error = errors[0];
123 expect(error.message, "Expected to find ';'"); 115 expect(error.message, "Expected to find ';'");
124 List<Fix> fixes = computeFixes(searchEngine, testUnit, error); 116 List<Fix> fixes = computeFixes(testUnit, error);
125 expect(fixes, isEmpty); 117 expect(fixes, isEmpty);
126 } 118 }
127 // Undefined name 'await' 119 // Undefined name 'await'
128 { 120 {
129 AnalysisError error = errors[1]; 121 AnalysisError error = errors[1];
130 expect(error.message, "Undefined name 'await'"); 122 expect(error.message, "Undefined name 'await'");
131 List<Fix> fixes = computeFixes(searchEngine, testUnit, error); 123 List<Fix> fixes = computeFixes(testUnit, error);
132 // has exactly one fix 124 // has exactly one fix
133 expect(fixes, hasLength(1)); 125 expect(fixes, hasLength(1));
134 Fix fix = fixes[0]; 126 Fix fix = fixes[0];
135 expect(fix.kind, FixKind.ADD_ASYNC); 127 expect(fix.kind, FixKind.ADD_ASYNC);
136 // apply to "file" 128 // apply to "file"
137 List<SourceFileEdit> fileEdits = fix.change.edits; 129 List<SourceFileEdit> fileEdits = fix.change.edits;
138 expect(fileEdits, hasLength(1)); 130 expect(fileEdits, hasLength(1));
139 resultCode = SourceEdit.applySequence(testCode, fileEdits[0].edits); 131 resultCode = SourceEdit.applySequence(testCode, fileEdits[0].edits);
140 // verify 132 // verify
141 expect(resultCode, ''' 133 expect(resultCode, '''
142 foo() {} 134 foo() {}
143 main() async { 135 main() async {
144 await foo(); 136 await foo();
145 } 137 }
146 '''); 138 ''');
147 } 139 }
148 } 140 }
149 141
150 void test_addSync_expressionFunctionBody() { 142 void test_addSync_expressionFunctionBody() {
151 errorFilter = (AnalysisError error) { 143 errorFilter = (AnalysisError error) {
152 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER; 144 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER;
153 }; 145 };
154 _indexTestUnit(''' 146 resolveTestUnit('''
155 foo() {} 147 foo() {}
156 main() => await foo(); 148 main() => await foo();
157 '''); 149 ''');
158 assertHasFix(FixKind.ADD_ASYNC, ''' 150 assertHasFix(FixKind.ADD_ASYNC, '''
159 foo() {} 151 foo() {}
160 main() async => await foo(); 152 main() async => await foo();
161 '''); 153 ''');
162 } 154 }
163 155
164 void test_boolean() { 156 void test_boolean() {
165 _indexTestUnit(''' 157 resolveTestUnit('''
166 main() { 158 main() {
167 boolean v; 159 boolean v;
168 } 160 }
169 '''); 161 ''');
170 assertHasFix(FixKind.REPLACE_BOOLEAN_WITH_BOOL, ''' 162 assertHasFix(FixKind.REPLACE_BOOLEAN_WITH_BOOL, '''
171 main() { 163 main() {
172 bool v; 164 bool v;
173 } 165 }
174 '''); 166 ''');
175 } 167 }
176 168
177 void test_changeToStaticAccess_method() { 169 void test_changeToStaticAccess_method() {
178 _indexTestUnit(''' 170 resolveTestUnit('''
179 class A { 171 class A {
180 static foo() {} 172 static foo() {}
181 } 173 }
182 main(A a) { 174 main(A a) {
183 a.foo(); 175 a.foo();
184 } 176 }
185 '''); 177 ''');
186 assertHasFix(FixKind.CHANGE_TO_STATIC_ACCESS, ''' 178 assertHasFix(FixKind.CHANGE_TO_STATIC_ACCESS, '''
187 class A { 179 class A {
188 static foo() {} 180 static foo() {}
189 } 181 }
190 main(A a) { 182 main(A a) {
191 A.foo(); 183 A.foo();
192 } 184 }
193 '''); 185 ''');
194 } 186 }
195 187
196 void test_changeToStaticAccess_method_prefixLibrary() { 188 void test_changeToStaticAccess_method_prefixLibrary() {
197 _indexTestUnit(''' 189 resolveTestUnit('''
198 import 'dart:async' as pref; 190 import 'dart:async' as pref;
199 main(pref.Future f) { 191 main(pref.Future f) {
200 f.wait([]); 192 f.wait([]);
201 } 193 }
202 '''); 194 ''');
203 assertHasFix(FixKind.CHANGE_TO_STATIC_ACCESS, ''' 195 assertHasFix(FixKind.CHANGE_TO_STATIC_ACCESS, '''
204 import 'dart:async' as pref; 196 import 'dart:async' as pref;
205 main(pref.Future f) { 197 main(pref.Future f) {
206 pref.Future.wait([]); 198 pref.Future.wait([]);
207 } 199 }
208 '''); 200 ''');
209 } 201 }
210 202
211 void test_changeToStaticAccess_property() { 203 void test_changeToStaticAccess_property() {
212 _indexTestUnit(''' 204 resolveTestUnit('''
213 class A { 205 class A {
214 static get foo => 42; 206 static get foo => 42;
215 } 207 }
216 main(A a) { 208 main(A a) {
217 a.foo; 209 a.foo;
218 } 210 }
219 '''); 211 ''');
220 assertHasFix(FixKind.CHANGE_TO_STATIC_ACCESS, ''' 212 assertHasFix(FixKind.CHANGE_TO_STATIC_ACCESS, '''
221 class A { 213 class A {
222 static get foo => 42; 214 static get foo => 42;
223 } 215 }
224 main(A a) { 216 main(A a) {
225 A.foo; 217 A.foo;
226 } 218 }
227 '''); 219 ''');
228 } 220 }
229 221
230 void test_createClass() { 222 void test_createClass() {
231 _indexTestUnit(''' 223 resolveTestUnit('''
232 main() { 224 main() {
233 Test v = null; 225 Test v = null;
234 } 226 }
235 '''); 227 ''');
236 assertHasFix(FixKind.CREATE_CLASS, ''' 228 assertHasFix(FixKind.CREATE_CLASS, '''
237 main() { 229 main() {
238 Test v = null; 230 Test v = null;
239 } 231 }
240 232
241 class Test { 233 class Test {
242 } 234 }
243 '''); 235 ''');
244 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']); 236 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']);
245 } 237 }
246 238
247 void test_createConstructor_insteadOfSyntheticDefault() { 239 void test_createConstructor_insteadOfSyntheticDefault() {
248 _indexTestUnit(''' 240 resolveTestUnit('''
249 class A { 241 class A {
250 int field; 242 int field;
251 243
252 method() {} 244 method() {}
253 } 245 }
254 main() { 246 main() {
255 new A(1, 2.0); 247 new A(1, 2.0);
256 } 248 }
257 '''); 249 ''');
258 assertHasFix(FixKind.CREATE_CONSTRUCTOR, ''' 250 assertHasFix(FixKind.CREATE_CONSTRUCTOR, '''
259 class A { 251 class A {
260 int field; 252 int field;
261 253
262 A(int i, double d) { 254 A(int i, double d) {
263 } 255 }
264 256
265 method() {} 257 method() {}
266 } 258 }
267 main() { 259 main() {
268 new A(1, 2.0); 260 new A(1, 2.0);
269 } 261 }
270 '''); 262 ''');
271 } 263 }
272 264
273 void test_createConstructor_named() { 265 void test_createConstructor_named() {
274 _indexTestUnit(''' 266 resolveTestUnit('''
275 class A { 267 class A {
276 method() {} 268 method() {}
277 } 269 }
278 main() { 270 main() {
279 new A.named(1, 2.0); 271 new A.named(1, 2.0);
280 } 272 }
281 '''); 273 ''');
282 assertHasFix(FixKind.CREATE_CONSTRUCTOR, ''' 274 assertHasFix(FixKind.CREATE_CONSTRUCTOR, '''
283 class A { 275 class A {
284 A.named(int i, double d) { 276 A.named(int i, double d) {
285 } 277 }
286 278
287 method() {} 279 method() {}
288 } 280 }
289 main() { 281 main() {
290 new A.named(1, 2.0); 282 new A.named(1, 2.0);
291 } 283 }
292 '''); 284 ''');
293 _assertLinkedGroup(change.linkedEditGroups[0], ['named(int ', 'named(1']); 285 _assertLinkedGroup(change.linkedEditGroups[0], ['named(int ', 'named(1']);
294 } 286 }
295 287
296 void test_createConstructorSuperExplicit() { 288 void test_createConstructorSuperExplicit() {
297 _indexTestUnit(''' 289 resolveTestUnit('''
298 class A { 290 class A {
299 A(bool p1, int p2, double p3, String p4, {p5}); 291 A(bool p1, int p2, double p3, String p4, {p5});
300 } 292 }
301 class B extends A { 293 class B extends A {
302 B() {} 294 B() {}
303 } 295 }
304 '''); 296 ''');
305 assertHasFix(FixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, ''' 297 assertHasFix(FixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, '''
306 class A { 298 class A {
307 A(bool p1, int p2, double p3, String p4, {p5}); 299 A(bool p1, int p2, double p3, String p4, {p5});
308 } 300 }
309 class B extends A { 301 class B extends A {
310 B() : super(false, 0, 0.0, '') {} 302 B() : super(false, 0, 0.0, '') {}
311 } 303 }
312 '''); 304 ''');
313 } 305 }
314 306
315 void test_createConstructorSuperExplicit_hasInitializers() { 307 void test_createConstructorSuperExplicit_hasInitializers() {
316 _indexTestUnit(''' 308 resolveTestUnit('''
317 class A { 309 class A {
318 A(int p); 310 A(int p);
319 } 311 }
320 class B extends A { 312 class B extends A {
321 int field; 313 int field;
322 B() : field = 42 {} 314 B() : field = 42 {}
323 } 315 }
324 '''); 316 ''');
325 assertHasFix(FixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, ''' 317 assertHasFix(FixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, '''
326 class A { 318 class A {
327 A(int p); 319 A(int p);
328 } 320 }
329 class B extends A { 321 class B extends A {
330 int field; 322 int field;
331 B() : field = 42, super(0) {} 323 B() : field = 42, super(0) {}
332 } 324 }
333 '''); 325 ''');
334 } 326 }
335 327
336 void test_createConstructorSuperExplicit_named() { 328 void test_createConstructorSuperExplicit_named() {
337 _indexTestUnit(''' 329 resolveTestUnit('''
338 class A { 330 class A {
339 A.named(int p); 331 A.named(int p);
340 } 332 }
341 class B extends A { 333 class B extends A {
342 B() {} 334 B() {}
343 } 335 }
344 '''); 336 ''');
345 assertHasFix(FixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, ''' 337 assertHasFix(FixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, '''
346 class A { 338 class A {
347 A.named(int p); 339 A.named(int p);
348 } 340 }
349 class B extends A { 341 class B extends A {
350 B() : super.named(0) {} 342 B() : super.named(0) {}
351 } 343 }
352 '''); 344 ''');
353 } 345 }
354 346
355 void test_createConstructorSuperExplicit_named_private() { 347 void test_createConstructorSuperExplicit_named_private() {
356 _indexTestUnit(''' 348 resolveTestUnit('''
357 class A { 349 class A {
358 A._named(int p); 350 A._named(int p);
359 } 351 }
360 class B extends A { 352 class B extends A {
361 B() {} 353 B() {}
362 } 354 }
363 '''); 355 ''');
364 assertNoFix(FixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION); 356 assertNoFix(FixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION);
365 } 357 }
366 358
367 void test_createConstructorSuperImplicit() { 359 void test_createConstructorSuperImplicit() {
368 _indexTestUnit(''' 360 resolveTestUnit('''
369 class A { 361 class A {
370 A(p1, int p2, List<String> p3, [int p4]); 362 A(p1, int p2, List<String> p3, [int p4]);
371 } 363 }
372 class B extends A { 364 class B extends A {
373 int existingField; 365 int existingField;
374 366
375 void existingMethod() {} 367 void existingMethod() {}
376 } 368 }
377 '''); 369 ''');
378 assertHasFix(FixKind.CREATE_CONSTRUCTOR_SUPER, ''' 370 assertHasFix(FixKind.CREATE_CONSTRUCTOR_SUPER, '''
379 class A { 371 class A {
380 A(p1, int p2, List<String> p3, [int p4]); 372 A(p1, int p2, List<String> p3, [int p4]);
381 } 373 }
382 class B extends A { 374 class B extends A {
383 int existingField; 375 int existingField;
384 376
385 B(p1, int p2, List<String> p3) : super(p1, p2, p3); 377 B(p1, int p2, List<String> p3) : super(p1, p2, p3);
386 378
387 void existingMethod() {} 379 void existingMethod() {}
388 } 380 }
389 '''); 381 ''');
390 } 382 }
391 383
392 void test_createConstructorSuperImplicit_fieldInitializer() { 384 void test_createConstructorSuperImplicit_fieldInitializer() {
393 _indexTestUnit(''' 385 resolveTestUnit('''
394 class A { 386 class A {
395 int _field; 387 int _field;
396 A(this._field); 388 A(this._field);
397 } 389 }
398 class B extends A { 390 class B extends A {
399 int existingField; 391 int existingField;
400 392
401 void existingMethod() {} 393 void existingMethod() {}
402 } 394 }
403 '''); 395 ''');
404 assertHasFix(FixKind.CREATE_CONSTRUCTOR_SUPER, ''' 396 assertHasFix(FixKind.CREATE_CONSTRUCTOR_SUPER, '''
405 class A { 397 class A {
406 int _field; 398 int _field;
407 A(this._field); 399 A(this._field);
408 } 400 }
409 class B extends A { 401 class B extends A {
410 int existingField; 402 int existingField;
411 403
412 B(int field) : super(field); 404 B(int field) : super(field);
413 405
414 void existingMethod() {} 406 void existingMethod() {}
415 } 407 }
416 '''); 408 ''');
417 } 409 }
418 410
419 void test_createConstructorSuperImplicit_named() { 411 void test_createConstructorSuperImplicit_named() {
420 _indexTestUnit(''' 412 resolveTestUnit('''
421 class A { 413 class A {
422 A.named(p1, int p2); 414 A.named(p1, int p2);
423 } 415 }
424 class B extends A { 416 class B extends A {
425 int existingField; 417 int existingField;
426 418
427 void existingMethod() {} 419 void existingMethod() {}
428 } 420 }
429 '''); 421 ''');
430 assertHasFix(FixKind.CREATE_CONSTRUCTOR_SUPER, ''' 422 assertHasFix(FixKind.CREATE_CONSTRUCTOR_SUPER, '''
431 class A { 423 class A {
432 A.named(p1, int p2); 424 A.named(p1, int p2);
433 } 425 }
434 class B extends A { 426 class B extends A {
435 int existingField; 427 int existingField;
436 428
437 B.named(p1, int p2) : super.named(p1, p2); 429 B.named(p1, int p2) : super.named(p1, p2);
438 430
439 void existingMethod() {} 431 void existingMethod() {}
440 } 432 }
441 '''); 433 ''');
442 } 434 }
443 435
444 void test_createConstructorSuperImplicit_private() { 436 void test_createConstructorSuperImplicit_private() {
445 _indexTestUnit(''' 437 resolveTestUnit('''
446 class A { 438 class A {
447 A._named(p); 439 A._named(p);
448 } 440 }
449 class B extends A { 441 class B extends A {
450 } 442 }
451 '''); 443 ''');
452 assertNoFix(FixKind.CREATE_CONSTRUCTOR_SUPER); 444 assertNoFix(FixKind.CREATE_CONSTRUCTOR_SUPER);
453 } 445 }
454 446
455 void test_createField_BAD_inSDK() { 447 void test_createField_BAD_inSDK() {
456 _indexTestUnit(''' 448 resolveTestUnit('''
457 main(List p) { 449 main(List p) {
458 p.foo = 1; 450 p.foo = 1;
459 } 451 }
460 '''); 452 ''');
461 assertNoFix(FixKind.CREATE_FIELD); 453 assertNoFix(FixKind.CREATE_FIELD);
462 } 454 }
463 455
464 void test_createField_getter_multiLevel() { 456 void test_createField_getter_multiLevel() {
465 _indexTestUnit(''' 457 resolveTestUnit('''
466 class A { 458 class A {
467 } 459 }
468 class B { 460 class B {
469 A a; 461 A a;
470 } 462 }
471 class C { 463 class C {
472 B b; 464 B b;
473 } 465 }
474 main(C c) { 466 main(C c) {
475 int v = c.b.a.test; 467 int v = c.b.a.test;
476 } 468 }
477 '''); 469 ''');
478 assertHasFix(FixKind.CREATE_FIELD, ''' 470 assertHasFix(FixKind.CREATE_FIELD, '''
479 class A { 471 class A {
480 int test; 472 int test;
481 } 473 }
482 class B { 474 class B {
483 A a; 475 A a;
484 } 476 }
485 class C { 477 class C {
486 B b; 478 B b;
487 } 479 }
488 main(C c) { 480 main(C c) {
489 int v = c.b.a.test; 481 int v = c.b.a.test;
490 } 482 }
491 '''); 483 ''');
492 } 484 }
493 485
494 void test_createField_getter_qualified_instance() { 486 void test_createField_getter_qualified_instance() {
495 _indexTestUnit(''' 487 resolveTestUnit('''
496 class A { 488 class A {
497 } 489 }
498 main(A a) { 490 main(A a) {
499 int v = a.test; 491 int v = a.test;
500 } 492 }
501 '''); 493 ''');
502 assertHasFix(FixKind.CREATE_FIELD, ''' 494 assertHasFix(FixKind.CREATE_FIELD, '''
503 class A { 495 class A {
504 int test; 496 int test;
505 } 497 }
506 main(A a) { 498 main(A a) {
507 int v = a.test; 499 int v = a.test;
508 } 500 }
509 '''); 501 ''');
510 } 502 }
511 503
512 void test_createField_getter_qualified_instance_dynamicType() { 504 void test_createField_getter_qualified_instance_dynamicType() {
513 _indexTestUnit(''' 505 resolveTestUnit('''
514 class A { 506 class A {
515 B b; 507 B b;
516 void f(Object p) { 508 void f(Object p) {
517 p == b.test; 509 p == b.test;
518 } 510 }
519 } 511 }
520 class B { 512 class B {
521 } 513 }
522 '''); 514 ''');
523 assertHasFix(FixKind.CREATE_FIELD, ''' 515 assertHasFix(FixKind.CREATE_FIELD, '''
524 class A { 516 class A {
525 B b; 517 B b;
526 void f(Object p) { 518 void f(Object p) {
527 p == b.test; 519 p == b.test;
528 } 520 }
529 } 521 }
530 class B { 522 class B {
531 var test; 523 var test;
532 } 524 }
533 '''); 525 ''');
534 } 526 }
535 527
536 void test_createField_getter_unqualified_instance_asInvocationArgument() { 528 void test_createField_getter_unqualified_instance_asInvocationArgument() {
537 _indexTestUnit(''' 529 resolveTestUnit('''
538 class A { 530 class A {
539 main() { 531 main() {
540 f(test); 532 f(test);
541 } 533 }
542 } 534 }
543 f(String s) {} 535 f(String s) {}
544 '''); 536 ''');
545 assertHasFix(FixKind.CREATE_FIELD, ''' 537 assertHasFix(FixKind.CREATE_FIELD, '''
546 class A { 538 class A {
547 String test; 539 String test;
548 540
549 main() { 541 main() {
550 f(test); 542 f(test);
551 } 543 }
552 } 544 }
553 f(String s) {} 545 f(String s) {}
554 '''); 546 ''');
555 } 547 }
556 548
557 void test_createField_getter_unqualified_instance_assignmentRhs() { 549 void test_createField_getter_unqualified_instance_assignmentRhs() {
558 _indexTestUnit(''' 550 resolveTestUnit('''
559 class A { 551 class A {
560 main() { 552 main() {
561 int v = test; 553 int v = test;
562 } 554 }
563 } 555 }
564 '''); 556 ''');
565 assertHasFix(FixKind.CREATE_FIELD, ''' 557 assertHasFix(FixKind.CREATE_FIELD, '''
566 class A { 558 class A {
567 int test; 559 int test;
568 560
569 main() { 561 main() {
570 int v = test; 562 int v = test;
571 } 563 }
572 } 564 }
573 '''); 565 ''');
574 } 566 }
575 567
576 void test_createField_getter_unqualified_instance_asStatement() { 568 void test_createField_getter_unqualified_instance_asStatement() {
577 _indexTestUnit(''' 569 resolveTestUnit('''
578 class A { 570 class A {
579 main() { 571 main() {
580 test; 572 test;
581 } 573 }
582 } 574 }
583 '''); 575 ''');
584 assertHasFix(FixKind.CREATE_FIELD, ''' 576 assertHasFix(FixKind.CREATE_FIELD, '''
585 class A { 577 class A {
586 var test; 578 var test;
587 579
588 main() { 580 main() {
589 test; 581 test;
590 } 582 }
591 } 583 }
592 '''); 584 ''');
593 } 585 }
594 586
595 void test_createField_setter_generic_BAD() { 587 void test_createField_setter_generic_BAD() {
596 _indexTestUnit(''' 588 resolveTestUnit('''
597 class A { 589 class A {
598 } 590 }
599 class B<T> { 591 class B<T> {
600 List<T> items; 592 List<T> items;
601 main(A a) { 593 main(A a) {
602 a.test = items; 594 a.test = items;
603 } 595 }
604 } 596 }
605 '''); 597 ''');
606 assertHasFix(FixKind.CREATE_FIELD, ''' 598 assertHasFix(FixKind.CREATE_FIELD, '''
607 class A { 599 class A {
608 List test; 600 List test;
609 } 601 }
610 class B<T> { 602 class B<T> {
611 List<T> items; 603 List<T> items;
612 main(A a) { 604 main(A a) {
613 a.test = items; 605 a.test = items;
614 } 606 }
615 } 607 }
616 '''); 608 ''');
617 } 609 }
618 610
619 void test_createField_setter_generic_OK_local() { 611 void test_createField_setter_generic_OK_local() {
620 _indexTestUnit(''' 612 resolveTestUnit('''
621 class A<T> { 613 class A<T> {
622 List<T> items; 614 List<T> items;
623 615
624 main(A a) { 616 main(A a) {
625 test = items; 617 test = items;
626 } 618 }
627 } 619 }
628 '''); 620 ''');
629 assertHasFix(FixKind.CREATE_FIELD, ''' 621 assertHasFix(FixKind.CREATE_FIELD, '''
630 class A<T> { 622 class A<T> {
631 List<T> items; 623 List<T> items;
632 624
633 List<T> test; 625 List<T> test;
634 626
635 main(A a) { 627 main(A a) {
636 test = items; 628 test = items;
637 } 629 }
638 } 630 }
639 '''); 631 ''');
640 } 632 }
641 633
642 void test_createField_setter_qualified_instance_hasField() { 634 void test_createField_setter_qualified_instance_hasField() {
643 _indexTestUnit(''' 635 resolveTestUnit('''
644 class A { 636 class A {
645 int aaa; 637 int aaa;
646 int zzz; 638 int zzz;
647 639
648 existingMethod() {} 640 existingMethod() {}
649 } 641 }
650 main(A a) { 642 main(A a) {
651 a.test = 5; 643 a.test = 5;
652 } 644 }
653 '''); 645 ''');
654 assertHasFix(FixKind.CREATE_FIELD, ''' 646 assertHasFix(FixKind.CREATE_FIELD, '''
655 class A { 647 class A {
656 int aaa; 648 int aaa;
657 int zzz; 649 int zzz;
658 650
659 int test; 651 int test;
660 652
661 existingMethod() {} 653 existingMethod() {}
662 } 654 }
663 main(A a) { 655 main(A a) {
664 a.test = 5; 656 a.test = 5;
665 } 657 }
666 '''); 658 ''');
667 } 659 }
668 660
669 void test_createField_setter_qualified_instance_hasMethod() { 661 void test_createField_setter_qualified_instance_hasMethod() {
670 _indexTestUnit(''' 662 resolveTestUnit('''
671 class A { 663 class A {
672 existingMethod() {} 664 existingMethod() {}
673 } 665 }
674 main(A a) { 666 main(A a) {
675 a.test = 5; 667 a.test = 5;
676 } 668 }
677 '''); 669 ''');
678 assertHasFix(FixKind.CREATE_FIELD, ''' 670 assertHasFix(FixKind.CREATE_FIELD, '''
679 class A { 671 class A {
680 int test; 672 int test;
681 673
682 existingMethod() {} 674 existingMethod() {}
683 } 675 }
684 main(A a) { 676 main(A a) {
685 a.test = 5; 677 a.test = 5;
686 } 678 }
687 '''); 679 ''');
688 } 680 }
689 681
690 void test_createField_setter_qualified_static() { 682 void test_createField_setter_qualified_static() {
691 _indexTestUnit(''' 683 resolveTestUnit('''
692 class A { 684 class A {
693 } 685 }
694 main() { 686 main() {
695 A.test = 5; 687 A.test = 5;
696 } 688 }
697 '''); 689 ''');
698 assertHasFix(FixKind.CREATE_FIELD, ''' 690 assertHasFix(FixKind.CREATE_FIELD, '''
699 class A { 691 class A {
700 static int test; 692 static int test;
701 } 693 }
702 main() { 694 main() {
703 A.test = 5; 695 A.test = 5;
704 } 696 }
705 '''); 697 ''');
706 } 698 }
707 699
708 void test_createField_setter_unqualified_instance() { 700 void test_createField_setter_unqualified_instance() {
709 _indexTestUnit(''' 701 resolveTestUnit('''
710 class A { 702 class A {
711 main() { 703 main() {
712 test = 5; 704 test = 5;
713 } 705 }
714 } 706 }
715 '''); 707 ''');
716 assertHasFix(FixKind.CREATE_FIELD, ''' 708 assertHasFix(FixKind.CREATE_FIELD, '''
717 class A { 709 class A {
718 int test; 710 int test;
719 711
720 main() { 712 main() {
721 test = 5; 713 test = 5;
722 } 714 }
723 } 715 }
724 '''); 716 ''');
725 } 717 }
726 718
727 void test_createField_setter_unqualified_static() { 719 void test_createField_setter_unqualified_static() {
728 _indexTestUnit(''' 720 resolveTestUnit('''
729 class A { 721 class A {
730 static main() { 722 static main() {
731 test = 5; 723 test = 5;
732 } 724 }
733 } 725 }
734 '''); 726 ''');
735 assertHasFix(FixKind.CREATE_FIELD, ''' 727 assertHasFix(FixKind.CREATE_FIELD, '''
736 class A { 728 class A {
737 static int test; 729 static int test;
738 730
739 static main() { 731 static main() {
740 test = 5; 732 test = 5;
741 } 733 }
742 } 734 }
743 '''); 735 ''');
744 } 736 }
745 737
746 void test_createFile_forImport() { 738 void test_createFile_forImport() {
747 testFile = '/my/project/bin/test.dart'; 739 testFile = '/my/project/bin/test.dart';
748 _indexTestUnit(''' 740 resolveTestUnit('''
749 import 'my_file.dart'; 741 import 'my_file.dart';
750 '''); 742 ''');
751 AnalysisError error = _findErrorToFix(); 743 AnalysisError error = _findErrorToFix();
752 fix = _assertHasFix(FixKind.CREATE_FILE, error); 744 fix = _assertHasFix(FixKind.CREATE_FILE, error);
753 change = fix.change; 745 change = fix.change;
754 // validate change 746 // validate change
755 List<SourceFileEdit> fileEdits = change.edits; 747 List<SourceFileEdit> fileEdits = change.edits;
756 expect(fileEdits, hasLength(1)); 748 expect(fileEdits, hasLength(1));
757 SourceFileEdit fileEdit = change.edits[0]; 749 SourceFileEdit fileEdit = change.edits[0];
758 expect(fileEdit.file, '/my/project/bin/my_file.dart'); 750 expect(fileEdit.file, '/my/project/bin/my_file.dart');
759 expect(fileEdit.fileStamp, -1); 751 expect(fileEdit.fileStamp, -1);
760 expect(fileEdit.edits[0].replacement, contains('library my.file;')); 752 expect(fileEdit.edits[0].replacement, contains('library my.file;'));
761 } 753 }
762 754
763 void test_createGetter_BAD_inSDK() { 755 void test_createGetter_BAD_inSDK() {
764 _indexTestUnit(''' 756 resolveTestUnit('''
765 main(List p) { 757 main(List p) {
766 int v = p.foo; 758 int v = p.foo;
767 } 759 }
768 '''); 760 ''');
769 assertNoFix(FixKind.CREATE_GETTER); 761 assertNoFix(FixKind.CREATE_GETTER);
770 } 762 }
771 763
772 void test_createGetter_multiLevel() { 764 void test_createGetter_multiLevel() {
773 _indexTestUnit(''' 765 resolveTestUnit('''
774 class A { 766 class A {
775 } 767 }
776 class B { 768 class B {
777 A a; 769 A a;
778 } 770 }
779 class C { 771 class C {
780 B b; 772 B b;
781 } 773 }
782 main(C c) { 774 main(C c) {
783 int v = c.b.a.test; 775 int v = c.b.a.test;
784 } 776 }
785 '''); 777 ''');
786 assertHasFix(FixKind.CREATE_GETTER, ''' 778 assertHasFix(FixKind.CREATE_GETTER, '''
787 class A { 779 class A {
788 int get test => null; 780 int get test => null;
789 } 781 }
790 class B { 782 class B {
791 A a; 783 A a;
792 } 784 }
793 class C { 785 class C {
794 B b; 786 B b;
795 } 787 }
796 main(C c) { 788 main(C c) {
797 int v = c.b.a.test; 789 int v = c.b.a.test;
798 } 790 }
799 '''); 791 ''');
800 } 792 }
801 793
802 void test_createGetter_qualified_instance() { 794 void test_createGetter_qualified_instance() {
803 _indexTestUnit(''' 795 resolveTestUnit('''
804 class A { 796 class A {
805 } 797 }
806 main(A a) { 798 main(A a) {
807 int v = a.test; 799 int v = a.test;
808 } 800 }
809 '''); 801 ''');
810 assertHasFix(FixKind.CREATE_GETTER, ''' 802 assertHasFix(FixKind.CREATE_GETTER, '''
811 class A { 803 class A {
812 int get test => null; 804 int get test => null;
813 } 805 }
814 main(A a) { 806 main(A a) {
815 int v = a.test; 807 int v = a.test;
816 } 808 }
817 '''); 809 ''');
818 } 810 }
819 811
820 void test_createGetter_qualified_instance_dynamicType() { 812 void test_createGetter_qualified_instance_dynamicType() {
821 _indexTestUnit(''' 813 resolveTestUnit('''
822 class A { 814 class A {
823 B b; 815 B b;
824 void f(Object p) { 816 void f(Object p) {
825 p == b.test; 817 p == b.test;
826 } 818 }
827 } 819 }
828 class B { 820 class B {
829 } 821 }
830 '''); 822 ''');
831 assertHasFix(FixKind.CREATE_GETTER, ''' 823 assertHasFix(FixKind.CREATE_GETTER, '''
832 class A { 824 class A {
833 B b; 825 B b;
834 void f(Object p) { 826 void f(Object p) {
835 p == b.test; 827 p == b.test;
836 } 828 }
837 } 829 }
838 class B { 830 class B {
839 get test => null; 831 get test => null;
840 } 832 }
841 '''); 833 ''');
842 } 834 }
843 835
844 void test_createGetter_setterContext() { 836 void test_createGetter_setterContext() {
845 _indexTestUnit(''' 837 resolveTestUnit('''
846 class A { 838 class A {
847 } 839 }
848 main(A a) { 840 main(A a) {
849 a.test = 42; 841 a.test = 42;
850 } 842 }
851 '''); 843 ''');
852 assertNoFix(FixKind.CREATE_GETTER); 844 assertNoFix(FixKind.CREATE_GETTER);
853 } 845 }
854 846
855 void test_createGetter_unqualified_instance_asInvocationArgument() { 847 void test_createGetter_unqualified_instance_asInvocationArgument() {
856 _indexTestUnit(''' 848 resolveTestUnit('''
857 class A { 849 class A {
858 main() { 850 main() {
859 f(test); 851 f(test);
860 } 852 }
861 } 853 }
862 f(String s) {} 854 f(String s) {}
863 '''); 855 ''');
864 assertHasFix(FixKind.CREATE_GETTER, ''' 856 assertHasFix(FixKind.CREATE_GETTER, '''
865 class A { 857 class A {
866 String get test => null; 858 String get test => null;
867 859
868 main() { 860 main() {
869 f(test); 861 f(test);
870 } 862 }
871 } 863 }
872 f(String s) {} 864 f(String s) {}
873 '''); 865 ''');
874 } 866 }
875 867
876 void test_createGetter_unqualified_instance_assignmentLhs() { 868 void test_createGetter_unqualified_instance_assignmentLhs() {
877 _indexTestUnit(''' 869 resolveTestUnit('''
878 class A { 870 class A {
879 main() { 871 main() {
880 test = 42; 872 test = 42;
881 } 873 }
882 } 874 }
883 '''); 875 ''');
884 assertNoFix(FixKind.CREATE_GETTER); 876 assertNoFix(FixKind.CREATE_GETTER);
885 } 877 }
886 878
887 void test_createGetter_unqualified_instance_assignmentRhs() { 879 void test_createGetter_unqualified_instance_assignmentRhs() {
888 _indexTestUnit(''' 880 resolveTestUnit('''
889 class A { 881 class A {
890 main() { 882 main() {
891 int v = test; 883 int v = test;
892 } 884 }
893 } 885 }
894 '''); 886 ''');
895 assertHasFix(FixKind.CREATE_GETTER, ''' 887 assertHasFix(FixKind.CREATE_GETTER, '''
896 class A { 888 class A {
897 int get test => null; 889 int get test => null;
898 890
899 main() { 891 main() {
900 int v = test; 892 int v = test;
901 } 893 }
902 } 894 }
903 '''); 895 ''');
904 } 896 }
905 897
906 void test_createGetter_unqualified_instance_asStatement() { 898 void test_createGetter_unqualified_instance_asStatement() {
907 _indexTestUnit(''' 899 resolveTestUnit('''
908 class A { 900 class A {
909 main() { 901 main() {
910 test; 902 test;
911 } 903 }
912 } 904 }
913 '''); 905 ''');
914 assertHasFix(FixKind.CREATE_GETTER, ''' 906 assertHasFix(FixKind.CREATE_GETTER, '''
915 class A { 907 class A {
916 get test => null; 908 get test => null;
917 909
918 main() { 910 main() {
919 test; 911 test;
920 } 912 }
921 } 913 }
922 '''); 914 ''');
923 } 915 }
924 916
925 void test_createLocalVariable_functionType_named() { 917 void test_createLocalVariable_functionType_named() {
926 _indexTestUnit(''' 918 resolveTestUnit('''
927 typedef MY_FUNCTION(int p); 919 typedef MY_FUNCTION(int p);
928 foo(MY_FUNCTION f) {} 920 foo(MY_FUNCTION f) {}
929 main() { 921 main() {
930 foo(bar); 922 foo(bar);
931 } 923 }
932 '''); 924 ''');
933 assertHasFix(FixKind.CREATE_LOCAL_VARIABLE, ''' 925 assertHasFix(FixKind.CREATE_LOCAL_VARIABLE, '''
934 typedef MY_FUNCTION(int p); 926 typedef MY_FUNCTION(int p);
935 foo(MY_FUNCTION f) {} 927 foo(MY_FUNCTION f) {}
936 main() { 928 main() {
937 MY_FUNCTION bar; 929 MY_FUNCTION bar;
938 foo(bar); 930 foo(bar);
939 } 931 }
940 '''); 932 ''');
941 } 933 }
942 934
943 void test_createLocalVariable_functionType_synthetic() { 935 void test_createLocalVariable_functionType_synthetic() {
944 _indexTestUnit(''' 936 resolveTestUnit('''
945 foo(f(int p)) {} 937 foo(f(int p)) {}
946 main() { 938 main() {
947 foo(bar); 939 foo(bar);
948 } 940 }
949 '''); 941 ''');
950 assertNoFix(FixKind.CREATE_LOCAL_VARIABLE); 942 assertNoFix(FixKind.CREATE_LOCAL_VARIABLE);
951 } 943 }
952 944
953 void test_createLocalVariable_read_typeAssignment() { 945 void test_createLocalVariable_read_typeAssignment() {
954 _indexTestUnit(''' 946 resolveTestUnit('''
955 main() { 947 main() {
956 int a = test; 948 int a = test;
957 } 949 }
958 '''); 950 ''');
959 assertHasFix(FixKind.CREATE_LOCAL_VARIABLE, ''' 951 assertHasFix(FixKind.CREATE_LOCAL_VARIABLE, '''
960 main() { 952 main() {
961 int test; 953 int test;
962 int a = test; 954 int a = test;
963 } 955 }
964 '''); 956 ''');
965 } 957 }
966 958
967 void test_createLocalVariable_read_typeCondition() { 959 void test_createLocalVariable_read_typeCondition() {
968 _indexTestUnit(''' 960 resolveTestUnit('''
969 main() { 961 main() {
970 if (!test) { 962 if (!test) {
971 print(42); 963 print(42);
972 } 964 }
973 } 965 }
974 '''); 966 ''');
975 assertHasFix(FixKind.CREATE_LOCAL_VARIABLE, ''' 967 assertHasFix(FixKind.CREATE_LOCAL_VARIABLE, '''
976 main() { 968 main() {
977 bool test; 969 bool test;
978 if (!test) { 970 if (!test) {
979 print(42); 971 print(42);
980 } 972 }
981 } 973 }
982 '''); 974 ''');
983 } 975 }
984 976
985 void test_createLocalVariable_read_typeInvocationArgument() { 977 void test_createLocalVariable_read_typeInvocationArgument() {
986 _indexTestUnit(''' 978 resolveTestUnit('''
987 main() { 979 main() {
988 f(test); 980 f(test);
989 } 981 }
990 f(String p) {} 982 f(String p) {}
991 '''); 983 ''');
992 assertHasFix(FixKind.CREATE_LOCAL_VARIABLE, ''' 984 assertHasFix(FixKind.CREATE_LOCAL_VARIABLE, '''
993 main() { 985 main() {
994 String test; 986 String test;
995 f(test); 987 f(test);
996 } 988 }
997 f(String p) {} 989 f(String p) {}
998 '''); 990 ''');
999 } 991 }
1000 992
1001 void test_createLocalVariable_write_assignment() { 993 void test_createLocalVariable_write_assignment() {
1002 _indexTestUnit(''' 994 resolveTestUnit('''
1003 main() { 995 main() {
1004 test = 42; 996 test = 42;
1005 } 997 }
1006 '''); 998 ''');
1007 assertHasFix(FixKind.CREATE_LOCAL_VARIABLE, ''' 999 assertHasFix(FixKind.CREATE_LOCAL_VARIABLE, '''
1008 main() { 1000 main() {
1009 var test = 42; 1001 var test = 42;
1010 } 1002 }
1011 '''); 1003 ''');
1012 } 1004 }
1013 1005
1014 void test_createLocalVariable_write_assignment_compound() { 1006 void test_createLocalVariable_write_assignment_compound() {
1015 _indexTestUnit(''' 1007 resolveTestUnit('''
1016 main() { 1008 main() {
1017 test += 42; 1009 test += 42;
1018 } 1010 }
1019 '''); 1011 ''');
1020 assertHasFix(FixKind.CREATE_LOCAL_VARIABLE, ''' 1012 assertHasFix(FixKind.CREATE_LOCAL_VARIABLE, '''
1021 main() { 1013 main() {
1022 int test; 1014 int test;
1023 test += 42; 1015 test += 42;
1024 } 1016 }
1025 '''); 1017 ''');
1026 } 1018 }
1027 1019
1028 void test_createMissingOverrides_functionTypeAlias() { 1020 void test_createMissingOverrides_functionTypeAlias() {
1029 _indexTestUnit(''' 1021 resolveTestUnit('''
1030 typedef int Binary(int left, int right); 1022 typedef int Binary(int left, int right);
1031 1023
1032 abstract class Emulator { 1024 abstract class Emulator {
1033 void performBinary(Binary binary); 1025 void performBinary(Binary binary);
1034 } 1026 }
1035 1027
1036 class MyEmulator extends Emulator { 1028 class MyEmulator extends Emulator {
1037 } 1029 }
1038 '''); 1030 ''');
1039 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, ''' 1031 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, '''
1040 typedef int Binary(int left, int right); 1032 typedef int Binary(int left, int right);
1041 1033
1042 abstract class Emulator { 1034 abstract class Emulator {
1043 void performBinary(Binary binary); 1035 void performBinary(Binary binary);
1044 } 1036 }
1045 1037
1046 class MyEmulator extends Emulator { 1038 class MyEmulator extends Emulator {
1047 @override 1039 @override
1048 void performBinary(Binary binary) { 1040 void performBinary(Binary binary) {
1049 // TODO: implement performBinary 1041 // TODO: implement performBinary
1050 } 1042 }
1051 } 1043 }
1052 '''); 1044 ''');
1053 } 1045 }
1054 1046
1055 void test_createMissingOverrides_functionTypedParameter() { 1047 void test_createMissingOverrides_functionTypedParameter() {
1056 _indexTestUnit(''' 1048 resolveTestUnit('''
1057 abstract class A { 1049 abstract class A {
1058 forEach(int f(double p1, String p2)); 1050 forEach(int f(double p1, String p2));
1059 } 1051 }
1060 1052
1061 class B extends A { 1053 class B extends A {
1062 } 1054 }
1063 '''); 1055 ''');
1064 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, ''' 1056 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, '''
1065 abstract class A { 1057 abstract class A {
1066 forEach(int f(double p1, String p2)); 1058 forEach(int f(double p1, String p2));
1067 } 1059 }
1068 1060
1069 class B extends A { 1061 class B extends A {
1070 @override 1062 @override
1071 forEach(int f(double p1, String p2)) { 1063 forEach(int f(double p1, String p2)) {
1072 // TODO: implement forEach 1064 // TODO: implement forEach
1073 } 1065 }
1074 } 1066 }
1075 '''); 1067 ''');
1076 } 1068 }
1077 1069
1078 void test_createMissingOverrides_generics() { 1070 void test_createMissingOverrides_generics() {
1079 _indexTestUnit(''' 1071 resolveTestUnit('''
1080 class Iterator<T> { 1072 class Iterator<T> {
1081 } 1073 }
1082 1074
1083 abstract class IterableMixin<T> { 1075 abstract class IterableMixin<T> {
1084 Iterator<T> get iterator; 1076 Iterator<T> get iterator;
1085 } 1077 }
1086 1078
1087 class Test extends IterableMixin<int> { 1079 class Test extends IterableMixin<int> {
1088 } 1080 }
1089 '''); 1081 ''');
1090 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, ''' 1082 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, '''
1091 class Iterator<T> { 1083 class Iterator<T> {
1092 } 1084 }
1093 1085
1094 abstract class IterableMixin<T> { 1086 abstract class IterableMixin<T> {
1095 Iterator<T> get iterator; 1087 Iterator<T> get iterator;
1096 } 1088 }
1097 1089
1098 class Test extends IterableMixin<int> { 1090 class Test extends IterableMixin<int> {
1099 // TODO: implement iterator 1091 // TODO: implement iterator
1100 @override 1092 @override
1101 Iterator<int> get iterator => null; 1093 Iterator<int> get iterator => null;
1102 } 1094 }
1103 '''); 1095 ''');
1104 } 1096 }
1105 1097
1106 void test_createMissingOverrides_getter() { 1098 void test_createMissingOverrides_getter() {
1107 _indexTestUnit(''' 1099 resolveTestUnit('''
1108 abstract class A { 1100 abstract class A {
1109 get g1; 1101 get g1;
1110 int get g2; 1102 int get g2;
1111 } 1103 }
1112 1104
1113 class B extends A { 1105 class B extends A {
1114 } 1106 }
1115 '''); 1107 ''');
1116 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, ''' 1108 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, '''
1117 abstract class A { 1109 abstract class A {
1118 get g1; 1110 get g1;
1119 int get g2; 1111 int get g2;
1120 } 1112 }
1121 1113
1122 class B extends A { 1114 class B extends A {
1123 // TODO: implement g1 1115 // TODO: implement g1
1124 @override 1116 @override
1125 get g1 => null; 1117 get g1 => null;
1126 1118
1127 // TODO: implement g2 1119 // TODO: implement g2
1128 @override 1120 @override
1129 int get g2 => null; 1121 int get g2 => null;
1130 } 1122 }
1131 '''); 1123 ''');
1132 } 1124 }
1133 1125
1134 void test_createMissingOverrides_importPrefix() { 1126 void test_createMissingOverrides_importPrefix() {
1135 _indexTestUnit(''' 1127 resolveTestUnit('''
1136 import 'dart:async' as aaa; 1128 import 'dart:async' as aaa;
1137 abstract class A { 1129 abstract class A {
1138 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p); 1130 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p);
1139 } 1131 }
1140 1132
1141 class B extends A { 1133 class B extends A {
1142 } 1134 }
1143 '''); 1135 ''');
1144 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, ''' 1136 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, '''
1145 import 'dart:async' as aaa; 1137 import 'dart:async' as aaa;
1146 abstract class A { 1138 abstract class A {
1147 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p); 1139 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p);
1148 } 1140 }
1149 1141
1150 class B extends A { 1142 class B extends A {
1151 @override 1143 @override
1152 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p) { 1144 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p) {
1153 // TODO: implement g 1145 // TODO: implement g
1154 } 1146 }
1155 } 1147 }
1156 '''); 1148 ''');
1157 } 1149 }
1158 1150
1159 void test_createMissingOverrides_mergeToField_getterSetter() { 1151 void test_createMissingOverrides_mergeToField_getterSetter() {
1160 _indexTestUnit(''' 1152 resolveTestUnit('''
1161 class A { 1153 class A {
1162 int ma; 1154 int ma;
1163 void mb() {} 1155 void mb() {}
1164 double mc; 1156 double mc;
1165 } 1157 }
1166 1158
1167 class B implements A { 1159 class B implements A {
1168 } 1160 }
1169 '''); 1161 ''');
1170 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, ''' 1162 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, '''
(...skipping 10 matching lines...) Expand all
1181 1173
1182 @override 1174 @override
1183 void mb() { 1175 void mb() {
1184 // TODO: implement mb 1176 // TODO: implement mb
1185 } 1177 }
1186 } 1178 }
1187 '''); 1179 ''');
1188 } 1180 }
1189 1181
1190 void test_createMissingOverrides_method() { 1182 void test_createMissingOverrides_method() {
1191 _indexTestUnit(''' 1183 resolveTestUnit('''
1192 abstract class A { 1184 abstract class A {
1193 m1(); 1185 m1();
1194 int m2(); 1186 int m2();
1195 String m3(int p1, double p2, Map<int, List<String>> p3); 1187 String m3(int p1, double p2, Map<int, List<String>> p3);
1196 String m4(p1, p2); 1188 String m4(p1, p2);
1197 String m5(p1, [int p2 = 2, int p3, p4 = 4]); 1189 String m5(p1, [int p2 = 2, int p3, p4 = 4]);
1198 String m6(p1, {int p2: 2, int p3, p4: 4}); 1190 String m6(p1, {int p2: 2, int p3, p4: 4});
1199 } 1191 }
1200 1192
1201 class B extends A { 1193 class B extends A {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 expect(endString, contains('m1')); 1246 expect(endString, contains('m1'));
1255 expect(endString, isNot(contains('m2'))); 1247 expect(endString, isNot(contains('m2')));
1256 expect(endString, isNot(contains('m3'))); 1248 expect(endString, isNot(contains('m3')));
1257 expect(endString, isNot(contains('m4'))); 1249 expect(endString, isNot(contains('m4')));
1258 expect(endString, isNot(contains('m5'))); 1250 expect(endString, isNot(contains('m5')));
1259 expect(endString, isNot(contains('m6'))); 1251 expect(endString, isNot(contains('m6')));
1260 } 1252 }
1261 } 1253 }
1262 1254
1263 void test_createMissingOverrides_operator() { 1255 void test_createMissingOverrides_operator() {
1264 _indexTestUnit(''' 1256 resolveTestUnit('''
1265 abstract class A { 1257 abstract class A {
1266 int operator [](int index); 1258 int operator [](int index);
1267 void operator []=(int index, String value); 1259 void operator []=(int index, String value);
1268 } 1260 }
1269 1261
1270 class B extends A { 1262 class B extends A {
1271 } 1263 }
1272 '''); 1264 ''');
1273 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, ''' 1265 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, '''
1274 abstract class A { 1266 abstract class A {
1275 int operator [](int index); 1267 int operator [](int index);
1276 void operator []=(int index, String value); 1268 void operator []=(int index, String value);
1277 } 1269 }
1278 1270
1279 class B extends A { 1271 class B extends A {
1280 @override 1272 @override
1281 int operator [](int index) { 1273 int operator [](int index) {
1282 // TODO: implement [] 1274 // TODO: implement []
1283 } 1275 }
1284 1276
1285 @override 1277 @override
1286 void operator []=(int index, String value) { 1278 void operator []=(int index, String value) {
1287 // TODO: implement []= 1279 // TODO: implement []=
1288 } 1280 }
1289 } 1281 }
1290 '''); 1282 ''');
1291 } 1283 }
1292 1284
1293 void test_createMissingOverrides_setter() { 1285 void test_createMissingOverrides_setter() {
1294 _indexTestUnit(''' 1286 resolveTestUnit('''
1295 abstract class A { 1287 abstract class A {
1296 set s1(x); 1288 set s1(x);
1297 set s2(int x); 1289 set s2(int x);
1298 void set s3(String x); 1290 void set s3(String x);
1299 } 1291 }
1300 1292
1301 class B extends A { 1293 class B extends A {
1302 } 1294 }
1303 '''); 1295 ''');
1304 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, ''' 1296 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, '''
(...skipping 16 matching lines...) Expand all
1321 1313
1322 @override 1314 @override
1323 void set s3(String x) { 1315 void set s3(String x) {
1324 // TODO: implement s3 1316 // TODO: implement s3
1325 } 1317 }
1326 } 1318 }
1327 '''); 1319 ''');
1328 } 1320 }
1329 1321
1330 void test_createNoSuchMethod() { 1322 void test_createNoSuchMethod() {
1331 _indexTestUnit(''' 1323 resolveTestUnit('''
1332 abstract class A { 1324 abstract class A {
1333 m1(); 1325 m1();
1334 int m2(); 1326 int m2();
1335 } 1327 }
1336 1328
1337 class B extends A { 1329 class B extends A {
1338 existing() {} 1330 existing() {}
1339 } 1331 }
1340 '''); 1332 ''');
1341 assertHasFix(FixKind.CREATE_NO_SUCH_METHOD, ''' 1333 assertHasFix(FixKind.CREATE_NO_SUCH_METHOD, '''
1342 abstract class A { 1334 abstract class A {
1343 m1(); 1335 m1();
1344 int m2(); 1336 int m2();
1345 } 1337 }
1346 1338
1347 class B extends A { 1339 class B extends A {
1348 existing() {} 1340 existing() {}
1349 1341
1350 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 1342 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
1351 } 1343 }
1352 '''); 1344 ''');
1353 } 1345 }
1354 1346
1355 void test_creatGetter_location_afterLastGetter() { 1347 void test_creatGetter_location_afterLastGetter() {
1356 _indexTestUnit(''' 1348 resolveTestUnit('''
1357 class A { 1349 class A {
1358 int existingField; 1350 int existingField;
1359 1351
1360 int get existingGetter => null; 1352 int get existingGetter => null;
1361 1353
1362 existingMethod() {} 1354 existingMethod() {}
1363 } 1355 }
1364 main(A a) { 1356 main(A a) {
1365 int v = a.test; 1357 int v = a.test;
1366 } 1358 }
1367 '''); 1359 ''');
1368 assertHasFix(FixKind.CREATE_GETTER, ''' 1360 assertHasFix(FixKind.CREATE_GETTER, '''
1369 class A { 1361 class A {
1370 int existingField; 1362 int existingField;
1371 1363
1372 int get existingGetter => null; 1364 int get existingGetter => null;
1373 1365
1374 int get test => null; 1366 int get test => null;
1375 1367
1376 existingMethod() {} 1368 existingMethod() {}
1377 } 1369 }
1378 main(A a) { 1370 main(A a) {
1379 int v = a.test; 1371 int v = a.test;
1380 } 1372 }
1381 '''); 1373 ''');
1382 } 1374 }
1383 1375
1384 void test_creationFunction_forFunctionType_cascadeSecond() { 1376 void test_creationFunction_forFunctionType_cascadeSecond() {
1385 _indexTestUnit(''' 1377 resolveTestUnit('''
1386 class A { 1378 class A {
1387 B ma() => null; 1379 B ma() => null;
1388 } 1380 }
1389 class B { 1381 class B {
1390 useFunction(int g(double a, String b)) {} 1382 useFunction(int g(double a, String b)) {}
1391 } 1383 }
1392 1384
1393 main() { 1385 main() {
1394 A a = new A(); 1386 A a = new A();
1395 a..ma().useFunction(test); 1387 a..ma().useFunction(test);
(...skipping 11 matching lines...) Expand all
1407 A a = new A(); 1399 A a = new A();
1408 a..ma().useFunction(test); 1400 a..ma().useFunction(test);
1409 } 1401 }
1410 1402
1411 int test(double a, String b) { 1403 int test(double a, String b) {
1412 } 1404 }
1413 '''); 1405 ''');
1414 } 1406 }
1415 1407
1416 void test_creationFunction_forFunctionType_coreFunction() { 1408 void test_creationFunction_forFunctionType_coreFunction() {
1417 _indexTestUnit(''' 1409 resolveTestUnit('''
1418 main() { 1410 main() {
1419 useFunction(g: test); 1411 useFunction(g: test);
1420 } 1412 }
1421 useFunction({Function g}) {} 1413 useFunction({Function g}) {}
1422 '''); 1414 ''');
1423 assertHasFix(FixKind.CREATE_FUNCTION, ''' 1415 assertHasFix(FixKind.CREATE_FUNCTION, '''
1424 main() { 1416 main() {
1425 useFunction(g: test); 1417 useFunction(g: test);
1426 } 1418 }
1427 useFunction({Function g}) {} 1419 useFunction({Function g}) {}
1428 1420
1429 test() { 1421 test() {
1430 } 1422 }
1431 '''); 1423 ''');
1432 } 1424 }
1433 1425
1434 void test_creationFunction_forFunctionType_dynamicArgument() { 1426 void test_creationFunction_forFunctionType_dynamicArgument() {
1435 _indexTestUnit(''' 1427 resolveTestUnit('''
1436 main() { 1428 main() {
1437 useFunction(test); 1429 useFunction(test);
1438 } 1430 }
1439 useFunction(int g(a, b)) {} 1431 useFunction(int g(a, b)) {}
1440 '''); 1432 ''');
1441 assertHasFix(FixKind.CREATE_FUNCTION, ''' 1433 assertHasFix(FixKind.CREATE_FUNCTION, '''
1442 main() { 1434 main() {
1443 useFunction(test); 1435 useFunction(test);
1444 } 1436 }
1445 useFunction(int g(a, b)) {} 1437 useFunction(int g(a, b)) {}
1446 1438
1447 int test(a, b) { 1439 int test(a, b) {
1448 } 1440 }
1449 '''); 1441 ''');
1450 } 1442 }
1451 1443
1452 void test_creationFunction_forFunctionType_function() { 1444 void test_creationFunction_forFunctionType_function() {
1453 _indexTestUnit(''' 1445 resolveTestUnit('''
1454 main() { 1446 main() {
1455 useFunction(test); 1447 useFunction(test);
1456 } 1448 }
1457 useFunction(int g(double a, String b)) {} 1449 useFunction(int g(double a, String b)) {}
1458 '''); 1450 ''');
1459 assertHasFix(FixKind.CREATE_FUNCTION, ''' 1451 assertHasFix(FixKind.CREATE_FUNCTION, '''
1460 main() { 1452 main() {
1461 useFunction(test); 1453 useFunction(test);
1462 } 1454 }
1463 useFunction(int g(double a, String b)) {} 1455 useFunction(int g(double a, String b)) {}
1464 1456
1465 int test(double a, String b) { 1457 int test(double a, String b) {
1466 } 1458 }
1467 '''); 1459 ''');
1468 } 1460 }
1469 1461
1470 void test_creationFunction_forFunctionType_function_namedArgument() { 1462 void test_creationFunction_forFunctionType_function_namedArgument() {
1471 _indexTestUnit(''' 1463 resolveTestUnit('''
1472 main() { 1464 main() {
1473 useFunction(g: test); 1465 useFunction(g: test);
1474 } 1466 }
1475 useFunction({int g(double a, String b)}) {} 1467 useFunction({int g(double a, String b)}) {}
1476 '''); 1468 ''');
1477 assertHasFix(FixKind.CREATE_FUNCTION, ''' 1469 assertHasFix(FixKind.CREATE_FUNCTION, '''
1478 main() { 1470 main() {
1479 useFunction(g: test); 1471 useFunction(g: test);
1480 } 1472 }
1481 useFunction({int g(double a, String b)}) {} 1473 useFunction({int g(double a, String b)}) {}
1482 1474
1483 int test(double a, String b) { 1475 int test(double a, String b) {
1484 } 1476 }
1485 '''); 1477 ''');
1486 } 1478 }
1487 1479
1488 void test_creationFunction_forFunctionType_method_enclosingClass_static() { 1480 void test_creationFunction_forFunctionType_method_enclosingClass_static() {
1489 _indexTestUnit(''' 1481 resolveTestUnit('''
1490 class A { 1482 class A {
1491 static foo() { 1483 static foo() {
1492 useFunction(test); 1484 useFunction(test);
1493 } 1485 }
1494 } 1486 }
1495 useFunction(int g(double a, String b)) {} 1487 useFunction(int g(double a, String b)) {}
1496 '''); 1488 ''');
1497 assertHasFix(FixKind.CREATE_METHOD, ''' 1489 assertHasFix(FixKind.CREATE_METHOD, '''
1498 class A { 1490 class A {
1499 static foo() { 1491 static foo() {
1500 useFunction(test); 1492 useFunction(test);
1501 } 1493 }
1502 1494
1503 static int test(double a, String b) { 1495 static int test(double a, String b) {
1504 } 1496 }
1505 } 1497 }
1506 useFunction(int g(double a, String b)) {} 1498 useFunction(int g(double a, String b)) {}
1507 '''); 1499 ''');
1508 } 1500 }
1509 1501
1510 void test_creationFunction_forFunctionType_method_enclosingClass_static2() { 1502 void test_creationFunction_forFunctionType_method_enclosingClass_static2() {
1511 _indexTestUnit(''' 1503 resolveTestUnit('''
1512 class A { 1504 class A {
1513 var f; 1505 var f;
1514 A() : f = useFunction(test); 1506 A() : f = useFunction(test);
1515 } 1507 }
1516 useFunction(int g(double a, String b)) {} 1508 useFunction(int g(double a, String b)) {}
1517 '''); 1509 ''');
1518 assertHasFix(FixKind.CREATE_METHOD, ''' 1510 assertHasFix(FixKind.CREATE_METHOD, '''
1519 class A { 1511 class A {
1520 var f; 1512 var f;
1521 A() : f = useFunction(test); 1513 A() : f = useFunction(test);
1522 1514
1523 static int test(double a, String b) { 1515 static int test(double a, String b) {
1524 } 1516 }
1525 } 1517 }
1526 useFunction(int g(double a, String b)) {} 1518 useFunction(int g(double a, String b)) {}
1527 '''); 1519 ''');
1528 } 1520 }
1529 1521
1530 void test_creationFunction_forFunctionType_method_targetClass() { 1522 void test_creationFunction_forFunctionType_method_targetClass() {
1531 _indexTestUnit(''' 1523 resolveTestUnit('''
1532 main(A a) { 1524 main(A a) {
1533 useFunction(a.test); 1525 useFunction(a.test);
1534 } 1526 }
1535 class A { 1527 class A {
1536 } 1528 }
1537 useFunction(int g(double a, String b)) {} 1529 useFunction(int g(double a, String b)) {}
1538 '''); 1530 ''');
1539 assertHasFix(FixKind.CREATE_METHOD, ''' 1531 assertHasFix(FixKind.CREATE_METHOD, '''
1540 main(A a) { 1532 main(A a) {
1541 useFunction(a.test); 1533 useFunction(a.test);
1542 } 1534 }
1543 class A { 1535 class A {
1544 int test(double a, String b) { 1536 int test(double a, String b) {
1545 } 1537 }
1546 } 1538 }
1547 useFunction(int g(double a, String b)) {} 1539 useFunction(int g(double a, String b)) {}
1548 '''); 1540 ''');
1549 } 1541 }
1550 1542
1551 void 1543 void
1552 test_creationFunction_forFunctionType_method_targetClass_hasOtherMember() { 1544 test_creationFunction_forFunctionType_method_targetClass_hasOtherMember() {
1553 _indexTestUnit(''' 1545 resolveTestUnit('''
1554 main(A a) { 1546 main(A a) {
1555 useFunction(a.test); 1547 useFunction(a.test);
1556 } 1548 }
1557 class A { 1549 class A {
1558 m() {} 1550 m() {}
1559 } 1551 }
1560 useFunction(int g(double a, String b)) {} 1552 useFunction(int g(double a, String b)) {}
1561 '''); 1553 ''');
1562 assertHasFix(FixKind.CREATE_METHOD, ''' 1554 assertHasFix(FixKind.CREATE_METHOD, '''
1563 main(A a) { 1555 main(A a) {
1564 useFunction(a.test); 1556 useFunction(a.test);
1565 } 1557 }
1566 class A { 1558 class A {
1567 m() {} 1559 m() {}
1568 1560
1569 int test(double a, String b) { 1561 int test(double a, String b) {
1570 } 1562 }
1571 } 1563 }
1572 useFunction(int g(double a, String b)) {} 1564 useFunction(int g(double a, String b)) {}
1573 '''); 1565 ''');
1574 } 1566 }
1575 1567
1576 void test_creationFunction_forFunctionType_notFunctionType() { 1568 void test_creationFunction_forFunctionType_notFunctionType() {
1577 _indexTestUnit(''' 1569 resolveTestUnit('''
1578 main(A a) { 1570 main(A a) {
1579 useFunction(a.test); 1571 useFunction(a.test);
1580 } 1572 }
1581 typedef A(); 1573 typedef A();
1582 useFunction(g) {} 1574 useFunction(g) {}
1583 '''); 1575 ''');
1584 assertNoFix(FixKind.CREATE_METHOD); 1576 assertNoFix(FixKind.CREATE_METHOD);
1585 assertNoFix(FixKind.CREATE_FUNCTION); 1577 assertNoFix(FixKind.CREATE_FUNCTION);
1586 } 1578 }
1587 1579
1588 void test_creationFunction_forFunctionType_unknownTarget() { 1580 void test_creationFunction_forFunctionType_unknownTarget() {
1589 _indexTestUnit(''' 1581 resolveTestUnit('''
1590 main(A a) { 1582 main(A a) {
1591 useFunction(a.test); 1583 useFunction(a.test);
1592 } 1584 }
1593 class A { 1585 class A {
1594 } 1586 }
1595 useFunction(g) {} 1587 useFunction(g) {}
1596 '''); 1588 ''');
1597 assertNoFix(FixKind.CREATE_METHOD); 1589 assertNoFix(FixKind.CREATE_METHOD);
1598 } 1590 }
1599 1591
1600 void test_expectedToken_semicolon() { 1592 void test_expectedToken_semicolon() {
1601 _indexTestUnit(''' 1593 resolveTestUnit('''
1602 main() { 1594 main() {
1603 print(0) 1595 print(0)
1604 } 1596 }
1605 '''); 1597 ''');
1606 assertHasFix(FixKind.INSERT_SEMICOLON, ''' 1598 assertHasFix(FixKind.INSERT_SEMICOLON, '''
1607 main() { 1599 main() {
1608 print(0); 1600 print(0);
1609 } 1601 }
1610 '''); 1602 ''');
1611 } 1603 }
1612 1604
1613 void test_importLibraryPackage_withType() { 1605 void test_importLibraryPackage_withType() {
1614 _configureMyPkg(''' 1606 _configureMyPkg('''
1615 library my_lib; 1607 library my_lib;
1616 class Test {} 1608 class Test {}
1617 '''); 1609 ''');
1618 // try to find a fix 1610 // try to find a fix
1619 _indexTestUnit(''' 1611 resolveTestUnit('''
1620 main() { 1612 main() {
1621 Test test = null; 1613 Test test = null;
1622 } 1614 }
1623 '''); 1615 ''');
1624 performAllAnalysisTasks(); 1616 performAllAnalysisTasks();
1625 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' 1617 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, '''
1626 import 'package:my_pkg/my_lib.dart'; 1618 import 'package:my_pkg/my_lib.dart';
1627 1619
1628 main() { 1620 main() {
1629 Test test = null; 1621 Test test = null;
1630 } 1622 }
1631 '''); 1623 ''');
1632 } 1624 }
1633 1625
1634 void test_importLibraryPrefix_withTopLevelVariable() { 1626 void test_importLibraryPrefix_withTopLevelVariable() {
1635 _indexTestUnit(''' 1627 resolveTestUnit('''
1636 import 'dart:math' as pref; 1628 import 'dart:math' as pref;
1637 main() { 1629 main() {
1638 print(pref.E); 1630 print(pref.E);
1639 print(PI); 1631 print(PI);
1640 } 1632 }
1641 '''); 1633 ''');
1642 assertHasFix(FixKind.IMPORT_LIBRARY_PREFIX, ''' 1634 assertHasFix(FixKind.IMPORT_LIBRARY_PREFIX, '''
1643 import 'dart:math' as pref; 1635 import 'dart:math' as pref;
1644 main() { 1636 main() {
1645 print(pref.E); 1637 print(pref.E);
1646 print(pref.PI); 1638 print(pref.PI);
1647 } 1639 }
1648 '''); 1640 ''');
1649 } 1641 }
1650 1642
1651 void test_importLibraryPrefix_withType() { 1643 void test_importLibraryPrefix_withType() {
1652 _indexTestUnit(''' 1644 resolveTestUnit('''
1653 import 'dart:async' as pref; 1645 import 'dart:async' as pref;
1654 main() { 1646 main() {
1655 pref.Stream s = null; 1647 pref.Stream s = null;
1656 Future f = null; 1648 Future f = null;
1657 } 1649 }
1658 '''); 1650 ''');
1659 assertHasFix(FixKind.IMPORT_LIBRARY_PREFIX, ''' 1651 assertHasFix(FixKind.IMPORT_LIBRARY_PREFIX, '''
1660 import 'dart:async' as pref; 1652 import 'dart:async' as pref;
1661 main() { 1653 main() {
1662 pref.Stream s = null; 1654 pref.Stream s = null;
1663 pref.Future f = null; 1655 pref.Future f = null;
1664 } 1656 }
1665 '''); 1657 ''');
1666 } 1658 }
1667 1659
1668 void test_importLibraryProject_withFunction() { 1660 void test_importLibraryProject_withFunction() {
1669 addSource('/lib.dart', ''' 1661 addSource('/lib.dart', '''
1670 library lib; 1662 library lib;
1671 myFunction() {} 1663 myFunction() {}
1672 '''); 1664 ''');
1673 _indexTestUnit(''' 1665 resolveTestUnit('''
1674 main() { 1666 main() {
1675 myFunction(); 1667 myFunction();
1676 } 1668 }
1677 '''); 1669 ''');
1678 performAllAnalysisTasks(); 1670 performAllAnalysisTasks();
1679 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' 1671 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, '''
1680 import 'lib.dart'; 1672 import 'lib.dart';
1681 1673
1682 main() { 1674 main() {
1683 myFunction(); 1675 myFunction();
1684 } 1676 }
1685 '''); 1677 ''');
1686 } 1678 }
1687 1679
1688 void test_importLibraryProject_withFunction_unresolvedMethod() { 1680 void test_importLibraryProject_withFunction_unresolvedMethod() {
1689 addSource('/lib.dart', ''' 1681 addSource('/lib.dart', '''
1690 library lib; 1682 library lib;
1691 myFunction() {} 1683 myFunction() {}
1692 '''); 1684 ''');
1693 _indexTestUnit(''' 1685 resolveTestUnit('''
1694 class A { 1686 class A {
1695 main() { 1687 main() {
1696 myFunction(); 1688 myFunction();
1697 } 1689 }
1698 } 1690 }
1699 '''); 1691 ''');
1700 performAllAnalysisTasks(); 1692 performAllAnalysisTasks();
1701 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' 1693 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, '''
1702 import 'lib.dart'; 1694 import 'lib.dart';
1703 1695
1704 class A { 1696 class A {
1705 main() { 1697 main() {
1706 myFunction(); 1698 myFunction();
1707 } 1699 }
1708 } 1700 }
1709 '''); 1701 ''');
1710 } 1702 }
1711 1703
1712 void test_importLibraryProject_withTopLevelVariable() { 1704 void test_importLibraryProject_withTopLevelVariable() {
1713 addSource('/lib.dart', ''' 1705 addSource('/lib.dart', '''
1714 library lib; 1706 library lib;
1715 int MY_VAR = 42; 1707 int MY_VAR = 42;
1716 '''); 1708 ''');
1717 _indexTestUnit(''' 1709 resolveTestUnit('''
1718 main() { 1710 main() {
1719 print(MY_VAR); 1711 print(MY_VAR);
1720 } 1712 }
1721 '''); 1713 ''');
1722 performAllAnalysisTasks(); 1714 performAllAnalysisTasks();
1723 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' 1715 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, '''
1724 import 'lib.dart'; 1716 import 'lib.dart';
1725 1717
1726 main() { 1718 main() {
1727 print(MY_VAR); 1719 print(MY_VAR);
1728 } 1720 }
1729 '''); 1721 ''');
1730 } 1722 }
1731 1723
1732 void test_importLibraryProject_withType_annotation() { 1724 void test_importLibraryProject_withType_annotation() {
1733 addSource('/lib.dart', ''' 1725 addSource('/lib.dart', '''
1734 library lib; 1726 library lib;
1735 class Test { 1727 class Test {
1736 const Test(int p); 1728 const Test(int p);
1737 } 1729 }
1738 '''); 1730 ''');
1739 _indexTestUnit(''' 1731 resolveTestUnit('''
1740 @Test(0) 1732 @Test(0)
1741 main() { 1733 main() {
1742 } 1734 }
1743 '''); 1735 ''');
1744 performAllAnalysisTasks(); 1736 performAllAnalysisTasks();
1745 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' 1737 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, '''
1746 import 'lib.dart'; 1738 import 'lib.dart';
1747 1739
1748 @Test(0) 1740 @Test(0)
1749 main() { 1741 main() {
1750 } 1742 }
1751 '''); 1743 ''');
1752 } 1744 }
1753 1745
1754 void test_importLibraryProject_withType_inParentFolder() { 1746 void test_importLibraryProject_withType_inParentFolder() {
1755 testFile = '/project/bin/test.dart'; 1747 testFile = '/project/bin/test.dart';
1756 addSource('/project/lib.dart', ''' 1748 addSource('/project/lib.dart', '''
1757 library lib; 1749 library lib;
1758 class Test {} 1750 class Test {}
1759 '''); 1751 ''');
1760 _indexTestUnit(''' 1752 resolveTestUnit('''
1761 main() { 1753 main() {
1762 Test t = null; 1754 Test t = null;
1763 } 1755 }
1764 '''); 1756 ''');
1765 performAllAnalysisTasks(); 1757 performAllAnalysisTasks();
1766 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' 1758 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, '''
1767 import '../lib.dart'; 1759 import '../lib.dart';
1768 1760
1769 main() { 1761 main() {
1770 Test t = null; 1762 Test t = null;
1771 } 1763 }
1772 '''); 1764 ''');
1773 } 1765 }
1774 1766
1775 void test_importLibraryProject_withType_inRelativeFolder() { 1767 void test_importLibraryProject_withType_inRelativeFolder() {
1776 testFile = '/project/bin/test.dart'; 1768 testFile = '/project/bin/test.dart';
1777 addSource('/project/lib/sub/folder/lib.dart', ''' 1769 addSource('/project/lib/sub/folder/lib.dart', '''
1778 library lib; 1770 library lib;
1779 class Test {} 1771 class Test {}
1780 '''); 1772 ''');
1781 _indexTestUnit(''' 1773 resolveTestUnit('''
1782 main() { 1774 main() {
1783 Test t = null; 1775 Test t = null;
1784 } 1776 }
1785 '''); 1777 ''');
1786 performAllAnalysisTasks(); 1778 performAllAnalysisTasks();
1787 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' 1779 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, '''
1788 import '../lib/sub/folder/lib.dart'; 1780 import '../lib/sub/folder/lib.dart';
1789 1781
1790 main() { 1782 main() {
1791 Test t = null; 1783 Test t = null;
1792 } 1784 }
1793 '''); 1785 ''');
1794 } 1786 }
1795 1787
1796 void test_importLibraryProject_withType_inSameFolder() { 1788 void test_importLibraryProject_withType_inSameFolder() {
1797 testFile = '/project/bin/test.dart'; 1789 testFile = '/project/bin/test.dart';
1798 addSource('/project/bin/lib.dart', ''' 1790 addSource('/project/bin/lib.dart', '''
1799 library lib; 1791 library lib;
1800 class Test {} 1792 class Test {}
1801 '''); 1793 ''');
1802 _indexTestUnit(''' 1794 resolveTestUnit('''
1803 main() { 1795 main() {
1804 Test t = null; 1796 Test t = null;
1805 } 1797 }
1806 '''); 1798 ''');
1807 performAllAnalysisTasks(); 1799 performAllAnalysisTasks();
1808 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' 1800 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, '''
1809 import 'lib.dart'; 1801 import 'lib.dart';
1810 1802
1811 main() { 1803 main() {
1812 Test t = null; 1804 Test t = null;
1813 } 1805 }
1814 '''); 1806 ''');
1815 } 1807 }
1816 1808
1817 void test_importLibrarySdk_withTopLevelVariable() { 1809 void test_importLibrarySdk_withTopLevelVariable() {
1818 _indexTestUnit(''' 1810 resolveTestUnit('''
1819 main() { 1811 main() {
1820 print(PI); 1812 print(PI);
1821 } 1813 }
1822 '''); 1814 ''');
1823 performAllAnalysisTasks(); 1815 performAllAnalysisTasks();
1824 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' 1816 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, '''
1825 import 'dart:math'; 1817 import 'dart:math';
1826 1818
1827 main() { 1819 main() {
1828 print(PI); 1820 print(PI);
1829 } 1821 }
1830 '''); 1822 ''');
1831 } 1823 }
1832 1824
1833 void test_importLibrarySdk_withTopLevelVariable_annotation() { 1825 void test_importLibrarySdk_withTopLevelVariable_annotation() {
1834 _indexTestUnit(''' 1826 resolveTestUnit('''
1835 @PI 1827 @PI
1836 main() { 1828 main() {
1837 } 1829 }
1838 '''); 1830 ''');
1839 performAllAnalysisTasks(); 1831 performAllAnalysisTasks();
1840 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' 1832 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, '''
1841 import 'dart:math'; 1833 import 'dart:math';
1842 1834
1843 @PI 1835 @PI
1844 main() { 1836 main() {
1845 } 1837 }
1846 '''); 1838 ''');
1847 } 1839 }
1848 1840
1849 void test_importLibrarySdk_withType_AsExpression() { 1841 void test_importLibrarySdk_withType_AsExpression() {
1850 _indexTestUnit(''' 1842 resolveTestUnit('''
1851 main(p) { 1843 main(p) {
1852 p as Future; 1844 p as Future;
1853 } 1845 }
1854 '''); 1846 ''');
1855 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' 1847 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, '''
1856 import 'dart:async'; 1848 import 'dart:async';
1857 1849
1858 main(p) { 1850 main(p) {
1859 p as Future; 1851 p as Future;
1860 } 1852 }
1861 '''); 1853 ''');
1862 } 1854 }
1863 1855
1864 void test_importLibrarySdk_withType_invocationTarget() { 1856 void test_importLibrarySdk_withType_invocationTarget() {
1865 _indexTestUnit(''' 1857 resolveTestUnit('''
1866 main() { 1858 main() {
1867 Future.wait(null); 1859 Future.wait(null);
1868 } 1860 }
1869 '''); 1861 ''');
1870 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' 1862 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, '''
1871 import 'dart:async'; 1863 import 'dart:async';
1872 1864
1873 main() { 1865 main() {
1874 Future.wait(null); 1866 Future.wait(null);
1875 } 1867 }
1876 '''); 1868 ''');
1877 } 1869 }
1878 1870
1879 void test_importLibrarySdk_withType_IsExpression() { 1871 void test_importLibrarySdk_withType_IsExpression() {
1880 _indexTestUnit(''' 1872 resolveTestUnit('''
1881 main(p) { 1873 main(p) {
1882 p is Future; 1874 p is Future;
1883 } 1875 }
1884 '''); 1876 ''');
1885 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' 1877 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, '''
1886 import 'dart:async'; 1878 import 'dart:async';
1887 1879
1888 main(p) { 1880 main(p) {
1889 p is Future; 1881 p is Future;
1890 } 1882 }
1891 '''); 1883 ''');
1892 } 1884 }
1893 1885
1894 void test_importLibrarySdk_withType_typeAnnotation() { 1886 void test_importLibrarySdk_withType_typeAnnotation() {
1895 _indexTestUnit(''' 1887 resolveTestUnit('''
1896 main() { 1888 main() {
1897 Future f = null; 1889 Future f = null;
1898 } 1890 }
1899 '''); 1891 ''');
1900 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' 1892 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, '''
1901 import 'dart:async'; 1893 import 'dart:async';
1902 1894
1903 main() { 1895 main() {
1904 Future f = null; 1896 Future f = null;
1905 } 1897 }
1906 '''); 1898 ''');
1907 } 1899 }
1908 1900
1909 void test_importLibrarySdk_withType_typeAnnotation_PrefixedIdentifier() { 1901 void test_importLibrarySdk_withType_typeAnnotation_PrefixedIdentifier() {
1910 _indexTestUnit(''' 1902 resolveTestUnit('''
1911 main() { 1903 main() {
1912 Future.wait; 1904 Future.wait;
1913 } 1905 }
1914 '''); 1906 ''');
1915 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' 1907 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, '''
1916 import 'dart:async'; 1908 import 'dart:async';
1917 1909
1918 main() { 1910 main() {
1919 Future.wait; 1911 Future.wait;
1920 } 1912 }
1921 '''); 1913 ''');
1922 } 1914 }
1923 1915
1924 void test_importLibrarySdk_withType_typeArgument() { 1916 void test_importLibrarySdk_withType_typeArgument() {
1925 _indexTestUnit(''' 1917 resolveTestUnit('''
1926 main() { 1918 main() {
1927 List<Future> futures = []; 1919 List<Future> futures = [];
1928 } 1920 }
1929 '''); 1921 ''');
1930 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' 1922 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, '''
1931 import 'dart:async'; 1923 import 'dart:async';
1932 1924
1933 main() { 1925 main() {
1934 List<Future> futures = []; 1926 List<Future> futures = [];
1935 } 1927 }
1936 '''); 1928 ''');
1937 } 1929 }
1938 1930
1939 void test_importLibraryShow() { 1931 void test_importLibraryShow() {
1940 _indexTestUnit(''' 1932 resolveTestUnit('''
1941 import 'dart:async' show Stream; 1933 import 'dart:async' show Stream;
1942 main() { 1934 main() {
1943 Stream s = null; 1935 Stream s = null;
1944 Future f = null; 1936 Future f = null;
1945 } 1937 }
1946 '''); 1938 ''');
1947 assertHasFix(FixKind.IMPORT_LIBRARY_SHOW, ''' 1939 assertHasFix(FixKind.IMPORT_LIBRARY_SHOW, '''
1948 import 'dart:async' show Future, Stream; 1940 import 'dart:async' show Future, Stream;
1949 main() { 1941 main() {
1950 Stream s = null; 1942 Stream s = null;
1951 Future f = null; 1943 Future f = null;
1952 } 1944 }
1953 '''); 1945 ''');
1954 } 1946 }
1955 1947
1956 void test_isNotNull() { 1948 void test_isNotNull() {
1957 _indexTestUnit(''' 1949 resolveTestUnit('''
1958 main(p) { 1950 main(p) {
1959 p is! Null; 1951 p is! Null;
1960 } 1952 }
1961 '''); 1953 ''');
1962 assertHasFix(FixKind.USE_NOT_EQ_NULL, ''' 1954 assertHasFix(FixKind.USE_NOT_EQ_NULL, '''
1963 main(p) { 1955 main(p) {
1964 p != null; 1956 p != null;
1965 } 1957 }
1966 '''); 1958 ''');
1967 } 1959 }
1968 1960
1969 void test_isNull() { 1961 void test_isNull() {
1970 _indexTestUnit(''' 1962 resolveTestUnit('''
1971 main(p) { 1963 main(p) {
1972 p is Null; 1964 p is Null;
1973 } 1965 }
1974 '''); 1966 ''');
1975 assertHasFix(FixKind.USE_EQ_EQ_NULL, ''' 1967 assertHasFix(FixKind.USE_EQ_EQ_NULL, '''
1976 main(p) { 1968 main(p) {
1977 p == null; 1969 p == null;
1978 } 1970 }
1979 '''); 1971 ''');
1980 } 1972 }
1981 1973
1982 void test_makeEnclosingClassAbstract_declaresAbstractMethod() { 1974 void test_makeEnclosingClassAbstract_declaresAbstractMethod() {
1983 _indexTestUnit(''' 1975 resolveTestUnit('''
1984 class A { 1976 class A {
1985 m(); 1977 m();
1986 } 1978 }
1987 '''); 1979 ''');
1988 assertHasFix(FixKind.MAKE_CLASS_ABSTRACT, ''' 1980 assertHasFix(FixKind.MAKE_CLASS_ABSTRACT, '''
1989 abstract class A { 1981 abstract class A {
1990 m(); 1982 m();
1991 } 1983 }
1992 '''); 1984 ''');
1993 } 1985 }
1994 1986
1995 void test_makeEnclosingClassAbstract_inheritsAbstractMethod() { 1987 void test_makeEnclosingClassAbstract_inheritsAbstractMethod() {
1996 _indexTestUnit(''' 1988 resolveTestUnit('''
1997 abstract class A { 1989 abstract class A {
1998 m(); 1990 m();
1999 } 1991 }
2000 class B extends A { 1992 class B extends A {
2001 } 1993 }
2002 '''); 1994 ''');
2003 assertHasFix(FixKind.MAKE_CLASS_ABSTRACT, ''' 1995 assertHasFix(FixKind.MAKE_CLASS_ABSTRACT, '''
2004 abstract class A { 1996 abstract class A {
2005 m(); 1997 m();
2006 } 1998 }
2007 abstract class B extends A { 1999 abstract class B extends A {
2008 } 2000 }
2009 '''); 2001 ''');
2010 } 2002 }
2011 2003
2012 void test_removeParentheses_inGetterDeclaration() { 2004 void test_removeParentheses_inGetterDeclaration() {
2013 _indexTestUnit(''' 2005 resolveTestUnit('''
2014 class A { 2006 class A {
2015 int get foo() => 0; 2007 int get foo() => 0;
2016 } 2008 }
2017 '''); 2009 ''');
2018 assertHasFix(FixKind.REMOVE_PARAMETERS_IN_GETTER_DECLARATION, ''' 2010 assertHasFix(FixKind.REMOVE_PARAMETERS_IN_GETTER_DECLARATION, '''
2019 class A { 2011 class A {
2020 int get foo => 0; 2012 int get foo => 0;
2021 } 2013 }
2022 '''); 2014 ''');
2023 } 2015 }
2024 2016
2025 void test_removeParentheses_inGetterInvocation() { 2017 void test_removeParentheses_inGetterInvocation() {
2026 _indexTestUnit(''' 2018 resolveTestUnit('''
2027 class A { 2019 class A {
2028 int get foo => 0; 2020 int get foo => 0;
2029 } 2021 }
2030 main(A a) { 2022 main(A a) {
2031 a.foo(); 2023 a.foo();
2032 } 2024 }
2033 '''); 2025 ''');
2034 assertHasFix(FixKind.REMOVE_PARENTHESIS_IN_GETTER_INVOCATION, ''' 2026 assertHasFix(FixKind.REMOVE_PARENTHESIS_IN_GETTER_INVOCATION, '''
2035 class A { 2027 class A {
2036 int get foo => 0; 2028 int get foo => 0;
2037 } 2029 }
2038 main(A a) { 2030 main(A a) {
2039 a.foo; 2031 a.foo;
2040 } 2032 }
2041 '''); 2033 ''');
2042 } 2034 }
2043 2035
2044 void test_removeUnnecessaryCast_assignment() { 2036 void test_removeUnnecessaryCast_assignment() {
2045 _indexTestUnit(''' 2037 resolveTestUnit('''
2046 main(Object p) { 2038 main(Object p) {
2047 if (p is String) { 2039 if (p is String) {
2048 String v = ((p as String)); 2040 String v = ((p as String));
2049 } 2041 }
2050 } 2042 }
2051 '''); 2043 ''');
2052 assertHasFix(FixKind.REMOVE_UNNECASSARY_CAST, ''' 2044 assertHasFix(FixKind.REMOVE_UNNECASSARY_CAST, '''
2053 main(Object p) { 2045 main(Object p) {
2054 if (p is String) { 2046 if (p is String) {
2055 String v = p; 2047 String v = p;
2056 } 2048 }
2057 } 2049 }
2058 '''); 2050 ''');
2059 } 2051 }
2060 2052
2061 void test_removeUnusedImport() { 2053 void test_removeUnusedImport() {
2062 _indexTestUnit(''' 2054 resolveTestUnit('''
2063 import 'dart:math'; 2055 import 'dart:math';
2064 main() { 2056 main() {
2065 } 2057 }
2066 '''); 2058 ''');
2067 assertHasFix(FixKind.REMOVE_UNUSED_IMPORT, ''' 2059 assertHasFix(FixKind.REMOVE_UNUSED_IMPORT, '''
2068 main() { 2060 main() {
2069 } 2061 }
2070 '''); 2062 ''');
2071 } 2063 }
2072 2064
2073 void test_removeUnusedImport_anotherImportOnLine() { 2065 void test_removeUnusedImport_anotherImportOnLine() {
2074 _indexTestUnit(''' 2066 resolveTestUnit('''
2075 import 'dart:math'; import 'dart:async'; 2067 import 'dart:math'; import 'dart:async';
2076 2068
2077 main() { 2069 main() {
2078 Future f; 2070 Future f;
2079 } 2071 }
2080 '''); 2072 ''');
2081 assertHasFix(FixKind.REMOVE_UNUSED_IMPORT, ''' 2073 assertHasFix(FixKind.REMOVE_UNUSED_IMPORT, '''
2082 import 'dart:async'; 2074 import 'dart:async';
2083 2075
2084 main() { 2076 main() {
2085 Future f; 2077 Future f;
2086 } 2078 }
2087 '''); 2079 ''');
2088 } 2080 }
2089 2081
2090 void test_removeUnusedImport_severalLines() { 2082 void test_removeUnusedImport_severalLines() {
2091 _indexTestUnit(''' 2083 resolveTestUnit('''
2092 import 2084 import
2093 'dart:math'; 2085 'dart:math';
2094 main() { 2086 main() {
2095 } 2087 }
2096 '''); 2088 ''');
2097 assertHasFix(FixKind.REMOVE_UNUSED_IMPORT, ''' 2089 assertHasFix(FixKind.REMOVE_UNUSED_IMPORT, '''
2098 main() { 2090 main() {
2099 } 2091 }
2100 '''); 2092 ''');
2101 } 2093 }
2102 2094
2103 void test_replaceImportUri_inProject() { 2095 void test_replaceImportUri_inProject() {
2104 testFile = '/project/bin/test.dart'; 2096 testFile = '/project/bin/test.dart';
2105 addSource('/project/foo/bar/lib.dart', ''); 2097 addSource('/project/foo/bar/lib.dart', '');
2106 _indexTestUnit(''' 2098 resolveTestUnit('''
2107 import 'no/matter/lib.dart'; 2099 import 'no/matter/lib.dart';
2108 '''); 2100 ''');
2109 performAllAnalysisTasks(); 2101 performAllAnalysisTasks();
2110 assertHasFix(FixKind.REPLACE_IMPORT_URI, ''' 2102 assertHasFix(FixKind.REPLACE_IMPORT_URI, '''
2111 import '../foo/bar/lib.dart'; 2103 import '../foo/bar/lib.dart';
2112 '''); 2104 ''');
2113 } 2105 }
2114 2106
2115 void test_replaceImportUri_package() { 2107 void test_replaceImportUri_package() {
2116 _configureMyPkg(''); 2108 _configureMyPkg('');
2117 _indexTestUnit(''' 2109 resolveTestUnit('''
2118 import 'no/matter/my_lib.dart'; 2110 import 'no/matter/my_lib.dart';
2119 '''); 2111 ''');
2120 performAllAnalysisTasks(); 2112 performAllAnalysisTasks();
2121 assertHasFix(FixKind.REPLACE_IMPORT_URI, ''' 2113 assertHasFix(FixKind.REPLACE_IMPORT_URI, '''
2122 import 'package:my_pkg/my_lib.dart'; 2114 import 'package:my_pkg/my_lib.dart';
2123 '''); 2115 ''');
2124 } 2116 }
2125 2117
2126 void test_replaceVarWithDynamic() { 2118 void test_replaceVarWithDynamic() {
2127 errorFilter = (AnalysisError error) { 2119 errorFilter = (AnalysisError error) {
2128 return error.errorCode == ParserErrorCode.VAR_AS_TYPE_NAME; 2120 return error.errorCode == ParserErrorCode.VAR_AS_TYPE_NAME;
2129 }; 2121 };
2130 _indexTestUnit(''' 2122 resolveTestUnit('''
2131 class A { 2123 class A {
2132 Map<String, var> m; 2124 Map<String, var> m;
2133 } 2125 }
2134 '''); 2126 ''');
2135 assertHasFix(FixKind.REPLACE_VAR_WITH_DYNAMIC, ''' 2127 assertHasFix(FixKind.REPLACE_VAR_WITH_DYNAMIC, '''
2136 class A { 2128 class A {
2137 Map<String, dynamic> m; 2129 Map<String, dynamic> m;
2138 } 2130 }
2139 '''); 2131 ''');
2140 } 2132 }
2141 2133
2142 void test_replaceWithConstInstanceCreation() { 2134 void test_replaceWithConstInstanceCreation() {
2143 _indexTestUnit(''' 2135 resolveTestUnit('''
2144 class A { 2136 class A {
2145 const A(); 2137 const A();
2146 } 2138 }
2147 const a = new A(); 2139 const a = new A();
2148 '''); 2140 ''');
2149 assertHasFix(FixKind.USE_CONST, ''' 2141 assertHasFix(FixKind.USE_CONST, '''
2150 class A { 2142 class A {
2151 const A(); 2143 const A();
2152 } 2144 }
2153 const a = const A(); 2145 const a = const A();
2154 '''); 2146 ''');
2155 } 2147 }
2156 2148
2157 void test_undefinedClass_useSimilar_fromImport() { 2149 void test_undefinedClass_useSimilar_fromImport() {
2158 _indexTestUnit(''' 2150 resolveTestUnit('''
2159 main() { 2151 main() {
2160 Stirng s = 'abc'; 2152 Stirng s = 'abc';
2161 } 2153 }
2162 '''); 2154 ''');
2163 assertHasFix(FixKind.CHANGE_TO, ''' 2155 assertHasFix(FixKind.CHANGE_TO, '''
2164 main() { 2156 main() {
2165 String s = 'abc'; 2157 String s = 'abc';
2166 } 2158 }
2167 '''); 2159 ''');
2168 } 2160 }
2169 2161
2170 void test_undefinedClass_useSimilar_fromThisLibrary() { 2162 void test_undefinedClass_useSimilar_fromThisLibrary() {
2171 _indexTestUnit(''' 2163 resolveTestUnit('''
2172 class MyClass {} 2164 class MyClass {}
2173 main() { 2165 main() {
2174 MyCalss v = null; 2166 MyCalss v = null;
2175 } 2167 }
2176 '''); 2168 ''');
2177 assertHasFix(FixKind.CHANGE_TO, ''' 2169 assertHasFix(FixKind.CHANGE_TO, '''
2178 class MyClass {} 2170 class MyClass {}
2179 main() { 2171 main() {
2180 MyClass v = null; 2172 MyClass v = null;
2181 } 2173 }
2182 '''); 2174 ''');
2183 } 2175 }
2184 2176
2185 void test_undefinedFunction_create_dynamicArgument() { 2177 void test_undefinedFunction_create_dynamicArgument() {
2186 _indexTestUnit(''' 2178 resolveTestUnit('''
2187 main() { 2179 main() {
2188 dynamic v; 2180 dynamic v;
2189 test(v); 2181 test(v);
2190 } 2182 }
2191 '''); 2183 ''');
2192 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2184 assertHasFix(FixKind.CREATE_FUNCTION, '''
2193 main() { 2185 main() {
2194 dynamic v; 2186 dynamic v;
2195 test(v); 2187 test(v);
2196 } 2188 }
2197 2189
2198 void test(v) { 2190 void test(v) {
2199 } 2191 }
2200 '''); 2192 ''');
2201 } 2193 }
2202 2194
2203 void test_undefinedFunction_create_dynamicReturnType() { 2195 void test_undefinedFunction_create_dynamicReturnType() {
2204 _indexTestUnit(''' 2196 resolveTestUnit('''
2205 main() { 2197 main() {
2206 dynamic v = test(); 2198 dynamic v = test();
2207 } 2199 }
2208 '''); 2200 ''');
2209 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2201 assertHasFix(FixKind.CREATE_FUNCTION, '''
2210 main() { 2202 main() {
2211 dynamic v = test(); 2203 dynamic v = test();
2212 } 2204 }
2213 2205
2214 test() { 2206 test() {
2215 } 2207 }
2216 '''); 2208 ''');
2217 } 2209 }
2218 2210
2219 void test_undefinedFunction_create_fromFunction() { 2211 void test_undefinedFunction_create_fromFunction() {
2220 _indexTestUnit(''' 2212 resolveTestUnit('''
2221 main() { 2213 main() {
2222 int v = myUndefinedFunction(1, 2.0, '3'); 2214 int v = myUndefinedFunction(1, 2.0, '3');
2223 } 2215 }
2224 '''); 2216 ''');
2225 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2217 assertHasFix(FixKind.CREATE_FUNCTION, '''
2226 main() { 2218 main() {
2227 int v = myUndefinedFunction(1, 2.0, '3'); 2219 int v = myUndefinedFunction(1, 2.0, '3');
2228 } 2220 }
2229 2221
2230 int myUndefinedFunction(int i, double d, String s) { 2222 int myUndefinedFunction(int i, double d, String s) {
2231 } 2223 }
2232 '''); 2224 ''');
2233 } 2225 }
2234 2226
2235 void test_undefinedFunction_create_fromMethod() { 2227 void test_undefinedFunction_create_fromMethod() {
2236 _indexTestUnit(''' 2228 resolveTestUnit('''
2237 class A { 2229 class A {
2238 main() { 2230 main() {
2239 int v = myUndefinedFunction(1, 2.0, '3'); 2231 int v = myUndefinedFunction(1, 2.0, '3');
2240 } 2232 }
2241 } 2233 }
2242 '''); 2234 ''');
2243 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2235 assertHasFix(FixKind.CREATE_FUNCTION, '''
2244 class A { 2236 class A {
2245 main() { 2237 main() {
2246 int v = myUndefinedFunction(1, 2.0, '3'); 2238 int v = myUndefinedFunction(1, 2.0, '3');
2247 } 2239 }
2248 } 2240 }
2249 2241
2250 int myUndefinedFunction(int i, double d, String s) { 2242 int myUndefinedFunction(int i, double d, String s) {
2251 } 2243 }
2252 '''); 2244 ''');
2253 } 2245 }
2254 2246
2255 void test_undefinedFunction_create_generic_BAD() { 2247 void test_undefinedFunction_create_generic_BAD() {
2256 _indexTestUnit(''' 2248 resolveTestUnit('''
2257 class A<T> { 2249 class A<T> {
2258 Map<int, T> items; 2250 Map<int, T> items;
2259 main() { 2251 main() {
2260 process(items); 2252 process(items);
2261 } 2253 }
2262 } 2254 }
2263 '''); 2255 ''');
2264 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2256 assertHasFix(FixKind.CREATE_FUNCTION, '''
2265 class A<T> { 2257 class A<T> {
2266 Map<int, T> items; 2258 Map<int, T> items;
2267 main() { 2259 main() {
2268 process(items); 2260 process(items);
2269 } 2261 }
2270 } 2262 }
2271 2263
2272 void process(Map items) { 2264 void process(Map items) {
2273 } 2265 }
2274 '''); 2266 ''');
2275 } 2267 }
2276 2268
2277 void test_undefinedFunction_create_generic_OK() { 2269 void test_undefinedFunction_create_generic_OK() {
2278 _indexTestUnit(''' 2270 resolveTestUnit('''
2279 class A { 2271 class A {
2280 List<int> items; 2272 List<int> items;
2281 main() { 2273 main() {
2282 process(items); 2274 process(items);
2283 } 2275 }
2284 } 2276 }
2285 '''); 2277 ''');
2286 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2278 assertHasFix(FixKind.CREATE_FUNCTION, '''
2287 class A { 2279 class A {
2288 List<int> items; 2280 List<int> items;
2289 main() { 2281 main() {
2290 process(items); 2282 process(items);
2291 } 2283 }
2292 } 2284 }
2293 2285
2294 void process(List<int> items) { 2286 void process(List<int> items) {
2295 } 2287 }
2296 '''); 2288 ''');
2297 } 2289 }
2298 2290
2299 void test_undefinedFunction_create_nullArgument() { 2291 void test_undefinedFunction_create_nullArgument() {
2300 _indexTestUnit(''' 2292 resolveTestUnit('''
2301 main() { 2293 main() {
2302 test(null); 2294 test(null);
2303 } 2295 }
2304 '''); 2296 ''');
2305 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2297 assertHasFix(FixKind.CREATE_FUNCTION, '''
2306 main() { 2298 main() {
2307 test(null); 2299 test(null);
2308 } 2300 }
2309 2301
2310 void test(arg0) { 2302 void test(arg0) {
(...skipping 10 matching lines...) Expand all
2321 } 2313 }
2322 2314
2323 void test_undefinedFunction_create_returnType_bool_statements() { 2315 void test_undefinedFunction_create_returnType_bool_statements() {
2324 assert_undefinedFunction_create_returnType_bool("assert ( test() );"); 2316 assert_undefinedFunction_create_returnType_bool("assert ( test() );");
2325 assert_undefinedFunction_create_returnType_bool("if ( test() ) {}"); 2317 assert_undefinedFunction_create_returnType_bool("if ( test() ) {}");
2326 assert_undefinedFunction_create_returnType_bool("while ( test() ) {}"); 2318 assert_undefinedFunction_create_returnType_bool("while ( test() ) {}");
2327 assert_undefinedFunction_create_returnType_bool("do {} while ( test() );"); 2319 assert_undefinedFunction_create_returnType_bool("do {} while ( test() );");
2328 } 2320 }
2329 2321
2330 void test_undefinedFunction_create_returnType_fromAssignment_eq() { 2322 void test_undefinedFunction_create_returnType_fromAssignment_eq() {
2331 _indexTestUnit(''' 2323 resolveTestUnit('''
2332 main() { 2324 main() {
2333 int v; 2325 int v;
2334 v = myUndefinedFunction(); 2326 v = myUndefinedFunction();
2335 } 2327 }
2336 '''); 2328 ''');
2337 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2329 assertHasFix(FixKind.CREATE_FUNCTION, '''
2338 main() { 2330 main() {
2339 int v; 2331 int v;
2340 v = myUndefinedFunction(); 2332 v = myUndefinedFunction();
2341 } 2333 }
2342 2334
2343 int myUndefinedFunction() { 2335 int myUndefinedFunction() {
2344 } 2336 }
2345 '''); 2337 ''');
2346 } 2338 }
2347 2339
2348 void test_undefinedFunction_create_returnType_fromAssignment_plusEq() { 2340 void test_undefinedFunction_create_returnType_fromAssignment_plusEq() {
2349 _indexTestUnit(''' 2341 resolveTestUnit('''
2350 main() { 2342 main() {
2351 int v; 2343 int v;
2352 v += myUndefinedFunction(); 2344 v += myUndefinedFunction();
2353 } 2345 }
2354 '''); 2346 ''');
2355 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2347 assertHasFix(FixKind.CREATE_FUNCTION, '''
2356 main() { 2348 main() {
2357 int v; 2349 int v;
2358 v += myUndefinedFunction(); 2350 v += myUndefinedFunction();
2359 } 2351 }
2360 2352
2361 num myUndefinedFunction() { 2353 num myUndefinedFunction() {
2362 } 2354 }
2363 '''); 2355 ''');
2364 } 2356 }
2365 2357
2366 void test_undefinedFunction_create_returnType_fromBinary_right() { 2358 void test_undefinedFunction_create_returnType_fromBinary_right() {
2367 _indexTestUnit(''' 2359 resolveTestUnit('''
2368 main() { 2360 main() {
2369 0 + myUndefinedFunction(); 2361 0 + myUndefinedFunction();
2370 } 2362 }
2371 '''); 2363 ''');
2372 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2364 assertHasFix(FixKind.CREATE_FUNCTION, '''
2373 main() { 2365 main() {
2374 0 + myUndefinedFunction(); 2366 0 + myUndefinedFunction();
2375 } 2367 }
2376 2368
2377 num myUndefinedFunction() { 2369 num myUndefinedFunction() {
2378 } 2370 }
2379 '''); 2371 ''');
2380 } 2372 }
2381 2373
2382 void test_undefinedFunction_create_returnType_fromInitializer() { 2374 void test_undefinedFunction_create_returnType_fromInitializer() {
2383 _indexTestUnit(''' 2375 resolveTestUnit('''
2384 main() { 2376 main() {
2385 int v = myUndefinedFunction(); 2377 int v = myUndefinedFunction();
2386 } 2378 }
2387 '''); 2379 ''');
2388 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2380 assertHasFix(FixKind.CREATE_FUNCTION, '''
2389 main() { 2381 main() {
2390 int v = myUndefinedFunction(); 2382 int v = myUndefinedFunction();
2391 } 2383 }
2392 2384
2393 int myUndefinedFunction() { 2385 int myUndefinedFunction() {
2394 } 2386 }
2395 '''); 2387 ''');
2396 } 2388 }
2397 2389
2398 void test_undefinedFunction_create_returnType_fromInvocationArgument() { 2390 void test_undefinedFunction_create_returnType_fromInvocationArgument() {
2399 _indexTestUnit(''' 2391 resolveTestUnit('''
2400 foo(int p) {} 2392 foo(int p) {}
2401 main() { 2393 main() {
2402 foo( myUndefinedFunction() ); 2394 foo( myUndefinedFunction() );
2403 } 2395 }
2404 '''); 2396 ''');
2405 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2397 assertHasFix(FixKind.CREATE_FUNCTION, '''
2406 foo(int p) {} 2398 foo(int p) {}
2407 main() { 2399 main() {
2408 foo( myUndefinedFunction() ); 2400 foo( myUndefinedFunction() );
2409 } 2401 }
2410 2402
2411 int myUndefinedFunction() { 2403 int myUndefinedFunction() {
2412 } 2404 }
2413 '''); 2405 ''');
2414 } 2406 }
2415 2407
2416 void test_undefinedFunction_create_returnType_fromReturn() { 2408 void test_undefinedFunction_create_returnType_fromReturn() {
2417 _indexTestUnit(''' 2409 resolveTestUnit('''
2418 int main() { 2410 int main() {
2419 return myUndefinedFunction(); 2411 return myUndefinedFunction();
2420 } 2412 }
2421 '''); 2413 ''');
2422 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2414 assertHasFix(FixKind.CREATE_FUNCTION, '''
2423 int main() { 2415 int main() {
2424 return myUndefinedFunction(); 2416 return myUndefinedFunction();
2425 } 2417 }
2426 2418
2427 int myUndefinedFunction() { 2419 int myUndefinedFunction() {
2428 } 2420 }
2429 '''); 2421 ''');
2430 } 2422 }
2431 2423
2432 void test_undefinedFunction_create_returnType_void() { 2424 void test_undefinedFunction_create_returnType_void() {
2433 _indexTestUnit(''' 2425 resolveTestUnit('''
2434 main() { 2426 main() {
2435 myUndefinedFunction(); 2427 myUndefinedFunction();
2436 } 2428 }
2437 '''); 2429 ''');
2438 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2430 assertHasFix(FixKind.CREATE_FUNCTION, '''
2439 main() { 2431 main() {
2440 myUndefinedFunction(); 2432 myUndefinedFunction();
2441 } 2433 }
2442 2434
2443 void myUndefinedFunction() { 2435 void myUndefinedFunction() {
2444 } 2436 }
2445 '''); 2437 ''');
2446 } 2438 }
2447 2439
2448 void test_undefinedFunction_useSimilar_fromImport() { 2440 void test_undefinedFunction_useSimilar_fromImport() {
2449 _indexTestUnit(''' 2441 resolveTestUnit('''
2450 main() { 2442 main() {
2451 pritn(0); 2443 pritn(0);
2452 } 2444 }
2453 '''); 2445 ''');
2454 assertHasFix(FixKind.CHANGE_TO, ''' 2446 assertHasFix(FixKind.CHANGE_TO, '''
2455 main() { 2447 main() {
2456 print(0); 2448 print(0);
2457 } 2449 }
2458 '''); 2450 ''');
2459 } 2451 }
2460 2452
2461 void test_undefinedFunction_useSimilar_thisLibrary() { 2453 void test_undefinedFunction_useSimilar_thisLibrary() {
2462 _indexTestUnit(''' 2454 resolveTestUnit('''
2463 myFunction() {} 2455 myFunction() {}
2464 main() { 2456 main() {
2465 myFuntcion(); 2457 myFuntcion();
2466 } 2458 }
2467 '''); 2459 ''');
2468 assertHasFix(FixKind.CHANGE_TO, ''' 2460 assertHasFix(FixKind.CHANGE_TO, '''
2469 myFunction() {} 2461 myFunction() {}
2470 main() { 2462 main() {
2471 myFunction(); 2463 myFunction();
2472 } 2464 }
2473 '''); 2465 ''');
2474 } 2466 }
2475 2467
2476 void test_undefinedMethod_create_BAD_inSDK() { 2468 void test_undefinedMethod_create_BAD_inSDK() {
2477 _indexTestUnit(''' 2469 resolveTestUnit('''
2478 main() { 2470 main() {
2479 List.foo(); 2471 List.foo();
2480 } 2472 }
2481 '''); 2473 ''');
2482 assertNoFix(FixKind.CREATE_METHOD); 2474 assertNoFix(FixKind.CREATE_METHOD);
2483 } 2475 }
2484 2476
2485 void test_undefinedMethod_create_generic_BAD() { 2477 void test_undefinedMethod_create_generic_BAD() {
2486 _indexTestUnit(''' 2478 resolveTestUnit('''
2487 class A<T> { 2479 class A<T> {
2488 B b; 2480 B b;
2489 Map<int, T> items; 2481 Map<int, T> items;
2490 main() { 2482 main() {
2491 b.process(items); 2483 b.process(items);
2492 } 2484 }
2493 } 2485 }
2494 2486
2495 class B { 2487 class B {
2496 } 2488 }
2497 '''); 2489 ''');
2498 assertHasFix(FixKind.CREATE_METHOD, ''' 2490 assertHasFix(FixKind.CREATE_METHOD, '''
2499 class A<T> { 2491 class A<T> {
2500 B b; 2492 B b;
2501 Map<int, T> items; 2493 Map<int, T> items;
2502 main() { 2494 main() {
2503 b.process(items); 2495 b.process(items);
2504 } 2496 }
2505 } 2497 }
2506 2498
2507 class B { 2499 class B {
2508 void process(Map items) { 2500 void process(Map items) {
2509 } 2501 }
2510 } 2502 }
2511 '''); 2503 ''');
2512 } 2504 }
2513 2505
2514 void test_undefinedMethod_create_generic_OK_literal() { 2506 void test_undefinedMethod_create_generic_OK_literal() {
2515 _indexTestUnit(''' 2507 resolveTestUnit('''
2516 class A { 2508 class A {
2517 B b; 2509 B b;
2518 List<int> items; 2510 List<int> items;
2519 main() { 2511 main() {
2520 b.process(items); 2512 b.process(items);
2521 } 2513 }
2522 } 2514 }
2523 2515
2524 class B { 2516 class B {
2525 } 2517 }
2526 '''); 2518 ''');
2527 assertHasFix(FixKind.CREATE_METHOD, ''' 2519 assertHasFix(FixKind.CREATE_METHOD, '''
2528 class A { 2520 class A {
2529 B b; 2521 B b;
2530 List<int> items; 2522 List<int> items;
2531 main() { 2523 main() {
2532 b.process(items); 2524 b.process(items);
2533 } 2525 }
2534 } 2526 }
2535 2527
2536 class B { 2528 class B {
2537 void process(List<int> items) { 2529 void process(List<int> items) {
2538 } 2530 }
2539 } 2531 }
2540 '''); 2532 ''');
2541 } 2533 }
2542 2534
2543 void test_undefinedMethod_create_generic_OK_local() { 2535 void test_undefinedMethod_create_generic_OK_local() {
2544 _indexTestUnit(''' 2536 resolveTestUnit('''
2545 class A<T> { 2537 class A<T> {
2546 List<T> items; 2538 List<T> items;
2547 main() { 2539 main() {
2548 process(items); 2540 process(items);
2549 } 2541 }
2550 } 2542 }
2551 '''); 2543 ''');
2552 assertHasFix(FixKind.CREATE_METHOD, ''' 2544 assertHasFix(FixKind.CREATE_METHOD, '''
2553 class A<T> { 2545 class A<T> {
2554 List<T> items; 2546 List<T> items;
2555 main() { 2547 main() {
2556 process(items); 2548 process(items);
2557 } 2549 }
2558 2550
2559 void process(List<T> items) { 2551 void process(List<T> items) {
2560 } 2552 }
2561 } 2553 }
2562 '''); 2554 ''');
2563 } 2555 }
2564 2556
2565 void test_undefinedMethod_createQualified_fromClass() { 2557 void test_undefinedMethod_createQualified_fromClass() {
2566 _indexTestUnit(''' 2558 resolveTestUnit('''
2567 class A { 2559 class A {
2568 } 2560 }
2569 main() { 2561 main() {
2570 A.myUndefinedMethod(); 2562 A.myUndefinedMethod();
2571 } 2563 }
2572 '''); 2564 ''');
2573 assertHasFix(FixKind.CREATE_METHOD, ''' 2565 assertHasFix(FixKind.CREATE_METHOD, '''
2574 class A { 2566 class A {
2575 static void myUndefinedMethod() { 2567 static void myUndefinedMethod() {
2576 } 2568 }
2577 } 2569 }
2578 main() { 2570 main() {
2579 A.myUndefinedMethod(); 2571 A.myUndefinedMethod();
2580 } 2572 }
2581 '''); 2573 ''');
2582 } 2574 }
2583 2575
2584 void test_undefinedMethod_createQualified_fromClass_hasOtherMember() { 2576 void test_undefinedMethod_createQualified_fromClass_hasOtherMember() {
2585 _indexTestUnit(''' 2577 resolveTestUnit('''
2586 class A { 2578 class A {
2587 foo() {} 2579 foo() {}
2588 } 2580 }
2589 main() { 2581 main() {
2590 A.myUndefinedMethod(); 2582 A.myUndefinedMethod();
2591 } 2583 }
2592 '''); 2584 ''');
2593 assertHasFix(FixKind.CREATE_METHOD, ''' 2585 assertHasFix(FixKind.CREATE_METHOD, '''
2594 class A { 2586 class A {
2595 foo() {} 2587 foo() {}
2596 2588
2597 static void myUndefinedMethod() { 2589 static void myUndefinedMethod() {
2598 } 2590 }
2599 } 2591 }
2600 main() { 2592 main() {
2601 A.myUndefinedMethod(); 2593 A.myUndefinedMethod();
2602 } 2594 }
2603 '''); 2595 ''');
2604 } 2596 }
2605 2597
2606 void test_undefinedMethod_createQualified_fromInstance() { 2598 void test_undefinedMethod_createQualified_fromInstance() {
2607 _indexTestUnit(''' 2599 resolveTestUnit('''
2608 class A { 2600 class A {
2609 } 2601 }
2610 main(A a) { 2602 main(A a) {
2611 a.myUndefinedMethod(); 2603 a.myUndefinedMethod();
2612 } 2604 }
2613 '''); 2605 ''');
2614 assertHasFix(FixKind.CREATE_METHOD, ''' 2606 assertHasFix(FixKind.CREATE_METHOD, '''
2615 class A { 2607 class A {
2616 void myUndefinedMethod() { 2608 void myUndefinedMethod() {
2617 } 2609 }
2618 } 2610 }
2619 main(A a) { 2611 main(A a) {
2620 a.myUndefinedMethod(); 2612 a.myUndefinedMethod();
2621 } 2613 }
2622 '''); 2614 ''');
2623 } 2615 }
2624 2616
2625 void test_undefinedMethod_createQualified_targetIsFunctionType() { 2617 void test_undefinedMethod_createQualified_targetIsFunctionType() {
2626 _indexTestUnit(''' 2618 resolveTestUnit('''
2627 typedef A(); 2619 typedef A();
2628 main() { 2620 main() {
2629 A.myUndefinedMethod(); 2621 A.myUndefinedMethod();
2630 } 2622 }
2631 '''); 2623 ''');
2632 assertNoFix(FixKind.CREATE_METHOD); 2624 assertNoFix(FixKind.CREATE_METHOD);
2633 } 2625 }
2634 2626
2635 void test_undefinedMethod_createQualified_targetIsUnresolved() { 2627 void test_undefinedMethod_createQualified_targetIsUnresolved() {
2636 _indexTestUnit(''' 2628 resolveTestUnit('''
2637 main() { 2629 main() {
2638 NoSuchClass.myUndefinedMethod(); 2630 NoSuchClass.myUndefinedMethod();
2639 } 2631 }
2640 '''); 2632 ''');
2641 assertNoFix(FixKind.CREATE_METHOD); 2633 assertNoFix(FixKind.CREATE_METHOD);
2642 } 2634 }
2643 2635
2644 void test_undefinedMethod_createUnqualified_parameters() { 2636 void test_undefinedMethod_createUnqualified_parameters() {
2645 _indexTestUnit(''' 2637 resolveTestUnit('''
2646 class A { 2638 class A {
2647 main() { 2639 main() {
2648 myUndefinedMethod(0, 1.0, '3'); 2640 myUndefinedMethod(0, 1.0, '3');
2649 } 2641 }
2650 } 2642 }
2651 '''); 2643 ''');
2652 assertHasFix(FixKind.CREATE_METHOD, ''' 2644 assertHasFix(FixKind.CREATE_METHOD, '''
2653 class A { 2645 class A {
2654 main() { 2646 main() {
2655 myUndefinedMethod(0, 1.0, '3'); 2647 myUndefinedMethod(0, 1.0, '3');
(...skipping 28 matching lines...) Expand all
2684 _assertLinkedGroup( 2676 _assertLinkedGroup(
2685 change.linkedEditGroups[index++], 2677 change.linkedEditGroups[index++],
2686 ['String s'], 2678 ['String s'],
2687 expectedSuggestions( 2679 expectedSuggestions(
2688 LinkedEditSuggestionKind.TYPE, 2680 LinkedEditSuggestionKind.TYPE,
2689 ['String', 'Object', 'Comparable'])); 2681 ['String', 'Object', 'Comparable']));
2690 _assertLinkedGroup(change.linkedEditGroups[index++], ['s)']); 2682 _assertLinkedGroup(change.linkedEditGroups[index++], ['s)']);
2691 } 2683 }
2692 2684
2693 void test_undefinedMethod_createUnqualified_returnType() { 2685 void test_undefinedMethod_createUnqualified_returnType() {
2694 _indexTestUnit(''' 2686 resolveTestUnit('''
2695 class A { 2687 class A {
2696 main() { 2688 main() {
2697 int v = myUndefinedMethod(); 2689 int v = myUndefinedMethod();
2698 } 2690 }
2699 } 2691 }
2700 '''); 2692 ''');
2701 assertHasFix(FixKind.CREATE_METHOD, ''' 2693 assertHasFix(FixKind.CREATE_METHOD, '''
2702 class A { 2694 class A {
2703 main() { 2695 main() {
2704 int v = myUndefinedMethod(); 2696 int v = myUndefinedMethod();
2705 } 2697 }
2706 2698
2707 int myUndefinedMethod() { 2699 int myUndefinedMethod() {
2708 } 2700 }
2709 } 2701 }
2710 '''); 2702 ''');
2711 // linked positions 2703 // linked positions
2712 _assertLinkedGroup(change.linkedEditGroups[0], ['int myUndefinedMethod(']); 2704 _assertLinkedGroup(change.linkedEditGroups[0], ['int myUndefinedMethod(']);
2713 _assertLinkedGroup( 2705 _assertLinkedGroup(
2714 change.linkedEditGroups[1], 2706 change.linkedEditGroups[1],
2715 ['myUndefinedMethod();', 'myUndefinedMethod() {']); 2707 ['myUndefinedMethod();', 'myUndefinedMethod() {']);
2716 } 2708 }
2717 2709
2718 void test_undefinedMethod_createUnqualified_staticFromField() { 2710 void test_undefinedMethod_createUnqualified_staticFromField() {
2719 _indexTestUnit(''' 2711 resolveTestUnit('''
2720 class A { 2712 class A {
2721 static var f = myUndefinedMethod(); 2713 static var f = myUndefinedMethod();
2722 } 2714 }
2723 '''); 2715 ''');
2724 assertHasFix(FixKind.CREATE_METHOD, ''' 2716 assertHasFix(FixKind.CREATE_METHOD, '''
2725 class A { 2717 class A {
2726 static var f = myUndefinedMethod(); 2718 static var f = myUndefinedMethod();
2727 2719
2728 static myUndefinedMethod() { 2720 static myUndefinedMethod() {
2729 } 2721 }
2730 } 2722 }
2731 '''); 2723 ''');
2732 } 2724 }
2733 2725
2734 void test_undefinedMethod_createUnqualified_staticFromMethod() { 2726 void test_undefinedMethod_createUnqualified_staticFromMethod() {
2735 _indexTestUnit(''' 2727 resolveTestUnit('''
2736 class A { 2728 class A {
2737 static main() { 2729 static main() {
2738 myUndefinedMethod(); 2730 myUndefinedMethod();
2739 } 2731 }
2740 } 2732 }
2741 '''); 2733 ''');
2742 assertHasFix(FixKind.CREATE_METHOD, ''' 2734 assertHasFix(FixKind.CREATE_METHOD, '''
2743 class A { 2735 class A {
2744 static main() { 2736 static main() {
2745 myUndefinedMethod(); 2737 myUndefinedMethod();
2746 } 2738 }
2747 2739
2748 static void myUndefinedMethod() { 2740 static void myUndefinedMethod() {
2749 } 2741 }
2750 } 2742 }
2751 '''); 2743 ''');
2752 } 2744 }
2753 2745
2754 void test_undefinedMethod_hint_createQualified_fromInstance() { 2746 void test_undefinedMethod_hint_createQualified_fromInstance() {
2755 _indexTestUnit(''' 2747 resolveTestUnit('''
2756 class A { 2748 class A {
2757 } 2749 }
2758 main() { 2750 main() {
2759 var a = new A(); 2751 var a = new A();
2760 a.myUndefinedMethod(); 2752 a.myUndefinedMethod();
2761 } 2753 }
2762 '''); 2754 ''');
2763 assertHasFix(FixKind.CREATE_METHOD, ''' 2755 assertHasFix(FixKind.CREATE_METHOD, '''
2764 class A { 2756 class A {
2765 void myUndefinedMethod() { 2757 void myUndefinedMethod() {
2766 } 2758 }
2767 } 2759 }
2768 main() { 2760 main() {
2769 var a = new A(); 2761 var a = new A();
2770 a.myUndefinedMethod(); 2762 a.myUndefinedMethod();
2771 } 2763 }
2772 '''); 2764 ''');
2773 } 2765 }
2774 2766
2775 void test_undefinedMethod_useSimilar_ignoreOperators() { 2767 void test_undefinedMethod_useSimilar_ignoreOperators() {
2776 _indexTestUnit(''' 2768 resolveTestUnit('''
2777 main(Object object) { 2769 main(Object object) {
2778 object.then(); 2770 object.then();
2779 } 2771 }
2780 '''); 2772 ''');
2781 assertNoFix(FixKind.CHANGE_TO); 2773 assertNoFix(FixKind.CHANGE_TO);
2782 } 2774 }
2783 2775
2784 void test_undefinedMethod_useSimilar_qualified() { 2776 void test_undefinedMethod_useSimilar_qualified() {
2785 _indexTestUnit(''' 2777 resolveTestUnit('''
2786 class A { 2778 class A {
2787 myMethod() {} 2779 myMethod() {}
2788 } 2780 }
2789 main() { 2781 main() {
2790 A a = new A(); 2782 A a = new A();
2791 a.myMehtod(); 2783 a.myMehtod();
2792 } 2784 }
2793 '''); 2785 ''');
2794 assertHasFix(FixKind.CHANGE_TO, ''' 2786 assertHasFix(FixKind.CHANGE_TO, '''
2795 class A { 2787 class A {
2796 myMethod() {} 2788 myMethod() {}
2797 } 2789 }
2798 main() { 2790 main() {
2799 A a = new A(); 2791 A a = new A();
2800 a.myMethod(); 2792 a.myMethod();
2801 } 2793 }
2802 '''); 2794 ''');
2803 } 2795 }
2804 2796
2805 void test_undefinedMethod_useSimilar_unqualified_superClass() { 2797 void test_undefinedMethod_useSimilar_unqualified_superClass() {
2806 _indexTestUnit(''' 2798 resolveTestUnit('''
2807 class A { 2799 class A {
2808 myMethod() {} 2800 myMethod() {}
2809 } 2801 }
2810 class B extends A { 2802 class B extends A {
2811 main() { 2803 main() {
2812 myMehtod(); 2804 myMehtod();
2813 } 2805 }
2814 } 2806 }
2815 '''); 2807 ''');
2816 assertHasFix(FixKind.CHANGE_TO, ''' 2808 assertHasFix(FixKind.CHANGE_TO, '''
2817 class A { 2809 class A {
2818 myMethod() {} 2810 myMethod() {}
2819 } 2811 }
2820 class B extends A { 2812 class B extends A {
2821 main() { 2813 main() {
2822 myMethod(); 2814 myMethod();
2823 } 2815 }
2824 } 2816 }
2825 '''); 2817 ''');
2826 } 2818 }
2827 2819
2828 void test_undefinedMethod_useSimilar_unqualified_thisClass() { 2820 void test_undefinedMethod_useSimilar_unqualified_thisClass() {
2829 _indexTestUnit(''' 2821 resolveTestUnit('''
2830 class A { 2822 class A {
2831 myMethod() {} 2823 myMethod() {}
2832 main() { 2824 main() {
2833 myMehtod(); 2825 myMehtod();
2834 } 2826 }
2835 } 2827 }
2836 '''); 2828 ''');
2837 assertHasFix(FixKind.CHANGE_TO, ''' 2829 assertHasFix(FixKind.CHANGE_TO, '''
2838 class A { 2830 class A {
2839 myMethod() {} 2831 myMethod() {}
2840 main() { 2832 main() {
2841 myMethod(); 2833 myMethod();
2842 } 2834 }
2843 } 2835 }
2844 '''); 2836 ''');
2845 } 2837 }
2846 2838
2847 void test_useEffectiveIntegerDivision() { 2839 void test_useEffectiveIntegerDivision() {
2848 _indexTestUnit(''' 2840 resolveTestUnit('''
2849 main() { 2841 main() {
2850 var a = 5; 2842 var a = 5;
2851 var b = 2; 2843 var b = 2;
2852 print((a / b).toInt()); 2844 print((a / b).toInt());
2853 } 2845 }
2854 '''); 2846 ''');
2855 assertHasFix(FixKind.USE_EFFECTIVE_INTEGER_DIVISION, ''' 2847 assertHasFix(FixKind.USE_EFFECTIVE_INTEGER_DIVISION, '''
2856 main() { 2848 main() {
2857 var a = 5; 2849 var a = 5;
2858 var b = 2; 2850 var b = 2;
2859 print(a ~/ b); 2851 print(a ~/ b);
2860 } 2852 }
2861 '''); 2853 ''');
2862 } 2854 }
2863 2855
2864 /** 2856 /**
2865 * Computes fixes and verifies that there is a fix of the given kind. 2857 * Computes fixes and verifies that there is a fix of the given kind.
2866 */ 2858 */
2867 Fix _assertHasFix(FixKind kind, AnalysisError error) { 2859 Fix _assertHasFix(FixKind kind, AnalysisError error) {
2868 List<Fix> fixes = computeFixes(searchEngine, testUnit, error); 2860 List<Fix> fixes = computeFixes(testUnit, error);
2869 for (Fix fix in fixes) { 2861 for (Fix fix in fixes) {
2870 if (fix.kind == kind) { 2862 if (fix.kind == kind) {
2871 return fix; 2863 return fix;
2872 } 2864 }
2873 } 2865 }
2874 throw fail('Expected to find fix $kind in\n${fixes.join('\n')}'); 2866 throw fail('Expected to find fix $kind in\n${fixes.join('\n')}');
2875 } 2867 }
2876 2868
2877 void _assertLinkedGroup(LinkedEditGroup group, List<String> expectedStrings, 2869 void _assertLinkedGroup(LinkedEditGroup group, List<String> expectedStrings,
2878 [List<LinkedEditSuggestion> expectedSuggestions]) { 2870 [List<LinkedEditSuggestion> expectedSuggestions]) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2915 } 2907 }
2916 2908
2917 List<Position> _findResultPositions(List<String> searchStrings) { 2909 List<Position> _findResultPositions(List<String> searchStrings) {
2918 List<Position> positions = <Position>[]; 2910 List<Position> positions = <Position>[];
2919 for (String search in searchStrings) { 2911 for (String search in searchStrings) {
2920 int offset = resultCode.indexOf(search); 2912 int offset = resultCode.indexOf(search);
2921 positions.add(new Position(testFile, offset)); 2913 positions.add(new Position(testFile, offset));
2922 } 2914 }
2923 return positions; 2915 return positions;
2924 } 2916 }
2925
2926 void _indexTestUnit(String code) {
2927 resolveTestUnit(code);
2928 index.indexUnit(context, testUnit);
2929 }
2930 } 2917 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698