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

Side by Side Diff: pkg/analysis_services/lib/src/correction/assist.dart

Issue 447613002: Make Change implementation consistent with the server spec. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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 // 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.assist; 8 library services.src.correction.assist;
9 9
10 import 'dart:collection'; 10 import 'dart:collection';
(...skipping 27 matching lines...) Expand all
38 final String file; 38 final String file;
39 final CompilationUnit unit; 39 final CompilationUnit unit;
40 final int selectionOffset; 40 final int selectionOffset;
41 final int selectionLength; 41 final int selectionLength;
42 CompilationUnitElement unitElement; 42 CompilationUnitElement unitElement;
43 LibraryElement unitLibraryElement; 43 LibraryElement unitLibraryElement;
44 String unitLibraryFile; 44 String unitLibraryFile;
45 String unitLibraryFolder; 45 String unitLibraryFolder;
46 46
47 final List<Edit> edits = <Edit>[]; 47 final List<Edit> edits = <Edit>[];
48 final Map<String, LinkedPositionGroup> linkedPositionGroups = <String, 48 final Map<String, LinkedEditGroup> linkedPositionGroups = <String,
49 LinkedPositionGroup>{}; 49 LinkedEditGroup>{};
50 Position endPosition = null; 50 Position endPosition = null;
51 final List<Assist> assists = <Assist>[]; 51 final List<Assist> assists = <Assist>[];
52 52
53 int selectionEnd; 53 int selectionEnd;
54 CorrectionUtils utils; 54 CorrectionUtils utils;
55 AstNode node; 55 AstNode node;
56 56
57 AssistProcessor(this.searchEngine, this.source, this.file, this.unit, 57 AssistProcessor(this.searchEngine, this.source, this.file, this.unit,
58 this.selectionOffset, this.selectionLength) { 58 this.selectionOffset, this.selectionLength) {
59 unitElement = unit.element; 59 unitElement = unit.element;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 if (assistFile == null) { 128 if (assistFile == null) {
129 assistFile = file; 129 assistFile = file;
130 } 130 }
131 FileEdit fileEdit = new FileEdit(file); 131 FileEdit fileEdit = new FileEdit(file);
132 edits.forEach((edit) => fileEdit.add(edit)); 132 edits.forEach((edit) => fileEdit.add(edit));
133 // prepare Change 133 // prepare Change
134 String message = JavaString.format(kind.message, args); 134 String message = JavaString.format(kind.message, args);
135 Change change = new Change(message); 135 Change change = new Change(message);
136 change.add(fileEdit); 136 change.add(fileEdit);
137 linkedPositionGroups.values.forEach( 137 linkedPositionGroups.values.forEach(
138 (group) => change.addLinkedPositionGroup(group)); 138 (group) => change.addLinkedEditGroup(group));
139 change.endPosition = endPosition; 139 change.endPosition = endPosition;
140 // add Assist 140 // add Assist
141 Assist assist = new Assist(kind, change); 141 Assist assist = new Assist(kind, change);
142 assists.add(assist); 142 assists.add(assist);
143 // clear 143 // clear
144 edits.clear(); 144 edits.clear();
145 linkedPositionGroups.clear(); 145 linkedPositionGroups.clear();
146 endPosition = null; 146 endPosition = null;
147 } 147 }
148 148
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 // name(s) 241 // name(s)
242 { 242 {
243 List<String> suggestions = 243 List<String> suggestions =
244 getVariableNameSuggestionsForExpression(type, expression, excluded); 244 getVariableNameSuggestionsForExpression(type, expression, excluded);
245 builder.startPosition("NAME"); 245 builder.startPosition("NAME");
246 for (int i = 0; i < suggestions.length; i++) { 246 for (int i = 0; i < suggestions.length; i++) {
247 String name = suggestions[i]; 247 String name = suggestions[i];
248 if (i == 0) { 248 if (i == 0) {
249 builder.append(name); 249 builder.append(name);
250 } 250 }
251 builder.addProposal(name); 251 builder.addSuggestion(LinkedEditSuggestionKind.VARIABLE, name);
252 } 252 }
253 builder.endPosition(); 253 builder.endPosition();
254 } 254 }
255 builder.append(" = "); 255 builder.append(" = ");
256 // add proposal 256 // add proposal
257 _insertBuilder(builder); 257 _insertBuilder(builder);
258 _addAssist(AssistKind.ASSIGN_TO_LOCAL_VARIABLE, []); 258 _addAssist(AssistKind.ASSIGN_TO_LOCAL_VARIABLE, []);
259 } 259 }
260 260
261 void _addProposal_convertToBlockFunctionBody() { 261 void _addProposal_convertToBlockFunctionBody() {
(...skipping 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 1519
1520 /** 1520 /**
1521 * Adds a new [Edit] to [edits]. 1521 * Adds a new [Edit] to [edits].
1522 */ 1522 */
1523 void _addReplaceEdit(SourceRange range, String text) { 1523 void _addReplaceEdit(SourceRange range, String text) {
1524 Edit edit = new Edit(range.offset, range.length, text); 1524 Edit edit = new Edit(range.offset, range.length, text);
1525 edits.add(edit); 1525 edits.add(edit);
1526 } 1526 }
1527 1527
1528 /** 1528 /**
1529 * Returns an existing or just added [LinkedPositionGroup] with [groupId]. 1529 * Returns an existing or just added [LinkedEditGroup] with [groupId].
1530 */ 1530 */
1531 LinkedPositionGroup _getLinkedPosition(String groupId) { 1531 LinkedEditGroup _getLinkedPosition(String groupId) {
1532 LinkedPositionGroup group = linkedPositionGroups[groupId]; 1532 LinkedEditGroup group = linkedPositionGroups[groupId];
1533 if (group == null) { 1533 if (group == null) {
1534 group = new LinkedPositionGroup(groupId); 1534 group = new LinkedEditGroup(groupId);
1535 linkedPositionGroups[groupId] = group; 1535 linkedPositionGroups[groupId] = group;
1536 } 1536 }
1537 return group; 1537 return group;
1538 } 1538 }
1539 1539
1540 /** 1540 /**
1541 * Returns the text of the given range in the unit. 1541 * Returns the text of the given range in the unit.
1542 */ 1542 */
1543 String _getSource(AstNode node) { 1543 String _getSource(AstNode node) {
1544 // TODO(scheglov) rename 1544 // TODO(scheglov) rename
1545 return utils.getText(node); 1545 return utils.getText(node);
1546 } 1546 }
1547 1547
1548 /** 1548 /**
1549 * Returns the text of the given range in the unit. 1549 * Returns the text of the given range in the unit.
1550 */ 1550 */
1551 String _getSource2(SourceRange range) { 1551 String _getSource2(SourceRange range) {
1552 // TODO(scheglov) rename 1552 // TODO(scheglov) rename
1553 return utils.getText3(range); 1553 return utils.getText3(range);
1554 } 1554 }
1555 1555
1556 /** 1556 /**
1557 * Inserts the given [SourceBuilder] at its offset. 1557 * Inserts the given [SourceBuilder] at its offset.
1558 */ 1558 */
1559 void _insertBuilder(SourceBuilder builder) { 1559 void _insertBuilder(SourceBuilder builder) {
1560 String text = builder.toString(); 1560 String text = builder.toString();
1561 _addInsertEdit(builder.offset, text); 1561 _addInsertEdit(builder.offset, text);
1562 // add linked positions 1562 // add linked positions
1563 builder.linkedPositionGroups.forEach((LinkedPositionGroup group) { 1563 builder.linkedPositionGroups.forEach((LinkedEditGroup group) {
1564 LinkedPositionGroup fixGroup = _getLinkedPosition(group.id); 1564 LinkedEditGroup fixGroup = _getLinkedPosition(group.id);
1565 group.positions.forEach((Position position) { 1565 group.positions.forEach((Position position) {
1566 fixGroup.addPosition(position); 1566 fixGroup.addPosition(position, group.length);
1567 }); 1567 });
1568 group.proposals.forEach((String proposal) { 1568 group.suggestions.forEach((LinkedEditSuggestion suggestion) {
1569 fixGroup.addProposal(proposal); 1569 fixGroup.addSuggestion(suggestion);
1570 }); 1570 });
1571 }); 1571 });
1572 } 1572 }
1573 1573
1574 /** 1574 /**
1575 * This method does nothing, but we invoke it in places where Dart VM 1575 * This method does nothing, but we invoke it in places where Dart VM
1576 * coverage agent fails to provide coverage information - such as almost 1576 * coverage agent fails to provide coverage information - such as almost
1577 * all "return" statements. 1577 * all "return" statements.
1578 * 1578 *
1579 * https://code.google.com/p/dart/issues/detail?id=19912 1579 * https://code.google.com/p/dart/issues/detail?id=19912
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1626 class _SimpleIdentifierRecursiveAstVisitor extends RecursiveAstVisitor { 1626 class _SimpleIdentifierRecursiveAstVisitor extends RecursiveAstVisitor {
1627 final _SimpleIdentifierVisitor visitor; 1627 final _SimpleIdentifierVisitor visitor;
1628 1628
1629 _SimpleIdentifierRecursiveAstVisitor(this.visitor); 1629 _SimpleIdentifierRecursiveAstVisitor(this.visitor);
1630 1630
1631 @override 1631 @override
1632 visitSimpleIdentifier(SimpleIdentifier node) { 1632 visitSimpleIdentifier(SimpleIdentifier node) {
1633 visitor(node); 1633 visitor(node);
1634 } 1634 }
1635 } 1635 }
OLDNEW
« no previous file with comments | « pkg/analysis_services/lib/correction/change.dart ('k') | pkg/analysis_services/lib/src/correction/fix.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698