Merged in PA1
This commit is contained in:
@@ -78,6 +78,7 @@ public abstract class Node {
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
private String errorMsg;
|
||||
|
||||
|
||||
/** A Node corresponding to source text between LEFT and RIGHT. */
|
||||
public Node(Location left, Location right) {
|
||||
if (left != null) {
|
||||
@@ -100,6 +101,7 @@ public abstract class Node {
|
||||
return location;
|
||||
}
|
||||
|
||||
|
||||
/** Copy LOCATION as getLocation(). */
|
||||
public void setLocation(final int[] location) {
|
||||
System.arraycopy(location, 0, this.location, 0, 4);
|
||||
@@ -113,6 +115,7 @@ public abstract class Node {
|
||||
this.errorMsg = msg;
|
||||
}
|
||||
|
||||
|
||||
/** Return true iff I have been marked with an error message. */
|
||||
@JsonIgnore
|
||||
public boolean hasError() {
|
||||
@@ -135,11 +138,13 @@ public abstract class Node {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Return a serialization of this node in JSON format. */
|
||||
public String toJSON() throws JsonProcessingException {
|
||||
return mapper.writeValueAsString(this);
|
||||
}
|
||||
|
||||
|
||||
/** Mapper to-and-from serialized JSON. */
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@@ -148,6 +153,7 @@ public abstract class Node {
|
||||
mapper.registerModule(new ParameterNamesModule());
|
||||
}
|
||||
|
||||
|
||||
/** Returns a T from JSON, a JSON-serialized T value with class CLAS. */
|
||||
public static <T> T fromJSON(String json, Class<T> clas) throws IOException {
|
||||
return mapper.readValue(json, clas);
|
||||
|
||||
Reference in New Issue
Block a user