| 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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library services.src.correction.fix; | 8 library services.src.correction.fix; |
| 9 | 9 |
| 10 import 'dart:collection'; | 10 import 'dart:collection'; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 final Source source; | 48 final Source source; |
| 49 final String file; | 49 final String file; |
| 50 final CompilationUnit unit; | 50 final CompilationUnit unit; |
| 51 final AnalysisError error; | 51 final AnalysisError error; |
| 52 CompilationUnitElement unitElement; | 52 CompilationUnitElement unitElement; |
| 53 LibraryElement unitLibraryElement; | 53 LibraryElement unitLibraryElement; |
| 54 String unitLibraryFile; | 54 String unitLibraryFile; |
| 55 String unitLibraryFolder; | 55 String unitLibraryFolder; |
| 56 | 56 |
| 57 final List<Edit> edits = <Edit>[]; | 57 final List<Edit> edits = <Edit>[]; |
| 58 final Map<String, LinkedPositionGroup> linkedPositionGroups = <String, | 58 final Map<String, LinkedEditGroup> linkedPositionGroups = <String, |
| 59 LinkedPositionGroup>{}; | 59 LinkedEditGroup>{}; |
| 60 Position endPosition = null; | 60 Position endPosition = null; |
| 61 final List<Fix> fixes = <Fix>[]; | 61 final List<Fix> fixes = <Fix>[]; |
| 62 | 62 |
| 63 CorrectionUtils utils; | 63 CorrectionUtils utils; |
| 64 int errorOffset; | 64 int errorOffset; |
| 65 int errorLength; | 65 int errorLength; |
| 66 int errorEnd; | 66 int errorEnd; |
| 67 AstNode node; | 67 AstNode node; |
| 68 AstNode coveredNode; | 68 AstNode coveredNode; |
| 69 | 69 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 if (fixFile == null) { | 208 if (fixFile == null) { |
| 209 fixFile = file; | 209 fixFile = file; |
| 210 } | 210 } |
| 211 FileEdit fileEdit = new FileEdit(file); | 211 FileEdit fileEdit = new FileEdit(file); |
| 212 edits.forEach((edit) => fileEdit.add(edit)); | 212 edits.forEach((edit) => fileEdit.add(edit)); |
| 213 // prepare Change | 213 // prepare Change |
| 214 String message = JavaString.format(kind.message, args); | 214 String message = JavaString.format(kind.message, args); |
| 215 Change change = new Change(message); | 215 Change change = new Change(message); |
| 216 change.add(fileEdit); | 216 change.add(fileEdit); |
| 217 linkedPositionGroups.values.forEach( | 217 linkedPositionGroups.values.forEach( |
| 218 (group) => change.addLinkedPositionGroup(group)); | 218 (group) => change.addLinkedEditGroup(group)); |
| 219 change.endPosition = endPosition; | 219 change.endPosition = endPosition; |
| 220 // add Fix | 220 // add Fix |
| 221 Fix fix = new Fix(kind, change); | 221 Fix fix = new Fix(kind, change); |
| 222 fixes.add(fix); | 222 fixes.add(fix); |
| 223 // clear | 223 // clear |
| 224 edits.clear(); | 224 edits.clear(); |
| 225 linkedPositionGroups.clear(); | 225 linkedPositionGroups.clear(); |
| 226 endPosition = null; | 226 endPosition = null; |
| 227 } | 227 } |
| 228 | 228 |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 // add elements | 616 // add elements |
| 617 bool isFirst = true; | 617 bool isFirst = true; |
| 618 for (ExecutableElement missingOverride in missingOverrides) { | 618 for (ExecutableElement missingOverride in missingOverrides) { |
| 619 if (!isFirst || !targetClass.members.isEmpty) { | 619 if (!isFirst || !targetClass.members.isEmpty) { |
| 620 sb.append(eol); | 620 sb.append(eol); |
| 621 } | 621 } |
| 622 _addFix_createMissingOverrides_single(sb, targetClass, missingOverride); | 622 _addFix_createMissingOverrides_single(sb, targetClass, missingOverride); |
| 623 isFirst = false; | 623 isFirst = false; |
| 624 } | 624 } |
| 625 // add proposal | 625 // add proposal |
| 626 endPosition = new Position(file, insertOffset, 0); | 626 endPosition = new Position(file, insertOffset); |
| 627 _insertBuilder(sb); | 627 _insertBuilder(sb); |
| 628 _addFix(FixKind.CREATE_MISSING_OVERRIDES, [missingOverrides.length]); | 628 _addFix(FixKind.CREATE_MISSING_OVERRIDES, [missingOverrides.length]); |
| 629 } | 629 } |
| 630 | 630 |
| 631 void _addFix_createMissingOverrides_single(SourceBuilder sb, | 631 void _addFix_createMissingOverrides_single(SourceBuilder sb, |
| 632 ClassDeclaration targetClass, ExecutableElement missingOverride) { | 632 ClassDeclaration targetClass, ExecutableElement missingOverride) { |
| 633 // prepare environment | 633 // prepare environment |
| 634 String prefix = utils.getIndent(1); | 634 String prefix = utils.getIndent(1); |
| 635 String prefix2 = utils.getIndent(2); | 635 String prefix2 = utils.getIndent(2); |
| 636 // may be property | 636 // may be property |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 sb.append(eol); | 694 sb.append(eol); |
| 695 } | 695 } |
| 696 // append method | 696 // append method |
| 697 sb.append(prefix); | 697 sb.append(prefix); |
| 698 sb.append( | 698 sb.append( |
| 699 "noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation)
;"); | 699 "noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation)
;"); |
| 700 sb.append(eol); | 700 sb.append(eol); |
| 701 } | 701 } |
| 702 // done | 702 // done |
| 703 _insertBuilder(sb); | 703 _insertBuilder(sb); |
| 704 endPosition = new Position(file, insertOffset, 0); | 704 endPosition = new Position(file, insertOffset); |
| 705 // add proposal | 705 // add proposal |
| 706 _addFix(FixKind.CREATE_NO_SUCH_METHOD, []); | 706 _addFix(FixKind.CREATE_NO_SUCH_METHOD, []); |
| 707 } | 707 } |
| 708 | 708 |
| 709 | 709 |
| 710 void _addFix_createPart() { | 710 void _addFix_createPart() { |
| 711 // TODO(scheglov) implement | 711 // TODO(scheglov) implement |
| 712 // if (node is SimpleStringLiteral && node.parent is PartDirective) { | 712 // if (node is SimpleStringLiteral && node.parent is PartDirective) { |
| 713 // SimpleStringLiteral uriLiteral = node as SimpleStringLiteral; | 713 // SimpleStringLiteral uriLiteral = node as SimpleStringLiteral; |
| 714 // String uriString = uriLiteral.value; | 714 // String uriString = uriLiteral.value; |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1229 } | 1229 } |
| 1230 sb.append(" "); | 1230 sb.append(" "); |
| 1231 // append parameter name | 1231 // append parameter name |
| 1232 { | 1232 { |
| 1233 List<String> suggestions = | 1233 List<String> suggestions = |
| 1234 _getArgumentNameSuggestions(excluded, type, argument, i); | 1234 _getArgumentNameSuggestions(excluded, type, argument, i); |
| 1235 String favorite = suggestions[0]; | 1235 String favorite = suggestions[0]; |
| 1236 excluded.add(favorite); | 1236 excluded.add(favorite); |
| 1237 sb.startPosition("ARG${i}"); | 1237 sb.startPosition("ARG${i}"); |
| 1238 sb.append(favorite); | 1238 sb.append(favorite); |
| 1239 sb.addProposals(suggestions); | 1239 sb.addSuggestions(LinkedEditSuggestionKind.PARAMETER, suggestions); |
| 1240 sb.endPosition(); | 1240 sb.endPosition(); |
| 1241 } | 1241 } |
| 1242 } | 1242 } |
| 1243 } | 1243 } |
| 1244 | 1244 |
| 1245 void _addFix_undefinedMethod_useSimilar() { | 1245 void _addFix_undefinedMethod_useSimilar() { |
| 1246 if (node is SimpleIdentifier && node.parent is MethodInvocation) { | 1246 if (node is SimpleIdentifier && node.parent is MethodInvocation) { |
| 1247 MethodInvocation invocation = node.parent as MethodInvocation; | 1247 MethodInvocation invocation = node.parent as MethodInvocation; |
| 1248 String name = (node as SimpleIdentifier).name; | 1248 String name = (node as SimpleIdentifier).name; |
| 1249 _ClosestElementFinder finder = | 1249 _ClosestElementFinder finder = |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1337 */ | 1337 */ |
| 1338 void _addInsertEdit(int offset, String text) { | 1338 void _addInsertEdit(int offset, String text) { |
| 1339 Edit edit = new Edit(offset, 0, text); | 1339 Edit edit = new Edit(offset, 0, text); |
| 1340 edits.add(edit); | 1340 edits.add(edit); |
| 1341 } | 1341 } |
| 1342 | 1342 |
| 1343 /** | 1343 /** |
| 1344 * Adds a single linked position to [groupId]. | 1344 * Adds a single linked position to [groupId]. |
| 1345 */ | 1345 */ |
| 1346 void _addLinkedPosition(String groupId, SourceRange range) { | 1346 void _addLinkedPosition(String groupId, SourceRange range) { |
| 1347 Position position = new Position(file, range.offset, range.length); | 1347 Position position = new Position(file, range.offset); |
| 1348 LinkedPositionGroup group = _getLinkedPosition(groupId); | 1348 LinkedEditGroup group = _getLinkedPosition(groupId); |
| 1349 group.addPosition(position); | 1349 group.addPosition(position, range.length); |
| 1350 } | 1350 } |
| 1351 | 1351 |
| 1352 /** | 1352 /** |
| 1353 * Adds a single linked position to [groupId]. | 1353 * Adds a single linked position to [groupId]. |
| 1354 */ | 1354 */ |
| 1355 void _addLinkedPosition3(String groupId, SourceBuilder sb, | 1355 void _addLinkedPosition3(String groupId, SourceBuilder sb, |
| 1356 SourceRange range) { | 1356 SourceRange range) { |
| 1357 if (sb.offset < range.offset) { | 1357 if (sb.offset < range.offset) { |
| 1358 int delta = sb.length; | 1358 int delta = sb.length; |
| 1359 range = range.getTranslated(delta); | 1359 range = range.getTranslated(delta); |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1621 } | 1621 } |
| 1622 String valueSource = | 1622 String valueSource = |
| 1623 sourceContent.substring(valueRange.offset, valueRange.end); | 1623 sourceContent.substring(valueRange.offset, valueRange.end); |
| 1624 defaultSourceMap[parameter] = valueSource; | 1624 defaultSourceMap[parameter] = valueSource; |
| 1625 } | 1625 } |
| 1626 } | 1626 } |
| 1627 return defaultSourceMap; | 1627 return defaultSourceMap; |
| 1628 } | 1628 } |
| 1629 | 1629 |
| 1630 /** | 1630 /** |
| 1631 * Returns an existing or just added [LinkedPositionGroup] with [groupId]. | 1631 * Returns an existing or just added [LinkedEditGroup] with [groupId]. |
| 1632 */ | 1632 */ |
| 1633 LinkedPositionGroup _getLinkedPosition(String groupId) { | 1633 LinkedEditGroup _getLinkedPosition(String groupId) { |
| 1634 LinkedPositionGroup group = linkedPositionGroups[groupId]; | 1634 LinkedEditGroup group = linkedPositionGroups[groupId]; |
| 1635 if (group == null) { | 1635 if (group == null) { |
| 1636 group = new LinkedPositionGroup(groupId); | 1636 group = new LinkedEditGroup(groupId); |
| 1637 linkedPositionGroups[groupId] = group; | 1637 linkedPositionGroups[groupId] = group; |
| 1638 } | 1638 } |
| 1639 return group; | 1639 return group; |
| 1640 } | 1640 } |
| 1641 | 1641 |
| 1642 /** | 1642 /** |
| 1643 * Returns `true` if [node] is in static context. | 1643 * Returns `true` if [node] is in static context. |
| 1644 */ | 1644 */ |
| 1645 bool _inStaticContext() { | 1645 bool _inStaticContext() { |
| 1646 // constructor initializer cannot reference "this" | 1646 // constructor initializer cannot reference "this" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1771 return null; | 1771 return null; |
| 1772 } | 1772 } |
| 1773 | 1773 |
| 1774 /** | 1774 /** |
| 1775 * Inserts the given [SourceBuilder] at its offset. | 1775 * Inserts the given [SourceBuilder] at its offset. |
| 1776 */ | 1776 */ |
| 1777 void _insertBuilder(SourceBuilder builder) { | 1777 void _insertBuilder(SourceBuilder builder) { |
| 1778 String text = builder.toString(); | 1778 String text = builder.toString(); |
| 1779 _addInsertEdit(builder.offset, text); | 1779 _addInsertEdit(builder.offset, text); |
| 1780 // add linked positions | 1780 // add linked positions |
| 1781 builder.linkedPositionGroups.forEach((LinkedPositionGroup group) { | 1781 builder.linkedPositionGroups.forEach((LinkedEditGroup group) { |
| 1782 LinkedPositionGroup fixGroup = _getLinkedPosition(group.id); | 1782 LinkedEditGroup fixGroup = _getLinkedPosition(group.id); |
| 1783 group.positions.forEach((Position position) { | 1783 group.positions.forEach((Position position) { |
| 1784 fixGroup.addPosition(position); | 1784 fixGroup.addPosition(position, group.length); |
| 1785 }); | 1785 }); |
| 1786 group.proposals.forEach((String proposal) { | 1786 group.suggestions.forEach((LinkedEditSuggestion suggestion) { |
| 1787 fixGroup.addProposal(proposal); | 1787 fixGroup.addSuggestion(suggestion); |
| 1788 }); | 1788 }); |
| 1789 }); | 1789 }); |
| 1790 } | 1790 } |
| 1791 | 1791 |
| 1792 // void _addLinkedPositionProposal(String group, | 1792 // void _addLinkedPositionProposal(String group, |
| 1793 // LinkedPositionProposal proposal) { | 1793 // LinkedPositionProposal proposal) { |
| 1794 // List<LinkedPositionProposal> nodeProposals = linkedPositionProposals[group
]; | 1794 // List<LinkedPositionProposal> nodeProposals = linkedPositionProposals[group
]; |
| 1795 // if (nodeProposals == null) { | 1795 // if (nodeProposals == null) { |
| 1796 // nodeProposals = <LinkedPositionProposal>[]; | 1796 // nodeProposals = <LinkedPositionProposal>[]; |
| 1797 // linkedPositionProposals[group] = nodeProposals; | 1797 // linkedPositionProposals[group] = nodeProposals; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1867 } | 1867 } |
| 1868 } | 1868 } |
| 1869 | 1869 |
| 1870 static void _addSuperTypeProposals(SourceBuilder sb, | 1870 static void _addSuperTypeProposals(SourceBuilder sb, |
| 1871 Set<DartType> alreadyAdded, DartType type) { | 1871 Set<DartType> alreadyAdded, DartType type) { |
| 1872 if (type != null && | 1872 if (type != null && |
| 1873 !alreadyAdded.contains(type) && | 1873 !alreadyAdded.contains(type) && |
| 1874 type.element is ClassElement) { | 1874 type.element is ClassElement) { |
| 1875 alreadyAdded.add(type); | 1875 alreadyAdded.add(type); |
| 1876 ClassElement element = type.element as ClassElement; | 1876 ClassElement element = type.element as ClassElement; |
| 1877 sb.addProposal(element.name); | 1877 sb.addSuggestion(LinkedEditSuggestionKind.TYPE, element.name); |
| 1878 _addSuperTypeProposals(sb, alreadyAdded, element.supertype); | 1878 _addSuperTypeProposals(sb, alreadyAdded, element.supertype); |
| 1879 for (InterfaceType interfaceType in element.interfaces) { | 1879 for (InterfaceType interfaceType in element.interfaces) { |
| 1880 _addSuperTypeProposals(sb, alreadyAdded, interfaceType); | 1880 _addSuperTypeProposals(sb, alreadyAdded, interfaceType); |
| 1881 } | 1881 } |
| 1882 } | 1882 } |
| 1883 } | 1883 } |
| 1884 | 1884 |
| 1885 /** | 1885 /** |
| 1886 * Attempts to convert the given absolute path into a "package" URI. | 1886 * Attempts to convert the given absolute path into a "package" URI. |
| 1887 * | 1887 * |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1965 /** | 1965 /** |
| 1966 * Describes the location for a newly created [ConstructorDeclaration]. | 1966 * Describes the location for a newly created [ConstructorDeclaration]. |
| 1967 */ | 1967 */ |
| 1968 class _ConstructorLocation { | 1968 class _ConstructorLocation { |
| 1969 final String _prefix; | 1969 final String _prefix; |
| 1970 final int _offset; | 1970 final int _offset; |
| 1971 final String _suffix; | 1971 final String _suffix; |
| 1972 | 1972 |
| 1973 _ConstructorLocation(this._prefix, this._offset, this._suffix); | 1973 _ConstructorLocation(this._prefix, this._offset, this._suffix); |
| 1974 } | 1974 } |
| OLD | NEW |