Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Element.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 * Information about an element (something that can be declared in code).
28 *
29 * @coverage dart.server.generated.types
30 */
31@SuppressWarnings("unused")
32public class Element {
33
34 public static final Element[] EMPTY_ARRAY = new Element[0];
35
36 public static final List<Element> EMPTY_LIST = Lists.newArrayList();
37
38 private static final int ABSTRACT = 0x01;
39
40 private static final int CONST = 0x02;
41
42 private static final int FINAL = 0x04;
43
44 private static final int TOP_LEVEL_STATIC = 0x08;
45
46 private static final int PRIVATE = 0x10;
47
48 private static final int DEPRECATED = 0x20;
49
50 /**
51 * The kind of the element.
52 */
53 private final String kind;
54
55 /**
56 * The name of the element. This is typically used as the label in the outline.
57 */
58 private final String name;
59
60 /**
61 * The location of the name in the declaration of the element.
62 */
63 private final Location location;
64
65 /**
66 * A bit-map containing the following flags:
67 *
68 * - 0x01 - set if the element is explicitly or implicitly abstract
69 * - 0x02 - set if the element was declared to be 'const'
70 * - 0x04 - set if the element was declared to be 'final'
71 * - 0x08 - set if the element is a static member of a class or is a top-level function or field
72 * - 0x10 - set if the element is private
73 * - 0x20 - set if the element is deprecated
74 */
75 private final int flags;
76
77 /**
78 * The parameter list for the element. If the element is not a method or function this field will
79 * not be defined. If the element doesn't have parameters (e.g. getter), this field will not be
80 * defined. If the element has zero parameters, this field will have a value of "()".
81 */
82 private final String parameters;
83
84 /**
85 * The return type of the element. If the element is not a method or function this field will not
86 * be defined. If the element does not have a declared return type, this field will contain an
87 * empty string.
88 */
89 private final String returnType;
90
91 /**
92 * The type parameter list for the element. If the element doesn't have type parameters, this field
93 * will not be defined.
94 */
95 private final String typeParameters;
96
97 /**
98 * If the element is a type alias, this field is the aliased type. Otherwise this field will not be
99 * defined.
100 */
101 private final String aliasedType;
102
103 /**
104 * Constructor for {@link Element}.
105 */
106 public Element(String kind, String name, Location location, int flags, String parameters, String returnType, String typeParameters, String aliasedType) {
107 this.kind = kind;
108 this.name = name;
109 this.location = location;
110 this.flags = flags;
111 this.parameters = parameters;
112 this.returnType = returnType;
113 this.typeParameters = typeParameters;
114 this.aliasedType = aliasedType;
115 }
116
117 @Override
118 public boolean equals(Object obj) {
119 if (obj instanceof Element) {
120 Element other = (Element) obj;
121 return
122 ObjectUtilities.equals(other.kind, kind) &&
123 ObjectUtilities.equals(other.name, name) &&
124 ObjectUtilities.equals(other.location, location) &&
125 other.flags == flags &&
126 ObjectUtilities.equals(other.parameters, parameters) &&
127 ObjectUtilities.equals(other.returnType, returnType) &&
128 ObjectUtilities.equals(other.typeParameters, typeParameters) &&
129 ObjectUtilities.equals(other.aliasedType, aliasedType);
130 }
131 return false;
132 }
133
134 public static Element fromJson(JsonObject jsonObject) {
135 String kind = jsonObject.get("kind").getAsString();
136 String name = jsonObject.get("name").getAsString();
137 Location location = jsonObject.get("location") == null ? null : Location.fromJson(jsonObject.get("location").getAsJsonObject());
138 int flags = jsonObject.get("flags").getAsInt();
139 String parameters = jsonObject.get("parameters") == null ? null : jsonObject.get("parameters").getAsString();
140 String returnType = jsonObject.get("returnType") == null ? null : jsonObject.get("returnType").getAsString();
141 String typeParameters = jsonObject.get("typeParameters") == null ? null : jsonObject.get("typeParameters").getAsString();
142 String aliasedType = jsonObject.get("aliasedType") == null ? null : jsonObject.get("aliasedType").getAsString();
143 return new Element(kind, name, location, flags, parameters, returnType, typeParameters, aliasedType);
144 }
145
146 public static List<Element> fromJsonArray(JsonArray jsonArray) {
147 if (jsonArray == null) {
148 return EMPTY_LIST;
149 }
150 ArrayList<Element> list = new ArrayList<Element>(jsonArray.size());
151 Iterator<JsonElement> iterator = jsonArray.iterator();
152 while (iterator.hasNext()) {
153 list.add(fromJson(iterator.next().getAsJsonObject()));
154 }
155 return list;
156 }
157
158 /**
159 * If the element is a type alias, this field is the aliased type. Otherwise this field will not be
160 * defined.
161 */
162 public String getAliasedType() {
163 return aliasedType;
164 }
165
166 /**
167 * A bit-map containing the following flags:
168 *
169 * - 0x01 - set if the element is explicitly or implicitly abstract
170 * - 0x02 - set if the element was declared to be 'const'
171 * - 0x04 - set if the element was declared to be 'final'
172 * - 0x08 - set if the element is a static member of a class or is a top-level function or field
173 * - 0x10 - set if the element is private
174 * - 0x20 - set if the element is deprecated
175 */
176 public int getFlags() {
177 return flags;
178 }
179
180 /**
181 * The kind of the element.
182 */
183 public String getKind() {
184 return kind;
185 }
186
187 /**
188 * The location of the name in the declaration of the element.
189 */
191 return location;
192 }
193
194 /**
195 * The name of the element. This is typically used as the label in the outline.
196 */
197 public String getName() {
198 return name;
199 }
200
201 /**
202 * The parameter list for the element. If the element is not a method or function this field will
203 * not be defined. If the element doesn't have parameters (e.g. getter), this field will not be
204 * defined. If the element has zero parameters, this field will have a value of "()".
205 */
206 public String getParameters() {
207 return parameters;
208 }
209
210 /**
211 * The return type of the element. If the element is not a method or function this field will not
212 * be defined. If the element does not have a declared return type, this field will contain an
213 * empty string.
214 */
215 public String getReturnType() {
216 return returnType;
217 }
218
219 /**
220 * The type parameter list for the element. If the element doesn't have type parameters, this field
221 * will not be defined.
222 */
223 public String getTypeParameters() {
224 return typeParameters;
225 }
226
227 @Override
228 public int hashCode() {
229 HashCodeBuilder builder = new HashCodeBuilder();
230 builder.append(kind);
231 builder.append(name);
232 builder.append(location);
233 builder.append(flags);
234 builder.append(parameters);
235 builder.append(returnType);
236 builder.append(typeParameters);
237 builder.append(aliasedType);
238 return builder.toHashCode();
239 }
240
241 public boolean isAbstract() {
242 return (flags & ABSTRACT) != 0;
243 }
244
245 public boolean isConst() {
246 return (flags & CONST) != 0;
247 }
248
249 public boolean isDeprecated() {
250 return (flags & DEPRECATED) != 0;
251 }
252
253 public boolean isFinal() {
254 return (flags & FINAL) != 0;
255 }
256
257 public boolean isPrivate() {
258 return (flags & PRIVATE) != 0;
259 }
260
261 public boolean isTopLevelOrStatic() {
262 return (flags & TOP_LEVEL_STATIC) != 0;
263 }
264
265 public JsonObject toJson() {
266 JsonObject jsonObject = new JsonObject();
267 jsonObject.addProperty("kind", kind);
268 jsonObject.addProperty("name", name);
269 if (location != null) {
270 jsonObject.add("location", location.toJson());
271 }
272 jsonObject.addProperty("flags", flags);
273 if (parameters != null) {
274 jsonObject.addProperty("parameters", parameters);
275 }
276 if (returnType != null) {
277 jsonObject.addProperty("returnType", returnType);
278 }
279 if (typeParameters != null) {
280 jsonObject.addProperty("typeParameters", typeParameters);
281 }
282 if (aliasedType != null) {
283 jsonObject.addProperty("aliasedType", aliasedType);
284 }
285 return jsonObject;
286 }
287
288 @Override
289 public String toString() {
290 StringBuilder builder = new StringBuilder();
291 builder.append("[");
292 builder.append("kind=");
293 builder.append(kind + ", ");
294 builder.append("name=");
295 builder.append(name + ", ");
296 builder.append("location=");
297 builder.append(location + ", ");
298 builder.append("flags=");
299 builder.append(flags + ", ");
300 builder.append("parameters=");
301 builder.append(parameters + ", ");
302 builder.append("returnType=");
303 builder.append(returnType + ", ");
304 builder.append("typeParameters=");
305 builder.append(typeParameters + ", ");
306 builder.append("aliasedType=");
307 builder.append(aliasedType);
308 builder.append("]");
309 return builder.toString();
310 }
311
312}
static List< Element > fromJsonArray(JsonArray jsonArray)
Definition Element.java:146
Element(String kind, String name, Location location, int flags, String parameters, String returnType, String typeParameters, String aliasedType)
Definition Element.java:106
static Element fromJson(JsonObject jsonObject)
Definition Element.java:134
static Location fromJson(JsonObject jsonObject)
FlutterSemanticsFlag flags
const char * name
Definition fuchsia.cc:50