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