Java Code Examples for jdk.nashorn.internal.runtime.Source#sourceFor()

The following examples show how to use jdk.nashorn.internal.runtime.Source#sourceFor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParserImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public CompilationUnitTree parse(final ScriptObjectMirror scriptObj, final DiagnosticListener listener) throws NashornException {
    if (moduleMode) {
        return parseModule(scriptObj, listener);
    }
    final Map<?, ?> map = Objects.requireNonNull(scriptObj);
    if (map.containsKey("script") && map.containsKey("name")) {
        final String script = JSType.toString(map.get("script"));
        final String name = JSType.toString(map.get("name"));
        final Source src = Source.sourceFor(name, script);
        return translate(makeParser(src, listener).parse());
    } else {
        throw new IllegalArgumentException("can't find 'script' and 'name' properties");
    }
}
 
Example 2
Source File: JSONParser.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
ParserException error(final String message, final int start, final int length) throws ParserException {
    final long token     = Token.toDesc(STRING, start, length);
    final int  pos       = Token.descPosition(token);
    final Source src     = Source.sourceFor("<json>", source);
    final int  lineNum   = src.getLine(pos);
    final int  columnNum = src.getColumn(pos);
    final String formatted = ErrorManager.format(message, src, lineNum, columnNum, token);
    return new ParserException(JSErrorType.SYNTAX_ERROR, formatted, src, lineNum, columnNum, token);
}
 
Example 3
Source File: JSONParser.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
ParserException error(final String message, final int start, final int length) throws ParserException {
    final long token     = Token.toDesc(STRING, start, length);
    final int  pos       = Token.descPosition(token);
    final Source src     = Source.sourceFor("<json>", source);
    final int  lineNum   = src.getLine(pos);
    final int  columnNum = src.getColumn(pos);
    final String formatted = ErrorManager.format(message, src, lineNum, columnNum, token);
    return new ParserException(JSErrorType.SYNTAX_ERROR, formatted, src, lineNum, columnNum, token);
}
 
Example 4
Source File: JSONParser.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
ParserException error(final String message, final int start, final int length) throws ParserException {
    final long token     = Token.toDesc(STRING, start, length);
    final int  pos       = Token.descPosition(token);
    final Source src     = Source.sourceFor("<json>", source);
    final int  lineNum   = src.getLine(pos);
    final int  columnNum = src.getColumn(pos);
    final String formatted = ErrorManager.format(message, src, lineNum, columnNum, token);
    return new ParserException(JSErrorType.SYNTAX_ERROR, formatted, src, lineNum, columnNum, token);
}
 
Example 5
Source File: ParserImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private CompilationUnitTree parseModule(final ScriptObjectMirror scriptObj, final DiagnosticListener listener) throws NashornException {
    final Map<?, ?> map = Objects.requireNonNull(scriptObj);
    if (map.containsKey("script") && map.containsKey("name")) {
        final String script = JSType.toString(map.get("script"));
        final String name = JSType.toString(map.get("name"));
        final Source src = Source.sourceFor(name, script);
        return makeModule(src, listener);
    } else {
        throw new IllegalArgumentException("can't find 'script' and 'name' properties");
    }
}
 
Example 6
Source File: JSONParser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
ParserException error(final String message, final int start, final int length) throws ParserException {
    final long token     = Token.toDesc(STRING, start, length);
    final int  pos       = Token.descPosition(token);
    final Source src     = Source.sourceFor("<json>", source);
    final int  lineNum   = src.getLine(pos);
    final int  columnNum = src.getColumn(pos);
    final String formatted = ErrorManager.format(message, src, lineNum, columnNum, token);
    return new ParserException(JSErrorType.SYNTAX_ERROR, formatted, src, lineNum, columnNum, token);
}
 
Example 7
Source File: ParserImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public CompilationUnitTree parse(final String name, final String code, final DiagnosticListener listener) throws NashornException {
    if (moduleMode) {
        return parseModule(name, code, listener);
    }
    final Source src = Source.sourceFor(name, code);
    return translate(makeParser(src, listener).parse());
}
 
Example 8
Source File: ParserImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public CompilationUnitTree parse(final String name, final Reader reader, final DiagnosticListener listener) throws IOException, NashornException {
    if (moduleMode) {
        return parseModule(name, reader, listener);
    }
    final Source src = Source.sourceFor(Objects.requireNonNull(name), Objects.requireNonNull(reader));
    return translate(makeParser(src, listener).parse());
}
 
