| 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.source_buffer; | 8 library services.src.correction.source_buffer; |
| 9 | 9 |
| 10 import 'package:analysis_services/correction/change.dart'; | 10 import 'package:analysis_services/correction/change.dart'; |
| 11 import 'package:analyzer/src/generated/source.dart'; | 11 import 'package:analyzer/src/generated/source.dart'; |
| 12 | 12 |
| 13 | 13 |
| 14 /** | 14 /** |
| 15 * Helper for building Dart source with linked positions. | 15 * Helper for building Dart source with linked positions. |
| 16 */ | 16 */ |
| 17 class SourceBuilder { | 17 class SourceBuilder { |
| 18 final String file; | 18 final String file; |
| 19 final int offset; | 19 final int offset; |
| 20 final StringBuffer _buffer = new StringBuffer(); | 20 final StringBuffer _buffer = new StringBuffer(); |
| 21 | 21 |
| 22 final List<LinkedPositionGroup> linkedPositionGroups = <LinkedPositionGroup>[ | 22 final List<LinkedEditGroup> linkedPositionGroups = <LinkedEditGroup>[ |
| 23 ]; | 23 ]; |
| 24 LinkedPositionGroup _currentLinkedPositionGroup; | 24 LinkedEditGroup _currentLinkedPositionGroup; |
| 25 int _currentPositionStart; | 25 int _currentPositionStart; |
| 26 | 26 |
| 27 SourceBuilder(this.file, this.offset); | 27 SourceBuilder(this.file, this.offset); |
| 28 | 28 |
| 29 SourceBuilder.buffer() : file = null, offset = 0; | 29 SourceBuilder.buffer() : file = null, offset = 0; |
| 30 | 30 |
| 31 int get length => _buffer.length; | 31 int get length => _buffer.length; |
| 32 | 32 |
| 33 void addProposal(String proposal) { | 33 void addSuggestion(LinkedEditSuggestionKind kind, String value) { |
| 34 _currentLinkedPositionGroup.addProposal(proposal); | 34 var suggestion = new LinkedEditSuggestion(kind, value); |
| 35 _currentLinkedPositionGroup.addSuggestion(suggestion); |
| 35 } | 36 } |
| 36 | 37 |
| 37 void addProposals(List<String> proposals) { | 38 void addSuggestions(LinkedEditSuggestionKind kind, List<String> values) { |
| 38 proposals.forEach((proposal) => addProposal(proposal)); | 39 values.forEach((value) => addSuggestion(kind, value)); |
| 39 } | 40 } |
| 40 | 41 |
| 41 /** | 42 /** |
| 42 * Appends [s] to the buffer. | 43 * Appends [s] to the buffer. |
| 43 */ | 44 */ |
| 44 SourceBuilder append(String s) { | 45 SourceBuilder append(String s) { |
| 45 _buffer.write(s); | 46 _buffer.write(s); |
| 46 return this; | 47 return this; |
| 47 } | 48 } |
| 48 | 49 |
| 49 /** | 50 /** |
| 50 * Ends position started using [startPosition]. | 51 * Ends position started using [startPosition]. |
| 51 */ | 52 */ |
| 52 void endPosition() { | 53 void endPosition() { |
| 53 assert(_currentLinkedPositionGroup != null); | 54 assert(_currentLinkedPositionGroup != null); |
| 54 _addPosition(); | 55 _addPosition(); |
| 55 _currentLinkedPositionGroup = null; | 56 _currentLinkedPositionGroup = null; |
| 56 } | 57 } |
| 57 | 58 |
| 58 /** | 59 /** |
| 59 * Marks start of a new linked position for the group with the given ID. | 60 * Marks start of a new linked position for the group with the given ID. |
| 60 */ | 61 */ |
| 61 void startPosition(String groupId) { | 62 void startPosition(String groupId) { |
| 62 assert(_currentLinkedPositionGroup == null); | 63 assert(_currentLinkedPositionGroup == null); |
| 63 for (LinkedPositionGroup position in linkedPositionGroups) { | 64 for (LinkedEditGroup position in linkedPositionGroups) { |
| 64 if (position.id == groupId) { | 65 if (position.id == groupId) { |
| 65 _currentLinkedPositionGroup = position; | 66 _currentLinkedPositionGroup = position; |
| 66 break; | 67 break; |
| 67 } | 68 } |
| 68 } | 69 } |
| 69 if (_currentLinkedPositionGroup == null) { | 70 if (_currentLinkedPositionGroup == null) { |
| 70 _currentLinkedPositionGroup = new LinkedPositionGroup(groupId); | 71 _currentLinkedPositionGroup = new LinkedEditGroup(groupId); |
| 71 linkedPositionGroups.add(_currentLinkedPositionGroup); | 72 linkedPositionGroups.add(_currentLinkedPositionGroup); |
| 72 } | 73 } |
| 73 _currentPositionStart = _buffer.length; | 74 _currentPositionStart = _buffer.length; |
| 74 } | 75 } |
| 75 | 76 |
| 76 @override | 77 @override |
| 77 String toString() => _buffer.toString(); | 78 String toString() => _buffer.toString(); |
| 78 | 79 |
| 79 /** | 80 /** |
| 80 * Adds position location [SourceRange] using current fields. | 81 * Adds position location [SourceRange] using current fields. |
| 81 */ | 82 */ |
| 82 void _addPosition() { | 83 void _addPosition() { |
| 83 int start = offset + _currentPositionStart; | 84 int start = offset + _currentPositionStart; |
| 84 int end = offset + _buffer.length; | 85 int end = offset + _buffer.length; |
| 85 Position position = new Position(file, start, end - start); | 86 int length = end - start; |
| 86 _currentLinkedPositionGroup.addPosition(position); | 87 Position position = new Position(file, start); |
| 88 _currentLinkedPositionGroup.addPosition(position, length); |
| 87 } | 89 } |
| 88 } | 90 } |
| OLD | NEW |