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

Unified Diff: editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/generated/types/HighlightRegion.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/HighlightRegion.java
diff --git a/editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/generated/types/HighlightRegion.java b/editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/generated/types/HighlightRegion.java
index e73e9f5d1fcd4d18dee78c181109ec8e76cccb88..0a5eb463364f1d47d8cde9af1fbfa9d5965efb84 100644
--- a/editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/generated/types/HighlightRegion.java
+++ b/editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/generated/types/HighlightRegion.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 HighlightRegion {
- /**
- * An empty array of {@link HighlightRegion}s.
- */
public static final HighlightRegion[] EMPTY_ARRAY = new HighlightRegion[0];
+ public static final List<HighlightRegion> EMPTY_LIST = Lists.newArrayList();
+
/**
* The type of highlight associated with the region.
*/
@@ -74,6 +78,25 @@ public class HighlightRegion {
return false;
}
+ public static HighlightRegion fromJson(JsonObject jsonObject) {
+ String type = jsonObject.get("type").getAsString();
+ Integer offset = jsonObject.get("offset").getAsInt();
+ Integer length = jsonObject.get("length").getAsInt();
+ return new HighlightRegion(type, offset, length);
+ }
+
+ public static List<HighlightRegion> fromJsonArray(JsonArray jsonArray) {
+ if (jsonArray == null) {
+ return EMPTY_LIST;
+ }
+ ArrayList<HighlightRegion> list = new ArrayList<HighlightRegion>(jsonArray.size());
+ Iterator<JsonElement> iterator = jsonArray.iterator();
+ while (iterator.hasNext()) {
+ list.add(fromJson(iterator.next().getAsJsonObject()));
+ }
+ return list;
+ }
+
/**
* The length of the region to be highlighted.
*/

Powered by Google App Engine
This is Rietveld 408576698