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

Side by Side Diff: pkg/analysis_services/lib/src/generated/change.dart

Issue 250823006: Translate parts of engine.services project. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Move to pkg/analysis_services/ Created 6 years, 7 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
« no previous file with comments | « pkg/analysis_services/LICENSE ('k') | pkg/analysis_services/lib/src/generated/proposal.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.change;
9
10 import 'package:analyzer/src/generated/java_io.dart' show JavaFile;
11 import 'package:analyzer/src/generated/source.dart';
12
13 /**
14 * Describes some abstract operation to perform.
15 *
16 * [Change] implementations in "services" plugin cannot perform operation themse lves, they are
17 * just descriptions of operation. Actual operation should be performed by clien t.
18 */
19 abstract class Change {
20 final String name;
21
22 Change(this.name);
23 }
24
25 /**
26 * Composition of several [Change]s.
27 */
28 class CompositeChange extends Change {
29 List<Change> _children = [];
30
31 CompositeChange(String name, [Iterable<Change> changes]) : super(name) {
32 if (changes != null) {
33 _children.addAll(changes);
34 }
35 }
36
37 /**
38 * Adds given [Change]s.
39 */
40 void add(List<Change> changes) {
41 _children.addAll(changes);
42 }
43
44 /**
45 * @return the children [Change]s.
46 */
47 List<Change> get children => _children;
48 }
49
50 /**
51 * [Change] to create new file.
52 */
53 class CreateFileChange extends Change {
54 final JavaFile file;
55
56 final String content;
57
58 CreateFileChange(String name, this.file, this.content) : super(name);
59 }
60
61 /**
62 * Describes a text edit. Edits are executed by applying them to a [Source].
63 */
64 class Edit {
65 /**
66 * The offset at which to apply the edit.
67 */
68 final int offset;
69
70 /**
71 * The length of the text interval to replace.
72 */
73 final int length;
74
75 /**
76 * The replacement text.
77 */
78 final String replacement;
79
80 /**
81 * Create an edit.
82 *
83 * @param offset the offset at which to apply the edit
84 * @param length the length of the text interval replace
85 * @param replacement the replacement text
86 */
87 Edit(this.offset, this.length, this.replacement);
88
89 /**
90 * Create an edit.
91 *
92 * @param range the [SourceRange] to replace
93 * @param replacement the replacement text
94 */
95 Edit.range(SourceRange range, String replacement) : this(range.offset, range.l ength, replacement);
96
97 @override
98 String toString() => "${(offset < 0 ? "(" : "X(")}offset: ${offset}, length ${ length}, replacement :>${replacement}<:)";
99 }
100
101 /**
102 * Composition of two [CompositeChange]s. First change should be displayed in pr eview, but
103 * merged into second one before execution.
104 */
105 class MergeCompositeChange extends Change {
106 final CompositeChange previewChange;
107
108 final CompositeChange executeChange;
109
110 MergeCompositeChange(String name, this.previewChange, this.executeChange) : su per(name);
111 }
112
113 /**
114 * [Change] to apply to single [Source].
115 */
116 class SourceChange extends Change {
117 final Source source;
118
119 final List<Edit> edits = [];
120
121 Map<String, List<Edit>> _editGroups = {};
122
123 /**
124 * @param name the name of this change to display in UI
125 * @param source the [Source] to change
126 */
127 SourceChange(String name, this.source) : super(name);
128
129 /**
130 * Adds the [Edit] to apply.
131 */
132 void addEdit(Edit edit, [String description = '']) {
133 // add to all edits
134 edits.add(edit);
135 // add to group
136 {
137 List<Edit> group = _editGroups[description];
138 if (group == null) {
139 group = [];
140 _editGroups[description] = group;
141 }
142 group.add(edit);
143 }
144 }
145
146 /**
147 * @return the [Edit]s grouped by their descriptions.
148 */
149 Map<String, List<Edit>> get editGroups => _editGroups;
150 }
151
152 /**
153 * Manages multiple [SourceChange] objects.
154 */
155 class SourceChangeManager {
156 Map<Source, SourceChange> _changeMap = {};
157
158 /**
159 * @return the [SourceChange] to record modifications for given [Source].
160 */
161 SourceChange get(Source source) {
162 SourceChange change = _changeMap[source];
163 if (change == null) {
164 change = new SourceChange(source.shortName, source);
165 _changeMap[source] = change;
166 }
167 return change;
168 }
169
170 /**
171 * @return all [SourceChange] in this manager.
172 */
173 List<SourceChange> get changes {
174 Iterable<SourceChange> changes = _changeMap.values;
175 return new List.from(changes);
176 }
177 }
OLDNEW
« no previous file with comments | « pkg/analysis_services/LICENSE ('k') | pkg/analysis_services/lib/src/generated/proposal.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698