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

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

Issue 1080653003: Create a public API for contributing fixes and make fixes pluggable (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Missed clean-up Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analysis_server/test/edit/sort_members_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library test.services.correction.fix; 5 library test.services.correction.fix;
6 6
7 import 'package:analysis_server/edit/fix/fix_core.dart';
8 import 'package:analysis_server/src/plugin/server_plugin.dart';
7 import 'package:analysis_server/src/protocol.dart' hide AnalysisError; 9 import 'package:analysis_server/src/protocol.dart' hide AnalysisError;
8 import 'package:analysis_server/src/services/correction/fix.dart'; 10 import 'package:analysis_server/src/services/correction/fix.dart';
9 import 'package:analyzer/file_system/file_system.dart'; 11 import 'package:analyzer/file_system/file_system.dart';
10 import 'package:analyzer/source/package_map_resolver.dart'; 12 import 'package:analyzer/source/package_map_resolver.dart';
11 import 'package:analyzer/src/generated/error.dart'; 13 import 'package:analyzer/src/generated/error.dart';
12 import 'package:analyzer/src/generated/parser.dart'; 14 import 'package:analyzer/src/generated/parser.dart';
13 import 'package:analyzer/src/generated/source.dart'; 15 import 'package:analyzer/src/generated/source.dart';
16 import 'package:analyzer/src/plugin/plugin_impl.dart';
14 import 'package:unittest/unittest.dart'; 17 import 'package:unittest/unittest.dart';
15 18
16 import '../../abstract_context.dart'; 19 import '../../abstract_context.dart';
17 import '../../abstract_single_unit.dart'; 20 import '../../abstract_single_unit.dart';
18 import '../../reflective_tests.dart'; 21 import '../../reflective_tests.dart';
19 22
20 main() { 23 main() {
21 groupSep = ' | '; 24 groupSep = ' | ';
22 runReflectiveTests(FixProcessorTest); 25 runReflectiveTests(FixProcessorTest);
23 } 26 }
24 27
25 typedef bool AnalysisErrorFilter(AnalysisError error); 28 typedef bool AnalysisErrorFilter(AnalysisError error);
26 29
27 @reflectiveTest 30 @reflectiveTest
28 class FixProcessorTest extends AbstractSingleUnitTest { 31 class FixProcessorTest extends AbstractSingleUnitTest {
29 AnalysisErrorFilter errorFilter = (AnalysisError error) { 32 AnalysisErrorFilter errorFilter = (AnalysisError error) {
30 return error.errorCode != HintCode.UNUSED_CATCH_CLAUSE && 33 return error.errorCode != HintCode.UNUSED_CATCH_CLAUSE &&
31 error.errorCode != HintCode.UNUSED_CATCH_STACK && 34 error.errorCode != HintCode.UNUSED_CATCH_STACK &&
32 error.errorCode != HintCode.UNUSED_ELEMENT && 35 error.errorCode != HintCode.UNUSED_ELEMENT &&
33 error.errorCode != HintCode.UNUSED_FIELD && 36 error.errorCode != HintCode.UNUSED_FIELD &&
34 error.errorCode != HintCode.UNUSED_LOCAL_VARIABLE; 37 error.errorCode != HintCode.UNUSED_LOCAL_VARIABLE;
35 }; 38 };
36 39
40 ServerPlugin plugin;
37 Fix fix; 41 Fix fix;
38 SourceChange change; 42 SourceChange change;
39 String resultCode; 43 String resultCode;
40 44
41 void assert_undefinedFunction_create_returnType_bool(String lineWithTest) { 45 void assert_undefinedFunction_create_returnType_bool(String lineWithTest) {
42 resolveTestUnit(''' 46 resolveTestUnit('''
43 main() { 47 main() {
44 bool b = true; 48 bool b = true;
45 $lineWithTest 49 $lineWithTest
46 } 50 }
47 '''); 51 ''');
48 assertHasFix(FixKind.CREATE_FUNCTION, ''' 52 assertHasFix(DartFixKind.CREATE_FUNCTION, '''
49 main() { 53 main() {
50 bool b = true; 54 bool b = true;
51 $lineWithTest 55 $lineWithTest
52 } 56 }
53 57
54 bool test() { 58 bool test() {
55 } 59 }
56 '''); 60 ''');
57 } 61 }
58 62
59 void assertHasFix(FixKind kind, String expected) { 63 void assertHasFix(FixKind kind, String expected) {
60 AnalysisError error = _findErrorToFix(); 64 AnalysisError error = _findErrorToFix();
61 fix = _assertHasFix(kind, error); 65 fix = _assertHasFix(kind, error);
62 change = fix.change; 66 change = fix.change;
63 // apply to "file" 67 // apply to "file"
64 List<SourceFileEdit> fileEdits = change.edits; 68 List<SourceFileEdit> fileEdits = change.edits;
65 expect(fileEdits, hasLength(1)); 69 expect(fileEdits, hasLength(1));
66 resultCode = SourceEdit.applySequence(testCode, change.edits[0].edits); 70 resultCode = SourceEdit.applySequence(testCode, change.edits[0].edits);
67 // verify 71 // verify
68 expect(resultCode, expected); 72 expect(resultCode, expected);
69 } 73 }
70 74
71 void assertNoFix(FixKind kind) { 75 void assertNoFix(FixKind kind) {
72 AnalysisError error = _findErrorToFix(); 76 AnalysisError error = _findErrorToFix();
73 List<Fix> fixes = computeFixes(testUnit, error); 77 List<Fix> fixes = computeFixes(plugin, context, error);
74 for (Fix fix in fixes) { 78 for (Fix fix in fixes) {
75 if (fix.kind == kind) { 79 if (fix.kind == kind) {
76 throw fail('Unexpected fix $kind in\n${fixes.join('\n')}'); 80 throw fail('Unexpected fix $kind in\n${fixes.join('\n')}');
77 } 81 }
78 } 82 }
79 } 83 }
80 84
81 Position expectedPosition(String search) { 85 Position expectedPosition(String search) {
82 int offset = resultCode.indexOf(search); 86 int offset = resultCode.indexOf(search);
83 return new Position(testFile, offset); 87 return new Position(testFile, offset);
(...skipping 10 matching lines...) Expand all
94 List<LinkedEditSuggestion> expectedSuggestions( 98 List<LinkedEditSuggestion> expectedSuggestions(
95 LinkedEditSuggestionKind kind, List<String> values) { 99 LinkedEditSuggestionKind kind, List<String> values) {
96 return values.map((value) { 100 return values.map((value) {
97 return new LinkedEditSuggestion(value, kind); 101 return new LinkedEditSuggestion(value, kind);
98 }).toList(); 102 }).toList();
99 } 103 }
100 104
101 void setUp() { 105 void setUp() {
102 super.setUp(); 106 super.setUp();
103 verifyNoTestUnitErrors = false; 107 verifyNoTestUnitErrors = false;
108 ExtensionManager manager = new ExtensionManager();
109 plugin = new ServerPlugin();
110 manager.processPlugins([plugin]);
104 } 111 }
105 112
106 void test_addFieldFormalParameters_hasRequiredParameter() { 113 void test_addFieldFormalParameters_hasRequiredParameter() {
107 resolveTestUnit(''' 114 resolveTestUnit('''
108 class Test { 115 class Test {
109 final int a; 116 final int a;
110 final int b; 117 final int b;
111 final int c; 118 final int c;
112 Test(this.a); 119 Test(this.a);
113 } 120 }
114 '''); 121 ''');
115 assertHasFix(FixKind.ADD_FIELD_FORMAL_PARAMETERS, ''' 122 assertHasFix(DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, '''
116 class Test { 123 class Test {
117 final int a; 124 final int a;
118 final int b; 125 final int b;
119 final int c; 126 final int c;
120 Test(this.a, this.b, this.c); 127 Test(this.a, this.b, this.c);
121 } 128 }
122 '''); 129 ''');
123 } 130 }
124 131
125 void test_addFieldFormalParameters_noParameters() { 132 void test_addFieldFormalParameters_noParameters() {
126 resolveTestUnit(''' 133 resolveTestUnit('''
127 class Test { 134 class Test {
128 final int a; 135 final int a;
129 final int b; 136 final int b;
130 final int c; 137 final int c;
131 Test(); 138 Test();
132 } 139 }
133 '''); 140 ''');
134 assertHasFix(FixKind.ADD_FIELD_FORMAL_PARAMETERS, ''' 141 assertHasFix(DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, '''
135 class Test { 142 class Test {
136 final int a; 143 final int a;
137 final int b; 144 final int b;
138 final int c; 145 final int c;
139 Test(this.a, this.b, this.c); 146 Test(this.a, this.b, this.c);
140 } 147 }
141 '''); 148 ''');
142 } 149 }
143 150
144 void test_addFieldFormalParameters_noRequiredParameter() { 151 void test_addFieldFormalParameters_noRequiredParameter() {
145 resolveTestUnit(''' 152 resolveTestUnit('''
146 class Test { 153 class Test {
147 final int a; 154 final int a;
148 final int b; 155 final int b;
149 final int c; 156 final int c;
150 Test([this.c]); 157 Test([this.c]);
151 } 158 }
152 '''); 159 ''');
153 assertHasFix(FixKind.ADD_FIELD_FORMAL_PARAMETERS, ''' 160 assertHasFix(DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, '''
154 class Test { 161 class Test {
155 final int a; 162 final int a;
156 final int b; 163 final int b;
157 final int c; 164 final int c;
158 Test(this.a, this.b, [this.c]); 165 Test(this.a, this.b, [this.c]);
159 } 166 }
160 '''); 167 ''');
161 } 168 }
162 169
163 void test_addSync_blockFunctionBody() { 170 void test_addSync_blockFunctionBody() {
164 resolveTestUnit(''' 171 resolveTestUnit('''
165 foo() {} 172 foo() {}
166 main() { 173 main() {
167 await foo(); 174 await foo();
168 } 175 }
169 '''); 176 ''');
170 List<AnalysisError> errors = context.computeErrors(testSource); 177 List<AnalysisError> errors = context.computeErrors(testSource);
171 expect(errors, hasLength(2)); 178 expect(errors, hasLength(2));
172 // ParserError: Expected to find ';' 179 // ParserError: Expected to find ';'
173 { 180 {
174 AnalysisError error = errors[0]; 181 AnalysisError error = errors[0];
175 expect(error.message, "Expected to find ';'"); 182 expect(error.message, "Expected to find ';'");
176 List<Fix> fixes = computeFixes(testUnit, error); 183 List<Fix> fixes = computeFixes(plugin, context, error);
177 expect(fixes, isEmpty); 184 expect(fixes, isEmpty);
178 } 185 }
179 // Undefined name 'await' 186 // Undefined name 'await'
180 { 187 {
181 AnalysisError error = errors[1]; 188 AnalysisError error = errors[1];
182 expect(error.message, "Undefined name 'await'"); 189 expect(error.message, "Undefined name 'await'");
183 List<Fix> fixes = computeFixes(testUnit, error); 190 List<Fix> fixes = computeFixes(plugin, context, error);
184 // has exactly one fix 191 // has exactly one fix
185 expect(fixes, hasLength(1)); 192 expect(fixes, hasLength(1));
186 Fix fix = fixes[0]; 193 Fix fix = fixes[0];
187 expect(fix.kind, FixKind.ADD_ASYNC); 194 expect(fix.kind, DartFixKind.ADD_ASYNC);
188 // apply to "file" 195 // apply to "file"
189 List<SourceFileEdit> fileEdits = fix.change.edits; 196 List<SourceFileEdit> fileEdits = fix.change.edits;
190 expect(fileEdits, hasLength(1)); 197 expect(fileEdits, hasLength(1));
191 resultCode = SourceEdit.applySequence(testCode, fileEdits[0].edits); 198 resultCode = SourceEdit.applySequence(testCode, fileEdits[0].edits);
192 // verify 199 // verify
193 expect(resultCode, ''' 200 expect(resultCode, '''
194 foo() {} 201 foo() {}
195 main() async { 202 main() async {
196 await foo(); 203 await foo();
197 } 204 }
198 '''); 205 ''');
199 } 206 }
200 } 207 }
201 208
202 void test_addSync_expressionFunctionBody() { 209 void test_addSync_expressionFunctionBody() {
203 errorFilter = (AnalysisError error) { 210 errorFilter = (AnalysisError error) {
204 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER; 211 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER;
205 }; 212 };
206 resolveTestUnit(''' 213 resolveTestUnit('''
207 foo() {} 214 foo() {}
208 main() => await foo(); 215 main() => await foo();
209 '''); 216 ''');
210 assertHasFix(FixKind.ADD_ASYNC, ''' 217 assertHasFix(DartFixKind.ADD_ASYNC, '''
211 foo() {} 218 foo() {}
212 main() async => await foo(); 219 main() async => await foo();
213 '''); 220 ''');
214 } 221 }
215 222
216 void test_boolean() { 223 void test_boolean() {
217 resolveTestUnit(''' 224 resolveTestUnit('''
218 main() { 225 main() {
219 boolean v; 226 boolean v;
220 } 227 }
221 '''); 228 ''');
222 assertHasFix(FixKind.REPLACE_BOOLEAN_WITH_BOOL, ''' 229 assertHasFix(DartFixKind.REPLACE_BOOLEAN_WITH_BOOL, '''
223 main() { 230 main() {
224 bool v; 231 bool v;
225 } 232 }
226 '''); 233 ''');
227 } 234 }
228 235
229 void test_changeToStaticAccess_method() { 236 void test_changeToStaticAccess_method() {
230 resolveTestUnit(''' 237 resolveTestUnit('''
231 class A { 238 class A {
232 static foo() {} 239 static foo() {}
233 } 240 }
234 main(A a) { 241 main(A a) {
235 a.foo(); 242 a.foo();
236 } 243 }
237 '''); 244 ''');
238 assertHasFix(FixKind.CHANGE_TO_STATIC_ACCESS, ''' 245 assertHasFix(DartFixKind.CHANGE_TO_STATIC_ACCESS, '''
239 class A { 246 class A {
240 static foo() {} 247 static foo() {}
241 } 248 }
242 main(A a) { 249 main(A a) {
243 A.foo(); 250 A.foo();
244 } 251 }
245 '''); 252 ''');
246 } 253 }
247 254
248 void test_changeToStaticAccess_method_importType() { 255 void test_changeToStaticAccess_method_importType() {
249 addSource('/libA.dart', r''' 256 addSource('/libA.dart', r'''
250 library libA; 257 library libA;
251 class A { 258 class A {
252 static foo() {} 259 static foo() {}
253 } 260 }
254 '''); 261 ''');
255 addSource('/libB.dart', r''' 262 addSource('/libB.dart', r'''
256 library libB; 263 library libB;
257 import 'libA.dart'; 264 import 'libA.dart';
258 class B extends A {} 265 class B extends A {}
259 '''); 266 ''');
260 resolveTestUnit(''' 267 resolveTestUnit('''
261 import 'libB.dart'; 268 import 'libB.dart';
262 main(B b) { 269 main(B b) {
263 b.foo(); 270 b.foo();
264 } 271 }
265 '''); 272 ''');
266 assertHasFix(FixKind.CHANGE_TO_STATIC_ACCESS, ''' 273 assertHasFix(DartFixKind.CHANGE_TO_STATIC_ACCESS, '''
267 import 'libB.dart'; 274 import 'libB.dart';
268 import 'libA.dart'; 275 import 'libA.dart';
269 main(B b) { 276 main(B b) {
270 A.foo(); 277 A.foo();
271 } 278 }
272 '''); 279 ''');
273 } 280 }
274 281
275 void test_changeToStaticAccess_method_prefixLibrary() { 282 void test_changeToStaticAccess_method_prefixLibrary() {
276 resolveTestUnit(''' 283 resolveTestUnit('''
277 import 'dart:async' as pref; 284 import 'dart:async' as pref;
278 main(pref.Future f) { 285 main(pref.Future f) {
279 f.wait([]); 286 f.wait([]);
280 } 287 }
281 '''); 288 ''');
282 assertHasFix(FixKind.CHANGE_TO_STATIC_ACCESS, ''' 289 assertHasFix(DartFixKind.CHANGE_TO_STATIC_ACCESS, '''
283 import 'dart:async' as pref; 290 import 'dart:async' as pref;
284 main(pref.Future f) { 291 main(pref.Future f) {
285 pref.Future.wait([]); 292 pref.Future.wait([]);
286 } 293 }
287 '''); 294 ''');
288 } 295 }
289 296
290 void test_changeToStaticAccess_property() { 297 void test_changeToStaticAccess_property() {
291 resolveTestUnit(''' 298 resolveTestUnit('''
292 class A { 299 class A {
293 static get foo => 42; 300 static get foo => 42;
294 } 301 }
295 main(A a) { 302 main(A a) {
296 a.foo; 303 a.foo;
297 } 304 }
298 '''); 305 ''');
299 assertHasFix(FixKind.CHANGE_TO_STATIC_ACCESS, ''' 306 assertHasFix(DartFixKind.CHANGE_TO_STATIC_ACCESS, '''
300 class A { 307 class A {
301 static get foo => 42; 308 static get foo => 42;
302 } 309 }
303 main(A a) { 310 main(A a) {
304 A.foo; 311 A.foo;
305 } 312 }
306 '''); 313 ''');
307 } 314 }
308 315
309 void test_changeToStaticAccess_property_importType() { 316 void test_changeToStaticAccess_property_importType() {
310 addSource('/libA.dart', r''' 317 addSource('/libA.dart', r'''
311 library libA; 318 library libA;
312 class A { 319 class A {
313 static get foo => null; 320 static get foo => null;
314 } 321 }
315 '''); 322 ''');
316 addSource('/libB.dart', r''' 323 addSource('/libB.dart', r'''
317 library libB; 324 library libB;
318 import 'libA.dart'; 325 import 'libA.dart';
319 class B extends A {} 326 class B extends A {}
320 '''); 327 ''');
321 resolveTestUnit(''' 328 resolveTestUnit('''
322 import 'libB.dart'; 329 import 'libB.dart';
323 main(B b) { 330 main(B b) {
324 b.foo; 331 b.foo;
325 } 332 }
326 '''); 333 ''');
327 assertHasFix(FixKind.CHANGE_TO_STATIC_ACCESS, ''' 334 assertHasFix(DartFixKind.CHANGE_TO_STATIC_ACCESS, '''
328 import 'libB.dart'; 335 import 'libB.dart';
329 import 'libA.dart'; 336 import 'libA.dart';
330 main(B b) { 337 main(B b) {
331 A.foo; 338 A.foo;
332 } 339 }
333 '''); 340 ''');
334 } 341 }
335 342
336 void test_createClass() { 343 void test_createClass() {
337 resolveTestUnit(''' 344 resolveTestUnit('''
338 main() { 345 main() {
339 Test v = null; 346 Test v = null;
340 } 347 }
341 '''); 348 ''');
342 assertHasFix(FixKind.CREATE_CLASS, ''' 349 assertHasFix(DartFixKind.CREATE_CLASS, '''
343 main() { 350 main() {
344 Test v = null; 351 Test v = null;
345 } 352 }
346 353
347 class Test { 354 class Test {
348 } 355 }
349 '''); 356 ''');
350 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']); 357 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']);
351 } 358 }
352 359
353 void test_createConstructor_forFinalFields() { 360 void test_createConstructor_forFinalFields() {
354 errorFilter = (AnalysisError error) { 361 errorFilter = (AnalysisError error) {
355 return error.message.contains("'a'"); 362 return error.message.contains("'a'");
356 }; 363 };
357 resolveTestUnit(''' 364 resolveTestUnit('''
358 class Test { 365 class Test {
359 final int a; 366 final int a;
360 final int b = 2; 367 final int b = 2;
361 final int c; 368 final int c;
362 } 369 }
363 '''); 370 ''');
364 assertHasFix(FixKind.CREATE_CONSTRUCTOR_FOR_FINAL_FIELDS, ''' 371 assertHasFix(DartFixKind.CREATE_CONSTRUCTOR_FOR_FINAL_FIELDS, '''
365 class Test { 372 class Test {
366 final int a; 373 final int a;
367 final int b = 2; 374 final int b = 2;
368 final int c; 375 final int c;
369 376
370 Test(this.a, this.c); 377 Test(this.a, this.c);
371 } 378 }
372 '''); 379 ''');
373 } 380 }
374 381
375 void test_createConstructor_insteadOfSyntheticDefault() { 382 void test_createConstructor_insteadOfSyntheticDefault() {
376 resolveTestUnit(''' 383 resolveTestUnit('''
377 class A { 384 class A {
378 int field; 385 int field;
379 386
380 method() {} 387 method() {}
381 } 388 }
382 main() { 389 main() {
383 new A(1, 2.0); 390 new A(1, 2.0);
384 } 391 }
385 '''); 392 ''');
386 assertHasFix(FixKind.CREATE_CONSTRUCTOR, ''' 393 assertHasFix(DartFixKind.CREATE_CONSTRUCTOR, '''
387 class A { 394 class A {
388 int field; 395 int field;
389 396
390 A(int i, double d) { 397 A(int i, double d) {
391 } 398 }
392 399
393 method() {} 400 method() {}
394 } 401 }
395 main() { 402 main() {
396 new A(1, 2.0); 403 new A(1, 2.0);
397 } 404 }
398 '''); 405 ''');
399 } 406 }
400 407
401 void test_createConstructor_named() { 408 void test_createConstructor_named() {
402 resolveTestUnit(''' 409 resolveTestUnit('''
403 class A { 410 class A {
404 method() {} 411 method() {}
405 } 412 }
406 main() { 413 main() {
407 new A.named(1, 2.0); 414 new A.named(1, 2.0);
408 } 415 }
409 '''); 416 ''');
410 assertHasFix(FixKind.CREATE_CONSTRUCTOR, ''' 417 assertHasFix(DartFixKind.CREATE_CONSTRUCTOR, '''
411 class A { 418 class A {
412 A.named(int i, double d) { 419 A.named(int i, double d) {
413 } 420 }
414 421
415 method() {} 422 method() {}
416 } 423 }
417 main() { 424 main() {
418 new A.named(1, 2.0); 425 new A.named(1, 2.0);
419 } 426 }
420 '''); 427 ''');
421 _assertLinkedGroup(change.linkedEditGroups[0], ['named(int ', 'named(1']); 428 _assertLinkedGroup(change.linkedEditGroups[0], ['named(int ', 'named(1']);
422 } 429 }
423 430
424 void test_createConstructorForFinalFields_inTopLevelMethod() { 431 void test_createConstructorForFinalFields_inTopLevelMethod() {
425 resolveTestUnit(''' 432 resolveTestUnit('''
426 main() { 433 main() {
427 final int v; 434 final int v;
428 } 435 }
429 '''); 436 ''');
430 assertNoFix(FixKind.CREATE_CONSTRUCTOR_FOR_FINAL_FIELDS); 437 assertNoFix(DartFixKind.CREATE_CONSTRUCTOR_FOR_FINAL_FIELDS);
431 } 438 }
432 439
433 void test_createConstructorForFinalFields_topLevelField() { 440 void test_createConstructorForFinalFields_topLevelField() {
434 resolveTestUnit(''' 441 resolveTestUnit('''
435 final int v; 442 final int v;
436 '''); 443 ''');
437 assertNoFix(FixKind.CREATE_CONSTRUCTOR_FOR_FINAL_FIELDS); 444 assertNoFix(DartFixKind.CREATE_CONSTRUCTOR_FOR_FINAL_FIELDS);
438 } 445 }
439 446
440 void test_createConstructorSuperExplicit() { 447 void test_createConstructorSuperExplicit() {
441 resolveTestUnit(''' 448 resolveTestUnit('''
442 class A { 449 class A {
443 A(bool p1, int p2, double p3, String p4, {p5}); 450 A(bool p1, int p2, double p3, String p4, {p5});
444 } 451 }
445 class B extends A { 452 class B extends A {
446 B() {} 453 B() {}
447 } 454 }
448 '''); 455 ''');
449 assertHasFix(FixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, ''' 456 assertHasFix(DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, '''
450 class A { 457 class A {
451 A(bool p1, int p2, double p3, String p4, {p5}); 458 A(bool p1, int p2, double p3, String p4, {p5});
452 } 459 }
453 class B extends A { 460 class B extends A {
454 B() : super(false, 0, 0.0, '') {} 461 B() : super(false, 0, 0.0, '') {}
455 } 462 }
456 '''); 463 ''');
457 } 464 }
458 465
459 void test_createConstructorSuperExplicit_hasInitializers() { 466 void test_createConstructorSuperExplicit_hasInitializers() {
460 resolveTestUnit(''' 467 resolveTestUnit('''
461 class A { 468 class A {
462 A(int p); 469 A(int p);
463 } 470 }
464 class B extends A { 471 class B extends A {
465 int field; 472 int field;
466 B() : field = 42 {} 473 B() : field = 42 {}
467 } 474 }
468 '''); 475 ''');
469 assertHasFix(FixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, ''' 476 assertHasFix(DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, '''
470 class A { 477 class A {
471 A(int p); 478 A(int p);
472 } 479 }
473 class B extends A { 480 class B extends A {
474 int field; 481 int field;
475 B() : field = 42, super(0) {} 482 B() : field = 42, super(0) {}
476 } 483 }
477 '''); 484 ''');
478 } 485 }
479 486
480 void test_createConstructorSuperExplicit_named() { 487 void test_createConstructorSuperExplicit_named() {
481 resolveTestUnit(''' 488 resolveTestUnit('''
482 class A { 489 class A {
483 A.named(int p); 490 A.named(int p);
484 } 491 }
485 class B extends A { 492 class B extends A {
486 B() {} 493 B() {}
487 } 494 }
488 '''); 495 ''');
489 assertHasFix(FixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, ''' 496 assertHasFix(DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, '''
490 class A { 497 class A {
491 A.named(int p); 498 A.named(int p);
492 } 499 }
493 class B extends A { 500 class B extends A {
494 B() : super.named(0) {} 501 B() : super.named(0) {}
495 } 502 }
496 '''); 503 ''');
497 } 504 }
498 505
499 void test_createConstructorSuperExplicit_named_private() { 506 void test_createConstructorSuperExplicit_named_private() {
500 resolveTestUnit(''' 507 resolveTestUnit('''
501 class A { 508 class A {
502 A._named(int p); 509 A._named(int p);
503 } 510 }
504 class B extends A { 511 class B extends A {
505 B() {} 512 B() {}
506 } 513 }
507 '''); 514 ''');
508 assertNoFix(FixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION); 515 assertNoFix(DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION);
509 } 516 }
510 517
511 void test_createConstructorSuperImplicit() { 518 void test_createConstructorSuperImplicit() {
512 resolveTestUnit(''' 519 resolveTestUnit('''
513 class A { 520 class A {
514 A(p1, int p2, List<String> p3, [int p4]); 521 A(p1, int p2, List<String> p3, [int p4]);
515 } 522 }
516 class B extends A { 523 class B extends A {
517 int existingField; 524 int existingField;
518 525
519 void existingMethod() {} 526 void existingMethod() {}
520 } 527 }
521 '''); 528 ''');
522 assertHasFix(FixKind.CREATE_CONSTRUCTOR_SUPER, ''' 529 assertHasFix(DartFixKind.CREATE_CONSTRUCTOR_SUPER, '''
523 class A { 530 class A {
524 A(p1, int p2, List<String> p3, [int p4]); 531 A(p1, int p2, List<String> p3, [int p4]);
525 } 532 }
526 class B extends A { 533 class B extends A {
527 int existingField; 534 int existingField;
528 535
529 B(p1, int p2, List<String> p3) : super(p1, p2, p3); 536 B(p1, int p2, List<String> p3) : super(p1, p2, p3);
530 537
531 void existingMethod() {} 538 void existingMethod() {}
532 } 539 }
533 '''); 540 ''');
534 } 541 }
535 542
536 void test_createConstructorSuperImplicit_fieldInitializer() { 543 void test_createConstructorSuperImplicit_fieldInitializer() {
537 resolveTestUnit(''' 544 resolveTestUnit('''
538 class A { 545 class A {
539 int _field; 546 int _field;
540 A(this._field); 547 A(this._field);
541 } 548 }
542 class B extends A { 549 class B extends A {
543 int existingField; 550 int existingField;
544 551
545 void existingMethod() {} 552 void existingMethod() {}
546 } 553 }
547 '''); 554 ''');
548 assertHasFix(FixKind.CREATE_CONSTRUCTOR_SUPER, ''' 555 assertHasFix(DartFixKind.CREATE_CONSTRUCTOR_SUPER, '''
549 class A { 556 class A {
550 int _field; 557 int _field;
551 A(this._field); 558 A(this._field);
552 } 559 }
553 class B extends A { 560 class B extends A {
554 int existingField; 561 int existingField;
555 562
556 B(int field) : super(field); 563 B(int field) : super(field);
557 564
558 void existingMethod() {} 565 void existingMethod() {}
(...skipping 11 matching lines...) Expand all
570 import 'libA.dart'; 577 import 'libA.dart';
571 class B { 578 class B {
572 B(A a); 579 B(A a);
573 } 580 }
574 '''); 581 ''');
575 resolveTestUnit(''' 582 resolveTestUnit('''
576 import 'libB.dart'; 583 import 'libB.dart';
577 class C extends B { 584 class C extends B {
578 } 585 }
579 '''); 586 ''');
580 assertHasFix(FixKind.CREATE_CONSTRUCTOR_SUPER, ''' 587 assertHasFix(DartFixKind.CREATE_CONSTRUCTOR_SUPER, '''
581 import 'libB.dart'; 588 import 'libB.dart';
582 import 'libA.dart'; 589 import 'libA.dart';
583 class C extends B { 590 class C extends B {
584 C(A a) : super(a); 591 C(A a) : super(a);
585 } 592 }
586 '''); 593 ''');
587 } 594 }
588 595
589 void test_createConstructorSuperImplicit_named() { 596 void test_createConstructorSuperImplicit_named() {
590 resolveTestUnit(''' 597 resolveTestUnit('''
591 class A { 598 class A {
592 A.named(p1, int p2); 599 A.named(p1, int p2);
593 } 600 }
594 class B extends A { 601 class B extends A {
595 int existingField; 602 int existingField;
596 603
597 void existingMethod() {} 604 void existingMethod() {}
598 } 605 }
599 '''); 606 ''');
600 assertHasFix(FixKind.CREATE_CONSTRUCTOR_SUPER, ''' 607 assertHasFix(DartFixKind.CREATE_CONSTRUCTOR_SUPER, '''
601 class A { 608 class A {
602 A.named(p1, int p2); 609 A.named(p1, int p2);
603 } 610 }
604 class B extends A { 611 class B extends A {
605 int existingField; 612 int existingField;
606 613
607 B.named(p1, int p2) : super.named(p1, p2); 614 B.named(p1, int p2) : super.named(p1, p2);
608 615
609 void existingMethod() {} 616 void existingMethod() {}
610 } 617 }
611 '''); 618 ''');
612 } 619 }
613 620
614 void test_createConstructorSuperImplicit_private() { 621 void test_createConstructorSuperImplicit_private() {
615 resolveTestUnit(''' 622 resolveTestUnit('''
616 class A { 623 class A {
617 A._named(p); 624 A._named(p);
618 } 625 }
619 class B extends A { 626 class B extends A {
620 } 627 }
621 '''); 628 ''');
622 assertNoFix(FixKind.CREATE_CONSTRUCTOR_SUPER); 629 assertNoFix(DartFixKind.CREATE_CONSTRUCTOR_SUPER);
623 } 630 }
624 631
625 void test_createField_BAD_inEnum() { 632 void test_createField_BAD_inEnum() {
626 resolveTestUnit(''' 633 resolveTestUnit('''
627 enum MyEnum { 634 enum MyEnum {
628 AAA, BBB 635 AAA, BBB
629 } 636 }
630 main() { 637 main() {
631 MyEnum.foo; 638 MyEnum.foo;
632 } 639 }
633 '''); 640 ''');
634 assertNoFix(FixKind.CREATE_FIELD); 641 assertNoFix(DartFixKind.CREATE_FIELD);
635 } 642 }
636 643
637 void test_createField_BAD_inSDK() { 644 void test_createField_BAD_inSDK() {
638 resolveTestUnit(''' 645 resolveTestUnit('''
639 main(List p) { 646 main(List p) {
640 p.foo = 1; 647 p.foo = 1;
641 } 648 }
642 '''); 649 ''');
643 assertNoFix(FixKind.CREATE_FIELD); 650 assertNoFix(DartFixKind.CREATE_FIELD);
644 } 651 }
645 652
646 void test_createField_getter_multiLevel() { 653 void test_createField_getter_multiLevel() {
647 resolveTestUnit(''' 654 resolveTestUnit('''
648 class A { 655 class A {
649 } 656 }
650 class B { 657 class B {
651 A a; 658 A a;
652 } 659 }
653 class C { 660 class C {
654 B b; 661 B b;
655 } 662 }
656 main(C c) { 663 main(C c) {
657 int v = c.b.a.test; 664 int v = c.b.a.test;
658 } 665 }
659 '''); 666 ''');
660 assertHasFix(FixKind.CREATE_FIELD, ''' 667 assertHasFix(DartFixKind.CREATE_FIELD, '''
661 class A { 668 class A {
662 int test; 669 int test;
663 } 670 }
664 class B { 671 class B {
665 A a; 672 A a;
666 } 673 }
667 class C { 674 class C {
668 B b; 675 B b;
669 } 676 }
670 main(C c) { 677 main(C c) {
671 int v = c.b.a.test; 678 int v = c.b.a.test;
672 } 679 }
673 '''); 680 ''');
674 } 681 }
675 682
676 void test_createField_getter_qualified_instance() { 683 void test_createField_getter_qualified_instance() {
677 resolveTestUnit(''' 684 resolveTestUnit('''
678 class A { 685 class A {
679 } 686 }
680 main(A a) { 687 main(A a) {
681 int v = a.test; 688 int v = a.test;
682 } 689 }
683 '''); 690 ''');
684 assertHasFix(FixKind.CREATE_FIELD, ''' 691 assertHasFix(DartFixKind.CREATE_FIELD, '''
685 class A { 692 class A {
686 int test; 693 int test;
687 } 694 }
688 main(A a) { 695 main(A a) {
689 int v = a.test; 696 int v = a.test;
690 } 697 }
691 '''); 698 ''');
692 } 699 }
693 700
694 void test_createField_getter_qualified_instance_dynamicType() { 701 void test_createField_getter_qualified_instance_dynamicType() {
695 resolveTestUnit(''' 702 resolveTestUnit('''
696 class A { 703 class A {
697 B b; 704 B b;
698 void f(Object p) { 705 void f(Object p) {
699 p == b.test; 706 p == b.test;
700 } 707 }
701 } 708 }
702 class B { 709 class B {
703 } 710 }
704 '''); 711 ''');
705 assertHasFix(FixKind.CREATE_FIELD, ''' 712 assertHasFix(DartFixKind.CREATE_FIELD, '''
706 class A { 713 class A {
707 B b; 714 B b;
708 void f(Object p) { 715 void f(Object p) {
709 p == b.test; 716 p == b.test;
710 } 717 }
711 } 718 }
712 class B { 719 class B {
713 var test; 720 var test;
714 } 721 }
715 '''); 722 ''');
716 } 723 }
717 724
718 void test_createField_getter_unqualified_instance_asInvocationArgument() { 725 void test_createField_getter_unqualified_instance_asInvocationArgument() {
719 resolveTestUnit(''' 726 resolveTestUnit('''
720 class A { 727 class A {
721 main() { 728 main() {
722 f(test); 729 f(test);
723 } 730 }
724 } 731 }
725 f(String s) {} 732 f(String s) {}
726 '''); 733 ''');
727 assertHasFix(FixKind.CREATE_FIELD, ''' 734 assertHasFix(DartFixKind.CREATE_FIELD, '''
728 class A { 735 class A {
729 String test; 736 String test;
730 737
731 main() { 738 main() {
732 f(test); 739 f(test);
733 } 740 }
734 } 741 }
735 f(String s) {} 742 f(String s) {}
736 '''); 743 ''');
737 } 744 }
738 745
739 void test_createField_getter_unqualified_instance_assignmentRhs() { 746 void test_createField_getter_unqualified_instance_assignmentRhs() {
740 resolveTestUnit(''' 747 resolveTestUnit('''
741 class A { 748 class A {
742 main() { 749 main() {
743 int v = test; 750 int v = test;
744 } 751 }
745 } 752 }
746 '''); 753 ''');
747 assertHasFix(FixKind.CREATE_FIELD, ''' 754 assertHasFix(DartFixKind.CREATE_FIELD, '''
748 class A { 755 class A {
749 int test; 756 int test;
750 757
751 main() { 758 main() {
752 int v = test; 759 int v = test;
753 } 760 }
754 } 761 }
755 '''); 762 ''');
756 } 763 }
757 764
758 void test_createField_getter_unqualified_instance_asStatement() { 765 void test_createField_getter_unqualified_instance_asStatement() {
759 resolveTestUnit(''' 766 resolveTestUnit('''
760 class A { 767 class A {
761 main() { 768 main() {
762 test; 769 test;
763 } 770 }
764 } 771 }
765 '''); 772 ''');
766 assertHasFix(FixKind.CREATE_FIELD, ''' 773 assertHasFix(DartFixKind.CREATE_FIELD, '''
767 class A { 774 class A {
768 var test; 775 var test;
769 776
770 main() { 777 main() {
771 test; 778 test;
772 } 779 }
773 } 780 }
774 '''); 781 ''');
775 } 782 }
776 783
777 void test_createField_hint() { 784 void test_createField_hint() {
778 resolveTestUnit(''' 785 resolveTestUnit('''
779 class A { 786 class A {
780 } 787 }
781 main(A a) { 788 main(A a) {
782 var x = a; 789 var x = a;
783 int v = x.test; 790 int v = x.test;
784 } 791 }
785 '''); 792 ''');
786 assertHasFix(FixKind.CREATE_FIELD, ''' 793 assertHasFix(DartFixKind.CREATE_FIELD, '''
787 class A { 794 class A {
788 int test; 795 int test;
789 } 796 }
790 main(A a) { 797 main(A a) {
791 var x = a; 798 var x = a;
792 int v = x.test; 799 int v = x.test;
793 } 800 }
794 '''); 801 ''');
795 } 802 }
796 803
797 void test_createField_hint_setter() { 804 void test_createField_hint_setter() {
798 resolveTestUnit(''' 805 resolveTestUnit('''
799 class A { 806 class A {
800 } 807 }
801 main(A a) { 808 main(A a) {
802 var x = a; 809 var x = a;
803 x.test = 0; 810 x.test = 0;
804 } 811 }
805 '''); 812 ''');
806 assertHasFix(FixKind.CREATE_FIELD, ''' 813 assertHasFix(DartFixKind.CREATE_FIELD, '''
807 class A { 814 class A {
808 int test; 815 int test;
809 } 816 }
810 main(A a) { 817 main(A a) {
811 var x = a; 818 var x = a;
812 x.test = 0; 819 x.test = 0;
813 } 820 }
814 '''); 821 ''');
815 } 822 }
816 823
817 void test_createField_importType() { 824 void test_createField_importType() {
818 addSource('/libA.dart', r''' 825 addSource('/libA.dart', r'''
819 library libA; 826 library libA;
820 class A {} 827 class A {}
821 '''); 828 ''');
822 addSource('/libB.dart', r''' 829 addSource('/libB.dart', r'''
823 library libB; 830 library libB;
824 import 'libA.dart'; 831 import 'libA.dart';
825 A getA() => null; 832 A getA() => null;
826 '''); 833 ''');
827 resolveTestUnit(''' 834 resolveTestUnit('''
828 import 'libB.dart'; 835 import 'libB.dart';
829 class C { 836 class C {
830 } 837 }
831 main(C c) { 838 main(C c) {
832 c.test = getA(); 839 c.test = getA();
833 } 840 }
834 '''); 841 ''');
835 assertHasFix(FixKind.CREATE_FIELD, ''' 842 assertHasFix(DartFixKind.CREATE_FIELD, '''
836 import 'libB.dart'; 843 import 'libB.dart';
837 import 'libA.dart'; 844 import 'libA.dart';
838 class C { 845 class C {
839 A test; 846 A test;
840 } 847 }
841 main(C c) { 848 main(C c) {
842 c.test = getA(); 849 c.test = getA();
843 } 850 }
844 '''); 851 ''');
845 } 852 }
846 853
847 void test_createField_setter_generic_BAD() { 854 void test_createField_setter_generic_BAD() {
848 resolveTestUnit(''' 855 resolveTestUnit('''
849 class A { 856 class A {
850 } 857 }
851 class B<T> { 858 class B<T> {
852 List<T> items; 859 List<T> items;
853 main(A a) { 860 main(A a) {
854 a.test = items; 861 a.test = items;
855 } 862 }
856 } 863 }
857 '''); 864 ''');
858 assertHasFix(FixKind.CREATE_FIELD, ''' 865 assertHasFix(DartFixKind.CREATE_FIELD, '''
859 class A { 866 class A {
860 List test; 867 List test;
861 } 868 }
862 class B<T> { 869 class B<T> {
863 List<T> items; 870 List<T> items;
864 main(A a) { 871 main(A a) {
865 a.test = items; 872 a.test = items;
866 } 873 }
867 } 874 }
868 '''); 875 ''');
869 } 876 }
870 877
871 void test_createField_setter_generic_OK_local() { 878 void test_createField_setter_generic_OK_local() {
872 resolveTestUnit(''' 879 resolveTestUnit('''
873 class A<T> { 880 class A<T> {
874 List<T> items; 881 List<T> items;
875 882
876 main(A a) { 883 main(A a) {
877 test = items; 884 test = items;
878 } 885 }
879 } 886 }
880 '''); 887 ''');
881 assertHasFix(FixKind.CREATE_FIELD, ''' 888 assertHasFix(DartFixKind.CREATE_FIELD, '''
882 class A<T> { 889 class A<T> {
883 List<T> items; 890 List<T> items;
884 891
885 List<T> test; 892 List<T> test;
886 893
887 main(A a) { 894 main(A a) {
888 test = items; 895 test = items;
889 } 896 }
890 } 897 }
891 '''); 898 ''');
892 } 899 }
893 900
894 void test_createField_setter_qualified_instance_hasField() { 901 void test_createField_setter_qualified_instance_hasField() {
895 resolveTestUnit(''' 902 resolveTestUnit('''
896 class A { 903 class A {
897 int aaa; 904 int aaa;
898 int zzz; 905 int zzz;
899 906
900 existingMethod() {} 907 existingMethod() {}
901 } 908 }
902 main(A a) { 909 main(A a) {
903 a.test = 5; 910 a.test = 5;
904 } 911 }
905 '''); 912 ''');
906 assertHasFix(FixKind.CREATE_FIELD, ''' 913 assertHasFix(DartFixKind.CREATE_FIELD, '''
907 class A { 914 class A {
908 int aaa; 915 int aaa;
909 int zzz; 916 int zzz;
910 917
911 int test; 918 int test;
912 919
913 existingMethod() {} 920 existingMethod() {}
914 } 921 }
915 main(A a) { 922 main(A a) {
916 a.test = 5; 923 a.test = 5;
917 } 924 }
918 '''); 925 ''');
919 } 926 }
920 927
921 void test_createField_setter_qualified_instance_hasMethod() { 928 void test_createField_setter_qualified_instance_hasMethod() {
922 resolveTestUnit(''' 929 resolveTestUnit('''
923 class A { 930 class A {
924 existingMethod() {} 931 existingMethod() {}
925 } 932 }
926 main(A a) { 933 main(A a) {
927 a.test = 5; 934 a.test = 5;
928 } 935 }
929 '''); 936 ''');
930 assertHasFix(FixKind.CREATE_FIELD, ''' 937 assertHasFix(DartFixKind.CREATE_FIELD, '''
931 class A { 938 class A {
932 int test; 939 int test;
933 940
934 existingMethod() {} 941 existingMethod() {}
935 } 942 }
936 main(A a) { 943 main(A a) {
937 a.test = 5; 944 a.test = 5;
938 } 945 }
939 '''); 946 ''');
940 } 947 }
941 948
942 void test_createField_setter_qualified_static() { 949 void test_createField_setter_qualified_static() {
943 resolveTestUnit(''' 950 resolveTestUnit('''
944 class A { 951 class A {
945 } 952 }
946 main() { 953 main() {
947 A.test = 5; 954 A.test = 5;
948 } 955 }
949 '''); 956 ''');
950 assertHasFix(FixKind.CREATE_FIELD, ''' 957 assertHasFix(DartFixKind.CREATE_FIELD, '''
951 class A { 958 class A {
952 static int test; 959 static int test;
953 } 960 }
954 main() { 961 main() {
955 A.test = 5; 962 A.test = 5;
956 } 963 }
957 '''); 964 ''');
958 } 965 }
959 966
960 void test_createField_setter_unqualified_instance() { 967 void test_createField_setter_unqualified_instance() {
961 resolveTestUnit(''' 968 resolveTestUnit('''
962 class A { 969 class A {
963 main() { 970 main() {
964 test = 5; 971 test = 5;
965 } 972 }
966 } 973 }
967 '''); 974 ''');
968 assertHasFix(FixKind.CREATE_FIELD, ''' 975 assertHasFix(DartFixKind.CREATE_FIELD, '''
969 class A { 976 class A {
970 int test; 977 int test;
971 978
972 main() { 979 main() {
973 test = 5; 980 test = 5;
974 } 981 }
975 } 982 }
976 '''); 983 ''');
977 } 984 }
978 985
979 void test_createField_setter_unqualified_static() { 986 void test_createField_setter_unqualified_static() {
980 resolveTestUnit(''' 987 resolveTestUnit('''
981 class A { 988 class A {
982 static main() { 989 static main() {
983 test = 5; 990 test = 5;
984 } 991 }
985 } 992 }
986 '''); 993 ''');
987 assertHasFix(FixKind.CREATE_FIELD, ''' 994 assertHasFix(DartFixKind.CREATE_FIELD, '''
988 class A { 995 class A {
989 static int test; 996 static int test;
990 997
991 static main() { 998 static main() {
992 test = 5; 999 test = 5;
993 } 1000 }
994 } 1001 }
995 '''); 1002 ''');
996 } 1003 }
997 1004
998 void test_createFile_forImport() { 1005 void test_createFile_forImport() {
999 testFile = '/my/project/bin/test.dart'; 1006 testFile = '/my/project/bin/test.dart';
1000 resolveTestUnit(''' 1007 resolveTestUnit('''
1001 import 'my_file.dart'; 1008 import 'my_file.dart';
1002 '''); 1009 ''');
1003 AnalysisError error = _findErrorToFix(); 1010 AnalysisError error = _findErrorToFix();
1004 fix = _assertHasFix(FixKind.CREATE_FILE, error); 1011 fix = _assertHasFix(DartFixKind.CREATE_FILE, error);
1005 change = fix.change; 1012 change = fix.change;
1006 // validate change 1013 // validate change
1007 List<SourceFileEdit> fileEdits = change.edits; 1014 List<SourceFileEdit> fileEdits = change.edits;
1008 expect(fileEdits, hasLength(1)); 1015 expect(fileEdits, hasLength(1));
1009 SourceFileEdit fileEdit = change.edits[0]; 1016 SourceFileEdit fileEdit = change.edits[0];
1010 expect(fileEdit.file, '/my/project/bin/my_file.dart'); 1017 expect(fileEdit.file, '/my/project/bin/my_file.dart');
1011 expect(fileEdit.fileStamp, -1); 1018 expect(fileEdit.fileStamp, -1);
1012 expect(fileEdit.edits[0].replacement, contains('library my.file;')); 1019 expect(fileEdit.edits[0].replacement, contains('library my.file;'));
1013 } 1020 }
1014 1021
1015 void test_createFile_forPart() { 1022 void test_createFile_forPart() {
1016 testFile = '/my/project/bin/test.dart'; 1023 testFile = '/my/project/bin/test.dart';
1017 resolveTestUnit(''' 1024 resolveTestUnit('''
1018 library my.lib; 1025 library my.lib;
1019 part 'my_part.dart'; 1026 part 'my_part.dart';
1020 '''); 1027 ''');
1021 AnalysisError error = _findErrorToFix(); 1028 AnalysisError error = _findErrorToFix();
1022 fix = _assertHasFix(FixKind.CREATE_FILE, error); 1029 fix = _assertHasFix(DartFixKind.CREATE_FILE, error);
1023 change = fix.change; 1030 change = fix.change;
1024 // validate change 1031 // validate change
1025 List<SourceFileEdit> fileEdits = change.edits; 1032 List<SourceFileEdit> fileEdits = change.edits;
1026 expect(fileEdits, hasLength(1)); 1033 expect(fileEdits, hasLength(1));
1027 SourceFileEdit fileEdit = change.edits[0]; 1034 SourceFileEdit fileEdit = change.edits[0];
1028 expect(fileEdit.file, '/my/project/bin/my_part.dart'); 1035 expect(fileEdit.file, '/my/project/bin/my_part.dart');
1029 expect(fileEdit.fileStamp, -1); 1036 expect(fileEdit.fileStamp, -1);
1030 expect(fileEdit.edits[0].replacement, contains('part of my.lib;')); 1037 expect(fileEdit.edits[0].replacement, contains('part of my.lib;'));
1031 } 1038 }
1032 1039
1033 void test_createGetter_BAD_inSDK() { 1040 void test_createGetter_BAD_inSDK() {
1034 resolveTestUnit(''' 1041 resolveTestUnit('''
1035 main(List p) { 1042 main(List p) {
1036 int v = p.foo; 1043 int v = p.foo;
1037 } 1044 }
1038 '''); 1045 ''');
1039 assertNoFix(FixKind.CREATE_GETTER); 1046 assertNoFix(DartFixKind.CREATE_GETTER);
1040 } 1047 }
1041 1048
1042 void test_createGetter_hint_getter() { 1049 void test_createGetter_hint_getter() {
1043 resolveTestUnit(''' 1050 resolveTestUnit('''
1044 class A { 1051 class A {
1045 } 1052 }
1046 main(A a) { 1053 main(A a) {
1047 var x = a; 1054 var x = a;
1048 int v = x.test; 1055 int v = x.test;
1049 } 1056 }
1050 '''); 1057 ''');
1051 assertHasFix(FixKind.CREATE_GETTER, ''' 1058 assertHasFix(DartFixKind.CREATE_GETTER, '''
1052 class A { 1059 class A {
1053 int get test => null; 1060 int get test => null;
1054 } 1061 }
1055 main(A a) { 1062 main(A a) {
1056 var x = a; 1063 var x = a;
1057 int v = x.test; 1064 int v = x.test;
1058 } 1065 }
1059 '''); 1066 ''');
1060 } 1067 }
1061 1068
1062 void test_createGetter_multiLevel() { 1069 void test_createGetter_multiLevel() {
1063 resolveTestUnit(''' 1070 resolveTestUnit('''
1064 class A { 1071 class A {
1065 } 1072 }
1066 class B { 1073 class B {
1067 A a; 1074 A a;
1068 } 1075 }
1069 class C { 1076 class C {
1070 B b; 1077 B b;
1071 } 1078 }
1072 main(C c) { 1079 main(C c) {
1073 int v = c.b.a.test; 1080 int v = c.b.a.test;
1074 } 1081 }
1075 '''); 1082 ''');
1076 assertHasFix(FixKind.CREATE_GETTER, ''' 1083 assertHasFix(DartFixKind.CREATE_GETTER, '''
1077 class A { 1084 class A {
1078 int get test => null; 1085 int get test => null;
1079 } 1086 }
1080 class B { 1087 class B {
1081 A a; 1088 A a;
1082 } 1089 }
1083 class C { 1090 class C {
1084 B b; 1091 B b;
1085 } 1092 }
1086 main(C c) { 1093 main(C c) {
1087 int v = c.b.a.test; 1094 int v = c.b.a.test;
1088 } 1095 }
1089 '''); 1096 ''');
1090 } 1097 }
1091 1098
1092 void test_createGetter_qualified_instance() { 1099 void test_createGetter_qualified_instance() {
1093 resolveTestUnit(''' 1100 resolveTestUnit('''
1094 class A { 1101 class A {
1095 } 1102 }
1096 main(A a) { 1103 main(A a) {
1097 int v = a.test; 1104 int v = a.test;
1098 } 1105 }
1099 '''); 1106 ''');
1100 assertHasFix(FixKind.CREATE_GETTER, ''' 1107 assertHasFix(DartFixKind.CREATE_GETTER, '''
1101 class A { 1108 class A {
1102 int get test => null; 1109 int get test => null;
1103 } 1110 }
1104 main(A a) { 1111 main(A a) {
1105 int v = a.test; 1112 int v = a.test;
1106 } 1113 }
1107 '''); 1114 ''');
1108 } 1115 }
1109 1116
1110 void test_createGetter_qualified_instance_dynamicType() { 1117 void test_createGetter_qualified_instance_dynamicType() {
1111 resolveTestUnit(''' 1118 resolveTestUnit('''
1112 class A { 1119 class A {
1113 B b; 1120 B b;
1114 void f(Object p) { 1121 void f(Object p) {
1115 p == b.test; 1122 p == b.test;
1116 } 1123 }
1117 } 1124 }
1118 class B { 1125 class B {
1119 } 1126 }
1120 '''); 1127 ''');
1121 assertHasFix(FixKind.CREATE_GETTER, ''' 1128 assertHasFix(DartFixKind.CREATE_GETTER, '''
1122 class A { 1129 class A {
1123 B b; 1130 B b;
1124 void f(Object p) { 1131 void f(Object p) {
1125 p == b.test; 1132 p == b.test;
1126 } 1133 }
1127 } 1134 }
1128 class B { 1135 class B {
1129 get test => null; 1136 get test => null;
1130 } 1137 }
1131 '''); 1138 ''');
1132 } 1139 }
1133 1140
1134 void test_createGetter_setterContext() { 1141 void test_createGetter_setterContext() {
1135 resolveTestUnit(''' 1142 resolveTestUnit('''
1136 class A { 1143 class A {
1137 } 1144 }
1138 main(A a) { 1145 main(A a) {
1139 a.test = 42; 1146 a.test = 42;
1140 } 1147 }
1141 '''); 1148 ''');
1142 assertNoFix(FixKind.CREATE_GETTER); 1149 assertNoFix(DartFixKind.CREATE_GETTER);
1143 } 1150 }
1144 1151
1145 void test_createGetter_unqualified_instance_asInvocationArgument() { 1152 void test_createGetter_unqualified_instance_asInvocationArgument() {
1146 resolveTestUnit(''' 1153 resolveTestUnit('''
1147 class A { 1154 class A {
1148 main() { 1155 main() {
1149 f(test); 1156 f(test);
1150 } 1157 }
1151 } 1158 }
1152 f(String s) {} 1159 f(String s) {}
1153 '''); 1160 ''');
1154 assertHasFix(FixKind.CREATE_GETTER, ''' 1161 assertHasFix(DartFixKind.CREATE_GETTER, '''
1155 class A { 1162 class A {
1156 String get test => null; 1163 String get test => null;
1157 1164
1158 main() { 1165 main() {
1159 f(test); 1166 f(test);
1160 } 1167 }
1161 } 1168 }
1162 f(String s) {} 1169 f(String s) {}
1163 '''); 1170 ''');
1164 } 1171 }
1165 1172
1166 void test_createGetter_unqualified_instance_assignmentLhs() { 1173 void test_createGetter_unqualified_instance_assignmentLhs() {
1167 resolveTestUnit(''' 1174 resolveTestUnit('''
1168 class A { 1175 class A {
1169 main() { 1176 main() {
1170 test = 42; 1177 test = 42;
1171 } 1178 }
1172 } 1179 }
1173 '''); 1180 ''');
1174 assertNoFix(FixKind.CREATE_GETTER); 1181 assertNoFix(DartFixKind.CREATE_GETTER);
1175 } 1182 }
1176 1183
1177 void test_createGetter_unqualified_instance_assignmentRhs() { 1184 void test_createGetter_unqualified_instance_assignmentRhs() {
1178 resolveTestUnit(''' 1185 resolveTestUnit('''
1179 class A { 1186 class A {
1180 main() { 1187 main() {
1181 int v = test; 1188 int v = test;
1182 } 1189 }
1183 } 1190 }
1184 '''); 1191 ''');
1185 assertHasFix(FixKind.CREATE_GETTER, ''' 1192 assertHasFix(DartFixKind.CREATE_GETTER, '''
1186 class A { 1193 class A {
1187 int get test => null; 1194 int get test => null;
1188 1195
1189 main() { 1196 main() {
1190 int v = test; 1197 int v = test;
1191 } 1198 }
1192 } 1199 }
1193 '''); 1200 ''');
1194 } 1201 }
1195 1202
1196 void test_createGetter_unqualified_instance_asStatement() { 1203 void test_createGetter_unqualified_instance_asStatement() {
1197 resolveTestUnit(''' 1204 resolveTestUnit('''
1198 class A { 1205 class A {
1199 main() { 1206 main() {
1200 test; 1207 test;
1201 } 1208 }
1202 } 1209 }
1203 '''); 1210 ''');
1204 assertHasFix(FixKind.CREATE_GETTER, ''' 1211 assertHasFix(DartFixKind.CREATE_GETTER, '''
1205 class A { 1212 class A {
1206 get test => null; 1213 get test => null;
1207 1214
1208 main() { 1215 main() {
1209 test; 1216 test;
1210 } 1217 }
1211 } 1218 }
1212 '''); 1219 ''');
1213 } 1220 }
1214 1221
1215 void test_createLocalVariable_functionType_named() { 1222 void test_createLocalVariable_functionType_named() {
1216 resolveTestUnit(''' 1223 resolveTestUnit('''
1217 typedef MY_FUNCTION(int p); 1224 typedef MY_FUNCTION(int p);
1218 foo(MY_FUNCTION f) {} 1225 foo(MY_FUNCTION f) {}
1219 main() { 1226 main() {
1220 foo(bar); 1227 foo(bar);
1221 } 1228 }
1222 '''); 1229 ''');
1223 assertHasFix(FixKind.CREATE_LOCAL_VARIABLE, ''' 1230 assertHasFix(DartFixKind.CREATE_LOCAL_VARIABLE, '''
1224 typedef MY_FUNCTION(int p); 1231 typedef MY_FUNCTION(int p);
1225 foo(MY_FUNCTION f) {} 1232 foo(MY_FUNCTION f) {}
1226 main() { 1233 main() {
1227 MY_FUNCTION bar; 1234 MY_FUNCTION bar;
1228 foo(bar); 1235 foo(bar);
1229 } 1236 }
1230 '''); 1237 ''');
1231 } 1238 }
1232 1239
1233 void test_createLocalVariable_functionType_synthetic() { 1240 void test_createLocalVariable_functionType_synthetic() {
1234 resolveTestUnit(''' 1241 resolveTestUnit('''
1235 foo(f(int p)) {} 1242 foo(f(int p)) {}
1236 main() { 1243 main() {
1237 foo(bar); 1244 foo(bar);
1238 } 1245 }
1239 '''); 1246 ''');
1240 assertNoFix(FixKind.CREATE_LOCAL_VARIABLE); 1247 assertNoFix(DartFixKind.CREATE_LOCAL_VARIABLE);
1241 } 1248 }
1242 1249
1243 void test_createLocalVariable_read_typeAssignment() { 1250 void test_createLocalVariable_read_typeAssignment() {
1244 resolveTestUnit(''' 1251 resolveTestUnit('''
1245 main() { 1252 main() {
1246 int a = test; 1253 int a = test;
1247 } 1254 }
1248 '''); 1255 ''');
1249 assertHasFix(FixKind.CREATE_LOCAL_VARIABLE, ''' 1256 assertHasFix(DartFixKind.CREATE_LOCAL_VARIABLE, '''
1250 main() { 1257 main() {
1251 int test; 1258 int test;
1252 int a = test; 1259 int a = test;
1253 } 1260 }
1254 '''); 1261 ''');
1255 } 1262 }
1256 1263
1257 void test_createLocalVariable_read_typeCondition() { 1264 void test_createLocalVariable_read_typeCondition() {
1258 resolveTestUnit(''' 1265 resolveTestUnit('''
1259 main() { 1266 main() {
1260 if (!test) { 1267 if (!test) {
1261 print(42); 1268 print(42);
1262 } 1269 }
1263 } 1270 }
1264 '''); 1271 ''');
1265 assertHasFix(FixKind.CREATE_LOCAL_VARIABLE, ''' 1272 assertHasFix(DartFixKind.CREATE_LOCAL_VARIABLE, '''
1266 main() { 1273 main() {
1267 bool test; 1274 bool test;
1268 if (!test) { 1275 if (!test) {
1269 print(42); 1276 print(42);
1270 } 1277 }
1271 } 1278 }
1272 '''); 1279 ''');
1273 } 1280 }
1274 1281
1275 void test_createLocalVariable_read_typeInvocationArgument() { 1282 void test_createLocalVariable_read_typeInvocationArgument() {
1276 resolveTestUnit(''' 1283 resolveTestUnit('''
1277 main() { 1284 main() {
1278 f(test); 1285 f(test);
1279 } 1286 }
1280 f(String p) {} 1287 f(String p) {}
1281 '''); 1288 ''');
1282 assertHasFix(FixKind.CREATE_LOCAL_VARIABLE, ''' 1289 assertHasFix(DartFixKind.CREATE_LOCAL_VARIABLE, '''
1283 main() { 1290 main() {
1284 String test; 1291 String test;
1285 f(test); 1292 f(test);
1286 } 1293 }
1287 f(String p) {} 1294 f(String p) {}
1288 '''); 1295 ''');
1289 } 1296 }
1290 1297
1291 void test_createLocalVariable_write_assignment() { 1298 void test_createLocalVariable_write_assignment() {
1292 resolveTestUnit(''' 1299 resolveTestUnit('''
1293 main() { 1300 main() {
1294 test = 42; 1301 test = 42;
1295 } 1302 }
1296 '''); 1303 ''');
1297 assertHasFix(FixKind.CREATE_LOCAL_VARIABLE, ''' 1304 assertHasFix(DartFixKind.CREATE_LOCAL_VARIABLE, '''
1298 main() { 1305 main() {
1299 var test = 42; 1306 var test = 42;
1300 } 1307 }
1301 '''); 1308 ''');
1302 } 1309 }
1303 1310
1304 void test_createLocalVariable_write_assignment_compound() { 1311 void test_createLocalVariable_write_assignment_compound() {
1305 resolveTestUnit(''' 1312 resolveTestUnit('''
1306 main() { 1313 main() {
1307 test += 42; 1314 test += 42;
1308 } 1315 }
1309 '''); 1316 ''');
1310 assertHasFix(FixKind.CREATE_LOCAL_VARIABLE, ''' 1317 assertHasFix(DartFixKind.CREATE_LOCAL_VARIABLE, '''
1311 main() { 1318 main() {
1312 int test; 1319 int test;
1313 test += 42; 1320 test += 42;
1314 } 1321 }
1315 '''); 1322 ''');
1316 } 1323 }
1317 1324
1318 void test_createMissingOverrides_functionTypeAlias() { 1325 void test_createMissingOverrides_functionTypeAlias() {
1319 resolveTestUnit(''' 1326 resolveTestUnit('''
1320 typedef int Binary(int left, int right); 1327 typedef int Binary(int left, int right);
1321 1328
1322 abstract class Emulator { 1329 abstract class Emulator {
1323 void performBinary(Binary binary); 1330 void performBinary(Binary binary);
1324 } 1331 }
1325 1332
1326 class MyEmulator extends Emulator { 1333 class MyEmulator extends Emulator {
1327 } 1334 }
1328 '''); 1335 ''');
1329 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, ''' 1336 assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, '''
1330 typedef int Binary(int left, int right); 1337 typedef int Binary(int left, int right);
1331 1338
1332 abstract class Emulator { 1339 abstract class Emulator {
1333 void performBinary(Binary binary); 1340 void performBinary(Binary binary);
1334 } 1341 }
1335 1342
1336 class MyEmulator extends Emulator { 1343 class MyEmulator extends Emulator {
1337 @override 1344 @override
1338 void performBinary(Binary binary) { 1345 void performBinary(Binary binary) {
1339 // TODO: implement performBinary 1346 // TODO: implement performBinary
1340 } 1347 }
1341 } 1348 }
1342 '''); 1349 ''');
1343 } 1350 }
1344 1351
1345 void test_createMissingOverrides_functionTypedParameter() { 1352 void test_createMissingOverrides_functionTypedParameter() {
1346 resolveTestUnit(''' 1353 resolveTestUnit('''
1347 abstract class A { 1354 abstract class A {
1348 forEach(int f(double p1, String p2)); 1355 forEach(int f(double p1, String p2));
1349 } 1356 }
1350 1357
1351 class B extends A { 1358 class B extends A {
1352 } 1359 }
1353 '''); 1360 ''');
1354 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, ''' 1361 assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, '''
1355 abstract class A { 1362 abstract class A {
1356 forEach(int f(double p1, String p2)); 1363 forEach(int f(double p1, String p2));
1357 } 1364 }
1358 1365
1359 class B extends A { 1366 class B extends A {
1360 @override 1367 @override
1361 forEach(int f(double p1, String p2)) { 1368 forEach(int f(double p1, String p2)) {
1362 // TODO: implement forEach 1369 // TODO: implement forEach
1363 } 1370 }
1364 } 1371 }
1365 '''); 1372 ''');
1366 } 1373 }
1367 1374
1368 void test_createMissingOverrides_generics() { 1375 void test_createMissingOverrides_generics() {
1369 resolveTestUnit(''' 1376 resolveTestUnit('''
1370 class Iterator<T> { 1377 class Iterator<T> {
1371 } 1378 }
1372 1379
1373 abstract class IterableMixin<T> { 1380 abstract class IterableMixin<T> {
1374 Iterator<T> get iterator; 1381 Iterator<T> get iterator;
1375 } 1382 }
1376 1383
1377 class Test extends IterableMixin<int> { 1384 class Test extends IterableMixin<int> {
1378 } 1385 }
1379 '''); 1386 ''');
1380 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, ''' 1387 assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, '''
1381 class Iterator<T> { 1388 class Iterator<T> {
1382 } 1389 }
1383 1390
1384 abstract class IterableMixin<T> { 1391 abstract class IterableMixin<T> {
1385 Iterator<T> get iterator; 1392 Iterator<T> get iterator;
1386 } 1393 }
1387 1394
1388 class Test extends IterableMixin<int> { 1395 class Test extends IterableMixin<int> {
1389 // TODO: implement iterator 1396 // TODO: implement iterator
1390 @override 1397 @override
1391 Iterator<int> get iterator => null; 1398 Iterator<int> get iterator => null;
1392 } 1399 }
1393 '''); 1400 ''');
1394 } 1401 }
1395 1402
1396 void test_createMissingOverrides_getter() { 1403 void test_createMissingOverrides_getter() {
1397 resolveTestUnit(''' 1404 resolveTestUnit('''
1398 abstract class A { 1405 abstract class A {
1399 get g1; 1406 get g1;
1400 int get g2; 1407 int get g2;
1401 } 1408 }
1402 1409
1403 class B extends A { 1410 class B extends A {
1404 } 1411 }
1405 '''); 1412 ''');
1406 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, ''' 1413 assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, '''
1407 abstract class A { 1414 abstract class A {
1408 get g1; 1415 get g1;
1409 int get g2; 1416 int get g2;
1410 } 1417 }
1411 1418
1412 class B extends A { 1419 class B extends A {
1413 // TODO: implement g1 1420 // TODO: implement g1
1414 @override 1421 @override
1415 get g1 => null; 1422 get g1 => null;
1416 1423
1417 // TODO: implement g2 1424 // TODO: implement g2
1418 @override 1425 @override
1419 int get g2 => null; 1426 int get g2 => null;
1420 } 1427 }
1421 '''); 1428 ''');
1422 } 1429 }
1423 1430
1424 void test_createMissingOverrides_importPrefix() { 1431 void test_createMissingOverrides_importPrefix() {
1425 resolveTestUnit(''' 1432 resolveTestUnit('''
1426 import 'dart:async' as aaa; 1433 import 'dart:async' as aaa;
1427 abstract class A { 1434 abstract class A {
1428 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p); 1435 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p);
1429 } 1436 }
1430 1437
1431 class B extends A { 1438 class B extends A {
1432 } 1439 }
1433 '''); 1440 ''');
1434 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, ''' 1441 assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, '''
1435 import 'dart:async' as aaa; 1442 import 'dart:async' as aaa;
1436 abstract class A { 1443 abstract class A {
1437 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p); 1444 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p);
1438 } 1445 }
1439 1446
1440 class B extends A { 1447 class B extends A {
1441 @override 1448 @override
1442 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p) { 1449 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p) {
1443 // TODO: implement g 1450 // TODO: implement g
1444 } 1451 }
1445 } 1452 }
1446 '''); 1453 ''');
1447 } 1454 }
1448 1455
1449 void test_createMissingOverrides_mergeToField_getterSetter() { 1456 void test_createMissingOverrides_mergeToField_getterSetter() {
1450 resolveTestUnit(''' 1457 resolveTestUnit('''
1451 class A { 1458 class A {
1452 int ma; 1459 int ma;
1453 void mb() {} 1460 void mb() {}
1454 double mc; 1461 double mc;
1455 } 1462 }
1456 1463
1457 class B implements A { 1464 class B implements A {
1458 } 1465 }
1459 '''); 1466 ''');
1460 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, ''' 1467 assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, '''
1461 class A { 1468 class A {
1462 int ma; 1469 int ma;
1463 void mb() {} 1470 void mb() {}
1464 double mc; 1471 double mc;
1465 } 1472 }
1466 1473
1467 class B implements A { 1474 class B implements A {
1468 int ma; 1475 int ma;
1469 1476
1470 double mc; 1477 double mc;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 String m5(p1, [int p2 = 2, int p3, p4 = 4]) { 1533 String m5(p1, [int p2 = 2, int p3, p4 = 4]) {
1527 // TODO: implement m5 1534 // TODO: implement m5
1528 } 1535 }
1529 1536
1530 @override 1537 @override
1531 String m6(p1, {int p2: 2, int p3, p4: 4}) { 1538 String m6(p1, {int p2: 2, int p3, p4: 4}) {
1532 // TODO: implement m6 1539 // TODO: implement m6
1533 } 1540 }
1534 } 1541 }
1535 '''; 1542 ''';
1536 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, expectedCode); 1543 assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, expectedCode);
1537 // end position should be on "m1", not on "m2", "m3", etc 1544 // end position should be on "m1", not on "m2", "m3", etc
1538 { 1545 {
1539 Position endPosition = change.selection; 1546 Position endPosition = change.selection;
1540 expect(endPosition, isNotNull); 1547 expect(endPosition, isNotNull);
1541 expect(endPosition.file, testFile); 1548 expect(endPosition.file, testFile);
1542 int endOffset = endPosition.offset; 1549 int endOffset = endPosition.offset;
1543 String endString = expectedCode.substring(endOffset, endOffset + 25); 1550 String endString = expectedCode.substring(endOffset, endOffset + 25);
1544 expect(endString, contains('m1')); 1551 expect(endString, contains('m1'));
1545 expect(endString, isNot(contains('m2'))); 1552 expect(endString, isNot(contains('m2')));
1546 expect(endString, isNot(contains('m3'))); 1553 expect(endString, isNot(contains('m3')));
1547 expect(endString, isNot(contains('m4'))); 1554 expect(endString, isNot(contains('m4')));
1548 expect(endString, isNot(contains('m5'))); 1555 expect(endString, isNot(contains('m5')));
1549 expect(endString, isNot(contains('m6'))); 1556 expect(endString, isNot(contains('m6')));
1550 } 1557 }
1551 } 1558 }
1552 1559
1553 void test_createMissingOverrides_operator() { 1560 void test_createMissingOverrides_operator() {
1554 resolveTestUnit(''' 1561 resolveTestUnit('''
1555 abstract class A { 1562 abstract class A {
1556 int operator [](int index); 1563 int operator [](int index);
1557 void operator []=(int index, String value); 1564 void operator []=(int index, String value);
1558 } 1565 }
1559 1566
1560 class B extends A { 1567 class B extends A {
1561 } 1568 }
1562 '''); 1569 ''');
1563 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, ''' 1570 assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, '''
1564 abstract class A { 1571 abstract class A {
1565 int operator [](int index); 1572 int operator [](int index);
1566 void operator []=(int index, String value); 1573 void operator []=(int index, String value);
1567 } 1574 }
1568 1575
1569 class B extends A { 1576 class B extends A {
1570 @override 1577 @override
1571 int operator [](int index) { 1578 int operator [](int index) {
1572 // TODO: implement [] 1579 // TODO: implement []
1573 } 1580 }
(...skipping 10 matching lines...) Expand all
1584 resolveTestUnit(''' 1591 resolveTestUnit('''
1585 abstract class A { 1592 abstract class A {
1586 set s1(x); 1593 set s1(x);
1587 set s2(int x); 1594 set s2(int x);
1588 void set s3(String x); 1595 void set s3(String x);
1589 } 1596 }
1590 1597
1591 class B extends A { 1598 class B extends A {
1592 } 1599 }
1593 '''); 1600 ''');
1594 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, ''' 1601 assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, '''
1595 abstract class A { 1602 abstract class A {
1596 set s1(x); 1603 set s1(x);
1597 set s2(int x); 1604 set s2(int x);
1598 void set s3(String x); 1605 void set s3(String x);
1599 } 1606 }
1600 1607
1601 class B extends A { 1608 class B extends A {
1602 @override 1609 @override
1603 set s1(x) { 1610 set s1(x) {
1604 // TODO: implement s1 1611 // TODO: implement s1
(...skipping 16 matching lines...) Expand all
1621 resolveTestUnit(''' 1628 resolveTestUnit('''
1622 abstract class A { 1629 abstract class A {
1623 m1(); 1630 m1();
1624 int m2(); 1631 int m2();
1625 } 1632 }
1626 1633
1627 class B extends A { 1634 class B extends A {
1628 existing() {} 1635 existing() {}
1629 } 1636 }
1630 '''); 1637 ''');
1631 assertHasFix(FixKind.CREATE_NO_SUCH_METHOD, ''' 1638 assertHasFix(DartFixKind.CREATE_NO_SUCH_METHOD, '''
1632 abstract class A { 1639 abstract class A {
1633 m1(); 1640 m1();
1634 int m2(); 1641 int m2();
1635 } 1642 }
1636 1643
1637 class B extends A { 1644 class B extends A {
1638 existing() {} 1645 existing() {}
1639 1646
1640 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 1647 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
1641 } 1648 }
1642 '''); 1649 ''');
1643 } 1650 }
1644 1651
1645 void test_creatGetter_location_afterLastGetter() { 1652 void test_creatGetter_location_afterLastGetter() {
1646 resolveTestUnit(''' 1653 resolveTestUnit('''
1647 class A { 1654 class A {
1648 int existingField; 1655 int existingField;
1649 1656
1650 int get existingGetter => null; 1657 int get existingGetter => null;
1651 1658
1652 existingMethod() {} 1659 existingMethod() {}
1653 } 1660 }
1654 main(A a) { 1661 main(A a) {
1655 int v = a.test; 1662 int v = a.test;
1656 } 1663 }
1657 '''); 1664 ''');
1658 assertHasFix(FixKind.CREATE_GETTER, ''' 1665 assertHasFix(DartFixKind.CREATE_GETTER, '''
1659 class A { 1666 class A {
1660 int existingField; 1667 int existingField;
1661 1668
1662 int get existingGetter => null; 1669 int get existingGetter => null;
1663 1670
1664 int get test => null; 1671 int get test => null;
1665 1672
1666 existingMethod() {} 1673 existingMethod() {}
1667 } 1674 }
1668 main(A a) { 1675 main(A a) {
1669 int v = a.test; 1676 int v = a.test;
1670 } 1677 }
1671 '''); 1678 ''');
1672 } 1679 }
1673 1680
1674 void test_creationFunction_forFunctionType_cascadeSecond() { 1681 void test_creationFunction_forFunctionType_cascadeSecond() {
1675 resolveTestUnit(''' 1682 resolveTestUnit('''
1676 class A { 1683 class A {
1677 B ma() => null; 1684 B ma() => null;
1678 } 1685 }
1679 class B { 1686 class B {
1680 useFunction(int g(double a, String b)) {} 1687 useFunction(int g(double a, String b)) {}
1681 } 1688 }
1682 1689
1683 main() { 1690 main() {
1684 A a = new A(); 1691 A a = new A();
1685 a..ma().useFunction(test); 1692 a..ma().useFunction(test);
1686 } 1693 }
1687 '''); 1694 ''');
1688 assertHasFix(FixKind.CREATE_FUNCTION, ''' 1695 assertHasFix(DartFixKind.CREATE_FUNCTION, '''
1689 class A { 1696 class A {
1690 B ma() => null; 1697 B ma() => null;
1691 } 1698 }
1692 class B { 1699 class B {
1693 useFunction(int g(double a, String b)) {} 1700 useFunction(int g(double a, String b)) {}
1694 } 1701 }
1695 1702
1696 main() { 1703 main() {
1697 A a = new A(); 1704 A a = new A();
1698 a..ma().useFunction(test); 1705 a..ma().useFunction(test);
1699 } 1706 }
1700 1707
1701 int test(double a, String b) { 1708 int test(double a, String b) {
1702 } 1709 }
1703 '''); 1710 ''');
1704 } 1711 }
1705 1712
1706 void test_creationFunction_forFunctionType_coreFunction() { 1713 void test_creationFunction_forFunctionType_coreFunction() {
1707 resolveTestUnit(''' 1714 resolveTestUnit('''
1708 main() { 1715 main() {
1709 useFunction(g: test); 1716 useFunction(g: test);
1710 } 1717 }
1711 useFunction({Function g}) {} 1718 useFunction({Function g}) {}
1712 '''); 1719 ''');
1713 assertHasFix(FixKind.CREATE_FUNCTION, ''' 1720 assertHasFix(DartFixKind.CREATE_FUNCTION, '''
1714 main() { 1721 main() {
1715 useFunction(g: test); 1722 useFunction(g: test);
1716 } 1723 }
1717 useFunction({Function g}) {} 1724 useFunction({Function g}) {}
1718 1725
1719 test() { 1726 test() {
1720 } 1727 }
1721 '''); 1728 ''');
1722 } 1729 }
1723 1730
1724 void test_creationFunction_forFunctionType_dynamicArgument() { 1731 void test_creationFunction_forFunctionType_dynamicArgument() {
1725 resolveTestUnit(''' 1732 resolveTestUnit('''
1726 main() { 1733 main() {
1727 useFunction(test); 1734 useFunction(test);
1728 } 1735 }
1729 useFunction(int g(a, b)) {} 1736 useFunction(int g(a, b)) {}
1730 '''); 1737 ''');
1731 assertHasFix(FixKind.CREATE_FUNCTION, ''' 1738 assertHasFix(DartFixKind.CREATE_FUNCTION, '''
1732 main() { 1739 main() {
1733 useFunction(test); 1740 useFunction(test);
1734 } 1741 }
1735 useFunction(int g(a, b)) {} 1742 useFunction(int g(a, b)) {}
1736 1743
1737 int test(a, b) { 1744 int test(a, b) {
1738 } 1745 }
1739 '''); 1746 ''');
1740 } 1747 }
1741 1748
1742 void test_creationFunction_forFunctionType_function() { 1749 void test_creationFunction_forFunctionType_function() {
1743 resolveTestUnit(''' 1750 resolveTestUnit('''
1744 main() { 1751 main() {
1745 useFunction(test); 1752 useFunction(test);
1746 } 1753 }
1747 useFunction(int g(double a, String b)) {} 1754 useFunction(int g(double a, String b)) {}
1748 '''); 1755 ''');
1749 assertHasFix(FixKind.CREATE_FUNCTION, ''' 1756 assertHasFix(DartFixKind.CREATE_FUNCTION, '''
1750 main() { 1757 main() {
1751 useFunction(test); 1758 useFunction(test);
1752 } 1759 }
1753 useFunction(int g(double a, String b)) {} 1760 useFunction(int g(double a, String b)) {}
1754 1761
1755 int test(double a, String b) { 1762 int test(double a, String b) {
1756 } 1763 }
1757 '''); 1764 ''');
1758 } 1765 }
1759 1766
1760 void test_creationFunction_forFunctionType_function_namedArgument() { 1767 void test_creationFunction_forFunctionType_function_namedArgument() {
1761 resolveTestUnit(''' 1768 resolveTestUnit('''
1762 main() { 1769 main() {
1763 useFunction(g: test); 1770 useFunction(g: test);
1764 } 1771 }
1765 useFunction({int g(double a, String b)}) {} 1772 useFunction({int g(double a, String b)}) {}
1766 '''); 1773 ''');
1767 assertHasFix(FixKind.CREATE_FUNCTION, ''' 1774 assertHasFix(DartFixKind.CREATE_FUNCTION, '''
1768 main() { 1775 main() {
1769 useFunction(g: test); 1776 useFunction(g: test);
1770 } 1777 }
1771 useFunction({int g(double a, String b)}) {} 1778 useFunction({int g(double a, String b)}) {}
1772 1779
1773 int test(double a, String b) { 1780 int test(double a, String b) {
1774 } 1781 }
1775 '''); 1782 ''');
1776 } 1783 }
1777 1784
1778 void test_creationFunction_forFunctionType_importType() { 1785 void test_creationFunction_forFunctionType_importType() {
1779 addSource('/libA.dart', r''' 1786 addSource('/libA.dart', r'''
1780 library libA; 1787 library libA;
1781 class A {} 1788 class A {}
1782 '''); 1789 ''');
1783 addSource('/libB.dart', r''' 1790 addSource('/libB.dart', r'''
1784 library libB; 1791 library libB;
1785 import 'libA.dart'; 1792 import 'libA.dart';
1786 useFunction(int g(A a)) {} 1793 useFunction(int g(A a)) {}
1787 '''); 1794 ''');
1788 resolveTestUnit(''' 1795 resolveTestUnit('''
1789 import 'libB.dart'; 1796 import 'libB.dart';
1790 main() { 1797 main() {
1791 useFunction(test); 1798 useFunction(test);
1792 } 1799 }
1793 '''); 1800 ''');
1794 assertHasFix(FixKind.CREATE_FUNCTION, ''' 1801 assertHasFix(DartFixKind.CREATE_FUNCTION, '''
1795 import 'libB.dart'; 1802 import 'libB.dart';
1796 import 'libA.dart'; 1803 import 'libA.dart';
1797 main() { 1804 main() {
1798 useFunction(test); 1805 useFunction(test);
1799 } 1806 }
1800 1807
1801 int test(A a) { 1808 int test(A a) {
1802 } 1809 }
1803 '''); 1810 ''');
1804 } 1811 }
1805 1812
1806 void test_creationFunction_forFunctionType_method_enclosingClass_static() { 1813 void test_creationFunction_forFunctionType_method_enclosingClass_static() {
1807 resolveTestUnit(''' 1814 resolveTestUnit('''
1808 class A { 1815 class A {
1809 static foo() { 1816 static foo() {
1810 useFunction(test); 1817 useFunction(test);
1811 } 1818 }
1812 } 1819 }
1813 useFunction(int g(double a, String b)) {} 1820 useFunction(int g(double a, String b)) {}
1814 '''); 1821 ''');
1815 assertHasFix(FixKind.CREATE_METHOD, ''' 1822 assertHasFix(DartFixKind.CREATE_METHOD, '''
1816 class A { 1823 class A {
1817 static foo() { 1824 static foo() {
1818 useFunction(test); 1825 useFunction(test);
1819 } 1826 }
1820 1827
1821 static int test(double a, String b) { 1828 static int test(double a, String b) {
1822 } 1829 }
1823 } 1830 }
1824 useFunction(int g(double a, String b)) {} 1831 useFunction(int g(double a, String b)) {}
1825 '''); 1832 ''');
1826 } 1833 }
1827 1834
1828 void test_creationFunction_forFunctionType_method_enclosingClass_static2() { 1835 void test_creationFunction_forFunctionType_method_enclosingClass_static2() {
1829 resolveTestUnit(''' 1836 resolveTestUnit('''
1830 class A { 1837 class A {
1831 var f; 1838 var f;
1832 A() : f = useFunction(test); 1839 A() : f = useFunction(test);
1833 } 1840 }
1834 useFunction(int g(double a, String b)) {} 1841 useFunction(int g(double a, String b)) {}
1835 '''); 1842 ''');
1836 assertHasFix(FixKind.CREATE_METHOD, ''' 1843 assertHasFix(DartFixKind.CREATE_METHOD, '''
1837 class A { 1844 class A {
1838 var f; 1845 var f;
1839 A() : f = useFunction(test); 1846 A() : f = useFunction(test);
1840 1847
1841 static int test(double a, String b) { 1848 static int test(double a, String b) {
1842 } 1849 }
1843 } 1850 }
1844 useFunction(int g(double a, String b)) {} 1851 useFunction(int g(double a, String b)) {}
1845 '''); 1852 ''');
1846 } 1853 }
1847 1854
1848 void test_creationFunction_forFunctionType_method_targetClass() { 1855 void test_creationFunction_forFunctionType_method_targetClass() {
1849 resolveTestUnit(''' 1856 resolveTestUnit('''
1850 main(A a) { 1857 main(A a) {
1851 useFunction(a.test); 1858 useFunction(a.test);
1852 } 1859 }
1853 class A { 1860 class A {
1854 } 1861 }
1855 useFunction(int g(double a, String b)) {} 1862 useFunction(int g(double a, String b)) {}
1856 '''); 1863 ''');
1857 assertHasFix(FixKind.CREATE_METHOD, ''' 1864 assertHasFix(DartFixKind.CREATE_METHOD, '''
1858 main(A a) { 1865 main(A a) {
1859 useFunction(a.test); 1866 useFunction(a.test);
1860 } 1867 }
1861 class A { 1868 class A {
1862 int test(double a, String b) { 1869 int test(double a, String b) {
1863 } 1870 }
1864 } 1871 }
1865 useFunction(int g(double a, String b)) {} 1872 useFunction(int g(double a, String b)) {}
1866 '''); 1873 ''');
1867 } 1874 }
1868 1875
1869 void test_creationFunction_forFunctionType_method_targetClass_hasOtherMember() { 1876 void test_creationFunction_forFunctionType_method_targetClass_hasOtherMember() {
1870 resolveTestUnit(''' 1877 resolveTestUnit('''
1871 main(A a) { 1878 main(A a) {
1872 useFunction(a.test); 1879 useFunction(a.test);
1873 } 1880 }
1874 class A { 1881 class A {
1875 m() {} 1882 m() {}
1876 } 1883 }
1877 useFunction(int g(double a, String b)) {} 1884 useFunction(int g(double a, String b)) {}
1878 '''); 1885 ''');
1879 assertHasFix(FixKind.CREATE_METHOD, ''' 1886 assertHasFix(DartFixKind.CREATE_METHOD, '''
1880 main(A a) { 1887 main(A a) {
1881 useFunction(a.test); 1888 useFunction(a.test);
1882 } 1889 }
1883 class A { 1890 class A {
1884 m() {} 1891 m() {}
1885 1892
1886 int test(double a, String b) { 1893 int test(double a, String b) {
1887 } 1894 }
1888 } 1895 }
1889 useFunction(int g(double a, String b)) {} 1896 useFunction(int g(double a, String b)) {}
1890 '''); 1897 ''');
1891 } 1898 }
1892 1899
1893 void test_creationFunction_forFunctionType_notFunctionType() { 1900 void test_creationFunction_forFunctionType_notFunctionType() {
1894 resolveTestUnit(''' 1901 resolveTestUnit('''
1895 main(A a) { 1902 main(A a) {
1896 useFunction(a.test); 1903 useFunction(a.test);
1897 } 1904 }
1898 typedef A(); 1905 typedef A();
1899 useFunction(g) {} 1906 useFunction(g) {}
1900 '''); 1907 ''');
1901 assertNoFix(FixKind.CREATE_METHOD); 1908 assertNoFix(DartFixKind.CREATE_METHOD);
1902 assertNoFix(FixKind.CREATE_FUNCTION); 1909 assertNoFix(DartFixKind.CREATE_FUNCTION);
1903 } 1910 }
1904 1911
1905 void test_creationFunction_forFunctionType_unknownTarget() { 1912 void test_creationFunction_forFunctionType_unknownTarget() {
1906 resolveTestUnit(''' 1913 resolveTestUnit('''
1907 main(A a) { 1914 main(A a) {
1908 useFunction(a.test); 1915 useFunction(a.test);
1909 } 1916 }
1910 class A { 1917 class A {
1911 } 1918 }
1912 useFunction(g) {} 1919 useFunction(g) {}
1913 '''); 1920 ''');
1914 assertNoFix(FixKind.CREATE_METHOD); 1921 assertNoFix(DartFixKind.CREATE_METHOD);
1915 } 1922 }
1916 1923
1917 void test_expectedToken_semicolon() { 1924 void test_expectedToken_semicolon() {
1918 resolveTestUnit(''' 1925 resolveTestUnit('''
1919 main() { 1926 main() {
1920 print(0) 1927 print(0)
1921 } 1928 }
1922 '''); 1929 ''');
1923 assertHasFix(FixKind.INSERT_SEMICOLON, ''' 1930 assertHasFix(DartFixKind.INSERT_SEMICOLON, '''
1924 main() { 1931 main() {
1925 print(0); 1932 print(0);
1926 } 1933 }
1927 '''); 1934 ''');
1928 } 1935 }
1929 1936
1930 void test_illegalAsyncReturnType_asyncLibrary_import() { 1937 void test_illegalAsyncReturnType_asyncLibrary_import() {
1931 errorFilter = (AnalysisError error) { 1938 errorFilter = (AnalysisError error) {
1932 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; 1939 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE;
1933 }; 1940 };
1934 resolveTestUnit(''' 1941 resolveTestUnit('''
1935 library main; 1942 library main;
1936 int main() async { 1943 int main() async {
1937 } 1944 }
1938 '''); 1945 ''');
1939 assertHasFix(FixKind.REPLACE_RETURN_TYPE_FUTURE, ''' 1946 assertHasFix(DartFixKind.REPLACE_RETURN_TYPE_FUTURE, '''
1940 library main; 1947 library main;
1941 import 'dart:async'; 1948 import 'dart:async';
1942 Future<int> main() async { 1949 Future<int> main() async {
1943 } 1950 }
1944 '''); 1951 ''');
1945 } 1952 }
1946 1953
1947 void test_illegalAsyncReturnType_asyncLibrary_usePrefix() { 1954 void test_illegalAsyncReturnType_asyncLibrary_usePrefix() {
1948 errorFilter = (AnalysisError error) { 1955 errorFilter = (AnalysisError error) {
1949 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; 1956 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE;
1950 }; 1957 };
1951 resolveTestUnit(''' 1958 resolveTestUnit('''
1952 import 'dart:async' as al; 1959 import 'dart:async' as al;
1953 int main() async { 1960 int main() async {
1954 } 1961 }
1955 '''); 1962 ''');
1956 assertHasFix(FixKind.REPLACE_RETURN_TYPE_FUTURE, ''' 1963 assertHasFix(DartFixKind.REPLACE_RETURN_TYPE_FUTURE, '''
1957 import 'dart:async' as al; 1964 import 'dart:async' as al;
1958 al.Future<int> main() async { 1965 al.Future<int> main() async {
1959 } 1966 }
1960 '''); 1967 ''');
1961 } 1968 }
1962 1969
1963 void test_illegalAsyncReturnType_complexTypeName() { 1970 void test_illegalAsyncReturnType_complexTypeName() {
1964 errorFilter = (AnalysisError error) { 1971 errorFilter = (AnalysisError error) {
1965 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; 1972 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE;
1966 }; 1973 };
1967 resolveTestUnit(''' 1974 resolveTestUnit('''
1968 import 'dart:async'; 1975 import 'dart:async';
1969 List<int> main() async { 1976 List<int> main() async {
1970 } 1977 }
1971 '''); 1978 ''');
1972 assertHasFix(FixKind.REPLACE_RETURN_TYPE_FUTURE, ''' 1979 assertHasFix(DartFixKind.REPLACE_RETURN_TYPE_FUTURE, '''
1973 import 'dart:async'; 1980 import 'dart:async';
1974 Future<List<int>> main() async { 1981 Future<List<int>> main() async {
1975 } 1982 }
1976 '''); 1983 ''');
1977 } 1984 }
1978 1985
1979 void test_illegalAsyncReturnType_void() { 1986 void test_illegalAsyncReturnType_void() {
1980 errorFilter = (AnalysisError error) { 1987 errorFilter = (AnalysisError error) {
1981 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; 1988 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE;
1982 }; 1989 };
1983 resolveTestUnit(''' 1990 resolveTestUnit('''
1984 import 'dart:async'; 1991 import 'dart:async';
1985 void main() async { 1992 void main() async {
1986 } 1993 }
1987 '''); 1994 ''');
1988 assertHasFix(FixKind.REPLACE_RETURN_TYPE_FUTURE, ''' 1995 assertHasFix(DartFixKind.REPLACE_RETURN_TYPE_FUTURE, '''
1989 import 'dart:async'; 1996 import 'dart:async';
1990 Future main() async { 1997 Future main() async {
1991 } 1998 }
1992 '''); 1999 ''');
1993 } 2000 }
1994 2001
1995 void test_importLibraryPackage_withClass() { 2002 void test_importLibraryPackage_withClass() {
1996 _configureMyPkg(''' 2003 _configureMyPkg('''
1997 library my_lib; 2004 library my_lib;
1998 class Test {} 2005 class Test {}
1999 '''); 2006 ''');
2000 // try to find a fix 2007 // try to find a fix
2001 resolveTestUnit(''' 2008 resolveTestUnit('''
2002 main() { 2009 main() {
2003 Test test = null; 2010 Test test = null;
2004 } 2011 }
2005 '''); 2012 ''');
2006 performAllAnalysisTasks(); 2013 performAllAnalysisTasks();
2007 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' 2014 assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT, '''
2008 import 'package:my_pkg/my_lib.dart'; 2015 import 'package:my_pkg/my_lib.dart';
2009 2016
2010 main() { 2017 main() {
2011 Test test = null; 2018 Test test = null;
2012 } 2019 }
2013 '''); 2020 ''');
2014 } 2021 }
2015 2022
2016 void test_importLibraryPrefix_withClass() { 2023 void test_importLibraryPrefix_withClass() {
2017 resolveTestUnit(''' 2024 resolveTestUnit('''
2018 import 'dart:async' as pref; 2025 import 'dart:async' as pref;
2019 main() { 2026 main() {
2020 pref.Stream s = null; 2027 pref.Stream s = null;
2021 Future f = null; 2028 Future f = null;
2022 } 2029 }
2023 '''); 2030 ''');
2024 assertHasFix(FixKind.IMPORT_LIBRARY_PREFIX, ''' 2031 assertHasFix(DartFixKind.IMPORT_LIBRARY_PREFIX, '''
2025 import 'dart:async' as pref; 2032 import 'dart:async' as pref;
2026 main() { 2033 main() {
2027 pref.Stream s = null; 2034 pref.Stream s = null;
2028 pref.Future f = null; 2035 pref.Future f = null;
2029 } 2036 }
2030 '''); 2037 ''');
2031 } 2038 }
2032 2039
2033 void test_importLibraryPrefix_withTopLevelVariable() { 2040 void test_importLibraryPrefix_withTopLevelVariable() {
2034 resolveTestUnit(''' 2041 resolveTestUnit('''
2035 import 'dart:math' as pref; 2042 import 'dart:math' as pref;
2036 main() { 2043 main() {
2037 print(pref.E); 2044 print(pref.E);
2038 print(PI); 2045 print(PI);
2039 } 2046 }
2040 '''); 2047 ''');
2041 assertHasFix(FixKind.IMPORT_LIBRARY_PREFIX, ''' 2048 assertHasFix(DartFixKind.IMPORT_LIBRARY_PREFIX, '''
2042 import 'dart:math' as pref; 2049 import 'dart:math' as pref;
2043 main() { 2050 main() {
2044 print(pref.E); 2051 print(pref.E);
2045 print(pref.PI); 2052 print(pref.PI);
2046 } 2053 }
2047 '''); 2054 ''');
2048 } 2055 }
2049 2056
2050 void test_importLibraryProject_withClass_annotation() { 2057 void test_importLibraryProject_withClass_annotation() {
2051 addSource('/lib.dart', ''' 2058 addSource('/lib.dart', '''
2052 library lib; 2059 library lib;
2053 class Test { 2060 class Test {
2054 const Test(int p); 2061 const Test(int p);
2055 } 2062 }
2056 '''); 2063 ''');
2057 resolveTestUnit(''' 2064 resolveTestUnit('''
2058 @Test(0) 2065 @Test(0)
2059 main() { 2066 main() {
2060 } 2067 }
2061 '''); 2068 ''');
2062 performAllAnalysisTasks(); 2069 performAllAnalysisTasks();
2063 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' 2070 assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT, '''
2064 import 'lib.dart'; 2071 import 'lib.dart';
2065 2072
2066 @Test(0) 2073 @Test(0)
2067 main() { 2074 main() {
2068 } 2075 }
2069 '''); 2076 ''');
2070 } 2077 }
2071 2078
2072 void test_importLibraryProject_withClass_inParentFolder() { 2079 void test_importLibraryProject_withClass_inParentFolder() {
2073 testFile = '/project/bin/test.dart'; 2080 testFile = '/project/bin/test.dart';
2074 addSource('/project/lib.dart', ''' 2081 addSource('/project/lib.dart', '''
2075 library lib; 2082 library lib;
2076 class Test {} 2083 class Test {}
2077 '''); 2084 ''');
2078 resolveTestUnit(''' 2085 resolveTestUnit('''
2079 main() { 2086 main() {
2080 Test t = null; 2087 Test t = null;
2081 } 2088 }
2082 '''); 2089 ''');
2083 performAllAnalysisTasks(); 2090 performAllAnalysisTasks();
2084 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' 2091 assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT, '''
2085 import '../lib.dart'; 2092 import '../lib.dart';
2086 2093
2087 main() { 2094 main() {
2088 Test t = null; 2095 Test t = null;
2089 } 2096 }
2090 '''); 2097 ''');
2091 } 2098 }
2092 2099
2093 void test_importLibraryProject_withClass_inRelativeFolder() { 2100 void test_importLibraryProject_withClass_inRelativeFolder() {
2094 testFile = '/project/bin/test.dart'; 2101 testFile = '/project/bin/test.dart';
2095 addSource('/project/lib/sub/folder/lib.dart', ''' 2102 addSource('/project/lib/sub/folder/lib.dart', '''
2096 library lib; 2103 library lib;
2097 class Test {} 2104 class Test {}
2098 '''); 2105 ''');
2099 resolveTestUnit(''' 2106 resolveTestUnit('''
2100 main() { 2107 main() {
2101 Test t = null; 2108 Test t = null;
2102 } 2109 }
2103 '''); 2110 ''');
2104 performAllAnalysisTasks(); 2111 performAllAnalysisTasks();
2105 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' 2112 assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT, '''
2106 import '../lib/sub/folder/lib.dart'; 2113 import '../lib/sub/folder/lib.dart';
2107 2114
2108 main() { 2115 main() {
2109 Test t = null; 2116 Test t = null;
2110 } 2117 }
2111 '''); 2118 ''');
2112 } 2119 }
2113 2120
2114 void test_importLibraryProject_withClass_inSameFolder() { 2121 void test_importLibraryProject_withClass_inSameFolder() {
2115 testFile = '/project/bin/test.dart'; 2122 testFile = '/project/bin/test.dart';
2116 addSource('/project/bin/lib.dart', ''' 2123 addSource('/project/bin/lib.dart', '''
2117 library lib; 2124 library lib;
2118 class Test {} 2125 class Test {}
2119 '''); 2126 ''');
2120 resolveTestUnit(''' 2127 resolveTestUnit('''
2121 main() { 2128 main() {
2122 Test t = null; 2129 Test t = null;
2123 } 2130 }
2124 '''); 2131 ''');
2125 performAllAnalysisTasks(); 2132 performAllAnalysisTasks();
2126 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' 2133 assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT, '''
2127 import 'lib.dart'; 2134 import 'lib.dart';
2128 2135
2129 main() { 2136 main() {
2130 Test t = null; 2137 Test t = null;
2131 } 2138 }
2132 '''); 2139 ''');
2133 } 2140 }
2134 2141
2135 void test_importLibraryProject_withFunction() { 2142 void test_importLibraryProject_withFunction() {
2136 addSource('/lib.dart', ''' 2143 addSource('/lib.dart', '''
2137 library lib; 2144 library lib;
2138 myFunction() {} 2145 myFunction() {}
2139 '''); 2146 ''');
2140 resolveTestUnit(''' 2147 resolveTestUnit('''
2141 main() { 2148 main() {
2142 myFunction(); 2149 myFunction();
2143 } 2150 }
2144 '''); 2151 ''');
2145 performAllAnalysisTasks(); 2152 performAllAnalysisTasks();
2146 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' 2153 assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT, '''
2147 import 'lib.dart'; 2154 import 'lib.dart';
2148 2155
2149 main() { 2156 main() {
2150 myFunction(); 2157 myFunction();
2151 } 2158 }
2152 '''); 2159 ''');
2153 } 2160 }
2154 2161
2155 void test_importLibraryProject_withFunction_unresolvedMethod() { 2162 void test_importLibraryProject_withFunction_unresolvedMethod() {
2156 addSource('/lib.dart', ''' 2163 addSource('/lib.dart', '''
2157 library lib; 2164 library lib;
2158 myFunction() {} 2165 myFunction() {}
2159 '''); 2166 ''');
2160 resolveTestUnit(''' 2167 resolveTestUnit('''
2161 class A { 2168 class A {
2162 main() { 2169 main() {
2163 myFunction(); 2170 myFunction();
2164 } 2171 }
2165 } 2172 }
2166 '''); 2173 ''');
2167 performAllAnalysisTasks(); 2174 performAllAnalysisTasks();
2168 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' 2175 assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT, '''
2169 import 'lib.dart'; 2176 import 'lib.dart';
2170 2177
2171 class A { 2178 class A {
2172 main() { 2179 main() {
2173 myFunction(); 2180 myFunction();
2174 } 2181 }
2175 } 2182 }
2176 '''); 2183 ''');
2177 } 2184 }
2178 2185
2179 void test_importLibraryProject_withFunctionTypeAlias() { 2186 void test_importLibraryProject_withFunctionTypeAlias() {
2180 testFile = '/project/bin/test.dart'; 2187 testFile = '/project/bin/test.dart';
2181 addSource('/project/bin/lib.dart', ''' 2188 addSource('/project/bin/lib.dart', '''
2182 library lib; 2189 library lib;
2183 typedef MyFunction(); 2190 typedef MyFunction();
2184 '''); 2191 ''');
2185 resolveTestUnit(''' 2192 resolveTestUnit('''
2186 main() { 2193 main() {
2187 MyFunction t = null; 2194 MyFunction t = null;
2188 } 2195 }
2189 '''); 2196 ''');
2190 performAllAnalysisTasks(); 2197 performAllAnalysisTasks();
2191 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' 2198 assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT, '''
2192 import 'lib.dart'; 2199 import 'lib.dart';
2193 2200
2194 main() { 2201 main() {
2195 MyFunction t = null; 2202 MyFunction t = null;
2196 } 2203 }
2197 '''); 2204 ''');
2198 } 2205 }
2199 2206
2200 void test_importLibraryProject_withTopLevelVariable() { 2207 void test_importLibraryProject_withTopLevelVariable() {
2201 addSource('/lib.dart', ''' 2208 addSource('/lib.dart', '''
2202 library lib; 2209 library lib;
2203 int MY_VAR = 42; 2210 int MY_VAR = 42;
2204 '''); 2211 ''');
2205 resolveTestUnit(''' 2212 resolveTestUnit('''
2206 main() { 2213 main() {
2207 print(MY_VAR); 2214 print(MY_VAR);
2208 } 2215 }
2209 '''); 2216 ''');
2210 performAllAnalysisTasks(); 2217 performAllAnalysisTasks();
2211 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' 2218 assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT, '''
2212 import 'lib.dart'; 2219 import 'lib.dart';
2213 2220
2214 main() { 2221 main() {
2215 print(MY_VAR); 2222 print(MY_VAR);
2216 } 2223 }
2217 '''); 2224 ''');
2218 } 2225 }
2219 2226
2220 void test_importLibrarySdk_withClass_AsExpression() { 2227 void test_importLibrarySdk_withClass_AsExpression() {
2221 resolveTestUnit(''' 2228 resolveTestUnit('''
2222 main(p) { 2229 main(p) {
2223 p as Future; 2230 p as Future;
2224 } 2231 }
2225 '''); 2232 ''');
2226 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' 2233 assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, '''
2227 import 'dart:async'; 2234 import 'dart:async';
2228 2235
2229 main(p) { 2236 main(p) {
2230 p as Future; 2237 p as Future;
2231 } 2238 }
2232 '''); 2239 ''');
2233 } 2240 }
2234 2241
2235 void test_importLibrarySdk_withClass_invocationTarget() { 2242 void test_importLibrarySdk_withClass_invocationTarget() {
2236 resolveTestUnit(''' 2243 resolveTestUnit('''
2237 main() { 2244 main() {
2238 Future.wait(null); 2245 Future.wait(null);
2239 } 2246 }
2240 '''); 2247 ''');
2241 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' 2248 assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, '''
2242 import 'dart:async'; 2249 import 'dart:async';
2243 2250
2244 main() { 2251 main() {
2245 Future.wait(null); 2252 Future.wait(null);
2246 } 2253 }
2247 '''); 2254 ''');
2248 } 2255 }
2249 2256
2250 void test_importLibrarySdk_withClass_IsExpression() { 2257 void test_importLibrarySdk_withClass_IsExpression() {
2251 resolveTestUnit(''' 2258 resolveTestUnit('''
2252 main(p) { 2259 main(p) {
2253 p is Future; 2260 p is Future;
2254 } 2261 }
2255 '''); 2262 ''');
2256 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' 2263 assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, '''
2257 import 'dart:async'; 2264 import 'dart:async';
2258 2265
2259 main(p) { 2266 main(p) {
2260 p is Future; 2267 p is Future;
2261 } 2268 }
2262 '''); 2269 ''');
2263 } 2270 }
2264 2271
2265 void test_importLibrarySdk_withClass_typeAnnotation() { 2272 void test_importLibrarySdk_withClass_typeAnnotation() {
2266 resolveTestUnit(''' 2273 resolveTestUnit('''
2267 main() { 2274 main() {
2268 Future f = null; 2275 Future f = null;
2269 } 2276 }
2270 '''); 2277 ''');
2271 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' 2278 assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, '''
2272 import 'dart:async'; 2279 import 'dart:async';
2273 2280
2274 main() { 2281 main() {
2275 Future f = null; 2282 Future f = null;
2276 } 2283 }
2277 '''); 2284 ''');
2278 } 2285 }
2279 2286
2280 void test_importLibrarySdk_withClass_typeAnnotation_PrefixedIdentifier() { 2287 void test_importLibrarySdk_withClass_typeAnnotation_PrefixedIdentifier() {
2281 resolveTestUnit(''' 2288 resolveTestUnit('''
2282 main() { 2289 main() {
2283 Future.wait; 2290 Future.wait;
2284 } 2291 }
2285 '''); 2292 ''');
2286 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' 2293 assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, '''
2287 import 'dart:async'; 2294 import 'dart:async';
2288 2295
2289 main() { 2296 main() {
2290 Future.wait; 2297 Future.wait;
2291 } 2298 }
2292 '''); 2299 ''');
2293 } 2300 }
2294 2301
2295 void test_importLibrarySdk_withClass_typeArgument() { 2302 void test_importLibrarySdk_withClass_typeArgument() {
2296 resolveTestUnit(''' 2303 resolveTestUnit('''
2297 main() { 2304 main() {
2298 List<Future> futures = []; 2305 List<Future> futures = [];
2299 } 2306 }
2300 '''); 2307 ''');
2301 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' 2308 assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, '''
2302 import 'dart:async'; 2309 import 'dart:async';
2303 2310
2304 main() { 2311 main() {
2305 List<Future> futures = []; 2312 List<Future> futures = [];
2306 } 2313 }
2307 '''); 2314 ''');
2308 } 2315 }
2309 2316
2310 void test_importLibrarySdk_withTopLevelVariable() { 2317 void test_importLibrarySdk_withTopLevelVariable() {
2311 resolveTestUnit(''' 2318 resolveTestUnit('''
2312 main() { 2319 main() {
2313 print(PI); 2320 print(PI);
2314 } 2321 }
2315 '''); 2322 ''');
2316 performAllAnalysisTasks(); 2323 performAllAnalysisTasks();
2317 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' 2324 assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, '''
2318 import 'dart:math'; 2325 import 'dart:math';
2319 2326
2320 main() { 2327 main() {
2321 print(PI); 2328 print(PI);
2322 } 2329 }
2323 '''); 2330 ''');
2324 } 2331 }
2325 2332
2326 void test_importLibrarySdk_withTopLevelVariable_annotation() { 2333 void test_importLibrarySdk_withTopLevelVariable_annotation() {
2327 resolveTestUnit(''' 2334 resolveTestUnit('''
2328 @PI 2335 @PI
2329 main() { 2336 main() {
2330 } 2337 }
2331 '''); 2338 ''');
2332 performAllAnalysisTasks(); 2339 performAllAnalysisTasks();
2333 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' 2340 assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, '''
2334 import 'dart:math'; 2341 import 'dart:math';
2335 2342
2336 @PI 2343 @PI
2337 main() { 2344 main() {
2338 } 2345 }
2339 '''); 2346 ''');
2340 } 2347 }
2341 2348
2342 void test_importLibraryShow() { 2349 void test_importLibraryShow() {
2343 resolveTestUnit(''' 2350 resolveTestUnit('''
2344 import 'dart:async' show Stream; 2351 import 'dart:async' show Stream;
2345 main() { 2352 main() {
2346 Stream s = null; 2353 Stream s = null;
2347 Future f = null; 2354 Future f = null;
2348 } 2355 }
2349 '''); 2356 ''');
2350 assertHasFix(FixKind.IMPORT_LIBRARY_SHOW, ''' 2357 assertHasFix(DartFixKind.IMPORT_LIBRARY_SHOW, '''
2351 import 'dart:async' show Future, Stream; 2358 import 'dart:async' show Future, Stream;
2352 main() { 2359 main() {
2353 Stream s = null; 2360 Stream s = null;
2354 Future f = null; 2361 Future f = null;
2355 } 2362 }
2356 '''); 2363 ''');
2357 } 2364 }
2358 2365
2359 void test_isNotNull() { 2366 void test_isNotNull() {
2360 resolveTestUnit(''' 2367 resolveTestUnit('''
2361 main(p) { 2368 main(p) {
2362 p is! Null; 2369 p is! Null;
2363 } 2370 }
2364 '''); 2371 ''');
2365 assertHasFix(FixKind.USE_NOT_EQ_NULL, ''' 2372 assertHasFix(DartFixKind.USE_NOT_EQ_NULL, '''
2366 main(p) { 2373 main(p) {
2367 p != null; 2374 p != null;
2368 } 2375 }
2369 '''); 2376 ''');
2370 } 2377 }
2371 2378
2372 void test_isNull() { 2379 void test_isNull() {
2373 resolveTestUnit(''' 2380 resolveTestUnit('''
2374 main(p) { 2381 main(p) {
2375 p is Null; 2382 p is Null;
2376 } 2383 }
2377 '''); 2384 ''');
2378 assertHasFix(FixKind.USE_EQ_EQ_NULL, ''' 2385 assertHasFix(DartFixKind.USE_EQ_EQ_NULL, '''
2379 main(p) { 2386 main(p) {
2380 p == null; 2387 p == null;
2381 } 2388 }
2382 '''); 2389 ''');
2383 } 2390 }
2384 2391
2385 void test_makeEnclosingClassAbstract_declaresAbstractMethod() { 2392 void test_makeEnclosingClassAbstract_declaresAbstractMethod() {
2386 resolveTestUnit(''' 2393 resolveTestUnit('''
2387 class A { 2394 class A {
2388 m(); 2395 m();
2389 } 2396 }
2390 '''); 2397 ''');
2391 assertHasFix(FixKind.MAKE_CLASS_ABSTRACT, ''' 2398 assertHasFix(DartFixKind.MAKE_CLASS_ABSTRACT, '''
2392 abstract class A { 2399 abstract class A {
2393 m(); 2400 m();
2394 } 2401 }
2395 '''); 2402 ''');
2396 } 2403 }
2397 2404
2398 void test_makeEnclosingClassAbstract_inheritsAbstractMethod() { 2405 void test_makeEnclosingClassAbstract_inheritsAbstractMethod() {
2399 resolveTestUnit(''' 2406 resolveTestUnit('''
2400 abstract class A { 2407 abstract class A {
2401 m(); 2408 m();
2402 } 2409 }
2403 class B extends A { 2410 class B extends A {
2404 } 2411 }
2405 '''); 2412 ''');
2406 assertHasFix(FixKind.MAKE_CLASS_ABSTRACT, ''' 2413 assertHasFix(DartFixKind.MAKE_CLASS_ABSTRACT, '''
2407 abstract class A { 2414 abstract class A {
2408 m(); 2415 m();
2409 } 2416 }
2410 abstract class B extends A { 2417 abstract class B extends A {
2411 } 2418 }
2412 '''); 2419 ''');
2413 } 2420 }
2414 2421
2415 void test_noException_1() { 2422 void test_noException_1() {
2416 resolveTestUnit(''' 2423 resolveTestUnit('''
2417 main(p) { 2424 main(p) {
2418 p i s Null; 2425 p i s Null;
2419 }'''); 2426 }''');
2420 List<AnalysisError> errors = context.computeErrors(testSource); 2427 List<AnalysisError> errors = context.computeErrors(testSource);
2421 for (var error in errors) { 2428 for (var error in errors) {
2422 computeFixes(testUnit, error); 2429 computeFixes(plugin, context, error);
2423 } 2430 }
2424 } 2431 }
2425 2432
2426 void test_removeParentheses_inGetterDeclaration() { 2433 void test_removeParentheses_inGetterDeclaration() {
2427 resolveTestUnit(''' 2434 resolveTestUnit('''
2428 class A { 2435 class A {
2429 int get foo() => 0; 2436 int get foo() => 0;
2430 } 2437 }
2431 '''); 2438 ''');
2432 assertHasFix(FixKind.REMOVE_PARAMETERS_IN_GETTER_DECLARATION, ''' 2439 assertHasFix(DartFixKind.REMOVE_PARAMETERS_IN_GETTER_DECLARATION, '''
2433 class A { 2440 class A {
2434 int get foo => 0; 2441 int get foo => 0;
2435 } 2442 }
2436 '''); 2443 ''');
2437 } 2444 }
2438 2445
2439 void test_removeParentheses_inGetterInvocation() { 2446 void test_removeParentheses_inGetterInvocation() {
2440 resolveTestUnit(''' 2447 resolveTestUnit('''
2441 class A { 2448 class A {
2442 int get foo => 0; 2449 int get foo => 0;
2443 } 2450 }
2444 main(A a) { 2451 main(A a) {
2445 a.foo(); 2452 a.foo();
2446 } 2453 }
2447 '''); 2454 ''');
2448 assertHasFix(FixKind.REMOVE_PARENTHESIS_IN_GETTER_INVOCATION, ''' 2455 assertHasFix(DartFixKind.REMOVE_PARENTHESIS_IN_GETTER_INVOCATION, '''
2449 class A { 2456 class A {
2450 int get foo => 0; 2457 int get foo => 0;
2451 } 2458 }
2452 main(A a) { 2459 main(A a) {
2453 a.foo; 2460 a.foo;
2454 } 2461 }
2455 '''); 2462 ''');
2456 } 2463 }
2457 2464
2458 void test_removeUnnecessaryCast_assignment() { 2465 void test_removeUnnecessaryCast_assignment() {
2459 resolveTestUnit(''' 2466 resolveTestUnit('''
2460 main(Object p) { 2467 main(Object p) {
2461 if (p is String) { 2468 if (p is String) {
2462 String v = ((p as String)); 2469 String v = ((p as String));
2463 } 2470 }
2464 } 2471 }
2465 '''); 2472 ''');
2466 assertHasFix(FixKind.REMOVE_UNNECASSARY_CAST, ''' 2473 assertHasFix(DartFixKind.REMOVE_UNNECASSARY_CAST, '''
2467 main(Object p) { 2474 main(Object p) {
2468 if (p is String) { 2475 if (p is String) {
2469 String v = p; 2476 String v = p;
2470 } 2477 }
2471 } 2478 }
2472 '''); 2479 ''');
2473 } 2480 }
2474 2481
2475 void test_removeUnusedCatchClause() { 2482 void test_removeUnusedCatchClause() {
2476 errorFilter = (AnalysisError error) => true; 2483 errorFilter = (AnalysisError error) => true;
2477 resolveTestUnit(''' 2484 resolveTestUnit('''
2478 main() { 2485 main() {
2479 try { 2486 try {
2480 throw 42; 2487 throw 42;
2481 } on int catch (e) { 2488 } on int catch (e) {
2482 } 2489 }
2483 } 2490 }
2484 '''); 2491 ''');
2485 assertHasFix(FixKind.REMOVE_UNUSED_CATCH_CLAUSE, ''' 2492 assertHasFix(DartFixKind.REMOVE_UNUSED_CATCH_CLAUSE, '''
2486 main() { 2493 main() {
2487 try { 2494 try {
2488 throw 42; 2495 throw 42;
2489 } on int { 2496 } on int {
2490 } 2497 }
2491 } 2498 }
2492 '''); 2499 ''');
2493 } 2500 }
2494 2501
2495 void test_removeUnusedCatchStack() { 2502 void test_removeUnusedCatchStack() {
2496 errorFilter = (AnalysisError error) => true; 2503 errorFilter = (AnalysisError error) => true;
2497 resolveTestUnit(''' 2504 resolveTestUnit('''
2498 main() { 2505 main() {
2499 try { 2506 try {
2500 throw 42; 2507 throw 42;
2501 } catch (e, stack) { 2508 } catch (e, stack) {
2502 } 2509 }
2503 } 2510 }
2504 '''); 2511 ''');
2505 assertHasFix(FixKind.REMOVE_UNUSED_CATCH_STACK, ''' 2512 assertHasFix(DartFixKind.REMOVE_UNUSED_CATCH_STACK, '''
2506 main() { 2513 main() {
2507 try { 2514 try {
2508 throw 42; 2515 throw 42;
2509 } catch (e) { 2516 } catch (e) {
2510 } 2517 }
2511 } 2518 }
2512 '''); 2519 ''');
2513 } 2520 }
2514 2521
2515 void test_removeUnusedImport() { 2522 void test_removeUnusedImport() {
2516 resolveTestUnit(''' 2523 resolveTestUnit('''
2517 import 'dart:math'; 2524 import 'dart:math';
2518 main() { 2525 main() {
2519 } 2526 }
2520 '''); 2527 ''');
2521 assertHasFix(FixKind.REMOVE_UNUSED_IMPORT, ''' 2528 assertHasFix(DartFixKind.REMOVE_UNUSED_IMPORT, '''
2522 main() { 2529 main() {
2523 } 2530 }
2524 '''); 2531 ''');
2525 } 2532 }
2526 2533
2527 void test_removeUnusedImport_anotherImportOnLine() { 2534 void test_removeUnusedImport_anotherImportOnLine() {
2528 resolveTestUnit(''' 2535 resolveTestUnit('''
2529 import 'dart:math'; import 'dart:async'; 2536 import 'dart:math'; import 'dart:async';
2530 2537
2531 main() { 2538 main() {
2532 Future f; 2539 Future f;
2533 } 2540 }
2534 '''); 2541 ''');
2535 assertHasFix(FixKind.REMOVE_UNUSED_IMPORT, ''' 2542 assertHasFix(DartFixKind.REMOVE_UNUSED_IMPORT, '''
2536 import 'dart:async'; 2543 import 'dart:async';
2537 2544
2538 main() { 2545 main() {
2539 Future f; 2546 Future f;
2540 } 2547 }
2541 '''); 2548 ''');
2542 } 2549 }
2543 2550
2544 void test_removeUnusedImport_severalLines() { 2551 void test_removeUnusedImport_severalLines() {
2545 resolveTestUnit(''' 2552 resolveTestUnit('''
2546 import 2553 import
2547 'dart:math'; 2554 'dart:math';
2548 main() { 2555 main() {
2549 } 2556 }
2550 '''); 2557 ''');
2551 assertHasFix(FixKind.REMOVE_UNUSED_IMPORT, ''' 2558 assertHasFix(DartFixKind.REMOVE_UNUSED_IMPORT, '''
2552 main() { 2559 main() {
2553 } 2560 }
2554 '''); 2561 ''');
2555 } 2562 }
2556 2563
2557 void test_replaceImportUri_inProject() { 2564 void test_replaceImportUri_inProject() {
2558 testFile = '/project/bin/test.dart'; 2565 testFile = '/project/bin/test.dart';
2559 addSource('/project/foo/bar/lib.dart', ''); 2566 addSource('/project/foo/bar/lib.dart', '');
2560 resolveTestUnit(''' 2567 resolveTestUnit('''
2561 import 'no/matter/lib.dart'; 2568 import 'no/matter/lib.dart';
2562 '''); 2569 ''');
2563 performAllAnalysisTasks(); 2570 performAllAnalysisTasks();
2564 assertHasFix(FixKind.REPLACE_IMPORT_URI, ''' 2571 assertHasFix(DartFixKind.REPLACE_IMPORT_URI, '''
2565 import '../foo/bar/lib.dart'; 2572 import '../foo/bar/lib.dart';
2566 '''); 2573 ''');
2567 } 2574 }
2568 2575
2569 void test_replaceImportUri_package() { 2576 void test_replaceImportUri_package() {
2570 _configureMyPkg(''); 2577 _configureMyPkg('');
2571 resolveTestUnit(''' 2578 resolveTestUnit('''
2572 import 'no/matter/my_lib.dart'; 2579 import 'no/matter/my_lib.dart';
2573 '''); 2580 ''');
2574 performAllAnalysisTasks(); 2581 performAllAnalysisTasks();
2575 assertHasFix(FixKind.REPLACE_IMPORT_URI, ''' 2582 assertHasFix(DartFixKind.REPLACE_IMPORT_URI, '''
2576 import 'package:my_pkg/my_lib.dart'; 2583 import 'package:my_pkg/my_lib.dart';
2577 '''); 2584 ''');
2578 } 2585 }
2579 2586
2580 void test_replaceVarWithDynamic() { 2587 void test_replaceVarWithDynamic() {
2581 errorFilter = (AnalysisError error) { 2588 errorFilter = (AnalysisError error) {
2582 return error.errorCode == ParserErrorCode.VAR_AS_TYPE_NAME; 2589 return error.errorCode == ParserErrorCode.VAR_AS_TYPE_NAME;
2583 }; 2590 };
2584 resolveTestUnit(''' 2591 resolveTestUnit('''
2585 class A { 2592 class A {
2586 Map<String, var> m; 2593 Map<String, var> m;
2587 } 2594 }
2588 '''); 2595 ''');
2589 assertHasFix(FixKind.REPLACE_VAR_WITH_DYNAMIC, ''' 2596 assertHasFix(DartFixKind.REPLACE_VAR_WITH_DYNAMIC, '''
2590 class A { 2597 class A {
2591 Map<String, dynamic> m; 2598 Map<String, dynamic> m;
2592 } 2599 }
2593 '''); 2600 ''');
2594 } 2601 }
2595 2602
2596 void test_replaceWithConstInstanceCreation() { 2603 void test_replaceWithConstInstanceCreation() {
2597 resolveTestUnit(''' 2604 resolveTestUnit('''
2598 class A { 2605 class A {
2599 const A(); 2606 const A();
2600 } 2607 }
2601 const a = new A(); 2608 const a = new A();
2602 '''); 2609 ''');
2603 assertHasFix(FixKind.USE_CONST, ''' 2610 assertHasFix(DartFixKind.USE_CONST, '''
2604 class A { 2611 class A {
2605 const A(); 2612 const A();
2606 } 2613 }
2607 const a = const A(); 2614 const a = const A();
2608 '''); 2615 ''');
2609 } 2616 }
2610 2617
2611 void test_undefinedClass_useSimilar_fromImport() { 2618 void test_undefinedClass_useSimilar_fromImport() {
2612 resolveTestUnit(''' 2619 resolveTestUnit('''
2613 main() { 2620 main() {
2614 Stirng s = 'abc'; 2621 Stirng s = 'abc';
2615 } 2622 }
2616 '''); 2623 ''');
2617 assertHasFix(FixKind.CHANGE_TO, ''' 2624 assertHasFix(DartFixKind.CHANGE_TO, '''
2618 main() { 2625 main() {
2619 String s = 'abc'; 2626 String s = 'abc';
2620 } 2627 }
2621 '''); 2628 ''');
2622 } 2629 }
2623 2630
2624 void test_undefinedClass_useSimilar_fromThisLibrary() { 2631 void test_undefinedClass_useSimilar_fromThisLibrary() {
2625 resolveTestUnit(''' 2632 resolveTestUnit('''
2626 class MyClass {} 2633 class MyClass {}
2627 main() { 2634 main() {
2628 MyCalss v = null; 2635 MyCalss v = null;
2629 } 2636 }
2630 '''); 2637 ''');
2631 assertHasFix(FixKind.CHANGE_TO, ''' 2638 assertHasFix(DartFixKind.CHANGE_TO, '''
2632 class MyClass {} 2639 class MyClass {}
2633 main() { 2640 main() {
2634 MyClass v = null; 2641 MyClass v = null;
2635 } 2642 }
2636 '''); 2643 ''');
2637 } 2644 }
2638 2645
2639 void test_undefinedFunction_create_dynamicArgument() { 2646 void test_undefinedFunction_create_dynamicArgument() {
2640 resolveTestUnit(''' 2647 resolveTestUnit('''
2641 main() { 2648 main() {
2642 dynamic v; 2649 dynamic v;
2643 test(v); 2650 test(v);
2644 } 2651 }
2645 '''); 2652 ''');
2646 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2653 assertHasFix(DartFixKind.CREATE_FUNCTION, '''
2647 main() { 2654 main() {
2648 dynamic v; 2655 dynamic v;
2649 test(v); 2656 test(v);
2650 } 2657 }
2651 2658
2652 void test(v) { 2659 void test(v) {
2653 } 2660 }
2654 '''); 2661 ''');
2655 } 2662 }
2656 2663
2657 void test_undefinedFunction_create_dynamicReturnType() { 2664 void test_undefinedFunction_create_dynamicReturnType() {
2658 resolveTestUnit(''' 2665 resolveTestUnit('''
2659 main() { 2666 main() {
2660 dynamic v = test(); 2667 dynamic v = test();
2661 } 2668 }
2662 '''); 2669 ''');
2663 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2670 assertHasFix(DartFixKind.CREATE_FUNCTION, '''
2664 main() { 2671 main() {
2665 dynamic v = test(); 2672 dynamic v = test();
2666 } 2673 }
2667 2674
2668 test() { 2675 test() {
2669 } 2676 }
2670 '''); 2677 ''');
2671 } 2678 }
2672 2679
2673 void test_undefinedFunction_create_fromFunction() { 2680 void test_undefinedFunction_create_fromFunction() {
2674 resolveTestUnit(''' 2681 resolveTestUnit('''
2675 main() { 2682 main() {
2676 int v = myUndefinedFunction(1, 2.0, '3'); 2683 int v = myUndefinedFunction(1, 2.0, '3');
2677 } 2684 }
2678 '''); 2685 ''');
2679 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2686 assertHasFix(DartFixKind.CREATE_FUNCTION, '''
2680 main() { 2687 main() {
2681 int v = myUndefinedFunction(1, 2.0, '3'); 2688 int v = myUndefinedFunction(1, 2.0, '3');
2682 } 2689 }
2683 2690
2684 int myUndefinedFunction(int i, double d, String s) { 2691 int myUndefinedFunction(int i, double d, String s) {
2685 } 2692 }
2686 '''); 2693 ''');
2687 } 2694 }
2688 2695
2689 void test_undefinedFunction_create_fromMethod() { 2696 void test_undefinedFunction_create_fromMethod() {
2690 resolveTestUnit(''' 2697 resolveTestUnit('''
2691 class A { 2698 class A {
2692 main() { 2699 main() {
2693 int v = myUndefinedFunction(1, 2.0, '3'); 2700 int v = myUndefinedFunction(1, 2.0, '3');
2694 } 2701 }
2695 } 2702 }
2696 '''); 2703 ''');
2697 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2704 assertHasFix(DartFixKind.CREATE_FUNCTION, '''
2698 class A { 2705 class A {
2699 main() { 2706 main() {
2700 int v = myUndefinedFunction(1, 2.0, '3'); 2707 int v = myUndefinedFunction(1, 2.0, '3');
2701 } 2708 }
2702 } 2709 }
2703 2710
2704 int myUndefinedFunction(int i, double d, String s) { 2711 int myUndefinedFunction(int i, double d, String s) {
2705 } 2712 }
2706 '''); 2713 ''');
2707 } 2714 }
2708 2715
2709 void test_undefinedFunction_create_generic_BAD() { 2716 void test_undefinedFunction_create_generic_BAD() {
2710 resolveTestUnit(''' 2717 resolveTestUnit('''
2711 class A<T> { 2718 class A<T> {
2712 Map<int, T> items; 2719 Map<int, T> items;
2713 main() { 2720 main() {
2714 process(items); 2721 process(items);
2715 } 2722 }
2716 } 2723 }
2717 '''); 2724 ''');
2718 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2725 assertHasFix(DartFixKind.CREATE_FUNCTION, '''
2719 class A<T> { 2726 class A<T> {
2720 Map<int, T> items; 2727 Map<int, T> items;
2721 main() { 2728 main() {
2722 process(items); 2729 process(items);
2723 } 2730 }
2724 } 2731 }
2725 2732
2726 void process(Map items) { 2733 void process(Map items) {
2727 } 2734 }
2728 '''); 2735 ''');
2729 } 2736 }
2730 2737
2731 void test_undefinedFunction_create_generic_OK() { 2738 void test_undefinedFunction_create_generic_OK() {
2732 resolveTestUnit(''' 2739 resolveTestUnit('''
2733 class A { 2740 class A {
2734 List<int> items; 2741 List<int> items;
2735 main() { 2742 main() {
2736 process(items); 2743 process(items);
2737 } 2744 }
2738 } 2745 }
2739 '''); 2746 ''');
2740 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2747 assertHasFix(DartFixKind.CREATE_FUNCTION, '''
2741 class A { 2748 class A {
2742 List<int> items; 2749 List<int> items;
2743 main() { 2750 main() {
2744 process(items); 2751 process(items);
2745 } 2752 }
2746 } 2753 }
2747 2754
2748 void process(List<int> items) { 2755 void process(List<int> items) {
2749 } 2756 }
2750 '''); 2757 ''');
2751 } 2758 }
2752 2759
2753 void test_undefinedFunction_create_importType() { 2760 void test_undefinedFunction_create_importType() {
2754 addSource('/lib.dart', r''' 2761 addSource('/lib.dart', r'''
2755 library lib; 2762 library lib;
2756 import 'dart:async'; 2763 import 'dart:async';
2757 Future getFuture() => null; 2764 Future getFuture() => null;
2758 '''); 2765 ''');
2759 resolveTestUnit(''' 2766 resolveTestUnit('''
2760 import 'lib.dart'; 2767 import 'lib.dart';
2761 main() { 2768 main() {
2762 test(getFuture()); 2769 test(getFuture());
2763 } 2770 }
2764 '''); 2771 ''');
2765 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2772 assertHasFix(DartFixKind.CREATE_FUNCTION, '''
2766 import 'lib.dart'; 2773 import 'lib.dart';
2767 import 'dart:async'; 2774 import 'dart:async';
2768 main() { 2775 main() {
2769 test(getFuture()); 2776 test(getFuture());
2770 } 2777 }
2771 2778
2772 void test(Future future) { 2779 void test(Future future) {
2773 } 2780 }
2774 '''); 2781 ''');
2775 } 2782 }
2776 2783
2777 void test_undefinedFunction_create_nullArgument() { 2784 void test_undefinedFunction_create_nullArgument() {
2778 resolveTestUnit(''' 2785 resolveTestUnit('''
2779 main() { 2786 main() {
2780 test(null); 2787 test(null);
2781 } 2788 }
2782 '''); 2789 ''');
2783 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2790 assertHasFix(DartFixKind.CREATE_FUNCTION, '''
2784 main() { 2791 main() {
2785 test(null); 2792 test(null);
2786 } 2793 }
2787 2794
2788 void test(arg0) { 2795 void test(arg0) {
2789 } 2796 }
2790 '''); 2797 ''');
2791 } 2798 }
2792 2799
2793 void test_undefinedFunction_create_returnType_bool_expressions() { 2800 void test_undefinedFunction_create_returnType_bool_expressions() {
(...skipping 11 matching lines...) Expand all
2805 assert_undefinedFunction_create_returnType_bool("do {} while ( test() );"); 2812 assert_undefinedFunction_create_returnType_bool("do {} while ( test() );");
2806 } 2813 }
2807 2814
2808 void test_undefinedFunction_create_returnType_fromAssignment_eq() { 2815 void test_undefinedFunction_create_returnType_fromAssignment_eq() {
2809 resolveTestUnit(''' 2816 resolveTestUnit('''
2810 main() { 2817 main() {
2811 int v; 2818 int v;
2812 v = myUndefinedFunction(); 2819 v = myUndefinedFunction();
2813 } 2820 }
2814 '''); 2821 ''');
2815 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2822 assertHasFix(DartFixKind.CREATE_FUNCTION, '''
2816 main() { 2823 main() {
2817 int v; 2824 int v;
2818 v = myUndefinedFunction(); 2825 v = myUndefinedFunction();
2819 } 2826 }
2820 2827
2821 int myUndefinedFunction() { 2828 int myUndefinedFunction() {
2822 } 2829 }
2823 '''); 2830 ''');
2824 } 2831 }
2825 2832
2826 void test_undefinedFunction_create_returnType_fromAssignment_plusEq() { 2833 void test_undefinedFunction_create_returnType_fromAssignment_plusEq() {
2827 resolveTestUnit(''' 2834 resolveTestUnit('''
2828 main() { 2835 main() {
2829 int v; 2836 int v;
2830 v += myUndefinedFunction(); 2837 v += myUndefinedFunction();
2831 } 2838 }
2832 '''); 2839 ''');
2833 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2840 assertHasFix(DartFixKind.CREATE_FUNCTION, '''
2834 main() { 2841 main() {
2835 int v; 2842 int v;
2836 v += myUndefinedFunction(); 2843 v += myUndefinedFunction();
2837 } 2844 }
2838 2845
2839 num myUndefinedFunction() { 2846 num myUndefinedFunction() {
2840 } 2847 }
2841 '''); 2848 ''');
2842 } 2849 }
2843 2850
2844 void test_undefinedFunction_create_returnType_fromBinary_right() { 2851 void test_undefinedFunction_create_returnType_fromBinary_right() {
2845 resolveTestUnit(''' 2852 resolveTestUnit('''
2846 main() { 2853 main() {
2847 0 + myUndefinedFunction(); 2854 0 + myUndefinedFunction();
2848 } 2855 }
2849 '''); 2856 ''');
2850 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2857 assertHasFix(DartFixKind.CREATE_FUNCTION, '''
2851 main() { 2858 main() {
2852 0 + myUndefinedFunction(); 2859 0 + myUndefinedFunction();
2853 } 2860 }
2854 2861
2855 num myUndefinedFunction() { 2862 num myUndefinedFunction() {
2856 } 2863 }
2857 '''); 2864 ''');
2858 } 2865 }
2859 2866
2860 void test_undefinedFunction_create_returnType_fromInitializer() { 2867 void test_undefinedFunction_create_returnType_fromInitializer() {
2861 resolveTestUnit(''' 2868 resolveTestUnit('''
2862 main() { 2869 main() {
2863 int v = myUndefinedFunction(); 2870 int v = myUndefinedFunction();
2864 } 2871 }
2865 '''); 2872 ''');
2866 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2873 assertHasFix(DartFixKind.CREATE_FUNCTION, '''
2867 main() { 2874 main() {
2868 int v = myUndefinedFunction(); 2875 int v = myUndefinedFunction();
2869 } 2876 }
2870 2877
2871 int myUndefinedFunction() { 2878 int myUndefinedFunction() {
2872 } 2879 }
2873 '''); 2880 ''');
2874 } 2881 }
2875 2882
2876 void test_undefinedFunction_create_returnType_fromInvocationArgument() { 2883 void test_undefinedFunction_create_returnType_fromInvocationArgument() {
2877 resolveTestUnit(''' 2884 resolveTestUnit('''
2878 foo(int p) {} 2885 foo(int p) {}
2879 main() { 2886 main() {
2880 foo( myUndefinedFunction() ); 2887 foo( myUndefinedFunction() );
2881 } 2888 }
2882 '''); 2889 ''');
2883 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2890 assertHasFix(DartFixKind.CREATE_FUNCTION, '''
2884 foo(int p) {} 2891 foo(int p) {}
2885 main() { 2892 main() {
2886 foo( myUndefinedFunction() ); 2893 foo( myUndefinedFunction() );
2887 } 2894 }
2888 2895
2889 int myUndefinedFunction() { 2896 int myUndefinedFunction() {
2890 } 2897 }
2891 '''); 2898 ''');
2892 } 2899 }
2893 2900
2894 void test_undefinedFunction_create_returnType_fromReturn() { 2901 void test_undefinedFunction_create_returnType_fromReturn() {
2895 resolveTestUnit(''' 2902 resolveTestUnit('''
2896 int main() { 2903 int main() {
2897 return myUndefinedFunction(); 2904 return myUndefinedFunction();
2898 } 2905 }
2899 '''); 2906 ''');
2900 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2907 assertHasFix(DartFixKind.CREATE_FUNCTION, '''
2901 int main() { 2908 int main() {
2902 return myUndefinedFunction(); 2909 return myUndefinedFunction();
2903 } 2910 }
2904 2911
2905 int myUndefinedFunction() { 2912 int myUndefinedFunction() {
2906 } 2913 }
2907 '''); 2914 ''');
2908 } 2915 }
2909 2916
2910 void test_undefinedFunction_create_returnType_void() { 2917 void test_undefinedFunction_create_returnType_void() {
2911 resolveTestUnit(''' 2918 resolveTestUnit('''
2912 main() { 2919 main() {
2913 myUndefinedFunction(); 2920 myUndefinedFunction();
2914 } 2921 }
2915 '''); 2922 ''');
2916 assertHasFix(FixKind.CREATE_FUNCTION, ''' 2923 assertHasFix(DartFixKind.CREATE_FUNCTION, '''
2917 main() { 2924 main() {
2918 myUndefinedFunction(); 2925 myUndefinedFunction();
2919 } 2926 }
2920 2927
2921 void myUndefinedFunction() { 2928 void myUndefinedFunction() {
2922 } 2929 }
2923 '''); 2930 ''');
2924 } 2931 }
2925 2932
2926 void test_undefinedFunction_useSimilar_fromImport() { 2933 void test_undefinedFunction_useSimilar_fromImport() {
2927 resolveTestUnit(''' 2934 resolveTestUnit('''
2928 main() { 2935 main() {
2929 pritn(0); 2936 pritn(0);
2930 } 2937 }
2931 '''); 2938 ''');
2932 assertHasFix(FixKind.CHANGE_TO, ''' 2939 assertHasFix(DartFixKind.CHANGE_TO, '''
2933 main() { 2940 main() {
2934 print(0); 2941 print(0);
2935 } 2942 }
2936 '''); 2943 ''');
2937 } 2944 }
2938 2945
2939 void test_undefinedFunction_useSimilar_thisLibrary() { 2946 void test_undefinedFunction_useSimilar_thisLibrary() {
2940 resolveTestUnit(''' 2947 resolveTestUnit('''
2941 myFunction() {} 2948 myFunction() {}
2942 main() { 2949 main() {
2943 myFuntcion(); 2950 myFuntcion();
2944 } 2951 }
2945 '''); 2952 ''');
2946 assertHasFix(FixKind.CHANGE_TO, ''' 2953 assertHasFix(DartFixKind.CHANGE_TO, '''
2947 myFunction() {} 2954 myFunction() {}
2948 main() { 2955 main() {
2949 myFunction(); 2956 myFunction();
2950 } 2957 }
2951 '''); 2958 ''');
2952 } 2959 }
2953 2960
2954 void test_undefinedGetter_useSimilar_hint() { 2961 void test_undefinedGetter_useSimilar_hint() {
2955 resolveTestUnit(''' 2962 resolveTestUnit('''
2956 class A { 2963 class A {
2957 int myField; 2964 int myField;
2958 } 2965 }
2959 main(A a) { 2966 main(A a) {
2960 var x = a; 2967 var x = a;
2961 print(x.myFild); 2968 print(x.myFild);
2962 } 2969 }
2963 '''); 2970 ''');
2964 assertHasFix(FixKind.CHANGE_TO, ''' 2971 assertHasFix(DartFixKind.CHANGE_TO, '''
2965 class A { 2972 class A {
2966 int myField; 2973 int myField;
2967 } 2974 }
2968 main(A a) { 2975 main(A a) {
2969 var x = a; 2976 var x = a;
2970 print(x.myField); 2977 print(x.myField);
2971 } 2978 }
2972 '''); 2979 ''');
2973 } 2980 }
2974 2981
2975 void test_undefinedGetter_useSimilar_qualified() { 2982 void test_undefinedGetter_useSimilar_qualified() {
2976 resolveTestUnit(''' 2983 resolveTestUnit('''
2977 class A { 2984 class A {
2978 int myField; 2985 int myField;
2979 } 2986 }
2980 main(A a) { 2987 main(A a) {
2981 print(a.myFild); 2988 print(a.myFild);
2982 } 2989 }
2983 '''); 2990 ''');
2984 assertHasFix(FixKind.CHANGE_TO, ''' 2991 assertHasFix(DartFixKind.CHANGE_TO, '''
2985 class A { 2992 class A {
2986 int myField; 2993 int myField;
2987 } 2994 }
2988 main(A a) { 2995 main(A a) {
2989 print(a.myField); 2996 print(a.myField);
2990 } 2997 }
2991 '''); 2998 ''');
2992 } 2999 }
2993 3000
2994 void test_undefinedGetter_useSimilar_qualified_static() { 3001 void test_undefinedGetter_useSimilar_qualified_static() {
2995 resolveTestUnit(''' 3002 resolveTestUnit('''
2996 class A { 3003 class A {
2997 static int MY_NAME = 1; 3004 static int MY_NAME = 1;
2998 } 3005 }
2999 main() { 3006 main() {
3000 A.MY_NAM; 3007 A.MY_NAM;
3001 } 3008 }
3002 '''); 3009 ''');
3003 assertHasFix(FixKind.CHANGE_TO, ''' 3010 assertHasFix(DartFixKind.CHANGE_TO, '''
3004 class A { 3011 class A {
3005 static int MY_NAME = 1; 3012 static int MY_NAME = 1;
3006 } 3013 }
3007 main() { 3014 main() {
3008 A.MY_NAME; 3015 A.MY_NAME;
3009 } 3016 }
3010 '''); 3017 ''');
3011 } 3018 }
3012 3019
3013 void test_undefinedGetter_useSimilar_unqualified() { 3020 void test_undefinedGetter_useSimilar_unqualified() {
3014 resolveTestUnit(''' 3021 resolveTestUnit('''
3015 class A { 3022 class A {
3016 int myField; 3023 int myField;
3017 main() { 3024 main() {
3018 print(myFild); 3025 print(myFild);
3019 } 3026 }
3020 } 3027 }
3021 '''); 3028 ''');
3022 assertHasFix(FixKind.CHANGE_TO, ''' 3029 assertHasFix(DartFixKind.CHANGE_TO, '''
3023 class A { 3030 class A {
3024 int myField; 3031 int myField;
3025 main() { 3032 main() {
3026 print(myField); 3033 print(myField);
3027 } 3034 }
3028 } 3035 }
3029 '''); 3036 ''');
3030 } 3037 }
3031 3038
3032 void test_undefinedMethod_create_BAD_inSDK() { 3039 void test_undefinedMethod_create_BAD_inSDK() {
3033 resolveTestUnit(''' 3040 resolveTestUnit('''
3034 main() { 3041 main() {
3035 List.foo(); 3042 List.foo();
3036 } 3043 }
3037 '''); 3044 ''');
3038 assertNoFix(FixKind.CREATE_METHOD); 3045 assertNoFix(DartFixKind.CREATE_METHOD);
3039 } 3046 }
3040 3047
3041 void test_undefinedMethod_create_generic_BAD() { 3048 void test_undefinedMethod_create_generic_BAD() {
3042 resolveTestUnit(''' 3049 resolveTestUnit('''
3043 class A<T> { 3050 class A<T> {
3044 B b; 3051 B b;
3045 Map<int, T> items; 3052 Map<int, T> items;
3046 main() { 3053 main() {
3047 b.process(items); 3054 b.process(items);
3048 } 3055 }
3049 } 3056 }
3050 3057
3051 class B { 3058 class B {
3052 } 3059 }
3053 '''); 3060 ''');
3054 assertHasFix(FixKind.CREATE_METHOD, ''' 3061 assertHasFix(DartFixKind.CREATE_METHOD, '''
3055 class A<T> { 3062 class A<T> {
3056 B b; 3063 B b;
3057 Map<int, T> items; 3064 Map<int, T> items;
3058 main() { 3065 main() {
3059 b.process(items); 3066 b.process(items);
3060 } 3067 }
3061 } 3068 }
3062 3069
3063 class B { 3070 class B {
3064 void process(Map items) { 3071 void process(Map items) {
3065 } 3072 }
3066 } 3073 }
3067 '''); 3074 ''');
3068 } 3075 }
3069 3076
3070 void test_undefinedMethod_create_generic_OK_literal() { 3077 void test_undefinedMethod_create_generic_OK_literal() {
3071 resolveTestUnit(''' 3078 resolveTestUnit('''
3072 class A { 3079 class A {
3073 B b; 3080 B b;
3074 List<int> items; 3081 List<int> items;
3075 main() { 3082 main() {
3076 b.process(items); 3083 b.process(items);
3077 } 3084 }
3078 } 3085 }
3079 3086
3080 class B { 3087 class B {
3081 } 3088 }
3082 '''); 3089 ''');
3083 assertHasFix(FixKind.CREATE_METHOD, ''' 3090 assertHasFix(DartFixKind.CREATE_METHOD, '''
3084 class A { 3091 class A {
3085 B b; 3092 B b;
3086 List<int> items; 3093 List<int> items;
3087 main() { 3094 main() {
3088 b.process(items); 3095 b.process(items);
3089 } 3096 }
3090 } 3097 }
3091 3098
3092 class B { 3099 class B {
3093 void process(List<int> items) { 3100 void process(List<int> items) {
3094 } 3101 }
3095 } 3102 }
3096 '''); 3103 ''');
3097 } 3104 }
3098 3105
3099 void test_undefinedMethod_create_generic_OK_local() { 3106 void test_undefinedMethod_create_generic_OK_local() {
3100 resolveTestUnit(''' 3107 resolveTestUnit('''
3101 class A<T> { 3108 class A<T> {
3102 List<T> items; 3109 List<T> items;
3103 main() { 3110 main() {
3104 process(items); 3111 process(items);
3105 } 3112 }
3106 } 3113 }
3107 '''); 3114 ''');
3108 assertHasFix(FixKind.CREATE_METHOD, ''' 3115 assertHasFix(DartFixKind.CREATE_METHOD, '''
3109 class A<T> { 3116 class A<T> {
3110 List<T> items; 3117 List<T> items;
3111 main() { 3118 main() {
3112 process(items); 3119 process(items);
3113 } 3120 }
3114 3121
3115 void process(List<T> items) { 3122 void process(List<T> items) {
3116 } 3123 }
3117 } 3124 }
3118 '''); 3125 ''');
3119 } 3126 }
3120 3127
3121 void test_undefinedMethod_createQualified_fromClass() { 3128 void test_undefinedMethod_createQualified_fromClass() {
3122 resolveTestUnit(''' 3129 resolveTestUnit('''
3123 class A { 3130 class A {
3124 } 3131 }
3125 main() { 3132 main() {
3126 A.myUndefinedMethod(); 3133 A.myUndefinedMethod();
3127 } 3134 }
3128 '''); 3135 ''');
3129 assertHasFix(FixKind.CREATE_METHOD, ''' 3136 assertHasFix(DartFixKind.CREATE_METHOD, '''
3130 class A { 3137 class A {
3131 static void myUndefinedMethod() { 3138 static void myUndefinedMethod() {
3132 } 3139 }
3133 } 3140 }
3134 main() { 3141 main() {
3135 A.myUndefinedMethod(); 3142 A.myUndefinedMethod();
3136 } 3143 }
3137 '''); 3144 ''');
3138 } 3145 }
3139 3146
3140 void test_undefinedMethod_createQualified_fromClass_hasOtherMember() { 3147 void test_undefinedMethod_createQualified_fromClass_hasOtherMember() {
3141 resolveTestUnit(''' 3148 resolveTestUnit('''
3142 class A { 3149 class A {
3143 foo() {} 3150 foo() {}
3144 } 3151 }
3145 main() { 3152 main() {
3146 A.myUndefinedMethod(); 3153 A.myUndefinedMethod();
3147 } 3154 }
3148 '''); 3155 ''');
3149 assertHasFix(FixKind.CREATE_METHOD, ''' 3156 assertHasFix(DartFixKind.CREATE_METHOD, '''
3150 class A { 3157 class A {
3151 foo() {} 3158 foo() {}
3152 3159
3153 static void myUndefinedMethod() { 3160 static void myUndefinedMethod() {
3154 } 3161 }
3155 } 3162 }
3156 main() { 3163 main() {
3157 A.myUndefinedMethod(); 3164 A.myUndefinedMethod();
3158 } 3165 }
3159 '''); 3166 ''');
3160 } 3167 }
3161 3168
3162 void test_undefinedMethod_createQualified_fromInstance() { 3169 void test_undefinedMethod_createQualified_fromInstance() {
3163 resolveTestUnit(''' 3170 resolveTestUnit('''
3164 class A { 3171 class A {
3165 } 3172 }
3166 main(A a) { 3173 main(A a) {
3167 a.myUndefinedMethod(); 3174 a.myUndefinedMethod();
3168 } 3175 }
3169 '''); 3176 ''');
3170 assertHasFix(FixKind.CREATE_METHOD, ''' 3177 assertHasFix(DartFixKind.CREATE_METHOD, '''
3171 class A { 3178 class A {
3172 void myUndefinedMethod() { 3179 void myUndefinedMethod() {
3173 } 3180 }
3174 } 3181 }
3175 main(A a) { 3182 main(A a) {
3176 a.myUndefinedMethod(); 3183 a.myUndefinedMethod();
3177 } 3184 }
3178 '''); 3185 ''');
3179 } 3186 }
3180 3187
3181 void test_undefinedMethod_createQualified_targetIsFunctionType() { 3188 void test_undefinedMethod_createQualified_targetIsFunctionType() {
3182 resolveTestUnit(''' 3189 resolveTestUnit('''
3183 typedef A(); 3190 typedef A();
3184 main() { 3191 main() {
3185 A.myUndefinedMethod(); 3192 A.myUndefinedMethod();
3186 } 3193 }
3187 '''); 3194 ''');
3188 assertNoFix(FixKind.CREATE_METHOD); 3195 assertNoFix(DartFixKind.CREATE_METHOD);
3189 } 3196 }
3190 3197
3191 void test_undefinedMethod_createQualified_targetIsUnresolved() { 3198 void test_undefinedMethod_createQualified_targetIsUnresolved() {
3192 resolveTestUnit(''' 3199 resolveTestUnit('''
3193 main() { 3200 main() {
3194 NoSuchClass.myUndefinedMethod(); 3201 NoSuchClass.myUndefinedMethod();
3195 } 3202 }
3196 '''); 3203 ''');
3197 assertNoFix(FixKind.CREATE_METHOD); 3204 assertNoFix(DartFixKind.CREATE_METHOD);
3198 } 3205 }
3199 3206
3200 void test_undefinedMethod_createUnqualified_parameters() { 3207 void test_undefinedMethod_createUnqualified_parameters() {
3201 resolveTestUnit(''' 3208 resolveTestUnit('''
3202 class A { 3209 class A {
3203 main() { 3210 main() {
3204 myUndefinedMethod(0, 1.0, '3'); 3211 myUndefinedMethod(0, 1.0, '3');
3205 } 3212 }
3206 } 3213 }
3207 '''); 3214 ''');
3208 assertHasFix(FixKind.CREATE_METHOD, ''' 3215 assertHasFix(DartFixKind.CREATE_METHOD, '''
3209 class A { 3216 class A {
3210 main() { 3217 main() {
3211 myUndefinedMethod(0, 1.0, '3'); 3218 myUndefinedMethod(0, 1.0, '3');
3212 } 3219 }
3213 3220
3214 void myUndefinedMethod(int i, double d, String s) { 3221 void myUndefinedMethod(int i, double d, String s) {
3215 } 3222 }
3216 } 3223 }
3217 '''); 3224 ''');
3218 // linked positions 3225 // linked positions
(...skipping 24 matching lines...) Expand all
3243 } 3250 }
3244 3251
3245 void test_undefinedMethod_createUnqualified_returnType() { 3252 void test_undefinedMethod_createUnqualified_returnType() {
3246 resolveTestUnit(''' 3253 resolveTestUnit('''
3247 class A { 3254 class A {
3248 main() { 3255 main() {
3249 int v = myUndefinedMethod(); 3256 int v = myUndefinedMethod();
3250 } 3257 }
3251 } 3258 }
3252 '''); 3259 ''');
3253 assertHasFix(FixKind.CREATE_METHOD, ''' 3260 assertHasFix(DartFixKind.CREATE_METHOD, '''
3254 class A { 3261 class A {
3255 main() { 3262 main() {
3256 int v = myUndefinedMethod(); 3263 int v = myUndefinedMethod();
3257 } 3264 }
3258 3265
3259 int myUndefinedMethod() { 3266 int myUndefinedMethod() {
3260 } 3267 }
3261 } 3268 }
3262 '''); 3269 ''');
3263 // linked positions 3270 // linked positions
3264 _assertLinkedGroup(change.linkedEditGroups[0], ['int myUndefinedMethod(']); 3271 _assertLinkedGroup(change.linkedEditGroups[0], ['int myUndefinedMethod(']);
3265 _assertLinkedGroup(change.linkedEditGroups[1], [ 3272 _assertLinkedGroup(change.linkedEditGroups[1], [
3266 'myUndefinedMethod();', 3273 'myUndefinedMethod();',
3267 'myUndefinedMethod() {' 3274 'myUndefinedMethod() {'
3268 ]); 3275 ]);
3269 } 3276 }
3270 3277
3271 void test_undefinedMethod_createUnqualified_staticFromField() { 3278 void test_undefinedMethod_createUnqualified_staticFromField() {
3272 resolveTestUnit(''' 3279 resolveTestUnit('''
3273 class A { 3280 class A {
3274 static var f = myUndefinedMethod(); 3281 static var f = myUndefinedMethod();
3275 } 3282 }
3276 '''); 3283 ''');
3277 assertHasFix(FixKind.CREATE_METHOD, ''' 3284 assertHasFix(DartFixKind.CREATE_METHOD, '''
3278 class A { 3285 class A {
3279 static var f = myUndefinedMethod(); 3286 static var f = myUndefinedMethod();
3280 3287
3281 static myUndefinedMethod() { 3288 static myUndefinedMethod() {
3282 } 3289 }
3283 } 3290 }
3284 '''); 3291 ''');
3285 } 3292 }
3286 3293
3287 void test_undefinedMethod_createUnqualified_staticFromMethod() { 3294 void test_undefinedMethod_createUnqualified_staticFromMethod() {
3288 resolveTestUnit(''' 3295 resolveTestUnit('''
3289 class A { 3296 class A {
3290 static main() { 3297 static main() {
3291 myUndefinedMethod(); 3298 myUndefinedMethod();
3292 } 3299 }
3293 } 3300 }
3294 '''); 3301 ''');
3295 assertHasFix(FixKind.CREATE_METHOD, ''' 3302 assertHasFix(DartFixKind.CREATE_METHOD, '''
3296 class A { 3303 class A {
3297 static main() { 3304 static main() {
3298 myUndefinedMethod(); 3305 myUndefinedMethod();
3299 } 3306 }
3300 3307
3301 static void myUndefinedMethod() { 3308 static void myUndefinedMethod() {
3302 } 3309 }
3303 } 3310 }
3304 '''); 3311 ''');
3305 } 3312 }
3306 3313
3307 void test_undefinedMethod_hint_createQualified_fromInstance() { 3314 void test_undefinedMethod_hint_createQualified_fromInstance() {
3308 resolveTestUnit(''' 3315 resolveTestUnit('''
3309 class A { 3316 class A {
3310 } 3317 }
3311 main() { 3318 main() {
3312 var a = new A(); 3319 var a = new A();
3313 a.myUndefinedMethod(); 3320 a.myUndefinedMethod();
3314 } 3321 }
3315 '''); 3322 ''');
3316 assertHasFix(FixKind.CREATE_METHOD, ''' 3323 assertHasFix(DartFixKind.CREATE_METHOD, '''
3317 class A { 3324 class A {
3318 void myUndefinedMethod() { 3325 void myUndefinedMethod() {
3319 } 3326 }
3320 } 3327 }
3321 main() { 3328 main() {
3322 var a = new A(); 3329 var a = new A();
3323 a.myUndefinedMethod(); 3330 a.myUndefinedMethod();
3324 } 3331 }
3325 '''); 3332 ''');
3326 } 3333 }
3327 3334
3328 void test_undefinedMethod_useSimilar_ignoreOperators() { 3335 void test_undefinedMethod_useSimilar_ignoreOperators() {
3329 resolveTestUnit(''' 3336 resolveTestUnit('''
3330 main(Object object) { 3337 main(Object object) {
3331 object.then(); 3338 object.then();
3332 } 3339 }
3333 '''); 3340 ''');
3334 assertNoFix(FixKind.CHANGE_TO); 3341 assertNoFix(DartFixKind.CHANGE_TO);
3335 } 3342 }
3336 3343
3337 void test_undefinedMethod_useSimilar_qualified() { 3344 void test_undefinedMethod_useSimilar_qualified() {
3338 resolveTestUnit(''' 3345 resolveTestUnit('''
3339 class A { 3346 class A {
3340 myMethod() {} 3347 myMethod() {}
3341 } 3348 }
3342 main() { 3349 main() {
3343 A a = new A(); 3350 A a = new A();
3344 a.myMehtod(); 3351 a.myMehtod();
3345 } 3352 }
3346 '''); 3353 ''');
3347 assertHasFix(FixKind.CHANGE_TO, ''' 3354 assertHasFix(DartFixKind.CHANGE_TO, '''
3348 class A { 3355 class A {
3349 myMethod() {} 3356 myMethod() {}
3350 } 3357 }
3351 main() { 3358 main() {
3352 A a = new A(); 3359 A a = new A();
3353 a.myMethod(); 3360 a.myMethod();
3354 } 3361 }
3355 '''); 3362 ''');
3356 } 3363 }
3357 3364
3358 void test_undefinedMethod_useSimilar_unqualified_superClass() { 3365 void test_undefinedMethod_useSimilar_unqualified_superClass() {
3359 resolveTestUnit(''' 3366 resolveTestUnit('''
3360 class A { 3367 class A {
3361 myMethod() {} 3368 myMethod() {}
3362 } 3369 }
3363 class B extends A { 3370 class B extends A {
3364 main() { 3371 main() {
3365 myMehtod(); 3372 myMehtod();
3366 } 3373 }
3367 } 3374 }
3368 '''); 3375 ''');
3369 assertHasFix(FixKind.CHANGE_TO, ''' 3376 assertHasFix(DartFixKind.CHANGE_TO, '''
3370 class A { 3377 class A {
3371 myMethod() {} 3378 myMethod() {}
3372 } 3379 }
3373 class B extends A { 3380 class B extends A {
3374 main() { 3381 main() {
3375 myMethod(); 3382 myMethod();
3376 } 3383 }
3377 } 3384 }
3378 '''); 3385 ''');
3379 } 3386 }
3380 3387
3381 void test_undefinedMethod_useSimilar_unqualified_thisClass() { 3388 void test_undefinedMethod_useSimilar_unqualified_thisClass() {
3382 resolveTestUnit(''' 3389 resolveTestUnit('''
3383 class A { 3390 class A {
3384 myMethod() {} 3391 myMethod() {}
3385 main() { 3392 main() {
3386 myMehtod(); 3393 myMehtod();
3387 } 3394 }
3388 } 3395 }
3389 '''); 3396 ''');
3390 assertHasFix(FixKind.CHANGE_TO, ''' 3397 assertHasFix(DartFixKind.CHANGE_TO, '''
3391 class A { 3398 class A {
3392 myMethod() {} 3399 myMethod() {}
3393 main() { 3400 main() {
3394 myMethod(); 3401 myMethod();
3395 } 3402 }
3396 } 3403 }
3397 '''); 3404 ''');
3398 } 3405 }
3399 3406
3400 void test_undefinedSetter_useSimilar_hint() { 3407 void test_undefinedSetter_useSimilar_hint() {
3401 resolveTestUnit(''' 3408 resolveTestUnit('''
3402 class A { 3409 class A {
3403 int myField; 3410 int myField;
3404 } 3411 }
3405 main(A a) { 3412 main(A a) {
3406 var x = a; 3413 var x = a;
3407 x.myFild = 42; 3414 x.myFild = 42;
3408 } 3415 }
3409 '''); 3416 ''');
3410 assertHasFix(FixKind.CHANGE_TO, ''' 3417 assertHasFix(DartFixKind.CHANGE_TO, '''
3411 class A { 3418 class A {
3412 int myField; 3419 int myField;
3413 } 3420 }
3414 main(A a) { 3421 main(A a) {
3415 var x = a; 3422 var x = a;
3416 x.myField = 42; 3423 x.myField = 42;
3417 } 3424 }
3418 '''); 3425 ''');
3419 } 3426 }
3420 3427
3421 void test_undefinedSetter_useSimilar_qualified() { 3428 void test_undefinedSetter_useSimilar_qualified() {
3422 resolveTestUnit(''' 3429 resolveTestUnit('''
3423 class A { 3430 class A {
3424 int myField; 3431 int myField;
3425 } 3432 }
3426 main(A a) { 3433 main(A a) {
3427 a.myFild = 42; 3434 a.myFild = 42;
3428 } 3435 }
3429 '''); 3436 ''');
3430 assertHasFix(FixKind.CHANGE_TO, ''' 3437 assertHasFix(DartFixKind.CHANGE_TO, '''
3431 class A { 3438 class A {
3432 int myField; 3439 int myField;
3433 } 3440 }
3434 main(A a) { 3441 main(A a) {
3435 a.myField = 42; 3442 a.myField = 42;
3436 } 3443 }
3437 '''); 3444 ''');
3438 } 3445 }
3439 3446
3440 void test_undefinedSetter_useSimilar_unqualified() { 3447 void test_undefinedSetter_useSimilar_unqualified() {
3441 resolveTestUnit(''' 3448 resolveTestUnit('''
3442 class A { 3449 class A {
3443 int myField; 3450 int myField;
3444 main() { 3451 main() {
3445 myFild = 42; 3452 myFild = 42;
3446 } 3453 }
3447 } 3454 }
3448 '''); 3455 ''');
3449 assertHasFix(FixKind.CHANGE_TO, ''' 3456 assertHasFix(DartFixKind.CHANGE_TO, '''
3450 class A { 3457 class A {
3451 int myField; 3458 int myField;
3452 main() { 3459 main() {
3453 myField = 42; 3460 myField = 42;
3454 } 3461 }
3455 } 3462 }
3456 '''); 3463 ''');
3457 } 3464 }
3458 3465
3459 void test_useEffectiveIntegerDivision() { 3466 void test_useEffectiveIntegerDivision() {
3460 resolveTestUnit(''' 3467 resolveTestUnit('''
3461 main() { 3468 main() {
3462 var a = 5; 3469 var a = 5;
3463 var b = 2; 3470 var b = 2;
3464 print((a / b).toInt()); 3471 print((a / b).toInt());
3465 } 3472 }
3466 '''); 3473 ''');
3467 assertHasFix(FixKind.USE_EFFECTIVE_INTEGER_DIVISION, ''' 3474 assertHasFix(DartFixKind.USE_EFFECTIVE_INTEGER_DIVISION, '''
3468 main() { 3475 main() {
3469 var a = 5; 3476 var a = 5;
3470 var b = 2; 3477 var b = 2;
3471 print(a ~/ b); 3478 print(a ~/ b);
3472 } 3479 }
3473 '''); 3480 ''');
3474 } 3481 }
3475 3482
3476 /** 3483 /**
3477 * Computes fixes and verifies that there is a fix of the given kind. 3484 * Computes fixes and verifies that there is a fix of the given kind.
3478 */ 3485 */
3479 Fix _assertHasFix(FixKind kind, AnalysisError error) { 3486 Fix _assertHasFix(FixKind kind, AnalysisError error) {
3480 List<Fix> fixes = computeFixes(testUnit, error); 3487 List<Fix> fixes = computeFixes(plugin, context, error);
3481 for (Fix fix in fixes) { 3488 for (Fix fix in fixes) {
3482 if (fix.kind == kind) { 3489 if (fix.kind == kind) {
3483 return fix; 3490 return fix;
3484 } 3491 }
3485 } 3492 }
3486 throw fail('Expected to find fix $kind in\n${fixes.join('\n')}'); 3493 throw fail('Expected to find fix $kind in\n${fixes.join('\n')}');
3487 } 3494 }
3488 3495
3489 void _assertLinkedGroup(LinkedEditGroup group, List<String> expectedStrings, 3496 void _assertLinkedGroup(LinkedEditGroup group, List<String> expectedStrings,
3490 [List<LinkedEditSuggestion> expectedSuggestions]) { 3497 [List<LinkedEditSuggestion> expectedSuggestions]) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3522 3529
3523 List<Position> _findResultPositions(List<String> searchStrings) { 3530 List<Position> _findResultPositions(List<String> searchStrings) {
3524 List<Position> positions = <Position>[]; 3531 List<Position> positions = <Position>[];
3525 for (String search in searchStrings) { 3532 for (String search in searchStrings) {
3526 int offset = resultCode.indexOf(search); 3533 int offset = resultCode.indexOf(search);
3527 positions.add(new Position(testFile, offset)); 3534 positions.add(new Position(testFile, offset));
3528 } 3535 }
3529 return positions; 3536 return positions;
3530 } 3537 }
3531 } 3538 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/edit/sort_members_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698