Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
TypeHierarchyItem.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 representation of a class in a type hierarchy.
28 *
29 * @coverage dart.server.generated.types
30 */
31@SuppressWarnings("unused")
32public class TypeHierarchyItem {
33
34 public static final TypeHierarchyItem[] EMPTY_ARRAY = new TypeHierarchyItem[0];
35
36 public static final List<TypeHierarchyItem> EMPTY_LIST = Lists.newArrayList();
37
38 /**
39 * The class element represented by this item.
40 */
41 private final Element classElement;
42
43 /**
44 * The name to be displayed for the class. This field will be omitted if the display name is the
45 * same as the name of the element. The display name is different if there is additional type
46 * information to be displayed, such as type arguments.
47 */
48 private final String displayName;
49
50 /**
51 * The member in the class corresponding to the member on which the hierarchy was requested. This
52 * field will be omitted if the hierarchy was not requested for a member or if the class does not
53 * have a corresponding member.
54 */
55 private final Element memberElement;
56
57 /**
58 * The index of the item representing the superclass of this class. This field will be omitted if
59 * this item represents the class Object.
60 */
61 private final Integer superclass;
62
63 /**
64 * The indexes of the items representing the interfaces implemented by this class. The list will be
65 * empty if there are no implemented interfaces.
66 */
67 private final int[] interfaces;
68
69 /**
70 * The indexes of the items representing the mixins referenced by this class. The list will be
71 * empty if there are no classes mixed into this class.
72 */
73 private final int[] mixins;
74
75 /**
76 * The indexes of the items representing the subtypes of this class. The list will be empty if
77 * there are no subtypes or if this item represents a supertype of the pivot type.
78 */
79 private final int[] subclasses;
80
81 /**
82 * Constructor for {@link TypeHierarchyItem}.
83 */
84 public TypeHierarchyItem(Element classElement, String displayName, Element memberElement, Integer superclass, int[] interfaces, int[] mixins, int[] subclasses) {
85 this.classElement = classElement;
86 this.displayName = displayName;
87 this.memberElement = memberElement;
88 this.superclass = superclass;
89 this.interfaces = interfaces;
90 this.mixins = mixins;
91 this.subclasses = subclasses;
92 }
93
94 @Override
95 public boolean equals(Object obj) {
96 if (obj instanceof TypeHierarchyItem) {
98 return
99 ObjectUtilities.equals(other.classElement, classElement) &&
100 ObjectUtilities.equals(other.displayName, displayName) &&
101 ObjectUtilities.equals(other.memberElement, memberElement) &&
102 ObjectUtilities.equals(other.superclass, superclass) &&
103 Arrays.equals(other.interfaces, interfaces) &&
104 Arrays.equals(other.mixins, mixins) &&
105 Arrays.equals(other.subclasses, subclasses);
106 }
107 return false;
108 }
109
110 public static TypeHierarchyItem fromJson(JsonObject jsonObject) {
111 Element classElement = Element.fromJson(jsonObject.get("classElement").getAsJsonObject());
112 String displayName = jsonObject.get("displayName") == null ? null : jsonObject.get("displayName").getAsString();
113 Element memberElement = jsonObject.get("memberElement") == null ? null : Element.fromJson(jsonObject.get("memberElement").getAsJsonObject());
114 Integer superclass = jsonObject.get("superclass") == null ? null : jsonObject.get("superclass").getAsInt();
115 int[] interfaces = JsonUtilities.decodeIntArray(jsonObject.get("interfaces").getAsJsonArray());
116 int[] mixins = JsonUtilities.decodeIntArray(jsonObject.get("mixins").getAsJsonArray());
117 int[] subclasses = JsonUtilities.decodeIntArray(jsonObject.get("subclasses").getAsJsonArray());
118 return new TypeHierarchyItem(classElement, displayName, memberElement, superclass, interfaces, mixins, subclasses);
119 }
120
121 public static List<TypeHierarchyItem> fromJsonArray(JsonArray jsonArray) {
122 if (jsonArray == null) {
123 return EMPTY_LIST;
124 }
125 ArrayList<TypeHierarchyItem> list = new ArrayList<TypeHierarchyItem>(jsonArray.size());
126 Iterator<JsonElement> iterator = jsonArray.iterator();
127 while (iterator.hasNext()) {
128 list.add(fromJson(iterator.next().getAsJsonObject()));
129 }
130 return list;
131 }
132
133 public String getBestName() {
134 if (displayName == null) {
135 return classElement.getName();
136 } else {
137 return displayName;
138 }
139 }
140
141 /**
142 * The class element represented by this item.
143 */
145 return classElement;
146 }
147
148 /**
149 * The name to be displayed for the class. This field will be omitted if the display name is the
150 * same as the name of the element. The display name is different if there is additional type
151 * information to be displayed, such as type arguments.
152 */
153 public String getDisplayName() {
154 return displayName;
155 }
156
157 /**
158 * The indexes of the items representing the interfaces implemented by this class. The list will be
159 * empty if there are no implemented interfaces.
160 */
161 public int[] getInterfaces() {
162 return interfaces;
163 }
164
165 /**
166 * The member in the class corresponding to the member on which the hierarchy was requested. This
167 * field will be omitted if the hierarchy was not requested for a member or if the class does not
168 * have a corresponding member.
169 */
171 return memberElement;
172 }
173
174 /**
175 * The indexes of the items representing the mixins referenced by this class. The list will be
176 * empty if there are no classes mixed into this class.
177 */
178 public int[] getMixins() {
179 return mixins;
180 }
181
182 /**
183 * The indexes of the items representing the subtypes of this class. The list will be empty if
184 * there are no subtypes or if this item represents a supertype of the pivot type.
185 */
186 public int[] getSubclasses() {
187 return subclasses;
188 }
189
190 /**
191 * The index of the item representing the superclass of this class. This field will be omitted if
192 * this item represents the class Object.
193 */
194 public Integer getSuperclass() {
195 return superclass;
196 }
197
198 @Override
199 public int hashCode() {
200 HashCodeBuilder builder = new HashCodeBuilder();
201 builder.append(classElement);
202 builder.append(displayName);
203 builder.append(memberElement);
204 builder.append(superclass);
205 builder.append(interfaces);
206 builder.append(mixins);
207 builder.append(subclasses);
208 return builder.toHashCode();
209 }
210
211 public JsonObject toJson() {
212 JsonObject jsonObject = new JsonObject();
213 jsonObject.add("classElement", classElement.toJson());
214 if (displayName != null) {
215 jsonObject.addProperty("displayName", displayName);
216 }
217 if (memberElement != null) {
218 jsonObject.add("memberElement", memberElement.toJson());
219 }
220 if (superclass != null) {
221 jsonObject.addProperty("superclass", superclass);
222 }
223 JsonArray jsonArrayInterfaces = new JsonArray();
224 for (int elt : interfaces) {
225 jsonArrayInterfaces.add(new JsonPrimitive(elt));
226 }
227 jsonObject.add("interfaces", jsonArrayInterfaces);
228 JsonArray jsonArrayMixins = new JsonArray();
229 for (int elt : mixins) {
230 jsonArrayMixins.add(new JsonPrimitive(elt));
231 }
232 jsonObject.add("mixins", jsonArrayMixins);
233 JsonArray jsonArraySubclasses = new JsonArray();
234 for (int elt : subclasses) {
235 jsonArraySubclasses.add(new JsonPrimitive(elt));
236 }
237 jsonObject.add("subclasses", jsonArraySubclasses);
238 return jsonObject;
239 }
240
241 @Override
242 public String toString() {
243 StringBuilder builder = new StringBuilder();
244 builder.append("[");
245 builder.append("classElement=");
246 builder.append(classElement + ", ");
247 builder.append("displayName=");
248 builder.append(displayName + ", ");
249 builder.append("memberElement=");
250 builder.append(memberElement + ", ");
251 builder.append("superclass=");
252 builder.append(superclass + ", ");
253 builder.append("interfaces=");
254 builder.append(StringUtils.join(interfaces, ", ") + ", ");
255 builder.append("mixins=");
256 builder.append(StringUtils.join(mixins, ", ") + ", ");
257 builder.append("subclasses=");
258 builder.append(StringUtils.join(subclasses, ", "));
259 builder.append("]");
260 return builder.toString();
261 }
262
263}
static Element fromJson(JsonObject jsonObject)
Definition Element.java:134
static List< TypeHierarchyItem > fromJsonArray(JsonArray jsonArray)
static TypeHierarchyItem fromJson(JsonObject jsonObject)
TypeHierarchyItem(Element classElement, String displayName, Element memberElement, Integer superclass, int[] interfaces, int[] mixins, int[] subclasses)