Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
NavigationRegion.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 description of a region from which the user can navigate to the declaration of an element.
28 *
29 * @coverage dart.server.generated.types
30 */
31@SuppressWarnings("unused")
32public class NavigationRegion {
33
34 public static final NavigationRegion[] EMPTY_ARRAY = new NavigationRegion[0];
35
36 public static final List<NavigationRegion> EMPTY_LIST = Lists.newArrayList();
37
38 /**
39 * The offset of the region from which the user can navigate.
40 */
41 private final int offset;
42
43 /**
44 * The length of the region from which the user can navigate.
45 */
46 private final int length;
47
48 /**
49 * The indexes of the targets (in the enclosing navigation response) to which the given region is
50 * bound. By opening the target, clients can implement one form of navigation. This list cannot be
51 * empty.
52 */
53 private final int[] targets;
54
55 private final List<NavigationTarget> targetObjects = Lists.newArrayList();
56
57 /**
58 * Constructor for {@link NavigationRegion}.
59 */
60 public NavigationRegion(int offset, int length, int[] targets) {
61 this.offset = offset;
62 this.length = length;
63 this.targets = targets;
64 }
65
66 public boolean containsInclusive(int x) {
67 return offset <= x && x <= offset + length;
68 }
69
70 @Override
71 public boolean equals(Object obj) {
72 if (obj instanceof NavigationRegion) {
74 return
75 other.offset == offset &&
76 other.length == length &&
77 Arrays.equals(other.targets, targets);
78 }
79 return false;
80 }
81
82 public static NavigationRegion fromJson(JsonObject jsonObject) {
83 int offset = jsonObject.get("offset").getAsInt();
84 int length = jsonObject.get("length").getAsInt();
85 int[] targets = JsonUtilities.decodeIntArray(jsonObject.get("targets").getAsJsonArray());
86 return new NavigationRegion(offset, length, targets);
87 }
88
89 public static List<NavigationRegion> fromJsonArray(JsonArray jsonArray) {
90 if (jsonArray == null) {
91 return EMPTY_LIST;
92 }
93 ArrayList<NavigationRegion> list = new ArrayList<NavigationRegion>(jsonArray.size());
94 Iterator<JsonElement> iterator = jsonArray.iterator();
95 while (iterator.hasNext()) {
96 list.add(fromJson(iterator.next().getAsJsonObject()));
97 }
98 return list;
99 }
100
102 return targetObjects;
103 }
104
105 /**
106 * The length of the region from which the user can navigate.
107 */
108 public int getLength() {
109 return length;
110 }
111
112 /**
113 * The offset of the region from which the user can navigate.
114 */
115 public int getOffset() {
116 return offset;
117 }
118
119 /**
120 * The indexes of the targets (in the enclosing navigation response) to which the given region is
121 * bound. By opening the target, clients can implement one form of navigation. This list cannot be
122 * empty.
123 */
124 public int[] getTargets() {
125 return targets;
126 }
127
128 @Override
129 public int hashCode() {
130 HashCodeBuilder builder = new HashCodeBuilder();
131 builder.append(offset);
132 builder.append(length);
133 builder.append(targets);
134 return builder.toHashCode();
135 }
136
137 public void lookupTargets(List<NavigationTarget> allTargets) {
138 for (int i = 0; i < targets.length; i++) {
139 int targetIndex = targets[i];
140 NavigationTarget target = allTargets.get(targetIndex);
141 targetObjects.add(target);
142 }
143 }
144
145 public JsonObject toJson() {
146 JsonObject jsonObject = new JsonObject();
147 jsonObject.addProperty("offset", offset);
148 jsonObject.addProperty("length", length);
149 JsonArray jsonArrayTargets = new JsonArray();
150 for (int elt : targets) {
151 jsonArrayTargets.add(new JsonPrimitive(elt));
152 }
153 jsonObject.add("targets", jsonArrayTargets);
154 return jsonObject;
155 }
156
157 @Override
158 public String toString() {
159 StringBuilder builder = new StringBuilder();
160 builder.append("[");
161 builder.append("offset=");
162 builder.append(offset + ", ");
163 builder.append("length=");
164 builder.append(length + ", ");
165 builder.append("targets=");
166 builder.append(StringUtils.join(targets, ", "));
167 builder.append("]");
168 return builder.toString();
169 }
170
171}
void add(sk_sp< SkIDChangeListener > listener) SK_EXCLUDES(fMutex)
static NavigationRegion fromJson(JsonObject jsonObject)
void lookupTargets(List< NavigationTarget > allTargets)
NavigationRegion(int offset, int length, int[] targets)
static List< NavigationRegion > fromJsonArray(JsonArray jsonArray)
uint32_t * target
size_t length
double x
Point offset