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

Unified Diff: editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/generated/types/Location.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/Location.java
diff --git a/editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/generated/types/Location.java b/editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/generated/types/Location.java
index ac9a15bfb4ebcfa35e892c16a72078217641af9b..1cd5c6fec3a57d6186f4769e2a4d4797934ab5af 100644
--- a/editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/generated/types/Location.java
+++ b/editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/generated/types/Location.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 Location {
- /**
- * An empty array of {@link Location}s.
- */
public static final Location[] EMPTY_ARRAY = new Location[0];
+ public static final List<Location> EMPTY_LIST = Lists.newArrayList();
+
/**
* The file containing the range.
*/
@@ -88,6 +92,27 @@ public class Location {
return false;
}
+ public static Location fromJson(JsonObject jsonObject) {
+ String file = jsonObject.get("file").getAsString();
+ Integer offset = jsonObject.get("offset").getAsInt();
+ Integer length = jsonObject.get("length").getAsInt();
+ Integer startLine = jsonObject.get("startLine").getAsInt();
+ Integer startColumn = jsonObject.get("startColumn").getAsInt();
+ return new Location(file, offset, length, startLine, startColumn);
+ }
+
+ public static List<Location> fromJsonArray(JsonArray jsonArray) {
+ if (jsonArray == null) {
+ return EMPTY_LIST;
+ }
+ ArrayList<Location> list = new ArrayList<Location>(jsonArray.size());
+ Iterator<JsonElement> iterator = jsonArray.iterator();
+ while (iterator.hasNext()) {
+ list.add(fromJson(iterator.next().getAsJsonObject()));
+ }
+ return list;
+ }
+
/**
* The file containing the range.
*/

Powered by Google App Engine
This is Rietveld 408576698