Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(449)

Unified Diff: editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/generated/types/SourceEdit.java

Issue 488413003: Initial factory constructors for generated objects in Java server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: review and rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/generated/types/SourceEdit.java
diff --git a/editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/generated/types/SourceEdit.java b/editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/generated/types/SourceEdit.java
index ebda4a86c858e0eba607fd3be5619a1b669f1fa8..e3fbbf0570be6b3b6799d7ee412759e483c4f690 100644
--- a/editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/generated/types/SourceEdit.java
+++ b/editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/generated/types/SourceEdit.java
@@ -19,10 +19,15 @@ package com.google.dart.server.generated.types;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
+import com.google.common.collect.Lists;
+import com.google.dart.server.utilities.general.JsonUtilities;
import com.google.dart.server.utilities.general.ObjectUtilities;
import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
+import java.util.ArrayList;
+import java.util.Iterator;
import org.apache.commons.lang3.StringUtils;
/**
@@ -33,11 +38,10 @@ import org.apache.commons.lang3.StringUtils;
@SuppressWarnings("unused")
public class SourceEdit {
- /**
- * An empty array of {@link SourceEdit}s.
- */
public static final SourceEdit[] EMPTY_ARRAY = new SourceEdit[0];
+ public static final List<SourceEdit> EMPTY_LIST = Lists.newArrayList();
+
/**
* The offset of the region to be modified.
*/
@@ -87,6 +91,26 @@ public class SourceEdit {
return false;
}
+ public static SourceEdit fromJson(JsonObject jsonObject) {
+ Integer offset = jsonObject.get("offset").getAsInt();
+ Integer length = jsonObject.get("length").getAsInt();
+ String replacement = jsonObject.get("replacement").getAsString();
+ String id = jsonObject.get("id") == null ? null : jsonObject.get("id").getAsString();
+ return new SourceEdit(offset, length, replacement, id);
+ }
+
+ public static List<SourceEdit> fromJsonArray(JsonArray jsonArray) {
+ if (jsonArray == null) {
+ return EMPTY_LIST;
+ }
+ ArrayList<SourceEdit> list = new ArrayList<SourceEdit>(jsonArray.size());
+ Iterator<JsonElement> iterator = jsonArray.iterator();
+ while (iterator.hasNext()) {
+ list.add(fromJson(iterator.next().getAsJsonObject()));
+ }
+ return list;
+ }
+
/**
* An identifier that uniquely identifies this source edit from other edits in the same response.
* This field is omitted unless a containing structure needs to be able to identify the edit for

Powered by Google App Engine
This is Rietveld 408576698