Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
ExtractMethodFeedback.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 * @coverage dart.server.generated.types
28 */
29@SuppressWarnings("unused")
31
32 public static final ExtractMethodFeedback[] EMPTY_ARRAY = new ExtractMethodFeedback[0];
33
34 public static final List<ExtractMethodFeedback> EMPTY_LIST = Lists.newArrayList();
35
36 /**
37 * The offset to the beginning of the expression or statements that will be extracted.
38 */
39 private final int offset;
40
41 /**
42 * The length of the expression or statements that will be extracted.
43 */
44 private final int length;
45
46 /**
47 * The proposed return type for the method. If the returned element does not have a declared return
48 * type, this field will contain an empty string.
49 */
50 private final String returnType;
51
52 /**
53 * The proposed names for the method.
54 */
55 private final List<String> names;
56
57 /**
58 * True if a getter could be created rather than a method.
59 */
60 private final boolean canCreateGetter;
61
62 /**
63 * The proposed parameters for the method.
64 */
65 private final List<RefactoringMethodParameter> parameters;
66
67 /**
68 * The offsets of the expressions or statements that would be replaced by an invocation of the
69 * method.
70 */
71 private final int[] offsets;
72
73 /**
74 * The lengths of the expressions or statements that would be replaced by an invocation of the
75 * method. The lengths correspond to the offsets. In other words, for a given expression (or block
76 * of statements), if the offset of that expression is offsets[i], then the length of that
77 * expression is lengths[i].
78 */
79 private final int[] lengths;
80
81 /**
82 * Constructor for {@link ExtractMethodFeedback}.
83 */
84 public ExtractMethodFeedback(int offset, int length, String returnType, List<String> names, boolean canCreateGetter, List<RefactoringMethodParameter> parameters, int[] offsets, int[] lengths) {
85 this.offset = offset;
86 this.length = length;
87 this.returnType = returnType;
88 this.names = names;
89 this.canCreateGetter = canCreateGetter;
90 this.parameters = parameters;
91 this.offsets = offsets;
92 this.lengths = lengths;
93 }
94
95 @Override
96 public boolean equals(Object obj) {
97 if (obj instanceof ExtractMethodFeedback) {
99 return
100 other.offset == offset &&
101 other.length == length &&
102 ObjectUtilities.equals(other.returnType, returnType) &&
103 ObjectUtilities.equals(other.names, names) &&
104 other.canCreateGetter == canCreateGetter &&
105 ObjectUtilities.equals(other.parameters, parameters) &&
106 Arrays.equals(other.offsets, offsets) &&
107 Arrays.equals(other.lengths, lengths);
108 }
109 return false;
110 }
111
112 public static ExtractMethodFeedback fromJson(JsonObject jsonObject) {
113 int offset = jsonObject.get("offset").getAsInt();
114 int length = jsonObject.get("length").getAsInt();
115 String returnType = jsonObject.get("returnType").getAsString();
116 List<String> names = JsonUtilities.decodeStringList(jsonObject.get("names").getAsJsonArray());
117 boolean canCreateGetter = jsonObject.get("canCreateGetter").getAsBoolean();
118 List<RefactoringMethodParameter> parameters = RefactoringMethodParameter.fromJsonArray(jsonObject.get("parameters").getAsJsonArray());
119 int[] offsets = JsonUtilities.decodeIntArray(jsonObject.get("offsets").getAsJsonArray());
120 int[] lengths = JsonUtilities.decodeIntArray(jsonObject.get("lengths").getAsJsonArray());
121 return new ExtractMethodFeedback(offset, length, returnType, names, canCreateGetter, parameters, offsets, lengths);
122 }
123
124 public static List<ExtractMethodFeedback> fromJsonArray(JsonArray jsonArray) {
125 if (jsonArray == null) {
126 return EMPTY_LIST;
127 }
128 ArrayList<ExtractMethodFeedback> list = new ArrayList<ExtractMethodFeedback>(jsonArray.size());
129 Iterator<JsonElement> iterator = jsonArray.iterator();
130 while (iterator.hasNext()) {
131 list.add(fromJson(iterator.next().getAsJsonObject()));
132 }
133 return list;
134 }
135
136 /**
137 * True if a getter could be created rather than a method.
138 */
139 public boolean canCreateGetter() {
140 return canCreateGetter;
141 }
142
143 /**
144 * The length of the expression or statements that will be extracted.
145 */
146 public int getLength() {
147 return length;
148 }
149
150 /**
151 * The lengths of the expressions or statements that would be replaced by an invocation of the
152 * method. The lengths correspond to the offsets. In other words, for a given expression (or block
153 * of statements), if the offset of that expression is offsets[i], then the length of that
154 * expression is lengths[i].
155 */
156 public int[] getLengths() {
157 return lengths;
158 }
159
160 /**
161 * The proposed names for the method.
162 */
164 return names;
165 }
166
167 /**
168 * The offset to the beginning of the expression or statements that will be extracted.
169 */
170 public int getOffset() {
171 return offset;
172 }
173
174 /**
175 * The offsets of the expressions or statements that would be replaced by an invocation of the
176 * method.
177 */
178 public int[] getOffsets() {
179 return offsets;
180 }
181
182 /**
183 * The proposed parameters for the method.
184 */
186 return parameters;
187 }
188
189 /**
190 * The proposed return type for the method. If the returned element does not have a declared return
191 * type, this field will contain an empty string.
192 */
193 public String getReturnType() {
194 return returnType;
195 }
196
197 @Override
198 public int hashCode() {
199 HashCodeBuilder builder = new HashCodeBuilder();
200 builder.append(offset);
201 builder.append(length);
202 builder.append(returnType);
203 builder.append(names);
204 builder.append(canCreateGetter);
205 builder.append(parameters);
206 builder.append(offsets);
207 builder.append(lengths);
208 return builder.toHashCode();
209 }
210
211 public JsonObject toJson() {
212 JsonObject jsonObject = new JsonObject();
213 jsonObject.addProperty("offset", offset);
214 jsonObject.addProperty("length", length);
215 jsonObject.addProperty("returnType", returnType);
216 JsonArray jsonArrayNames = new JsonArray();
217 for (String elt : names) {
218 jsonArrayNames.add(new JsonPrimitive(elt));
219 }
220 jsonObject.add("names", jsonArrayNames);
221 jsonObject.addProperty("canCreateGetter", canCreateGetter);
222 JsonArray jsonArrayParameters = new JsonArray();
223 for (RefactoringMethodParameter elt : parameters) {
224 jsonArrayParameters.add(elt.toJson());
225 }
226 jsonObject.add("parameters", jsonArrayParameters);
227 JsonArray jsonArrayOffsets = new JsonArray();
228 for (int elt : offsets) {
229 jsonArrayOffsets.add(new JsonPrimitive(elt));
230 }
231 jsonObject.add("offsets", jsonArrayOffsets);
232 JsonArray jsonArrayLengths = new JsonArray();
233 for (int elt : lengths) {
234 jsonArrayLengths.add(new JsonPrimitive(elt));
235 }
236 jsonObject.add("lengths", jsonArrayLengths);
237 return jsonObject;
238 }
239
240 @Override
241 public String toString() {
242 StringBuilder builder = new StringBuilder();
243 builder.append("[");
244 builder.append("offset=");
245 builder.append(offset + ", ");
246 builder.append("length=");
247 builder.append(length + ", ");
248 builder.append("returnType=");
249 builder.append(returnType + ", ");
250 builder.append("names=");
251 builder.append(StringUtils.join(names, ", ") + ", ");
252 builder.append("canCreateGetter=");
253 builder.append(canCreateGetter + ", ");
254 builder.append("parameters=");
255 builder.append(StringUtils.join(parameters, ", ") + ", ");
256 builder.append("offsets=");
257 builder.append(StringUtils.join(offsets, ", ") + ", ");
258 builder.append("lengths=");
259 builder.append(StringUtils.join(lengths, ", "));
260 builder.append("]");
261 return builder.toString();
262 }
263
264}
ExtractMethodFeedback(int offset, int length, String returnType, List< String > names, boolean canCreateGetter, List< RefactoringMethodParameter > parameters, int[] offsets, int[] lengths)
static List< ExtractMethodFeedback > fromJsonArray(JsonArray jsonArray)
static ExtractMethodFeedback fromJson(JsonObject jsonObject)
static List< RefactoringMethodParameter > fromJsonArray(JsonArray jsonArray)
size_t length
Point offset