当前位置: 首页>>代码示例>>Java>>正文


Java RenderContext类代码示例

本文整理汇总了Java中com.google.caja.reporting.RenderContext的典型用法代码示例。如果您正苦于以下问题:Java RenderContext类的具体用法?Java RenderContext怎么用?Java RenderContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RenderContext类属于com.google.caja.reporting包,在下文中一共展示了RenderContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testNoops

import com.google.caja.reporting.RenderContext; //导入依赖的package包/类
public final void testNoops() throws ParseException {
  ParseTreeNode b = js(fromString(
      "for (;;) {",
      "  if (foo)",
      "    bar();",
      "  else",
      "    ;",
      "}"));
  StringBuilder out = new StringBuilder();
  JsMinimalPrinter pp = new JsMinimalPrinter(out);
  b.render(new RenderContext(pp));
  pp.noMoreTokens();
  assertEquals(
      "{for(;;){if(foo)bar();else;}}",
      out.toString());
}
 
开发者ID:google,项目名称:caja,代码行数:17,代码来源:JsMinimalPrinterTest.java

示例2: renderUnquotedValue

import com.google.caja.reporting.RenderContext; //导入依赖的package包/类
public static void renderUnquotedValue(String unquoted, RenderContext rc) {
  StringBuilder sb = new StringBuilder(unquoted.length() + 18);

  // JSON requires double quotes for all string literals but in
  // embeddable mode we need to produce output that can be safely
  // embedded in HTML or XML.  We make no guarantees for attribute
  // values, and cajoled output should not be included in an
  // attribute value, but to be on the safe side, we use single
  // quotes since when naive HTML authors use quotes at all for
  // attribute values, they tend to use double quotes, and putting
  // single quotes around strings allows us to produce output that
  // contains no double quotes.
  // TODO(felix8a): avoid-double-quotes might not be worth it
  if (rc.asJson()) {
    sb.append('"');
    Escaping.escapeJsonString(unquoted, true, sb);
    sb.append('"');
  } else {
    sb.append('\'');
    Escaping.escapeJsString(unquoted, true, true, sb);
    sb.append('\'');
  }
  rc.getOut().consume(sb.toString());
}
 
开发者ID:google,项目名称:caja,代码行数:25,代码来源:StringLiteral.java

示例3: render

import com.google.caja.reporting.RenderContext; //导入依赖的package包/类
@Override
public void render(RenderContext rc) {
  FunctionConstructor fc = getInitializer();
  TokenConsumer out = rc.getOut();
  out.mark(getFilePosition());
  out.consume("function");
  getIdentifier().render(rc);
  out.consume("(");
  boolean seen = false;
  for (FormalParam p : fc.getParams()) {
    if (seen) {
      out.consume(",");
    } else {
      seen = true;
    }
    p.render(rc);
  }
  out.consume(")");
  fc.getBody().renderBlock(rc, false);
}
 
开发者ID:google,项目名称:caja,代码行数:21,代码来源:FunctionDeclaration.java

示例4: render

import com.google.caja.reporting.RenderContext; //导入依赖的package包/类
public void render(RenderContext rc) {
  TokenConsumer out = rc.getOut();
  out.mark(getFilePosition());
  String label = getRenderedLabel();
  if (null != label) {
    out.consume(label);
    out.consume(":");
  }
  Iterator<? extends ParseTreeNode> it = children().iterator();
  out.consume("switch");
  out.consume("(");
  it.next().render(rc);
  out.consume(")");
  out.consume("{");
  while (it.hasNext()) {
    SwitchCase caseStmt = (SwitchCase) it.next();
    caseStmt.render(rc);
  }
  out.mark(FilePosition.endOfOrNull(getFilePosition()));
  out.consume("}");
}
 
开发者ID:google,项目名称:caja,代码行数:22,代码来源:SwitchStmt.java

示例5: render

import com.google.caja.reporting.RenderContext; //导入依赖的package包/类
public void render(RenderContext rc) {
  TokenConsumer out = rc.getOut();
  out.mark(getFilePosition());
  if (children().isEmpty()) {
    throw new SomethingWidgyHappenedError("Empty MultiDeclaration");
  }
  out.consume("var");
  boolean seen = false;
  for (Declaration decl : children()) {
    if (seen) {
      out.consume(",");
    } else {
      seen = true;
    }
    decl.renderShort(rc);
  }
}
 
开发者ID:google,项目名称:caja,代码行数:18,代码来源:MultiDeclaration.java

