Java 类org.mozilla.javascript.json.JsonParser.ParseException 实例源码

项目:jshint-for-netbeans    文件:JSHint.java   
public LinkedList<JSHintError> lint(Document d) {
    Context cx = Context.enter();
    LinkedList<JSHintError> result = new LinkedList<>();
    FileObject fo = NbEditorUtilities.getFileObject(d);

    try {
        Scriptable config = getConfig(cx, fo);
        String code = d.getText(0, d.getLength());
        result = lint(cx, code, config);
    } catch (IOException | ParseException | BadLocationException ex) {
        Exceptions.printStackTrace(ex);
    } finally {
        Context.exit();
    }

    return result;
}
项目:jshint-for-netbeans    文件:JSHint.java   
public LinkedList<JSHintError> lint(FileObject fo) {
    Context cx = Context.enter();
    LinkedList<JSHintError> result = new LinkedList<>();

    try {
        Scriptable config = getConfig(cx, fo);
        String code = fo.asText();
        result = lint(cx, code, config);
    } catch (IOException | ParseException ex) {
        Exceptions.printStackTrace(ex);
    } finally {
        Context.exit();
    }

    return result;
}
项目:jshint-for-netbeans    文件:JSHint.java   
@NbBundle.Messages({
    "LBL_InvalidRC=Invalid .jshintrc",
    "# {0} - Linted JavaScript file",
    "# {1} - RC file",
    "DESC_InvalidRC=File {0} was linted with default configuration because its related {1} is not valid json",
    "ICON_InvalidRC="
})
private Scriptable getConfig(Context cx, FileObject fo) throws ParseException, IOException {
    JsonParser parser = new JsonParser(cx, scope);
    FileObject config = findConfig(fo);

    if (config == null) {
        return cx.newObject(scope);
    }

    String json = config.asText();

    try {
        return (Scriptable) parser.parseValue(json);
    }
    catch (ParseException ex) {
        JTextArea text = new JTextArea(Bundle.DESC_InvalidRC(fo.getPath(), config.getPath()));
        NotificationDisplayer.getDefault().notify(Bundle.LBL_InvalidRC(), new ImageIcon(Bundle.ICON_InvalidRC()), text, text, NotificationDisplayer.Priority.NORMAL);
        return cx.newObject(scope);
    }
}
项目:minium    文件:RhinoEngine.java   
@Override
public void putJson(final String varName, final String json) {
    runWithContext(new RhinoCallable<Object, RuntimeException>() {
        @Override
        protected Object doCall(Context cx, Scriptable scope) throws RuntimeException {
            try {
                Object obj = new JsonParser(cx, scope).parseValue(json);
                scope.put(varName, scope, obj);
                return null;
            } catch (ParseException e) {
                throw Throwables.propagate(e);
            }
        }
    });
}
项目:minium    文件:RhinoWebModules.java   
@Override
public Object coerce(Object obj, Type type) {
    Context cx = Context.enter();
    try {
        if (obj instanceof String) {
            return new JsonParser(cx, cx.initStandardObjects()).parseValue((String) obj);
        }
        return obj;
    } catch (ParseException e) {
        // just assume it's actually a string
        return obj;
    }
}
项目:whackpad    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseIllegalWhitespaceChars() throws Exception {
    parser.parseValue(" \u000b 1");
}
项目:whackpad    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseJavaNull() throws Exception {
    parser.parseValue(null);
}
项目:whackpad    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseDoubleNegativeNumbers() throws Exception {
    parser.parseValue("--5");
}
项目:whackpad    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseNumbersWithDecimalExponent() throws Exception {
    parser.parseValue("5e5.5");
}
项目:whackpad    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseNumbersBeginningWithZero() throws Exception {
    parser.parseValue("05");
}
项目:whackpad    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseEmptyJavaString() throws Exception {
    parser.parseValue("");
}
项目:whackpad    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseSingleDoubleQuote() throws Exception {
    parser.parseValue(str('"'));
}
项目:whackpad    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseStringContainingSingleBackslash() throws Exception {
    parser.parseValue(str('"', '\\', '"'));
}
项目:whackpad    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseStringIllegalStringChars() throws Exception {
    parser.parseValue(str('"', '\n', '"'));
}
项目:whackpad    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseArrayWithInvalidElements() throws Exception {
    parser.parseValue("[wtf]");
}
项目:whackpad    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseJsonObjectsWithInvalidFormat() throws Exception {
    parser.parseValue("{\"only\", \"keys\"}");
}
项目:whackpad    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseMoreThanOneToplevelValue() throws Exception {
    parser.parseValue("1 2");
}
项目:whackpad    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseStringTruncatedUnicode() throws Exception {
        parser.parseValue("\"\\u00f\"");
}
项目:whackpad    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseStringControlChars1() throws Exception {
        parser.parseValue("\"\u0000\"");
}
项目:whackpad    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseStringControlChars2() throws Exception {
        parser.parseValue("\"\u001f\"");
}
项目:whackpad    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldThrowParseExceptionWhenIncompleteObject() throws Exception {
    parser.parseValue("{\"a\" ");
}
项目:whackpad    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldThrowParseExceptionWhenIncompleteArray() throws Exception {
    parser.parseValue("[1 ");
}
项目:rhino-android    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseIllegalWhitespaceChars() throws Exception {
    parser.parseValue(" \u000b 1");
}
项目:rhino-android    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseJavaNull() throws Exception {
    parser.parseValue(null);
}
项目:rhino-android    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseDoubleNegativeNumbers() throws Exception {
    parser.parseValue("--5");
}
项目:rhino-android    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseNumbersWithDecimalExponent() throws Exception {
    parser.parseValue("5e5.5");
}
项目:rhino-android    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseNumbersBeginningWithZero() throws Exception {
    parser.parseValue("05");
}
项目:rhino-android    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseEmptyJavaString() throws Exception {
    parser.parseValue("");
}
项目:rhino-android    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseSingleDoubleQuote() throws Exception {
    parser.parseValue(str('"'));
}
项目:rhino-android    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseStringContainingSingleBackslash() throws Exception {
    parser.parseValue(str('"', '\\', '"'));
}
项目:rhino-android    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseStringIllegalStringChars() throws Exception {
    parser.parseValue(str('"', '\n', '"'));
}
项目:rhino-android    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseArrayWithInvalidElements() throws Exception {
    parser.parseValue("[wtf]");
}
项目:rhino-android    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseJsonObjectsWithInvalidFormat() throws Exception {
    parser.parseValue("{\"only\", \"keys\"}");
}
项目:rhino-android    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseMoreThanOneToplevelValue() throws Exception {
    parser.parseValue("1 2");
}
项目:rhino-android    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseStringTruncatedUnicode() throws Exception {
        parser.parseValue("\"\\u00f\"");
}
项目:rhino-android    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseStringControlChars1() throws Exception {
        parser.parseValue("\"\u0000\"");
}
项目:rhino-android    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseStringControlChars2() throws Exception {
        parser.parseValue("\"\u001f\"");
}
项目:rhino-android    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldThrowParseExceptionWhenIncompleteObject() throws Exception {
    parser.parseValue("{\"a\" ");
}
项目:rhino-android    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldThrowParseExceptionWhenIncompleteArray() throws Exception {
    parser.parseValue("[1 ");
}
项目:rhino-android    文件:JsonParserTest.java   
@Test(expected = ParseException.class)
public void shouldFailToParseIllegalUnicodeEscapeSeq() throws Exception {
    parser.parseValue("\"\\u-123\"");
}