Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SourceEdit.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 single change to a single file.
28 *
29 * @coverage dart.server.generated.types
30 */
31@SuppressWarnings("unused")
32public class SourceEdit {
33
34 public static final SourceEdit[] EMPTY_ARRAY = new SourceEdit[0];
35
36 public static final List<SourceEdit> EMPTY_LIST = Lists.newArrayList();
37
38 /**
39 * The offset of the region to be modified.
40 */
41 private final int offset;
42
43 /**
44 * The length of the region to be modified.
45 */
46 private final int length;
47
48 /**
49 * The code that is to replace the specified region in the original code.
50 */
51 private final String replacement;
52
53 /**
54 * An identifier that uniquely identifies this source edit from other edits in the same response.
55 * This field is omitted unless a containing structure needs to be able to identify the edit for
56 * some reason.
57 *
58 * For example, some refactoring operations can produce edits that might not be appropriate
59 * (referred to as potential edits). Such edits will have an id so that they can be referenced.
60 * Edits in the same response that do not need to be referenced will not have an id.
61 */
62 private final String id;
63
64 /**
65 * A human readable description of the change made by this edit.
66 *
67 * This description should be short and suitable to use as a heading with changes grouped by it.
68 * For example, a change made as part of a quick-fix may use the message "Replace final with var",
69 * allowing multiple changes and multiple applications of the fix to be grouped together.
70 *
71 * This value may be more specific than any value in an enclosing SourceChange.message which could
72 * contain edits made for different reasons (such as during a bulk fix operation).
73 */
74 private final String description;
75
76 /**
77 * Constructor for {@link SourceEdit}.
78 */
79 public SourceEdit(int offset, int length, String replacement, String id, String description) {
80 this.offset = offset;
81 this.length = length;
82 this.replacement = replacement;
83 this.id = id;
84 this.description = description;
85 }
86
87 @Override
88 public boolean equals(Object obj) {
89 if (obj instanceof SourceEdit) {
90 SourceEdit other = (SourceEdit) obj;
91 return
92 other.offset == offset &&
93 other.length == length &&
94 ObjectUtilities.equals(other.replacement, replacement) &&
95 ObjectUtilities.equals(other.id, id) &&
96 ObjectUtilities.equals(other.description, description);
97 }
98 return false;
99 }
100
101 public static SourceEdit fromJson(JsonObject jsonObject) {
102 int offset = jsonObject.get("offset").getAsInt();
103 int length = jsonObject.get("length").getAsInt();
104 String replacement = jsonObject.get("replacement").getAsString();
105 String id = jsonObject.get("id") == null ? null : jsonObject.get("id").getAsString();
106 String description = jsonObject.get("description") == null ? null : jsonObject.get("description").getAsString();
107 return new SourceEdit(offset, length, replacement, id, description);
108 }
109
110 public static List<SourceEdit> fromJsonArray(JsonArray jsonArray) {
111 if (jsonArray == null) {
112 return EMPTY_LIST;
113 }
114 ArrayList<SourceEdit> list = new ArrayList<SourceEdit>(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 human readable description of the change made by this edit.
124 *
125 * This description should be short and suitable to use as a heading with changes grouped by it.
126 * For example, a change made as part of a quick-fix may use the message "Replace final with var",
127 * allowing multiple changes and multiple applications of the fix to be grouped together.
128 *
129 * This value may be more specific than any value in an enclosing SourceChange.message which could
130 * contain edits made for different reasons (such as during a bulk fix operation).
131 */
132 public String getDescription() {
133 return description;
134 }
135
136 /**
137 * An identifier that uniquely identifies this source edit from other edits in the same response.
138 * This field is omitted unless a containing structure needs to be able to identify the edit for
139 * some reason.
140 *
141 * For example, some refactoring operations can produce edits that might not be appropriate
142 * (referred to as potential edits). Such edits will have an id so that they can be referenced.
143 * Edits in the same response that do not need to be referenced will not have an id.
144 */
145 public String getId() {
146 return id;
147 }
148
149 /**
150 * The length of the region to be modified.
151 */
152 public int getLength() {
153 return length;
154 }
155
156 /**
157 * The offset of the region to be modified.
158 */
159 public int getOffset() {
160 return offset;
161 }
162
163 /**
164 * The code that is to replace the specified region in the original code.
165 */
166 public String getReplacement() {
167 return replacement;
168 }
169
170 @Override
171 public int hashCode() {
172 HashCodeBuilder builder = new HashCodeBuilder();
173 builder.append(offset);
174 builder.append(length);
175 builder.append(replacement);
176 builder.append(id);
177 builder.append(description);
178 return builder.toHashCode();
179 }
180
181 public JsonObject toJson() {
182 JsonObject jsonObject = new JsonObject();
183 jsonObject.addProperty("offset", offset);
184 jsonObject.addProperty("length", length);
185 jsonObject.addProperty("replacement", replacement);
186 if (id != null) {
187 jsonObject.addProperty("id", id);
188 }
189 if (description != null) {
190 jsonObject.addProperty("description", description);
191 }
192 return jsonObject;
193 }
194
195 @Override
196 public String toString() {
197 StringBuilder builder = new StringBuilder();
198 builder.append("[");
199 builder.append("offset=");
200 builder.append(offset + ", ");
201 builder.append("length=");
202 builder.append(length + ", ");
203 builder.append("replacement=");
204 builder.append(replacement + ", ");
205 builder.append("id=");
206 builder.append(id + ", ");
207 builder.append("description=");
208 builder.append(description);
209 builder.append("]");
210 return builder.toString();
211 }
212
213}
SourceEdit(int offset, int length, String replacement, String id, String description)
static List< SourceEdit > fromJsonArray(JsonArray jsonArray)
static SourceEdit fromJson(JsonObject jsonObject)
size_t length
Point offset
const uintptr_t id