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

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

Issue 608363003: Issue 19670. 'Create field' quick fix. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library test.services.correction.fix; 5 library test.services.correction.fix;
6 6
7 import 'package:analysis_server/src/protocol.dart' hide AnalysisError; 7 import 'package:analysis_server/src/protocol.dart' hide AnalysisError;
8 import 'package:analysis_server/src/services/correction/fix.dart'; 8 import 'package:analysis_server/src/services/correction/fix.dart';
9 import 'package:analysis_server/src/services/index/index.dart'; 9 import 'package:analysis_server/src/services/index/index.dart';
10 import 'package:analysis_server/src/services/index/local_memory_index.dart'; 10 import 'package:analysis_server/src/services/index/local_memory_index.dart';
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 } 388 }
389 389
390 method() {} 390 method() {}
391 } 391 }
392 main() { 392 main() {
393 new A.named(1, 2.0); 393 new A.named(1, 2.0);
394 } 394 }
395 '''); 395 ''');
396 } 396 }
397 397
398 void test_createField_qualified_instance_hasField() {
399 _indexTestUnit('''
400 class A {
401 int aaa;
402 int zzz;
403
404 existingMethod() {}
405 }
406 main(A a) {
407 a.test = 5;
408 }
409 ''');
410 assertHasFix(FixKind.CREATE_FIELD, '''
411 class A {
412 int aaa;
413 int zzz;
414
415 int test;
416
417 existingMethod() {}
418 }
419 main(A a) {
420 a.test = 5;
421 }
422 ''');
423 }
424
425 void test_createField_qualified_instance_hasMethod() {
426 _indexTestUnit('''
427 class A {
428 existingMethod() {}
429 }
430 main(A a) {
431 a.test = 5;
432 }
433 ''');
434 assertHasFix(FixKind.CREATE_FIELD, '''
435 class A {
436 int test;
437
438 existingMethod() {}
439 }
440 main(A a) {
441 a.test = 5;
442 }
443 ''');
444 }
445
446 void test_createField_qualified_static() {
447 _indexTestUnit('''
448 class A {
449 }
450 main() {
451 A.test = 5;
452 }
453 ''');
454 assertHasFix(FixKind.CREATE_FIELD, '''
455 class A {
456 static int test;
457 }
458 main() {
459 A.test = 5;
460 }
461 ''');
462 }
463
464 void test_createField_unqualified_instance() {
465 _indexTestUnit('''
466 class A {
467 main() {
468 test = 5;
469 }
470 }
471 ''');
472 assertHasFix(FixKind.CREATE_FIELD, '''
473 class A {
474 int test;
475
476 main() {
477 test = 5;
478 }
479 }
480 ''');
481 }
482
483 void test_createField_unqualified_static() {
484 _indexTestUnit('''
485 class A {
486 static main() {
487 test = 5;
488 }
489 }
490 ''');
491 assertHasFix(FixKind.CREATE_FIELD, '''
492 class A {
493 static int test;
494
495 static main() {
496 test = 5;
497 }
498 }
499 ''');
500 }
501
398 void test_createFile_forImport() { 502 void test_createFile_forImport() {
399 testFile = '/my/project/bin/test.dart'; 503 testFile = '/my/project/bin/test.dart';
400 _indexTestUnit(''' 504 _indexTestUnit('''
401 import 'my_file.dart'; 505 import 'my_file.dart';
402 '''); 506 ''');
403 AnalysisError error = _findErrorToFix(); 507 AnalysisError error = _findErrorToFix();
404 fix = _assertHasFix(FixKind.CREATE_FILE, error); 508 fix = _assertHasFix(FixKind.CREATE_FILE, error);
405 change = fix.change; 509 change = fix.change;
406 // validate change 510 // validate change
407 List<SourceFileEdit> fileEdits = change.edits; 511 List<SourceFileEdit> fileEdits = change.edits;
(...skipping 1600 matching lines...) Expand 10 before | Expand all | Expand 10 after
2008 positions.add(new Position(testFile, offset)); 2112 positions.add(new Position(testFile, offset));
2009 } 2113 }
2010 return positions; 2114 return positions;
2011 } 2115 }
2012 2116
2013 void _indexTestUnit(String code) { 2117 void _indexTestUnit(String code) {
2014 resolveTestUnit(code); 2118 resolveTestUnit(code);
2015 index.indexUnit(context, testUnit); 2119 index.indexUnit(context, testUnit);
2016 } 2120 }
2017 } 2121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698