Flutter Engine
The Flutter Engine
LinkedEditGroup.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 collection of positions that should be linked (edited simultaneously) for the purposes of
28 * updating code after a source change. For example, if a set of edits introduced a new variable
29 * name, the group would contain all of the positions of the variable name so that if the client
30 * wanted to let the user edit the variable name after the operation, all occurrences of the name
31 * could be edited simultaneously.
32 *
33 * Edit groups may have a length of 0 and function as tabstops where there is no default text, for
34 * example, an edit that inserts an if statement might provide an empty group between parens where
35 * a condition should be typed. For this reason, it's also valid for a group to contain only a
36 * single position that is not linked to others.
37 *
38 * @coverage dart.server.generated.types
39 */
40@SuppressWarnings("unused")
41public class LinkedEditGroup {
42
43 public static final LinkedEditGroup[] EMPTY_ARRAY = new LinkedEditGroup[0];
44
45 public static final List<LinkedEditGroup> EMPTY_LIST = Lists.newArrayList();
46
47 /**
48 * The positions of the regions (after applying the relevant edits) that should be edited
49 * simultaneously.
50 */
51 private final List<Position> positions;
52
53 /**
54 * The length of the regions that should be edited simultaneously.
55 */
56 private final int length;
57
58 /**
59 * Pre-computed suggestions for what every region might want to be changed to.
60 */
61 private final List<LinkedEditSuggestion> suggestions;
62
63 /**
64 * Constructor for {@link LinkedEditGroup}.
65 */
67 this.positions = positions;
68 this.length = length;
69 this.suggestions = suggestions;
70 }
71
72 @Override
73 public boolean equals(Object obj) {
74 if (obj instanceof LinkedEditGroup) {
75 LinkedEditGroup other = (LinkedEditGroup) obj;
76 return
77 ObjectUtilities.equals(other.positions, positions) &&
78 other.length == length &&
79 ObjectUtilities.equals(other.suggestions, suggestions);
80 }
81 return false;
82 }
83
84 public static LinkedEditGroup fromJson(JsonObject jsonObject) {
85 List<Position> positions = Position.fromJsonArray(jsonObject.get("positions").getAsJsonArray());
86 int length = jsonObject.get("length").getAsInt();
87 List<LinkedEditSuggestion> suggestions = LinkedEditSuggestion.fromJsonArray(jsonObject.get("suggestions").getAsJsonArray());
88 return new LinkedEditGroup(positions, length, suggestions);
89 }
90
91 public static List<LinkedEditGroup> fromJsonArray(JsonArray jsonArray) {
92 if (jsonArray == null) {
93 return EMPTY_LIST;
94 }
95 ArrayList<LinkedEditGroup> list = new ArrayList<LinkedEditGroup>(jsonArray.size());
96 Iterator<JsonElement> iterator = jsonArray.iterator();
97 while (iterator.hasNext()) {
98 list.add(fromJson(iterator.next().getAsJsonObject()));
99 }
100 return list;
101 }
102
103 /**
104 * The length of the regions that should be edited simultaneously.
105 */
106 public int getLength() {
107 return length;
108 }
109
110 /**
111 * The positions of the regions (after applying the relevant edits) that should be edited
112 * simultaneously.
113 */
115 return positions;
116 }
117
118 /**
119 * Pre-computed suggestions for what every region might want to be changed to.
120 */
122 return suggestions;
123 }
124
125 @Override
126 public int hashCode() {
127 HashCodeBuilder builder = new HashCodeBuilder();
128 builder.append(positions);
129 builder.append(length);
130 builder.append(suggestions);
131 return builder.toHashCode();
132 }
133
134 public JsonObject toJson() {
135 JsonObject jsonObject = new JsonObject();
136 JsonArray jsonArrayPositions = new JsonArray();
137 for (Position elt : positions) {
138 jsonArrayPositions.add(elt.toJson());
139 }
140 jsonObject.add("positions", jsonArrayPositions);
141 jsonObject.addProperty("length", length);
142 JsonArray jsonArraySuggestions = new JsonArray();
143 for (LinkedEditSuggestion elt : suggestions) {
144 jsonArraySuggestions.add(elt.toJson());
145 }
146 jsonObject.add("suggestions", jsonArraySuggestions);
147 return jsonObject;
148 }
149
150 @Override
151 public String toString() {
152 StringBuilder builder = new StringBuilder();
153 builder.append("[");
154 builder.append("positions=");
155 builder.append(StringUtils.join(positions, ", ") + ", ");
156 builder.append("length=");
157 builder.append(length + ", ");
158 builder.append("suggestions=");
159 builder.append(StringUtils.join(suggestions, ", "));
160 builder.append("]");
161 return builder.toString();
162 }
163
164}
static LinkedEditGroup fromJson(JsonObject jsonObject)
LinkedEditGroup(List< Position > positions, int length, List< LinkedEditSuggestion > suggestions)
static List< LinkedEditGroup > fromJsonArray(JsonArray jsonArray)
static List< LinkedEditSuggestion > fromJsonArray(JsonArray jsonArray)
static List< Position > fromJsonArray(JsonArray jsonArray)
Definition: Position.java:73
size_t length