Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SourceChange.java
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
3 * for details. All rights reserved. Use of this source code is governed by a
4 * BSD-style license that can be found in the LICENSE file.
5 *
6 * This file has been automatically generated. Please do not edit it manually.
7 * To regenerate the file, use the script "pkg/analysis_server/tool/spec/generate_files".
8 */
9package org.dartlang.analysis.server.protocol;
10
11import java.util.Arrays;
12import java.util.List;
13import java.util.Map;
14import com.google.common.collect.Lists;
15import com.google.dart.server.utilities.general.JsonUtilities;
16import com.google.dart.server.utilities.general.ObjectUtilities;
17import com.google.gson.JsonArray;
18import com.google.gson.JsonElement;
19import com.google.gson.JsonObject;
20import com.google.gson.JsonPrimitive;
21import org.apache.commons.lang3.builder.HashCodeBuilder;
22import java.util.ArrayList;
23import java.util.Iterator;
24import org.apache.commons.lang3.StringUtils;
25
26/**
27 * A description of a set of edits that implement a single conceptual change.
28 *
29 * @coverage dart.server.generated.types
30 */
31@SuppressWarnings("unused")
32public class SourceChange {
33
34 public static final SourceChange[] EMPTY_ARRAY = new SourceChange[0];
35
36 public static final List<SourceChange> EMPTY_LIST = Lists.newArrayList();
37
38 /**
39 * A human-readable description of the change to be applied.
40 *
41 * If this change includes multiple edits made for different reasons (such as during a bulk fix
42 * operation), the individual items in edits may contain more specific descriptions.
43 */
44 private final String message;
45
46 /**
47 * A list of the edits used to effect the change, grouped by file.
48 */
49 private final List<SourceFileEdit> edits;
50
51 /**
52 * A list of the linked editing groups used to customize the changes that were made.
53 */
54 private final List<LinkedEditGroup> linkedEditGroups;
55
56 /**
57 * The position that should be selected after the edits have been applied.
58 */
59 private final Position selection;
60
61 /**
62 * The length of the selection (starting at Position) that should be selected after the edits have
63 * been applied.
64 */
65 private final Integer selectionLength;
66
67 /**
68 * The optional identifier of the change kind. The identifier remains stable even if the message
69 * changes, or is parameterized.
70 */
71 private final String id;
72
73 /**
74 * Constructor for {@link SourceChange}.
75 */
76 public SourceChange(String message, List<SourceFileEdit> edits, List<LinkedEditGroup> linkedEditGroups, Position selection, Integer selectionLength, String id) {
77 this.message = message;
78 this.edits = edits;
79 this.linkedEditGroups = linkedEditGroups;
80 this.selection = selection;
81 this.selectionLength = selectionLength;
82 this.id = id;
83 }
84
85 @Override
86 public boolean equals(Object obj) {
87 if (obj instanceof SourceChange) {
88 SourceChange other = (SourceChange) obj;
89 return
90 ObjectUtilities.equals(other.message, message) &&
91 ObjectUtilities.equals(other.edits, edits) &&
92 ObjectUtilities.equals(other.linkedEditGroups, linkedEditGroups) &&
93 ObjectUtilities.equals(other.selection, selection) &&
94 ObjectUtilities.equals(other.selectionLength, selectionLength) &&
95 ObjectUtilities.equals(other.id, id);
96 }
97 return false;
98 }
99
100 public static SourceChange fromJson(JsonObject jsonObject) {
101 String message = jsonObject.get("message").getAsString();
102 List<SourceFileEdit> edits = SourceFileEdit.fromJsonArray(jsonObject.get("edits").getAsJsonArray());
103 List<LinkedEditGroup> linkedEditGroups = LinkedEditGroup.fromJsonArray(jsonObject.get("linkedEditGroups").getAsJsonArray());
104 Position selection = jsonObject.get("selection") == null ? null : Position.fromJson(jsonObject.get("selection").getAsJsonObject());
105 Integer selectionLength = jsonObject.get("selectionLength") == null ? null : jsonObject.get("selectionLength").getAsInt();
106 String id = jsonObject.get("id") == null ? null : jsonObject.get("id").getAsString();
107 return new SourceChange(message, edits, linkedEditGroups, selection, selectionLength, id);
108 }
109
110 public static List<SourceChange> fromJsonArray(JsonArray jsonArray) {
111 if (jsonArray == null) {
112 return EMPTY_LIST;
113 }
114 ArrayList<SourceChange> list = new ArrayList<SourceChange>(jsonArray.size());
115 Iterator<JsonElement> iterator = jsonArray.iterator();
116 while (iterator.hasNext()) {
117 list.add(fromJson(iterator.next().getAsJsonObject()));
118 }
119 return list;
120 }
121
122 /**
123 * A list of the edits used to effect the change, grouped by file.
124 */
126 return edits;
127 }
128
129 /**
130 * The optional identifier of the change kind. The identifier remains stable even if the message
131 * changes, or is parameterized.
132 */
133 public String getId() {
134 return id;
135 }
136
137 /**
138 * A list of the linked editing groups used to customize the changes that were made.
139 */
141 return linkedEditGroups;
142 }
143
144 /**
145 * A human-readable description of the change to be applied.
146 *
147 * If this change includes multiple edits made for different reasons (such as during a bulk fix
148 * operation), the individual items in edits may contain more specific descriptions.
149 */
150 public String getMessage() {
151 return message;
152 }
153
154 /**
155 * The position that should be selected after the edits have been applied.
156 */
158 return selection;
159 }
160
161 /**
162 * The length of the selection (starting at Position) that should be selected after the edits have
163 * been applied.
164 */
165 public Integer getSelectionLength() {
166 return selectionLength;
167 }
168
169 @Override
170 public int hashCode() {
171 HashCodeBuilder builder = new HashCodeBuilder();
172 builder.append(message);
173 builder.append(edits);
174 builder.append(linkedEditGroups);
175 builder.append(selection);
176 builder.append(selectionLength);
177 builder.append(id);
178 return builder.toHashCode();
179 }
180
181 public JsonObject toJson() {
182 JsonObject jsonObject = new JsonObject();
183 jsonObject.addProperty("message", message);
184 JsonArray jsonArrayEdits = new JsonArray();
185 for (SourceFileEdit elt : edits) {
186 jsonArrayEdits.add(elt.toJson());
187 }
188 jsonObject.add("edits", jsonArrayEdits);
189 JsonArray jsonArrayLinkedEditGroups = new JsonArray();
190 for (LinkedEditGroup elt : linkedEditGroups) {
191 jsonArrayLinkedEditGroups.add(elt.toJson());
192 }
193 jsonObject.add("linkedEditGroups", jsonArrayLinkedEditGroups);
194 if (selection != null) {
195 jsonObject.add("selection", selection.toJson());
196 }
197 if (selectionLength != null) {
198 jsonObject.addProperty("selectionLength", selectionLength);
199 }
200 if (id != null) {
201 jsonObject.addProperty("id", id);
202 }
203 return jsonObject;
204 }
205
206 @Override
207 public String toString() {
208 StringBuilder builder = new StringBuilder();
209 builder.append("[");
210 builder.append("message=");
211 builder.append(message + ", ");
212 builder.append("edits=");
213 builder.append(StringUtils.join(edits, ", ") + ", ");
214 builder.append("linkedEditGroups=");
215 builder.append(StringUtils.join(linkedEditGroups, ", ") + ", ");
216 builder.append("selection=");
217 builder.append(selection + ", ");
218 builder.append("selectionLength=");
219 builder.append(selectionLength + ", ");
220 builder.append("id=");
221 builder.append(id);
222 builder.append("]");
223 return builder.toString();
224 }
225
226}
static List< LinkedEditGroup > fromJsonArray(JsonArray jsonArray)
static Position fromJson(JsonObject jsonObject)
Definition Position.java:67
static List< SourceChange > fromJsonArray(JsonArray jsonArray)
SourceChange(String message, List< SourceFileEdit > edits, List< LinkedEditGroup > linkedEditGroups, Position selection, Integer selectionLength, String id)
static SourceChange fromJson(JsonObject jsonObject)
static List< SourceFileEdit > fromJsonArray(JsonArray jsonArray)
Win32Message message
const uintptr_t id