本文整理汇总了Java中jdk.nashorn.internal.runtime.Source.sourceFor方法的典型用法代码示例。如果您正苦于以下问题:Java Source.sourceFor方法的具体用法?Java Source.sourceFor怎么用?Java Source.sourceFor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.runtime.Source
的用法示例。
在下文中一共展示了Source.sourceFor方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import jdk.nashorn.internal.runtime.Source; //导入方法依赖的package包/类
@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());
}
示例2: parseModule
import jdk.nashorn.internal.runtime.Source; //导入方法依赖的package包/类
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");
}
}
示例3: error
import jdk.nashorn.internal.runtime.Source; //导入方法依赖的package包/类
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);
}
示例4: parse
import jdk.nashorn.internal.runtime.Source; //导入方法依赖的package包/类
@Override
public CompilationUnitTree parse(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 translate(makeParser(src, listener).parse());
} else {
throw new IllegalArgumentException("can't find 'script' and 'name' properties");
}
}