String locationString() { int line = lineNumber + 1; int column = pos - lineStart + 1; return " at line " + line + " column " + column + " path " + getPath(); }
private String locationString() { int line = lineNumber + 1; int column = pos - lineStart + 1; return " at line " + line + " column " + column + " path " + getPath(); }
public String getPath() { String path = reader.getPath(); return currentPath = path; }
public String getPath() { String path = reader.getPath(); return currentPath = path; }
@Override public IValue visitVoid(Type type) throws IOException { throw new IOException("Can not read json values of type void: " + in.getPath()); }
@Override public IValue visitExternal(Type type) throws IOException { throw new IOException("External type " + type + "is not implemented yet by the json reader:" + in.getPath()); }
private Type checkNameCons(Type adt, String consName) throws IOException { Set<Type> alternatives = store.lookupConstructor(adt, consName); if (alternatives.size() == 0) { throw new IOException("No constructor with this name was declared for " + adt + ":" + in.getPath()); } else if (alternatives.size() > 1) { throw new IOException("Overloading of constructor names is not supported (" + adt + "):" + in.getPath()); } return alternatives.iterator().next(); } });
private static Map<String, Object> parseJsonObject(JsonReader jr) throws IOException { jr.beginObject(); Map<String, Object> obj = new LinkedHashMap<String, Object>(); while (jr.hasNext()) { String name = jr.nextName(); Object value = parseRecursive(jr); obj.put(name, value); } checkState(jr.peek() == JsonToken.END_OBJECT, "Bad token: " + jr.getPath()); jr.endObject(); return Collections.unmodifiableMap(obj); }
@Override public IValue visitDateTime(Type type) throws IOException { try { switch (in.peek()) { case STRING: return vf.datetime(format.get().parse(in.nextString()).toInstant().toEpochMilli()); case NUMBER: return vf.datetime(in.nextLong()); default: throw new IOException("Expected a datetime instant " + in.getPath()); } } catch (ParseException e) { throw new IOException("Could not parse date: " + in.getPath()); } }
private static Map<String, Object> parseJsonObject(JsonReader jr) throws IOException { jr.beginObject(); Map<String, Object> obj = new LinkedHashMap<String, Object>(); while (jr.hasNext()) { String name = jr.nextName(); Object value = parseRecursive(jr); obj.put(name, value); } checkState(jr.peek() == JsonToken.END_OBJECT, "Bad token: " + jr.getPath()); jr.endObject(); return Collections.unmodifiableMap(obj); }
@Override public IValue visitSourceLocation(Type type) throws IOException { switch (in.peek()) { case STRING: return sourceLocationString(); case BEGIN_OBJECT: return sourceLocationObject(); default: throw new IOException("Could not find string or source location object here: " + in.getPath()); } }
private static List<Object> parseJsonArray(JsonReader jr) throws IOException { jr.beginArray(); List<Object> array = new ArrayList<>(); while (jr.hasNext()) { Object value = parseRecursive(jr); array.add(value); } checkState(jr.peek() == JsonToken.END_ARRAY, "Bad token: " + jr.getPath()); jr.endArray(); return Collections.unmodifiableList(array); }
private static List<Object> parseJsonArray(JsonReader jr) throws IOException { jr.beginArray(); List<Object> array = new ArrayList<Object>(); while (jr.hasNext()) { Object value = parseRecursive(jr); array.add(value); } checkState(jr.peek() == JsonToken.END_ARRAY, "Bad token: " + jr.getPath()); jr.endArray(); return Collections.unmodifiableList(array); }
/** * Throws a new IO exception with the given message and a context snippet * with this reader's content. */ private IOException syntaxError(String message) throws IOException { throw new MalformedJsonException(message + " at line " + getLineNumber() + " column " + getColumnNumber() + " path " + getPath()); }
/** * Throws a new IO exception with the given message and a context snippet * with this reader's content. */ private IOException syntaxError(String message) throws IOException { throw new MalformedJsonException(message + " at line " + getLineNumber() + " column " + getColumnNumber() + " path " + getPath()); }
/** * Throws a new IO exception with the given message and a context snippet * with this reader's content. */ private IOException syntaxError(String message) throws IOException { throw new MalformedJsonException(message + " at line " + getLineNumber() + " column " + getColumnNumber() + " path " + getPath()); }
/** * Consumes the next token from the JSON stream and asserts that it is the * beginning of a new object. */ public void beginObject() throws IOException { int p = peeked; if (p == PEEKED_NONE) { p = doPeek(); } if (p == PEEKED_BEGIN_OBJECT) { push(JsonScope.EMPTY_OBJECT); peeked = PEEKED_NONE; } else { throw new IllegalStateException("Expected BEGIN_OBJECT but was " + peek() + " at line " + getLineNumber() + " column " + getColumnNumber() + " path " + getPath()); } }
/** * Consumes the next token from the JSON stream and asserts that it is the * beginning of a new object. */ public void beginObject() throws IOException { int p = peeked; if (p == PEEKED_NONE) { p = doPeek(); } if (p == PEEKED_BEGIN_OBJECT) { push(JsonScope.EMPTY_OBJECT); peeked = PEEKED_NONE; } else { throw new IllegalStateException("Expected BEGIN_OBJECT but was " + peek() + " at line " + getLineNumber() + " column " + getColumnNumber() + " path " + getPath()); } }
protected void throwJsonPropertyNumberParseFailureException(JsonReader in, RuntimeException e) { final Class<?> numberType = getNumberType(); final String properthPath = in.getPath(); final ExceptionMessageBuilder br = new ExceptionMessageBuilder(); br.addNotice("Failed to parse number for the JSON property."); br.addItem("Advice"); br.addElement("Confirm the next exception message."); br.addElement("And make sure your specified value for the JSON property."); br.addItem("Number Type"); br.addElement(numberType.getName()); br.addItem("JSON Property"); br.addElement(properthPath); final String msg = br.buildExceptionMessage(); throw new JsonPropertyNumberParseFailureException(msg, numberType, properthPath, e); }
protected void throwJsonPropertyNumberParseFailureException(JsonReader in, RuntimeException e) { final Class<?> numberType = getNumberType(); final String properthPath = in.getPath(); final ExceptionMessageBuilder br = new ExceptionMessageBuilder(); br.addNotice("Failed to parse number for the JSON property."); br.addItem("Advice"); br.addElement("Confirm the next exception message."); br.addElement("And make sure your specified value for the JSON property."); br.addItem("Number Type"); br.addElement(numberType.getName()); br.addItem("JSON Property"); br.addElement(properthPath); final String msg = br.buildExceptionMessage(); throw new JsonPropertyNumberParseFailureException(msg, numberType, properthPath, e); }