Flutter Engine
The Flutter Engine
FlutterOutline.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 * An node in the Flutter specific outline structure of a file.
28 *
29 * @coverage dart.server.generated.types
30 */
31@SuppressWarnings("unused")
32public class FlutterOutline {
33
34 public static final FlutterOutline[] EMPTY_ARRAY = new FlutterOutline[0];
35
36 public static final List<FlutterOutline> EMPTY_LIST = Lists.newArrayList();
37
38 /**
39 * The kind of the node.
40 */
41 private final String kind;
42
43 /**
44 * The offset of the first character of the element. This is different than the offset in the
45 * Element, which is the offset of the name of the element. It can be used, for example, to map
46 * locations in the file back to an outline.
47 */
48 private final int offset;
49
50 /**
51 * The length of the element.
52 */
53 private final int length;
54
55 /**
56 * The offset of the first character of the element code, which is neither documentation, nor
57 * annotation.
58 */
59 private final int codeOffset;
60
61 /**
62 * The length of the element code.
63 */
64 private final int codeLength;
65
66 /**
67 * The text label of the node children of the node. It is provided for any
68 * FlutterOutlineKind.GENERIC node, where better information is not available.
69 */
70 private final String label;
71
72 /**
73 * If this node is a Dart element, the description of it; omitted otherwise.
74 */
75 private final Element dartElement;
76
77 /**
78 * Additional attributes for this node, which might be interesting to display on the client. These
79 * attributes are usually arguments for the instance creation or the invocation that created the
80 * widget.
81 */
82 private final List<FlutterOutlineAttribute> attributes;
83
84 /**
85 * If the node creates a new class instance, or a reference to an instance, this field has the name
86 * of the class.
87 */
88 private final String className;
89
90 /**
91 * A short text description how this node is associated with the parent node. For example "appBar"
92 * or "body" in Scaffold.
93 */
94 private final String parentAssociationLabel;
95
96 /**
97 * If FlutterOutlineKind.VARIABLE, the name of the variable.
98 */
99 private final String variableName;
100
101 /**
102 * The children of the node. The field will be omitted if the node has no children.
103 */
104 private final List<FlutterOutline> children;
105
106 /**
107 * Constructor for {@link FlutterOutline}.
108 */
109 public FlutterOutline(String kind, int offset, int length, int codeOffset, int codeLength, String label, Element dartElement, List<FlutterOutlineAttribute> attributes, String className, String parentAssociationLabel, String variableName, List<FlutterOutline> children) {
110 this.kind = kind;
111 this.offset = offset;
112 this.length = length;
113 this.codeOffset = codeOffset;
114 this.codeLength = codeLength;
115 this.label = label;
116 this.dartElement = dartElement;
117 this.attributes = attributes;
118 this.className = className;
119 this.parentAssociationLabel = parentAssociationLabel;
120 this.variableName = variableName;
121 this.children = children;
122 }
123
124 @Override
125 public boolean equals(Object obj) {
126 if (obj instanceof FlutterOutline) {
127 FlutterOutline other = (FlutterOutline) obj;
128 return
129 ObjectUtilities.equals(other.kind, kind) &&
130 other.offset == offset &&
131 other.length == length &&
132 other.codeOffset == codeOffset &&
133 other.codeLength == codeLength &&
134 ObjectUtilities.equals(other.label, label) &&
135 ObjectUtilities.equals(other.dartElement, dartElement) &&
136 ObjectUtilities.equals(other.attributes, attributes) &&
137 ObjectUtilities.equals(other.className, className) &&
138 ObjectUtilities.equals(other.parentAssociationLabel, parentAssociationLabel) &&
139 ObjectUtilities.equals(other.variableName, variableName) &&
140 ObjectUtilities.equals(other.children, children);
141 }
142 return false;
143 }
144
145 public static FlutterOutline fromJson(JsonObject jsonObject) {
146 String kind = jsonObject.get("kind").getAsString();
147 int offset = jsonObject.get("offset").getAsInt();
148 int length = jsonObject.get("length").getAsInt();
149 int codeOffset = jsonObject.get("codeOffset").getAsInt();
150 int codeLength = jsonObject.get("codeLength").getAsInt();
151 String label = jsonObject.get("label") == null ? null : jsonObject.get("label").getAsString();
152 Element dartElement = jsonObject.get("dartElement") == null ? null : Element.fromJson(jsonObject.get("dartElement").getAsJsonObject());
153 List<FlutterOutlineAttribute> attributes = jsonObject.get("attributes") == null ? null : FlutterOutlineAttribute.fromJsonArray(jsonObject.get("attributes").getAsJsonArray());
154 String className = jsonObject.get("className") == null ? null : jsonObject.get("className").getAsString();
155 String parentAssociationLabel = jsonObject.get("parentAssociationLabel") == null ? null : jsonObject.get("parentAssociationLabel").getAsString();
156 String variableName = jsonObject.get("variableName") == null ? null : jsonObject.get("variableName").getAsString();
157 List<FlutterOutline> children = jsonObject.get("children") == null ? null : FlutterOutline.fromJsonArray(jsonObject.get("children").getAsJsonArray());
158 return new FlutterOutline(kind, offset, length, codeOffset, codeLength, label, dartElement, attributes, className, parentAssociationLabel, variableName, children);
159 }
160
161 public static List<FlutterOutline> fromJsonArray(JsonArray jsonArray) {
162 if (jsonArray == null) {
163 return EMPTY_LIST;
164 }
165 ArrayList<FlutterOutline> list = new ArrayList<FlutterOutline>(jsonArray.size());
166 Iterator<JsonElement> iterator = jsonArray.iterator();
167 while (iterator.hasNext()) {
168 list.add(fromJson(iterator.next().getAsJsonObject()));
169 }
170 return list;
171 }
172
173 /**
174 * Additional attributes for this node, which might be interesting to display on the client. These
175 * attributes are usually arguments for the instance creation or the invocation that created the
176 * widget.
177 */
179 return attributes;
180 }
181
182 /**
183 * The children of the node. The field will be omitted if the node has no children.
184 */
186 return children;
187 }
188
189 /**
190 * If the node creates a new class instance, or a reference to an instance, this field has the name
191 * of the class.
192 */
193 public String getClassName() {
194 return className;
195 }
196
197 /**
198 * The length of the element code.
199 */
200 public int getCodeLength() {
201 return codeLength;
202 }
203
204 /**
205 * The offset of the first character of the element code, which is neither documentation, nor
206 * annotation.
207 */
208 public int getCodeOffset() {
209 return codeOffset;
210 }
211
212 /**
213 * If this node is a Dart element, the description of it; omitted otherwise.
214 */
216 return dartElement;
217 }
218
219 /**
220 * The kind of the node.
221 */
222 public String getKind() {
223 return kind;
224 }
225
226 /**
227 * The text label of the node children of the node. It is provided for any
228 * FlutterOutlineKind.GENERIC node, where better information is not available.
229 */
230 public String getLabel() {
231 return label;
232 }
233
234 /**
235 * The length of the element.
236 */
237 public int getLength() {
238 return length;
239 }
240
241 /**
242 * The offset of the first character of the element. This is different than the offset in the
243 * Element, which is the offset of the name of the element. It can be used, for example, to map
244 * locations in the file back to an outline.
245 */
246 public int getOffset() {
247 return offset;
248 }
249
250 /**
251 * A short text description how this node is associated with the parent node. For example "appBar"
252 * or "body" in Scaffold.
253 */
255 return parentAssociationLabel;
256 }
257
258 /**
259 * If FlutterOutlineKind.VARIABLE, the name of the variable.
260 */
261 public String getVariableName() {
262 return variableName;
263 }
264
265 @Override
266 public int hashCode() {
267 HashCodeBuilder builder = new HashCodeBuilder();
268 builder.append(kind);
269 builder.append(offset);
270 builder.append(length);
271 builder.append(codeOffset);
272 builder.append(codeLength);
273 builder.append(label);
274 builder.append(dartElement);
275 builder.append(attributes);
276 builder.append(className);
277 builder.append(parentAssociationLabel);
278 builder.append(variableName);
279 builder.append(children);
280 return builder.toHashCode();
281 }
282
283 public JsonObject toJson() {
284 JsonObject jsonObject = new JsonObject();
285 jsonObject.addProperty("kind", kind);
286 jsonObject.addProperty("offset", offset);
287 jsonObject.addProperty("length", length);
288 jsonObject.addProperty("codeOffset", codeOffset);
289 jsonObject.addProperty("codeLength", codeLength);
290 if (label != null) {
291 jsonObject.addProperty("label", label);
292 }
293 if (dartElement != null) {
294 jsonObject.add("dartElement", dartElement.toJson());
295 }
296 if (attributes != null) {
297 JsonArray jsonArrayAttributes = new JsonArray();
298 for (FlutterOutlineAttribute elt : attributes) {
299 jsonArrayAttributes.add(elt.toJson());
300 }
301 jsonObject.add("attributes", jsonArrayAttributes);
302 }
303 if (className != null) {
304 jsonObject.addProperty("className", className);
305 }
306 if (parentAssociationLabel != null) {
307 jsonObject.addProperty("parentAssociationLabel", parentAssociationLabel);
308 }
309 if (variableName != null) {
310 jsonObject.addProperty("variableName", variableName);
311 }
312 if (children != null) {
313 JsonArray jsonArrayChildren = new JsonArray();
314 for (FlutterOutline elt : children) {
315 jsonArrayChildren.add(elt.toJson());
316 }
317 jsonObject.add("children", jsonArrayChildren);
318 }
319 return jsonObject;
320 }
321
322 @Override
323 public String toString() {
324 StringBuilder builder = new StringBuilder();
325 builder.append("[");
326 builder.append("kind=");
327 builder.append(kind + ", ");
328 builder.append("offset=");
329 builder.append(offset + ", ");
330 builder.append("length=");
331 builder.append(length + ", ");
332 builder.append("codeOffset=");
333 builder.append(codeOffset + ", ");
334 builder.append("codeLength=");
335 builder.append(codeLength + ", ");
336 builder.append("label=");
337 builder.append(label + ", ");
338 builder.append("dartElement=");
339 builder.append(dartElement + ", ");
340 builder.append("attributes=");
341 builder.append(StringUtils.join(attributes, ", ") + ", ");
342 builder.append("className=");
343 builder.append(className + ", ");
344 builder.append("parentAssociationLabel=");
345 builder.append(parentAssociationLabel + ", ");
346 builder.append("variableName=");
347 builder.append(variableName + ", ");
348 builder.append("children=");
349 builder.append(StringUtils.join(children, ", "));
350 builder.append("]");
351 return builder.toString();
352 }
353
354}
static Element fromJson(JsonObject jsonObject)
Definition: Element.java:134
static List< FlutterOutlineAttribute > fromJsonArray(JsonArray jsonArray)
static FlutterOutline fromJson(JsonObject jsonObject)
FlutterOutline(String kind, int offset, int length, int codeOffset, int codeLength, String label, Element dartElement, List< FlutterOutlineAttribute > attributes, String className, String parentAssociationLabel, String variableName, List< FlutterOutline > children)
static List< FlutterOutline > fromJsonArray(JsonArray jsonArray)
size_t length
SeparatedVector2 offset