Flutter Engine
The Flutter Engine
SourceFileEdit.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 set of changes to a single file.
28 *
29 * @coverage dart.server.generated.types
30 */
31@SuppressWarnings("unused")
32public class SourceFileEdit {
33
34 public static final SourceFileEdit[] EMPTY_ARRAY = new SourceFileEdit[0];
35
36 public static final List<SourceFileEdit> EMPTY_LIST = Lists.newArrayList();
37
38 /**
39 * The file containing the code to be modified.
40 */
41 private final String file;
42
43 /**
44 * The modification stamp of the file at the moment when the change was created, in milliseconds
45 * since the "Unix epoch". Will be -1 if the file did not exist and should be created. The client
46 * may use this field to make sure that the file was not changed since then, so it is safe to apply
47 * the change.
48 */
49 private final long fileStamp;
50
51 /**
52 * A list of the edits used to effect the change.
53 */
54 private final List<SourceEdit> edits;
55
56 /**
57 * Constructor for {@link SourceFileEdit}.
58 */
59 public SourceFileEdit(String file, long fileStamp, List<SourceEdit> edits) {
60 this.file = file;
61 this.fileStamp = fileStamp;
62 this.edits = edits;
63 }
64
65 @Override
66 public boolean equals(Object obj) {
67 if (obj instanceof SourceFileEdit) {
68 SourceFileEdit other = (SourceFileEdit) obj;
69 return
70 ObjectUtilities.equals(other.file, file) &&
71 other.fileStamp == fileStamp &&
72 ObjectUtilities.equals(other.edits, edits);
73 }
74 return false;
75 }
76
77 public static SourceFileEdit fromJson(JsonObject jsonObject) {
78 String file = jsonObject.get("file").getAsString();
79 long fileStamp = jsonObject.get("fileStamp").getAsLong();
80 List<SourceEdit> edits = SourceEdit.fromJsonArray(jsonObject.get("edits").getAsJsonArray());
81 return new SourceFileEdit(file, fileStamp, edits);
82 }
83
84 public static List<SourceFileEdit> fromJsonArray(JsonArray jsonArray) {
85 if (jsonArray == null) {
86 return EMPTY_LIST;
87 }
88 ArrayList<SourceFileEdit> list = new ArrayList<SourceFileEdit>(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 * A list of the edits used to effect the change.
98 */
100 return edits;
101 }
102
103 /**
104 * The file containing the code to be modified.
105 */
106 public String getFile() {
107 return file;
108 }
109
110 /**
111 * The modification stamp of the file at the moment when the change was created, in milliseconds
112 * since the "Unix epoch". Will be -1 if the file did not exist and should be created. The client
113 * may use this field to make sure that the file was not changed since then, so it is safe to apply
114 * the change.
115 */
116 public long getFileStamp() {
117 return fileStamp;
118 }
119
120 @Override
121 public int hashCode() {
122 HashCodeBuilder builder = new HashCodeBuilder();
123 builder.append(file);
124 builder.append(fileStamp);
125 builder.append(edits);
126 return builder.toHashCode();
127 }
128
129 public JsonObject toJson() {
130 JsonObject jsonObject = new JsonObject();
131 jsonObject.addProperty("file", file);
132 jsonObject.addProperty("fileStamp", fileStamp);
133 JsonArray jsonArrayEdits = new JsonArray();
134 for (SourceEdit elt : edits) {
135 jsonArrayEdits.add(elt.toJson());
136 }
137 jsonObject.add("edits", jsonArrayEdits);
138 return jsonObject;
139 }
140
141 @Override
142 public String toString() {
143 StringBuilder builder = new StringBuilder();
144 builder.append("[");
145 builder.append("file=");
146 builder.append(file + ", ");
147 builder.append("fileStamp=");
148 builder.append(fileStamp + ", ");
149 builder.append("edits=");
150 builder.append(StringUtils.join(edits, ", "));
151 builder.append("]");
152 return builder.toString();
153 }
154
155}
static List< SourceEdit > fromJsonArray(JsonArray jsonArray)
static List< SourceFileEdit > fromJsonArray(JsonArray jsonArray)
SourceFileEdit(String file, long fileStamp, List< SourceEdit > edits)
static SourceFileEdit fromJson(JsonObject jsonObject)