org.mozilla.javascript.Context.stringIsCompilableUnit()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 JavaScript  
字(3.1k)|赞(0)|评价(0)|浏览(242)

本文整理了Java中org.mozilla.javascript.Context.stringIsCompilableUnit()方法的一些代码示例,展示了Context.stringIsCompilableUnit()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.stringIsCompilableUnit()方法的具体详情如下:
包路径:org.mozilla.javascript.Context
类名称:Context
方法名:stringIsCompilableUnit

Context.stringIsCompilableUnit介绍

[英]Check whether a string is ready to be compiled.

stringIsCompilableUnit is intended to support interactive compilation of JavaScript. If compiling the string would result in an error that might be fixed by appending more source, this method returns false. In every other case, it returns true.

Interactive shells may accumulate source lines, using this method after each new line is appended to check whether the statement being entered is complete.
[中]检查字符串是否已准备好进行编译。
stringIsCompilableUnit旨在支持JavaScript的交互式编译。如果编译字符串会导致错误,而该错误可能通过追加更多源代码得到修复,则此方法返回false。在其他任何情况下,它都返回true。
交互式Shell可能会累积源代码行,在追加每一新行后使用此方法检查输入的语句是否完整。

代码示例

代码示例来源:origin: org.geoserver.script/gs-script-js

private String collectInput(Context cx) throws IOException {
  String source = "";
  // Collect lines of source to compile.
  while (true) {
    String newline;
    newline = in.readLine();
    if (newline == null) {
      // hit EOF
      source = null;
      break;
    }
    source = source + newline + "\n";
    if (cx.stringIsCompilableUnit(source)) {
      break;
    }
  }
  return source;
}

代码示例来源:origin: javanna/elasticshell

@Override
  public boolean isCompilable(String source) {
    return Context.getCurrentContext().stringIsCompilableUnit(source);
  }
}

代码示例来源:origin: joinery/joinery-dataframe

public String read(final Console console)
throws IOException {
  final Context ctx = Context.getCurrentContext();
  final StringBuilder buffer = new StringBuilder();
  String line = null;
  if ((line = console.readLine(PROMPT)) != null) {
    // apply continued lines to last value
    if (line.startsWith(".") && has(LAST_VALUE_NAME, this)) {
      buffer.append(LAST_VALUE_NAME);
    }
    // read lines a complete statement is found or eof
    buffer.append(line);
    while (!ctx.stringIsCompilableUnit(buffer.toString()) &&
        (line = console.readLine(PROMPT_CONTINUE)) != null) {
      buffer.append(NEWLINE).append(line);
    }
    return buffer.toString();
  }
  return null;
}

代码示例来源:origin: cardillo/joinery

public String read(final Console console)
throws IOException {
  final Context ctx = Context.getCurrentContext();
  final StringBuilder buffer = new StringBuilder();
  String line = null;
  if ((line = console.readLine(PROMPT)) != null) {
    // apply continued lines to last value
    if (line.startsWith(".") && has(LAST_VALUE_NAME, this)) {
      buffer.append(LAST_VALUE_NAME);
    }
    // read lines a complete statement is found or eof
    buffer.append(line);
    while (!ctx.stringIsCompilableUnit(buffer.toString()) &&
        (line = console.readLine(PROMPT_CONTINUE)) != null) {
      buffer.append(NEWLINE).append(line);
    }
    return buffer.toString();
  }
  return null;
}

代码示例来源:origin: org.zkoss.maven/yuicompressor-maven-plugin-zk

if (cx.stringIsCompilableUnit(source)) {
  break;

代码示例来源:origin: com.github.tntim96/rhino

booleanResult = cx.stringIsCompilableUnit(text);
break;

代码示例来源:origin: ro.isdc.wro4j/rhino

booleanResult = cx.stringIsCompilableUnit(text);
break;

代码示例来源:origin: ro.isdc.wro4j/rhino

if (cx.stringIsCompilableUnit(source))
  break;
prompt = prompts[1];

代码示例来源:origin: com.github.tntim96/rhino

if (cx.stringIsCompilableUnit(source))
  break;
prompt = prompts[1];

相关文章

微信公众号

Context类方法