org.mozilla.javascript.ast.WhileLoop类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 JavaScript  
字(7.7k)|赞(0)|评价(0)|浏览(336)

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

WhileLoop介绍

[英]While statement. Node type is Token#WHILE.

WhileStatement: 
while ( Expression ) Statement

[中]While声明。节点类型为令牌#WHILE。

WhileStatement: 
while ( Expression ) Statement

代码示例

代码示例来源:origin: konsoletyper/teavm

private void print(WhileLoop node) throws IOException {
  writer.append("while").ws().append('(');
  print(node.getCondition());
  writer.append(')').ws();
  print(node.getBody());
}

代码示例来源:origin: geogebra/geogebra

private WhileLoop whileLoop()
  throws IOException
{
  if (currentToken != Token.WHILE) codeBug();
  consumeToken();
  int pos = ts.tokenBeg;
  WhileLoop pn = new WhileLoop(pos);
  pn.setLineno(ts.lineno);
  enterLoop(pn);
  try {
    ConditionData data = condition();
    pn.setCondition(data.condition);
    pn.setParens(data.lp - pos, data.rp - pos);
    AstNode body = statement();
    pn.setLength(getNodeEnd(body) - pos);
    pn.setBody(body);
  } finally {
    exitLoop();
  }
  return pn;
}

代码示例来源:origin: io.apigee/rhino

private Node transformWhileLoop(WhileLoop loop) {
  decompiler.addToken(Token.WHILE);
  loop.setType(Token.LOOP);
  pushScope(loop);
  try {
    decompiler.addToken(Token.LP);
    Node cond = transform(loop.getCondition());
    decompiler.addToken(Token.RP);
    decompiler.addEOL(Token.LC);
    Node body = transform(loop.getBody());
    decompiler.addEOL(Token.RC);
    return createLoop(loop, LOOP_WHILE, body, cond, null, null);
  } finally {
    popScope();
  }
}

代码示例来源:origin: com.fifesoft/languagesupport

/**
 * Extract while loop from node and add new code block
 */
private void processWhileNode(Node child, CodeBlock block,
    Set<Completion> set, String entered, int offset) {
  WhileLoop loop = (WhileLoop) child;
  if (canProcessNode(loop)) {
    offset = loop.getAbsolutePosition() + loop.getLength();
    addCodeBlock(loop.getBody(), set, entered, block, offset);
  }
}

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

/**
 * Sets loop condition
 * @throws IllegalArgumentException} if condition is {@code null}
 */
public void setCondition(AstNode condition) {
  assertNotNull(condition);
  this.condition = condition;
  condition.setParent(this);
}

代码示例来源:origin: io.apigee/rhino

@Override
public String toSource(int depth) {
  StringBuilder sb = new StringBuilder();
  sb.append(makeIndent(depth));
  sb.append("while (");
  sb.append(condition.toSource(0));
  sb.append(") ");
  if (body.getType() == Token.BLOCK) {
    sb.append(body.toSource(depth).trim());
    sb.append("\n");
  } else {
    sb.append("\n").append(body.toSource(depth+1));
  }
  return sb.toString();
}

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

private WhileLoop whileLoop()
  throws IOException
{
  if (currentToken != Token.WHILE) codeBug();
  consumeToken();
  int pos = ts.tokenBeg;
  WhileLoop pn = new WhileLoop(pos);
  pn.setLineno(ts.lineno);
  enterLoop(pn);
  try {
    ConditionData data = condition();
    pn.setCondition(data.condition);
    pn.setParens(data.lp - pos, data.rp - pos);
    AstNode body = statement();
    pn.setLength(getNodeEnd(body) - pos);
    pn.setBody(body);
  } finally {
    exitLoop();
  }
  return pn;
}

代码示例来源:origin: geogebra/geogebra

private Node transformWhileLoop(WhileLoop loop) {
  decompiler.addToken(Token.WHILE);
  loop.setType(Token.LOOP);
  pushScope(loop);
  try {
    decompiler.addToken(Token.LP);
    Node cond = transform(loop.getCondition());
    decompiler.addToken(Token.RP);
    decompiler.addEOL(Token.LC);
    Node body = transform(loop.getBody());
    decompiler.addEOL(Token.RC);
    return createLoop(loop, LOOP_WHILE, body, cond, null, null);
  } finally {
    popScope();
  }
}

代码示例来源:origin: geogebra/geogebra

/**
 * Sets loop condition
 * @throws IllegalArgumentException} if condition is {@code null}
 */
public void setCondition(AstNode condition) {
  assertNotNull(condition);
  this.condition = condition;
  condition.setParent(this);
}

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

@Override
public String toSource(int depth) {
  StringBuilder sb = new StringBuilder();
  sb.append(makeIndent(depth));
  sb.append("while (");
  sb.append(condition.toSource(0));
  sb.append(") ");
  if (body.getType() == Token.BLOCK) {
    sb.append(body.toSource(depth).trim());
    sb.append("\n");
  } else {
    sb.append("\n").append(body.toSource(depth+1));
  }
  return sb.toString();
}

