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