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

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

Issue 405483007: More fixes in the Fixes service. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
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.
7
8 library services.src.correction.source_buffer;
9
10 import 'package:analysis_services/correction/change.dart';
11 import 'package:analyzer/src/generated/source.dart';
12
13
14 /**
15 * Helper for building Dart source with linked positions.
16 */
17 class SourceBuilder {
18 final String file;
19 final int offset;
20 final StringBuffer _buffer = new StringBuffer();
21
22 final List<PositionGroup> positionGroups = <PositionGroup>[];
23 PositionGroup _currentPositionGroup;
24 int _currentPositionStart;
25
26 SourceBuilder(this.file, this.offset);
27
28 void addProposal(String proposal) {
29 // TODO(scheglov) implement
30 // _currentPositionGroup.addProposal();
31 }
32
33 void addProposals(List<String> proposals) {
34 proposals.forEach((proposal) => addProposal(proposal));
35 }
36
37 /**
38 * Appends [s] to the buffer.
39 */
40 SourceBuilder append(String s) {
41 _buffer.write(s);
42 return this;
43 }
44
45 /**
46 * Ends position started using [startPosition].
47 */
48 void endPosition() {
49 assert(_currentPositionGroup != null);
50 _addPosition();
51 _currentPositionGroup = null;
52 }
53
54 /**
55 * Marks start of a new linked position for the group with the given ID.
56 */
57 void startPosition(String groupId) {
58 assert(_currentPositionGroup == null);
59 for (PositionGroup position in positionGroups) {
60 if (position.id == groupId) {
61 _currentPositionGroup = position;
62 break;
63 }
64 }
65 if (_currentPositionGroup == null) {
66 _currentPositionGroup = new PositionGroup(groupId);
67 positionGroups.add(_currentPositionGroup);
68 }
69 _currentPositionStart = _buffer.length;
70 }
71
72 @override
73 String toString() => _buffer.toString();
74
75 /**
76 * Adds position location [SourceRange] using current fields.
77 */
78 void _addPosition() {
79 int start = offset + _currentPositionStart;
80 int end = offset + _buffer.length;
81 Position position = new Position(file, start, end - start);
82 _currentPositionGroup.add(position);
83 }
84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698