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

Side by Side Diff: pkg/analysis_server/lib/utilities/change_builder_core.dart

Issue 1110583002: Add utilities for creating SourceChanges (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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) 2015, 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 library analysis_server.utilities.change_builder_core;
6
7 import 'package:analysis_server/src/utilities/change_builder_core.dart';
8 import 'package:analysis_server/src/protocol.dart';
9 import 'package:analyzer/src/generated/source.dart';
10
11 /**
12 * A builder used to build a [SourceChange].
13 *
14 * Clients are not expected to subtype this class.
15 */
16 abstract class ChangeBuilder {
17 /**
18 * Initialize a newly created change builder.
19 */
20 factory ChangeBuilder() = ChangeBuilderImpl;
21
22 /**
23 * Return the source change that was built.
24 */
25 SourceChange get sourceChange;
26
27 /**
28 * Use the [buildFileEdit] function to create a collection of edits to the
29 * given [source]. The edits will be added to the source change that is being
30 * built. The [timeStamp] is the time at which the [source] was last modified
31 * and is used by clients to ensure that it is safe to apply the edits.
32 */
33 void addFileEdit(Source source, int timeStamp,
34 void buildFileEdit(FileEditBuilder builder));
35 }
36
37 /**
38 * A builder used to build a [SourceEdit] as part of a [SourceFileEdit].
39 *
40 * Clients are not expected to subtype this class.
41 */
42 abstract class EditBuilder {
43 /**
44 * Add a region of text that is part of the linked edit group with the given
45 * [groupName]. The [buildLinkedEdit] function is used to write the content of
46 * the region of text and to add suggestions for other possible values for
47 * that region.
48 */
49 void addLinkedEdit(
50 String groupName, void buildLinkedEdit(LinkedEditBuilder builder));
51
52 /**
53 * Add the given [string] to the content of the current edit.
54 */
55 void write(String string);
56
57 /**
58 * Add the given [string] to the content of the current edit and then add an
59 * end-of-line marker.
60 */
61 void writeln([String string]);
62 }
63
64 /**
65 * A builder used to build a [SourceFileEdit] within a [SourceChange].
66 *
67 * Clients are not expected to subtype this class.
68 */
69 abstract class FileEditBuilder {
70 /**
71 * Add an insertion of text at the given [offset]. The [buildEdit] function is
72 * used to write the text to be inserted. This is fully equivalent to
73 *
74 * addReplacement(offset, 0, buildEdit);
75 */
76 void addInsertion(int offset, void buildEdit(EditBuilder builder));
77
78 /**
79 * Add the region of text starting at the given [offset] and continuing for
Paul Berry 2015/04/27 16:30:10 Since this class is used to build up a change to a
Brian Wilkerson 2015/04/28 15:17:00 Good point. I'll work on improving the docs.
80 * the given [length] to the linked edit group with the given [groupName].
81 * This is typically used to include pre-existing regions of text in a group.
82 */
83 void addLinkedPosition(int offset, int length, String groupName);
84
85 /**
86 * Add a replacement of text starting at the given [offset] and continuing for
Paul Berry 2015/04/27 16:30:10 Similarly, it's not clear here whether the offset
Brian Wilkerson 2015/04/28 15:17:00 Ditto
87 * the given [length]. The [buildEdit] function is used to write the text that
88 * will replace the specified region.
89 */
90 void addReplacement(
91 int offset, int length, void buildEdit(EditBuilder builder));
92 }
93
94 /**
95 * A builder used to build a [LinkedEdit] region within an edit.
96 *
97 * Clients are not expected to subtype this class.
98 */
99 abstract class LinkedEditBuilder {
100 /**
101 * Add the given [value] as a suggestion with the given [kind].
102 */
103 void addSuggestion(LinkedEditSuggestionKind kind, String value);
104
105 /**
106 * Add each of the given [values] as a suggestion with the given [kind].
107 */
108 void addSuggestions(LinkedEditSuggestionKind kind, List<String> values);
Paul Berry 2015/04/27 16:30:10 s/List/Iterable/ so that the caller doesn't have t
Brian Wilkerson 2015/04/28 15:17:00 Done
109
110 /**
111 * Add the given [string] to the content of the current edit.
112 */
113 void write(String string);
114
115 /**
116 * Add the given [string] to the content of the current edit and then add an
117 * end-of-line marker.
118 */
119 void writeln([String string]);
120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698