9package org.dartlang.analysis.server.protocol;
11import java.util.Arrays;
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;
31@SuppressWarnings(
"unused")
41 private final Element classElement;
48 private final String displayName;
55 private final Element memberElement;
61 private final Integer superclass;
67 private final int[] interfaces;
73 private final int[] mixins;
79 private final int[] subclasses;
85 this.classElement = classElement;
86 this.displayName = displayName;
87 this.memberElement = memberElement;
88 this.superclass = superclass;
89 this.interfaces = interfaces;
91 this.subclasses = subclasses;
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);
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);
122 if (jsonArray ==
null) {
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()));
134 if (displayName ==
null) {
171 return memberElement;
200 HashCodeBuilder
builder =
new HashCodeBuilder();
212 JsonObject jsonObject =
new JsonObject();
213 jsonObject.add(
"classElement", classElement.
toJson());
214 if (displayName !=
null) {
215 jsonObject.addProperty(
"displayName", displayName);
217 if (memberElement !=
null) {
218 jsonObject.add(
"memberElement", memberElement.
toJson());
220 if (superclass !=
null) {
221 jsonObject.addProperty(
"superclass", superclass);
223 JsonArray jsonArrayInterfaces =
new JsonArray();
224 for (
int elt : interfaces) {
225 jsonArrayInterfaces.add(
new JsonPrimitive(elt));
227 jsonObject.add(
"interfaces", jsonArrayInterfaces);
228 JsonArray jsonArrayMixins =
new JsonArray();
229 for (
int elt : mixins) {
230 jsonArrayMixins.add(
new JsonPrimitive(elt));
232 jsonObject.add(
"mixins", jsonArrayMixins);
233 JsonArray jsonArraySubclasses =
new JsonArray();
234 for (
int elt : subclasses) {
235 jsonArraySubclasses.add(
new JsonPrimitive(elt));
237 jsonObject.add(
"subclasses", jsonArraySubclasses);
243 StringBuilder
builder =
new StringBuilder();
245 builder.append(
"classElement=");
246 builder.append(classElement +
", ");
247 builder.append(
"displayName=");
248 builder.append(displayName +
", ");
249 builder.append(
"memberElement=");
250 builder.append(memberElement +
", ");
252 builder.append(superclass +
", ");
254 builder.append(StringUtils.join(interfaces,
", ") +
", ");
256 builder.append(StringUtils.join(mixins,
", ") +
", ");
258 builder.append(StringUtils.join(subclasses,
", "));
static Element fromJson(JsonObject jsonObject)
static List< TypeHierarchyItem > fromJsonArray(JsonArray jsonArray)
boolean equals(Object obj)
Element getMemberElement()
static TypeHierarchyItem fromJson(JsonObject jsonObject)
Element getClassElement()
TypeHierarchyItem(Element classElement, String displayName, Element memberElement, Integer superclass, int[] interfaces, int[] mixins, int[] subclasses)