Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
ExistingImport.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 existing import, with elements that it provides.
28 *
29 * @coverage dart.server.generated.types
30 */
31@SuppressWarnings("unused")
32public class ExistingImport {
33
34 public static final ExistingImport[] EMPTY_ARRAY = new ExistingImport[0];
35
36 public static final List<ExistingImport> EMPTY_LIST = Lists.newArrayList();
37
38 /**
39 * The URI of the imported library. It is an index in the strings field, in the enclosing
40 * ExistingImports and its ImportedElementSet object.
41 */
42 private final int uri;
43
44 /**
45 * The list of indexes of elements, in the enclosing ExistingImports object.
46 */
47 private final int[] elements;
48
49 /**
50 * Constructor for {@link ExistingImport}.
51 */
52 public ExistingImport(int uri, int[] elements) {
53 this.uri = uri;
54 this.elements = elements;
55 }
56
57 @Override
58 public boolean equals(Object obj) {
59 if (obj instanceof ExistingImport) {
60 ExistingImport other = (ExistingImport) obj;
61 return
62 other.uri == uri &&
63 Arrays.equals(other.elements, elements);
64 }
65 return false;
66 }
67
68 public static ExistingImport fromJson(JsonObject jsonObject) {
69 int uri = jsonObject.get("uri").getAsInt();
70 int[] elements = JsonUtilities.decodeIntArray(jsonObject.get("elements").getAsJsonArray());
71 return new ExistingImport(uri, elements);
72 }
73
74 public static List<ExistingImport> fromJsonArray(JsonArray jsonArray) {
75 if (jsonArray == null) {
76 return EMPTY_LIST;
77 }
78 ArrayList<ExistingImport> list = new ArrayList<ExistingImport>(jsonArray.size());
79 Iterator<JsonElement> iterator = jsonArray.iterator();
80 while (iterator.hasNext()) {
81 list.add(fromJson(iterator.next().getAsJsonObject()));
82 }
83 return list;
84 }
85
86 /**
87 * The list of indexes of elements, in the enclosing ExistingImports object.
88 */
89 public int[] getElements() {
90 return elements;
91 }
92
93 /**
94 * The URI of the imported library. It is an index in the strings field, in the enclosing
95 * ExistingImports and its ImportedElementSet object.
96 */
97 public int getUri() {
98 return uri;
99 }
100
101 @Override
102 public int hashCode() {
103 HashCodeBuilder builder = new HashCodeBuilder();
104 builder.append(uri);
105 builder.append(elements);
106 return builder.toHashCode();
107 }
108
109 public JsonObject toJson() {
110 JsonObject jsonObject = new JsonObject();
111 jsonObject.addProperty("uri", uri);
112 JsonArray jsonArrayElements = new JsonArray();
113 for (int elt : elements) {
114 jsonArrayElements.add(new JsonPrimitive(elt));
115 }
116 jsonObject.add("elements", jsonArrayElements);
117 return jsonObject;
118 }
119
120 @Override
121 public String toString() {
122 StringBuilder builder = new StringBuilder();
123 builder.append("[");
124 builder.append("uri=");
125 builder.append(uri + ", ");
126 builder.append("elements=");
127 builder.append(StringUtils.join(elements, ", "));
128 builder.append("]");
129 return builder.toString();
130 }
131
132}
static ExistingImport fromJson(JsonObject jsonObject)
static List< ExistingImport > fromJsonArray(JsonArray jsonArray)