Example 9
Source File: ParserImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public CompilationUnitTree parse(final URL url, final DiagnosticListener listener) throws IOException, NashornException {
    if (moduleMode) {
        return parseModule(url, listener);
    }
    final Source src = Source.sourceFor(url.toString(), url);
    return translate(makeParser(src, listener).parse());
}
 
Example 10
Source File: ParserImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public CompilationUnitTree parse(final Path path, final DiagnosticListener listener) throws IOException, NashornException {
    if (moduleMode) {
        return parseModule(path, listener);
    }
    final Source src = Source.sourceFor(Objects.requireNonNull(path).toString(), path);
    return translate(makeParser(src, listener).parse());
}
 
Example 11
Source File: ParserImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public CompilationUnitTree parse(final File file, final DiagnosticListener listener) throws IOException, NashornException {
    if (moduleMode) {
        return parseModule(file, listener);
    }
    final Source src = Source.sourceFor(Objects.requireNonNull(file).getName(), file);
    return translate(makeParser(src, listener).parse());
}
 
Example 12
Source File: JSONParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
ParserException error(final String message, final int start, final int length) throws ParserException {
    final long token     = Token.toDesc(STRING, start, length);
    final int  pos       = Token.descPosition(token);
    final Source src     = Source.sourceFor("<json>", source);
    final int  lineNum   = src.getLine(pos);
    final int  columnNum = src.getColumn(pos);
    final String formatted = ErrorManager.format(message, src, lineNum, columnNum, token);
    return new ParserException(JSErrorType.SYNTAX_ERROR, formatted, src, lineNum, columnNum, token);
}
 
Example 13
Source File: JSONParser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
ParserException error(final String message, final int start, final int length) throws ParserException {
    final long token     = Token.toDesc(STRING, start, length);
    final int  pos       = Token.descPosition(token);
    final Source src     = Source.sourceFor("<json>", source);
    final int  lineNum   = src.getLine(pos);
    final int  columnNum = src.getColumn(pos);
    final String formatted = ErrorManager.format(message, src, lineNum, columnNum, token);
    return new ParserException(JSErrorType.SYNTAX_ERROR, formatted, src, lineNum, columnNum, token);
}
 
Example 14
Source File: JSONParser.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
ParserException error(final String message, final int start, final int length) throws ParserException {
    final long token     = Token.toDesc(STRING, start, length);
    final int  pos       = Token.descPosition(token);
    final Source src     = Source.sourceFor("<json>", source);
    final int  lineNum   = src.getLine(pos);
    final int  columnNum = src.getColumn(pos);
    final String formatted = ErrorManager.format(message, src, lineNum, columnNum, token);
    return new ParserException(JSErrorType.SYNTAX_ERROR, formatted, src, lineNum, columnNum, token);
}
 
Example 15
Source File: ParserImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private CompilationUnitTree parseModule(final File file, final DiagnosticListener listener) throws IOException, NashornException {
    final Source src = Source.sourceFor(Objects.requireNonNull(file).getName(), file);
    return makeModule(src, listener);
}
 
Example 16
Source File: ParserImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private CompilationUnitTree parseModule(final Path path, final DiagnosticListener listener) throws IOException, NashornException {
    final Source src = Source.sourceFor(Objects.requireNonNull(path).toString(), path);
    return makeModule(src, listener);
}
 
Example 17
Source File: ParserImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private CompilationUnitTree parseModule(final URL url, final DiagnosticListener listener) throws IOException, NashornException {
    final Source src = Source.sourceFor(url.toString(), url);
    return makeModule(src, listener);
}
 
Example 18
Source File: ParserImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private CompilationUnitTree parseModule(final String name, final Reader reader, final DiagnosticListener listener) throws IOException, NashornException {
    final Source src = Source.sourceFor(Objects.requireNonNull(name), Objects.requireNonNull(reader));
    return makeModule(src, listener);
}
 
Example 19
Source File: ParserImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private CompilationUnitTree parseModule(final String name, final String code, final DiagnosticListener listener) throws NashornException {
    final Source src = Source.sourceFor(name, code);
    return makeModule(src, listener);
}