Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SearchResult.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 single result from a search request.
28 *
29 * @coverage dart.server.generated.types
30 */
31@SuppressWarnings("unused")
32public class SearchResult {
33
34 public static final SearchResult[] EMPTY_ARRAY = new SearchResult[0];
35
36 public static final List<SearchResult> EMPTY_LIST = Lists.newArrayList();
37
38 /**
39 * The location of the code that matched the search criteria.
40 */
41 private final Location location;
42
43 /**
44 * The kind of element that was found or the kind of reference that was found.
45 */
46 private final String kind;
47
48 /**
49 * True if the result is a potential match but cannot be confirmed to be a match. For example, if
50 * all references to a method m defined in some class were requested, and a reference to a method m
51 * from an unknown class were found, it would be marked as being a potential match.
52 */
53 private final boolean isPotential;
54
55 /**
56 * The elements that contain the result, starting with the most immediately enclosing ancestor and
57 * ending with the library.
58 */
59 private final List<Element> path;
60
61 /**
62 * Constructor for {@link SearchResult}.
63 */
64 public SearchResult(Location location, String kind, boolean isPotential, List<Element> path) {
65 this.location = location;
66 this.kind = kind;
67 this.isPotential = isPotential;
68 this.path = path;
69 }
70
71 @Override
72 public boolean equals(Object obj) {
73 if (obj instanceof SearchResult) {
74 SearchResult other = (SearchResult) obj;
75 return
76 ObjectUtilities.equals(other.location, location) &&
77 ObjectUtilities.equals(other.kind, kind) &&
78 other.isPotential == isPotential &&
79 ObjectUtilities.equals(other.path, path);
80 }
81 return false;
82 }
83
84 public static SearchResult fromJson(JsonObject jsonObject) {
85 Location location = Location.fromJson(jsonObject.get("location").getAsJsonObject());
86 String kind = jsonObject.get("kind").getAsString();
87 boolean isPotential = jsonObject.get("isPotential").getAsBoolean();
88 List<Element> path = Element.fromJsonArray(jsonObject.get("path").getAsJsonArray());
89 return new SearchResult(location, kind, isPotential, path);
90 }
91
92 public static List<SearchResult> fromJsonArray(JsonArray jsonArray) {
93 if (jsonArray == null) {
94 return EMPTY_LIST;
95 }
96 ArrayList<SearchResult> list = new ArrayList<SearchResult>(jsonArray.size());
97 Iterator<JsonElement> iterator = jsonArray.iterator();
98 while (iterator.hasNext()) {
99 list.add(fromJson(iterator.next().getAsJsonObject()));
100 }
101 return list;
102 }
103
104 /**
105 * True if the result is a potential match but cannot be confirmed to be a match. For example, if
106 * all references to a method m defined in some class were requested, and a reference to a method m
107 * from an unknown class were found, it would be marked as being a potential match.
108 */
109 public boolean isPotential() {
110 return isPotential;
111 }
112
113 /**
114 * The kind of element that was found or the kind of reference that was found.
115 */
116 public String getKind() {
117 return kind;
118 }
119
120 /**
121 * The location of the code that matched the search criteria.
122 */
124 return location;
125 }
126
127 /**
128 * The elements that contain the result, starting with the most immediately enclosing ancestor and
129 * ending with the library.
130 */
132 return path;
133 }
134
135 @Override
136 public int hashCode() {
137 HashCodeBuilder builder = new HashCodeBuilder();
138 builder.append(location);
139 builder.append(kind);
140 builder.append(isPotential);
141 builder.append(path);
142 return builder.toHashCode();
143 }
144
145 public JsonObject toJson() {
146 JsonObject jsonObject = new JsonObject();
147 jsonObject.add("location", location.toJson());
148 jsonObject.addProperty("kind", kind);
149 jsonObject.addProperty("isPotential", isPotential);
150 JsonArray jsonArrayPath = new JsonArray();
151 for (Element elt : path) {
152 jsonArrayPath.add(elt.toJson());
153 }
154 jsonObject.add("path", jsonArrayPath);
155 return jsonObject;
156 }
157
158 @Override
159 public String toString() {
160 StringBuilder builder = new StringBuilder();
161 builder.append("[");
162 builder.append("location=");
163 builder.append(location + ", ");
164 builder.append("kind=");
165 builder.append(kind + ", ");
166 builder.append("isPotential=");
167 builder.append(isPotential + ", ");
168 builder.append("path=");
169 builder.append(StringUtils.join(path, ", "));
170 builder.append("]");
171 return builder.toString();
172 }
173
174}
static List< Element > fromJsonArray(JsonArray jsonArray)
Definition Element.java:146
static Location fromJson(JsonObject jsonObject)
static List< SearchResult > fromJsonArray(JsonArray jsonArray)
SearchResult(Location location, String kind, boolean isPotential, List< Element > path)
static SearchResult fromJson(JsonObject jsonObject)