代码示例来源:origin: io.apigee/rhino

private WhileLoop whileLoop()
  throws IOException
{
  if (currentToken != Token.WHILE) codeBug();
  consumeToken();
  int pos = ts.tokenBeg;
  WhileLoop pn = new WhileLoop(pos);
  pn.setLineno(ts.lineno);
  enterLoop(pn);
  try {
    ConditionData data = condition();
    pn.setCondition(data.condition);
    pn.setParens(data.lp - pos, data.rp - pos);
    AstNode body = statement();
    pn.setLength(getNodeEnd(body) - pos);
    pn.setBody(body);
  } finally {
    exitLoop();
  }
  return pn;
}

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

private Node transformWhileLoop(WhileLoop loop) {
  decompiler.addToken(Token.WHILE);
  loop.setType(Token.LOOP);
  pushScope(loop);
  try {
    decompiler.addToken(Token.LP);
    Node cond = transform(loop.getCondition());
    decompiler.addToken(Token.RP);
    decompiler.addEOL(Token.LC);
    Node body = transform(loop.getBody());
    decompiler.addEOL(Token.RC);
    return createLoop(loop, LOOP_WHILE, body, cond, null, null);
  } finally {
    popScope();
  }
}

代码示例来源:origin: org.teavm/teavm-jso-impl

private void print(WhileLoop node) throws IOException {
  writer.append("while").ws().append('(');
  print(node.getCondition());
  writer.append(')').ws();
  print(node.getBody());
}

代码示例来源:origin: io.apigee/rhino

/**
 * Sets loop condition
 * @throws IllegalArgumentException} if condition is {@code null}
 */
public void setCondition(AstNode condition) {
  assertNotNull(condition);
  this.condition = condition;
  condition.setParent(this);
}

代码示例来源:origin: geogebra/geogebra

@Override
public String toSource(int depth) {
  StringBuilder sb = new StringBuilder();
  sb.append(makeIndent(depth));
  sb.append("while (");
  sb.append(condition.toSource(0));
  sb.append(") ");
  if (body.getType() == Token.BLOCK) {
    sb.append(body.toSource(depth).trim());
    sb.append("\n");
  } else {
    sb.append("\n").append(body.toSource(depth+1));
  }
  return sb.toString();
}

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

private WhileLoop whileLoop()
  throws IOException
{
  if (currentToken != Token.WHILE) codeBug();
  consumeToken();
  int pos = ts.tokenBeg;
  WhileLoop pn = new WhileLoop(pos);
  pn.setLineno(ts.lineno);
  enterLoop(pn);
  try {
    ConditionData data = condition();
    pn.setCondition(data.condition);
    pn.setParens(data.lp - pos, data.rp - pos);
    AstNode body = statement();
    pn.setLength(getNodeEnd(body) - pos);
    pn.setBody(body);
  } finally {
    exitLoop();
  }
  return pn;
}

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

private Node transformWhileLoop(WhileLoop loop) {
  decompiler.addToken(Token.WHILE);
  loop.setType(Token.LOOP);
  pushScope(loop);
  try {
    decompiler.addToken(Token.LP);
    Node cond = transform(loop.getCondition());
    decompiler.addToken(Token.RP);
    decompiler.addEOL(Token.LC);
    Node body = transform(loop.getBody());
    decompiler.addEOL(Token.RC);
    return createLoop(loop, LOOP_WHILE, body, cond, null, null);
  } finally {
    popScope();
  }
}

代码示例来源:origin: wala/WALA

@Override
public CAstNode visitWhileLoop(WhileLoop node, WalkContext arg) {
  AstNode breakStmt = makeEmptyLabelStmt("breakLabel");
  CAstNode breakLabel = visit(breakStmt, arg);
  AstNode contStmt = makeEmptyLabelStmt("contLabel");
  CAstNode contLabel = visit(contStmt, arg);
  WalkContext loopContext = makeLoopContext(node, arg, breakStmt, contStmt);

  CAstNode loop = Ast.makeNode(CAstNode.BLOCK_STMT, 
    contLabel,
    Ast.makeNode(CAstNode.LOOP, 
        visit(node.getCondition(), arg), 
        visit(node.getBody(), loopContext)),
    breakLabel);
  
  arg.cfg().map(node, loop);
  
  return loop;
}

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

/**
 * Sets loop condition
 * @throws IllegalArgumentException} if condition is {@code null}
 */
public void setCondition(AstNode condition) {
  assertNotNull(condition);
  this.condition = condition;
  condition.setParent(this);
}

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

@Override
public String toSource(int depth) {
  StringBuilder sb = new StringBuilder();
  sb.append(makeIndent(depth));
  sb.append("while (");
  sb.append(condition.toSource(0));
  sb.append(") ");
  if (body.getType() == Token.BLOCK) {
    sb.append(body.toSource(depth).trim());
    sb.append("\n");
  } else {
    sb.append("\n").append(body.toSource(depth+1));
  }
  return sb.toString();
}

相关文章