Flutter Engine
The Flutter Engine
Occurrences.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 the references to a single element within a single file.
28 *
29 * @coverage dart.server.generated.types
30 */
31@SuppressWarnings("unused")
32public class Occurrences {
33
34 public static final Occurrences[] EMPTY_ARRAY = new Occurrences[0];
35
36 public static final List<Occurrences> EMPTY_LIST = Lists.newArrayList();
37
38 /**
39 * The element that was referenced.
40 */
41 private final Element element;
42
43 /**
44 * The offsets of the name of the referenced element within the file.
45 */
46 private final int[] offsets;
47
48 /**
49 * The length of the name of the referenced element.
50 */
51 private final int length;
52
53 /**
54 * Constructor for {@link Occurrences}.
55 */
56 public Occurrences(Element element, int[] offsets, int length) {
57 this.element = element;
58 this.offsets = offsets;
59 this.length = length;
60 }
61
62 public boolean containsInclusive(int x) {
63 for (int offset : offsets) {
64 if (offset <= x && x <= offset + length) {
65 return true;
66 }
67 }
68 return false;
69 }
70
71 @Override
72 public boolean equals(Object obj) {
73 if (obj instanceof Occurrences) {
74 Occurrences other = (Occurrences) obj;
75 return
76 ObjectUtilities.equals(other.element, element) &&
77 Arrays.equals(other.offsets, offsets) &&
78 other.length == length;
79 }
80 return false;
81 }
82
83 public static Occurrences fromJson(JsonObject jsonObject) {
84 Element element = Element.fromJson(jsonObject.get("element").getAsJsonObject());
85 int[] offsets = JsonUtilities.decodeIntArray(jsonObject.get("offsets").getAsJsonArray());
86 int length = jsonObject.get("length").getAsInt();
87 return new Occurrences(element, offsets, length);
88 }
89
90 public static List<Occurrences> fromJsonArray(JsonArray jsonArray) {
91 if (jsonArray == null) {
92 return EMPTY_LIST;
93 }
94 ArrayList<Occurrences> list = new ArrayList<Occurrences>(jsonArray.size());
95 Iterator<JsonElement> iterator = jsonArray.iterator();
96 while (iterator.hasNext()) {
97 list.add(fromJson(iterator.next().getAsJsonObject()));
98 }
99 return list;
100 }
101
102 /**
103 * The element that was referenced.
104 */
106 return element;
107 }
108
109 /**
110 * The length of the name of the referenced element.
111 */
112 public int getLength() {
113 return length;
114 }
115
116 /**
117 * The offsets of the name of the referenced element within the file.
118 */
119 public int[] getOffsets() {
120 return offsets;
121 }
122
123 @Override
124 public int hashCode() {
125 HashCodeBuilder builder = new HashCodeBuilder();
126 builder.append(element);
127 builder.append(offsets);
128 builder.append(length);
129 return builder.toHashCode();
130 }
131
132 public JsonObject toJson() {
133 JsonObject jsonObject = new JsonObject();
134 jsonObject.add("element", element.toJson());
135 JsonArray jsonArrayOffsets = new JsonArray();
136 for (int elt : offsets) {
137 jsonArrayOffsets.add(new JsonPrimitive(elt));
138 }
139 jsonObject.add("offsets", jsonArrayOffsets);
140 jsonObject.addProperty("length", length);
141 return jsonObject;
142 }
143
144 @Override
145 public String toString() {
146 StringBuilder builder = new StringBuilder();
147 builder.append("[");
148 builder.append("element=");
149 builder.append(element + ", ");
150 builder.append("offsets=");
151 builder.append(StringUtils.join(offsets, ", ") + ", ");
152 builder.append("length=");
153 builder.append(length);
154 builder.append("]");
155 return builder.toString();
156 }
157
158}
static Element fromJson(JsonObject jsonObject)
Definition: Element.java:134
static List< Occurrences > fromJsonArray(JsonArray jsonArray)
static Occurrences fromJson(JsonObject jsonObject)
Occurrences(Element element, int[] offsets, int length)
size_t length
double x
list offsets
Definition: mskp_parser.py:37
SeparatedVector2 offset