Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Location.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 location (character range) within a file.
28 *
29 * @coverage dart.server.generated.types
30 */
31@SuppressWarnings("unused")
32public class Location {
33
34 public static final Location[] EMPTY_ARRAY = new Location[0];
35
36 public static final List<Location> EMPTY_LIST = Lists.newArrayList();
37
38 /**
39 * The file containing the range.
40 */
41 private final String file;
42
43 /**
44 * The offset of the range.
45 */
46 private final int offset;
47
48 /**
49 * The length of the range.
50 */
51 private final int length;
52
53 /**
54 * The one-based index of the line containing the first character of the range.
55 */
56 private final int startLine;
57
58 /**
59 * The one-based index of the column containing the first character of the range.
60 */
61 private final int startColumn;
62
63 /**
64 * The one-based index of the line containing the character immediately following the range.
65 */
66 private final Integer endLine;
67
68 /**
69 * The one-based index of the column containing the character immediately following the range.
70 */
71 private final Integer endColumn;
72
73 /**
74 * Constructor for {@link Location}.
75 */
76 public Location(String file, int offset, int length, int startLine, int startColumn, Integer endLine, Integer endColumn) {
77 this.file = file;
78 this.offset = offset;
79 this.length = length;
80 this.startLine = startLine;
81 this.startColumn = startColumn;
82 this.endLine = endLine;
83 this.endColumn = endColumn;
84 }
85
86 @Override
87 public boolean equals(Object obj) {
88 if (obj instanceof Location) {
89 Location other = (Location) obj;
90 return
91 ObjectUtilities.equals(other.file, file) &&
92 other.offset == offset &&
93 other.length == length &&
94 other.startLine == startLine &&
95 other.startColumn == startColumn &&
96 ObjectUtilities.equals(other.endLine, endLine) &&
97 ObjectUtilities.equals(other.endColumn, endColumn);
98 }
99 return false;
100 }
101
102 public static Location fromJson(JsonObject jsonObject) {
103 String file = jsonObject.get("file").getAsString();
104 int offset = jsonObject.get("offset").getAsInt();
105 int length = jsonObject.get("length").getAsInt();
106 int startLine = jsonObject.get("startLine").getAsInt();
107 int startColumn = jsonObject.get("startColumn").getAsInt();
108 Integer endLine = jsonObject.get("endLine") == null ? null : jsonObject.get("endLine").getAsInt();
109 Integer endColumn = jsonObject.get("endColumn") == null ? null : jsonObject.get("endColumn").getAsInt();
110 return new Location(file, offset, length, startLine, startColumn, endLine, endColumn);
111 }
112
113 public static List<Location> fromJsonArray(JsonArray jsonArray) {
114 if (jsonArray == null) {
115 return EMPTY_LIST;
116 }
117 ArrayList<Location> list = new ArrayList<Location>(jsonArray.size());
118 Iterator<JsonElement> iterator = jsonArray.iterator();
119 while (iterator.hasNext()) {
120 list.add(fromJson(iterator.next().getAsJsonObject()));
121 }
122 return list;
123 }
124
125 /**
126 * The one-based index of the column containing the character immediately following the range.
127 */
128 public Integer getEndColumn() {
129 return endColumn;
130 }
131
132 /**
133 * The one-based index of the line containing the character immediately following the range.
134 */
135 public Integer getEndLine() {
136 return endLine;
137 }
138
139 /**
140 * The file containing the range.
141 */
142 public String getFile() {
143 return file;
144 }
145
146 /**
147 * The length of the range.
148 */
149 public int getLength() {
150 return length;
151 }
152
153 /**
154 * The offset of the range.
155 */
156 public int getOffset() {
157 return offset;
158 }
159
160 /**
161 * The one-based index of the column containing the first character of the range.
162 */
163 public int getStartColumn() {
164 return startColumn;
165 }
166
167 /**
168 * The one-based index of the line containing the first character of the range.
169 */
170 public int getStartLine() {
171 return startLine;
172 }
173
174 @Override
175 public int hashCode() {
176 HashCodeBuilder builder = new HashCodeBuilder();
177 builder.append(file);
178 builder.append(offset);
179 builder.append(length);
180 builder.append(startLine);
181 builder.append(startColumn);
182 builder.append(endLine);
183 builder.append(endColumn);
184 return builder.toHashCode();
185 }
186
187 public JsonObject toJson() {
188 JsonObject jsonObject = new JsonObject();
189 jsonObject.addProperty("file", file);
190 jsonObject.addProperty("offset", offset);
191 jsonObject.addProperty("length", length);
192 jsonObject.addProperty("startLine", startLine);
193 jsonObject.addProperty("startColumn", startColumn);
194 if (endLine != null) {
195 jsonObject.addProperty("endLine", endLine);
196 }
197 if (endColumn != null) {
198 jsonObject.addProperty("endColumn", endColumn);
199 }
200 return jsonObject;
201 }
202
203 @Override
204 public String toString() {
205 StringBuilder builder = new StringBuilder();
206 builder.append("[");
207 builder.append("file=");
208 builder.append(file + ", ");
209 builder.append("offset=");
210 builder.append(offset + ", ");
211 builder.append("length=");
212 builder.append(length + ", ");
213 builder.append("startLine=");
214 builder.append(startLine + ", ");
215 builder.append("startColumn=");
216 builder.append(startColumn + ", ");
217 builder.append("endLine=");
218 builder.append(endLine + ", ");
219 builder.append("endColumn=");
220 builder.append(endColumn);
221 builder.append("]");
222 return builder.toString();
223 }
224
225}
static Location fromJson(JsonObject jsonObject)
static List< Location > fromJsonArray(JsonArray jsonArray)
Location(String file, int offset, int length, int startLine, int startColumn, Integer endLine, Integer endColumn)
Definition Location.java:76
size_t length
Point offset