Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; | 7 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; |
| 8 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart'; | 8 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart'; |
| 9 import 'package:analysis_server/src/services/correction/fix.dart'; | 9 import 'package:analysis_server/src/services/correction/fix.dart'; |
| 10 import 'package:analysis_server/src/services/correction/fix_internal.dart'; | 10 import 'package:analysis_server/src/services/correction/fix_internal.dart'; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 | 78 |
| 79 assertHasFix(FixKind kind, String expected, {String target}) async { | 79 assertHasFix(FixKind kind, String expected, {String target}) async { |
| 80 AnalysisError error = await _findErrorToFix(); | 80 AnalysisError error = await _findErrorToFix(); |
| 81 fix = await _assertHasFix(kind, error); | 81 fix = await _assertHasFix(kind, error); |
| 82 change = fix.change; | 82 change = fix.change; |
| 83 | 83 |
| 84 // apply to "file" | 84 // apply to "file" |
| 85 List<SourceFileEdit> fileEdits = change.edits; | 85 List<SourceFileEdit> fileEdits = change.edits; |
| 86 expect(fileEdits, hasLength(1)); | 86 expect(fileEdits, hasLength(1)); |
| 87 | 87 |
| 88 String fileContent = testCode; | |
| 88 if (target != null) { | 89 if (target != null) { |
| 89 expect(target, fileEdits.first.file); | 90 expect(target, fileEdits.first.file); |
| 91 fileContent = provider.getFile(target).readAsStringSync(); | |
| 90 } | 92 } |
| 91 | 93 |
| 92 resultCode = SourceEdit.applySequence(testCode, change.edits[0].edits); | 94 resultCode = SourceEdit.applySequence(fileContent, change.edits[0].edits); |
| 93 // verify | 95 // verify |
| 94 expect(resultCode, expected); | 96 expect(resultCode, expected); |
| 95 } | 97 } |
| 96 | 98 |
| 97 assertNoFix(FixKind kind) async { | 99 assertNoFix(FixKind kind) async { |
| 98 AnalysisError error = await _findErrorToFix(); | 100 AnalysisError error = await _findErrorToFix(); |
| 99 List<Fix> fixes = await _computeFixes(error); | 101 List<Fix> fixes = await _computeFixes(error); |
| 100 for (Fix fix in fixes) { | 102 for (Fix fix in fixes) { |
| 101 if (fix.kind == kind) { | 103 if (fix.kind == kind) { |
| 102 throw fail('Unexpected fix $kind in\n${fixes.join('\n')}'); | 104 throw fail('Unexpected fix $kind in\n${fixes.join('\n')}'); |
| (...skipping 1520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1623 await assertHasFix(DartFixKind.CREATE_FIELD, ''' | 1625 await assertHasFix(DartFixKind.CREATE_FIELD, ''' |
| 1624 class A { | 1626 class A { |
| 1625 int test; | 1627 int test; |
| 1626 } | 1628 } |
| 1627 main(A a) { | 1629 main(A a) { |
| 1628 int v = a.test; | 1630 int v = a.test; |
| 1629 } | 1631 } |
| 1630 '''); | 1632 '''); |
| 1631 } | 1633 } |
| 1632 | 1634 |
| 1635 test_createField_getter_qualified_instance_differentLibrary() async { | |
|
scheglov
2017/08/09 15:52:07
There were two changes - for fields and for getter
Brian Wilkerson
2017/08/09 15:56:33
Not the way the code is currently written, but I'v
| |
| 1636 addSource('/other.dart', ''' | |
| 1637 /** | |
| 1638 * A comment to push the offset of the braces for the following class | |
| 1639 * declaration past the end of the content of the test file. Used to catch an | |
| 1640 * index out of bounds exception that occurs when using the test source instead | |
| 1641 * of the target source to compute the location at which to insert the field. | |
| 1642 */ | |
| 1643 class A { | |
| 1644 } | |
| 1645 '''); | |
| 1646 await resolveTestUnit(''' | |
| 1647 import 'other.dart'; | |
| 1648 main(A a) { | |
| 1649 int v = a.test; | |
| 1650 } | |
| 1651 '''); | |
| 1652 await assertHasFix( | |
| 1653 DartFixKind.CREATE_FIELD, | |
| 1654 ''' | |
| 1655 /** | |
| 1656 * A comment to push the offset of the braces for the following class | |
| 1657 * declaration past the end of the content of the test file. Used to catch an | |
| 1658 * index out of bounds exception that occurs when using the test source instead | |
| 1659 * of the target source to compute the location at which to insert the field. | |
| 1660 */ | |
| 1661 class A { | |
| 1662 int test; | |
| 1663 } | |
| 1664 ''', | |
| 1665 target: '/other.dart'); | |
| 1666 } | |
| 1667 | |
| 1633 test_createField_getter_qualified_instance_dynamicType() async { | 1668 test_createField_getter_qualified_instance_dynamicType() async { |
| 1634 await resolveTestUnit(''' | 1669 await resolveTestUnit(''' |
| 1635 class A { | 1670 class A { |
| 1636 B b; | 1671 B b; |
| 1637 void f(Object p) { | 1672 void f(Object p) { |
| 1638 p == b.test; | 1673 p == b.test; |
| 1639 } | 1674 } |
| 1640 } | 1675 } |
| 1641 class B { | 1676 class B { |
| 1642 } | 1677 } |
| (...skipping 4770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6413 @override | 6448 @override |
| 6414 final AnalysisError error; | 6449 final AnalysisError error; |
| 6415 | 6450 |
| 6416 _DartFixContextImpl(this.resourceProvider, this.analysisDriver, | 6451 _DartFixContextImpl(this.resourceProvider, this.analysisDriver, |
| 6417 this.astProvider, this.unit, this.error); | 6452 this.astProvider, this.unit, this.error); |
| 6418 | 6453 |
| 6419 @override | 6454 @override |
| 6420 GetTopLevelDeclarations get getTopLevelDeclarations => | 6455 GetTopLevelDeclarations get getTopLevelDeclarations => |
| 6421 analysisDriver.getTopLevelNameDeclarations; | 6456 analysisDriver.getTopLevelNameDeclarations; |
| 6422 } | 6457 } |
| OLD | NEW |