示例6: testRenderPostInsert3

import com.google.caja.reporting.RenderContext; //导入依赖的package包/类
public final void testRenderPostInsert3() {
  doInsert(-1);
  StringBuilder sb = new StringBuilder();
  TokenConsumer tc = new JsPrettyPrinter(sb);
  root.render(new RenderContext(tc));
  tc.noMoreTokens();
  assertEquals(
      "$0: {\n"
      + "  $1: {\n"
      + "    2;\n"
      + "    3;\n"
      + "    4;\n"
      + "  }\n"
      + "  $5: {\n"
      + "    6;\n"
      + "    7;\n"
      + "    8;\n"
      + "  }\n"
      + "  $9: {\n"
      + "    10;\n"
      + "    11;\n"
      + "    12;\n"
      + "  }\n"
      + "}",
      sb.toString());
}
 
开发者ID:google,项目名称:caja,代码行数:27,代码来源:ParseTreeNodeTest.java

示例7: testRenderPostRemove2

import com.google.caja.reporting.RenderContext; //导入依赖的package包/类
public final void testRenderPostRemove2() {
  doRemove(1);
  StringBuilder sb = new StringBuilder();
  TokenConsumer tc = new JsPrettyPrinter(sb);
  root.render(new RenderContext(tc));
  tc.noMoreTokens();
  assertEquals(
      "$0: {\n"
      + "  $5: {\n"
      + "    6;\n"
      + "    7;\n"
      + "    8;\n"
      + "  }\n"
      + "}",
      sb.toString());
}
 
开发者ID:google,项目名称:caja,代码行数:17,代码来源:ParseTreeNodeTest.java

示例8: render

import com.google.caja.reporting.RenderContext; //导入依赖的package包/类
public void render(RenderContext rc) {
  TokenConsumer out = rc.getOut();
  out.mark(getFilePosition());
  out.consume("{");
  boolean seen = false;
  for (ObjProperty prop : children()) {
    if (seen) {
      out.consume(",");
      out.consume("\n");
    } else {
      seen = true;
    }
    prop.render(rc);
  }
  out.mark(FilePosition.endOfOrNull(getFilePosition()));
  out.consume("}");
}
 
开发者ID:google,项目名称:caja,代码行数:18,代码来源:ObjectConstructor.java

示例9: render

import com.google.caja.reporting.RenderContext; //导入依赖的package包/类
public void render(RenderContext rc) {
  TokenConsumer out = rc.getOut();
  out.mark(getFilePosition());
  String label = getRenderedLabel();
  if (null != label) {
    out.consume(label);
    out.consume(":");
  }
  out.consume("for");
  out.consume("(");
  keyReceiver.render(rc);
  out.consume("in");
  container.render(rc);
  out.consume(")");
  body.renderBlock(rc, false);
}
 
开发者ID:google,项目名称:caja,代码行数:17,代码来源:ForEachLoop.java

示例10: renderShort

import com.google.caja.reporting.RenderContext; //导入依赖的package包/类
/**
 * Renders the short form without the "var" keyword.
 * This is used in multi declarations, such as in
 * {@code for (var a = 0, b = 1, ...)}.
 */
void renderShort(RenderContext rc) {
  TokenConsumer out = rc.getOut();
  out.mark(getFilePosition());
  if (identifier.getName() == null) {
    throw new IllegalStateException(
        "null name for declaration at " + getFilePosition());
  }
  identifier.render(rc);
  if (null != initializer) {
    out.consume("=");
    boolean isComma = Operation.is(initializer, Operator.COMMA);
    if (isComma) { out.consume("("); }
    initializer.render(rc);
    if (isComma) { out.consume(")"); }
  }
}
 
开发者ID:google,项目名称:caja,代码行数:22,代码来源:Declaration.java

示例11: render

import com.google.caja.reporting.RenderContext; //导入依赖的package包/类
@Override
public void render(RenderContext rc) {
  long n = getValue().longValue();
  // Use hex if it would be shorter.
  // The hex form requires a "0x" at the front so will be shorter at the
  // inequality:
  //   log(n) / log(10)             = 2 + log(n) / log(16)
  //   log(n) * log(16)             = 2 * log(10) * log(16) + log(n) * log(10)
  //   log(n) * (log(16) - log(10)) = 2 * log(10) * log(16)
  //   log(n) * log(1.6)            = 2 * log(10) * log(16)
  //   log(n)                       = 2 * log(10) * log(16) / log(1.6)
  //   n                            = e ** (2 * log(10) * log(16) / log(1.6))
  //   9 < n < 10
  String str;
  if ((-1L << 36) > n && n < (1L << 36)) {
    str = Long.toString(n, 16);
    if (str.charAt(0) == '-') {
      str = "-0x" + str.substring(1);
    } else {
      str = "0x" + str;
    }
  } else {
    str = Long.toString(n, 10);
  }
  rc.getOut().consume(str);
}
 
