Flutter Engine
The Flutter Engine
AnalysisError.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 * An indication of an error, warning, or hint that was produced by the analysis.
28 *
29 * @coverage dart.server.generated.types
30 */
31@SuppressWarnings("unused")
32public class AnalysisError {
33
34 public static final AnalysisError[] EMPTY_ARRAY = new AnalysisError[0];
35
36 public static final List<AnalysisError> EMPTY_LIST = Lists.newArrayList();
37
38 /**
39 * The severity of the error.
40 */
41 private final String severity;
42
43 /**
44 * The type of the error.
45 */
46 private final String type;
47
48 /**
49 * The location associated with the error.
50 */
51 private final Location location;
52
53 /**
54 * The message to be displayed for this error. The message should indicate what is wrong with the
55 * code and why it is wrong.
56 */
57 private final String message;
58
59 /**
60 * The correction message to be displayed for this error. The correction message should indicate
61 * how the user can fix the error. The field is omitted if there is no correction message
62 * associated with the error code.
63 */
64 private final String correction;
65
66 /**
67 * The name, as a string, of the error code associated with this error.
68 */
69 private final String code;
70
71 /**
72 * The URL of a page containing documentation associated with this error.
73 */
74 private final String url;
75
76 /**
77 * Additional messages associated with this diagnostic that provide context to help the user
78 * understand the diagnostic.
79 */
80 private final List<DiagnosticMessage> contextMessages;
81
82 /**
83 * A hint to indicate to interested clients that this error has an associated fix (or fixes). The
84 * absence of this field implies there are not known to be fixes. Note that since the operation to
85 * calculate whether fixes apply needs to be performant it is possible that complicated tests will
86 * be skipped and a false negative returned. For this reason, this attribute should be treated as a
87 * "hint". Despite the possibility of false negatives, no false positives should be returned. If a
88 * client sees this flag set they can proceed with the confidence that there are in fact associated
89 * fixes.
90 */
91 private final Boolean hasFix;
92
93 /**
94 * Constructor for {@link AnalysisError}.
95 */
96 public AnalysisError(String severity, String type, Location location, String message, String correction, String code, String url, List<DiagnosticMessage> contextMessages, Boolean hasFix) {
97 this.severity = severity;
98 this.type = type;
99 this.location = location;
100 this.message = message;
101 this.correction = correction;
102 this.code = code;
103 this.url = url;
104 this.contextMessages = contextMessages;
105 this.hasFix = hasFix;
106 }
107
108 @Override
109 public boolean equals(Object obj) {
110 if (obj instanceof AnalysisError) {
111 AnalysisError other = (AnalysisError) obj;
112 return
113 ObjectUtilities.equals(other.severity, severity) &&
114 ObjectUtilities.equals(other.type, type) &&
115 ObjectUtilities.equals(other.location, location) &&
116 ObjectUtilities.equals(other.message, message) &&
117 ObjectUtilities.equals(other.correction, correction) &&
118 ObjectUtilities.equals(other.code, code) &&
119 ObjectUtilities.equals(other.url, url) &&
120 ObjectUtilities.equals(other.contextMessages, contextMessages) &&
121 ObjectUtilities.equals(other.hasFix, hasFix);
122 }
123 return false;
124 }
125
126 public static AnalysisError fromJson(JsonObject jsonObject) {
127 String severity = jsonObject.get("severity").getAsString();
128 String type = jsonObject.get("type").getAsString();
129 Location location = Location.fromJson(jsonObject.get("location").getAsJsonObject());
130 String message = jsonObject.get("message").getAsString();
131 String correction = jsonObject.get("correction") == null ? null : jsonObject.get("correction").getAsString();
132 String code = jsonObject.get("code").getAsString();
133 String url = jsonObject.get("url") == null ? null : jsonObject.get("url").getAsString();
134 List<DiagnosticMessage> contextMessages = jsonObject.get("contextMessages") == null ? null : DiagnosticMessage.fromJsonArray(jsonObject.get("contextMessages").getAsJsonArray());
135 Boolean hasFix = jsonObject.get("hasFix") == null ? null : jsonObject.get("hasFix").getAsBoolean();
136 return new AnalysisError(severity, type, location, message, correction, code, url, contextMessages, hasFix);
137 }
138
139 public static List<AnalysisError> fromJsonArray(JsonArray jsonArray) {
140 if (jsonArray == null) {
141 return EMPTY_LIST;
142 }
143 ArrayList<AnalysisError> list = new ArrayList<AnalysisError>(jsonArray.size());
144 Iterator<JsonElement> iterator = jsonArray.iterator();
145 while (iterator.hasNext()) {
146 list.add(fromJson(iterator.next().getAsJsonObject()));
147 }
148 return list;
149 }
150
151 /**
152 * The name, as a string, of the error code associated with this error.
153 */
154 public String getCode() {
155 return code;
156 }
157
158 /**
159 * Additional messages associated with this diagnostic that provide context to help the user
160 * understand the diagnostic.
161 */
163 return contextMessages;
164 }
165
166 /**
167 * The correction message to be displayed for this error. The correction message should indicate
168 * how the user can fix the error. The field is omitted if there is no correction message
169 * associated with the error code.
170 */
171 public String getCorrection() {
172 return correction;
173 }
174
175 /**
176 * A hint to indicate to interested clients that this error has an associated fix (or fixes). The
177 * absence of this field implies there are not known to be fixes. Note that since the operation to
178 * calculate whether fixes apply needs to be performant it is possible that complicated tests will
179 * be skipped and a false negative returned. For this reason, this attribute should be treated as a
180 * "hint". Despite the possibility of false negatives, no false positives should be returned. If a
181 * client sees this flag set they can proceed with the confidence that there are in fact associated
182 * fixes.
183 */
184 public Boolean getHasFix() {
185 return hasFix;
186 }
187
188 /**
189 * The location associated with the error.
190 */
192 return location;
193 }
194
195 /**
196 * The message to be displayed for this error. The message should indicate what is wrong with the
197 * code and why it is wrong.
198 */
199 public String getMessage() {
200 return message;
201 }
202
203 /**
204 * The severity of the error.
205 */
206 public String getSeverity() {
207 return severity;
208 }
209
210 /**
211 * The type of the error.
212 */
213 public String getType() {
214 return type;
215 }
216
217 /**
218 * The URL of a page containing documentation associated with this error.
219 */
220 public String getUrl() {
221 return url;
222 }
223
224 @Override
225 public int hashCode() {
226 HashCodeBuilder builder = new HashCodeBuilder();
227 builder.append(severity);
228 builder.append(type);
229 builder.append(location);
230 builder.append(message);
231 builder.append(correction);
232 builder.append(code);
233 builder.append(url);
234 builder.append(contextMessages);
235 builder.append(hasFix);
236 return builder.toHashCode();
237 }
238
239 public JsonObject toJson() {
240 JsonObject jsonObject = new JsonObject();
241 jsonObject.addProperty("severity", severity);
242 jsonObject.addProperty("type", type);
243 jsonObject.add("location", location.toJson());
244 jsonObject.addProperty("message", message);
245 if (correction != null) {
246 jsonObject.addProperty("correction", correction);
247 }
248 jsonObject.addProperty("code", code);
249 if (url != null) {
250 jsonObject.addProperty("url", url);
251 }
252 if (contextMessages != null) {
253 JsonArray jsonArrayContextMessages = new JsonArray();
254 for (DiagnosticMessage elt : contextMessages) {
255 jsonArrayContextMessages.add(elt.toJson());
256 }
257 jsonObject.add("contextMessages", jsonArrayContextMessages);
258 }
259 if (hasFix != null) {
260 jsonObject.addProperty("hasFix", hasFix);
261 }
262 return jsonObject;
263 }
264
265 @Override
266 public String toString() {
267 StringBuilder builder = new StringBuilder();
268 builder.append("[");
269 builder.append("severity=");
270 builder.append(severity + ", ");
271 builder.append("type=");
272 builder.append(type + ", ");
273 builder.append("location=");
274 builder.append(location + ", ");
275 builder.append("message=");
276 builder.append(message + ", ");
277 builder.append("correction=");
278 builder.append(correction + ", ");
279 builder.append("code=");
280 builder.append(code + ", ");
281 builder.append("url=");
282 builder.append(url + ", ");
283 builder.append("contextMessages=");
284 builder.append(StringUtils.join(contextMessages, ", ") + ", ");
285 builder.append("hasFix=");
286 builder.append(hasFix);
287 builder.append("]");
288 return builder.toString();
289 }
290
291}
GLenum type
static AnalysisError fromJson(JsonObject jsonObject)
AnalysisError(String severity, String type, Location location, String message, String correction, String code, String url, List< DiagnosticMessage > contextMessages, Boolean hasFix)
static List< AnalysisError > fromJsonArray(JsonArray jsonArray)
static List< DiagnosticMessage > fromJsonArray(JsonArray jsonArray)
static Location fromJson(JsonObject jsonObject)
Definition: Location.java:102
Win32Message message