开发者ID:google,项目名称:caja,代码行数:27,代码来源:IntegerLiteral.java

示例12: render

import com.google.caja.reporting.RenderContext; //导入依赖的package包/类
public void render(RenderContext rc) {
  TokenConsumer out = rc.getOut();
  out.mark(getFilePosition());
  String label = getRenderedLabel();
  if (null != label) {
    out.consume(label);
    out.consume(":");
  }
  out.consume("for");
  out.consume("(");
  if (!(initializer instanceof Noop)) { initializer.render(rc); }
  out.consume(JsMinimalPrinter.NOOP);
  if (!(condition instanceof BooleanLiteral
        && ((BooleanLiteral) condition).getValue())) {
    condition.render(rc);
  }
  out.consume(JsMinimalPrinter.NOOP);
  if (!(increment instanceof Noop)) { increment.render(rc); }
  out.consume(")");
  getBody().renderBlock(rc, false);
}
 
开发者ID:google,项目名称:caja,代码行数:22,代码来源:ForLoop.java

示例13: render

import com.google.caja.reporting.RenderContext; //导入依赖的package包/类
public void render(RenderContext rc) {
  TokenConsumer out = rc.getOut();
  FilePosition pos = getFilePosition();
  out.mark(pos);
  out.consume("[");
  Expression last = null;
  for (Expression e : children()) {
    if (last != null) {
      out.consume(",");
    }
    last = e;
    if (!Operation.is(e, Operator.COMMA)) {
      if (!(e instanceof Elision)) {
        e.render(rc);
      }
    } else {
      out.consume("(");
      e.render(rc);
      out.consume(")");
    }
  }
  out.mark(FilePosition.endOfOrNull(pos));
  out.consume("]");
}
 
开发者ID:google,项目名称:caja,代码行数:25,代码来源:ArrayConstructor.java

示例14: render

import com.google.caja.reporting.RenderContext; //导入依赖的package包/类
private static void render(
    DocumentType docType, Node node, Namespaces ns, RenderContext rc,
    boolean renderUnsafe) {
  StringBuilder sb = new StringBuilder(1 << 18);
  if (null != docType) {
    String rendering = renderDocumentType(docType);
    if (null != rendering) {
      sb.append(rendering);
    }
  }
  new Renderer(rc, sb, rc.markupRenderMode(), ns)
      .render(node, ns, renderUnsafe);
  TokenConsumer out = rc.getOut();
  FilePosition pos = getFilePositionFor(node);
  out.mark(FilePosition.startOf(pos));
  out.consume(sb.toString());
  out.mark(FilePosition.endOf(pos));
}
 
开发者ID:google,项目名称:caja,代码行数:19,代码来源:Nodes.java

示例15: testHtmlNamesNormalized

import com.google.caja.reporting.RenderContext; //导入依赖的package包/类
public final void testHtmlNamesNormalized() throws Exception {
  Document doc = DomParser.makeDocument(null, null);
  Element el = doc.createElementNS(Namespaces.HTML_NAMESPACE_URI, "SPAN");
  el.setAttributeNS(Namespaces.HTML_NAMESPACE_URI, "TITLE", "Howdy");

  assertEquals("<span title=\"Howdy\"></span>", Nodes.render(el));

  Namespaces ns = new Namespaces(
      Namespaces.HTML_DEFAULT, "html", Namespaces.HTML_NAMESPACE_URI);
  StringBuilder sb = new StringBuilder();
  RenderContext rc = new RenderContext(new Concatenator(sb))
      .withMarkupRenderMode(MarkupRenderMode.HTML);
  Nodes.render(el, ns, rc);
  rc.getOut().noMoreTokens();
  assertEquals("<html:span title=\"Howdy\"></html:span>", sb.toString());
}
 
开发者ID:google,项目名称:caja,代码行数:17,代码来源:NodesTest.java


注:本文中的com.google.caja.reporting.RenderContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。