Package com.google.caja.parser.js

Examples of com.google.caja.parser.js.ObjectConstructor


  @Override
  public void setUp() throws Exception {
    super.setUp();
    opt = new JsOptimizer(mq);
    opt.setRename(true);
    opt.setEnvJson(new ObjectConstructor(FilePosition.UNKNOWN));
  }
View Full Code Here


  public static void main(String... args) throws IOException {
    MessageQueue mq = new SimpleMessageQueue();
    MessageContext mc = new MessageContext();
    JsOptimizer opt = new JsOptimizer(mq);
    opt.setRename(true);
    opt.setEnvJson(new ObjectConstructor(FilePosition.UNKNOWN));
    try {
      for (int i = 0, n = args.length; i < n; ++i) {
        String arg = args[i];
        if ("--norename".equals(arg)) {
          opt.setRename(false);
View Full Code Here

    } catch (IOException ex) {
      mq.addMessage(
          MessageType.IO_ERROR, MessagePart.Factory.valueOf(ex.toString()));
      return;
    }
    ObjectConstructor envJson;
    try {
      Parser p = parser(cp, mq);
      Expression e = p.parseExpression(true); // TODO(mikesamuel): limit to JSON
      p.getTokenQueue().expectEmpty();
      if (!(e instanceof ObjectConstructor)) {
View Full Code Here

  protected boolean consumeSpecimens(
      List<ParseTreeNode> specimens, Map<String, ParseTreeNode> bindings) {
    if (specimens.isEmpty()) { return false; }
    ParseTreeNode specimen = specimens.get(0);
    if (!(specimen instanceof ObjectConstructor)) { return false; }
    ObjectConstructor obj = (ObjectConstructor) specimen;
    List<ParseTreeNode> parts = Lists.<ParseTreeNode>newLinkedList(
        obj.children());
    MultiPropertyQuasi hole = null;
    for (QuasiNode q : getChildren()) {
      if (q instanceof MultiPropertyQuasi) {
        hole = (MultiPropertyQuasi) q;
      } else {
View Full Code Here

    for (QuasiNode q : getChildren()) {
      if (!q.createSubstitutes(props, bindings)) { return false; }
    }
    ObjProperty[] propArr = new ObjProperty[props.size()];
    props.toArray(propArr);
    substitutes.add(new ObjectConstructor(
        FilePosition.UNKNOWN, Arrays.asList(propArr)));
    return true;
  }
View Full Code Here

      Pair<CssSchema.CssPropertyInfo, CssPropertyData> d
          = propData.get(propIndex);
      CssSchema.CssPropertyInfo prop = d.a;
      CssPropertyData data = d.b;

      ObjectConstructor dataObj = new ObjectConstructor(unk);

      String regex = data.regex;
      if (regex != null) {
        int poolIndex = regexPoolMap.get(regex)[0];
        Expression re = poolIndex < 0
            ? makeRegexp(commonSubstringMap, regex)
            : (Expression) QuasiBuilder.substV(
                "c[@i]", "i", new IntegerLiteral(unk, poolIndex));
        dataObj.appendChild(new ValueProperty(regexObjKey, re));
      }

      String dom2property = propertyNameToDom2Property(prop.name);
      ArrayConstructor altNames = null;
      for (String altDom2Property : prop.dom2properties) {
        if (altDom2Property.equals(dom2property)) { continue; }
        if (altNames == null) {
          altNames = new ArrayConstructor(
              unk, Collections.<Expression>emptyList());
        }
        altNames.appendChild(StringLiteral.valueOf(unk, altDom2Property));
      }
      if (altNames != null) {
        dataObj.appendChild(new ValueProperty(alternatesObjKey, altNames));
      }

      cssSchemaProps.add(new ValueProperty(
          unk, StringLiteral.valueOf(unk, prop.name.getCanonicalForm()),
          dataObj));

      int propBits = 0;
      for (CssPropBit b : data.properties) {
        propBits |= b.jsValue;
      }
      if (LinkStyleWhitelist.HISTORY_INSENSITIVE_STYLE_WHITELIST
          .contains(prop.name)) {
        propBits |= CssPropBit.HISTORY_INSENSITIVE.jsValue;
      } else if (LinkStyleWhitelist.PROPERTIES_ALLOWED_IN_LINK_CLASSES
                 .contains(prop.name)) {
        propBits |= CssPropBit.ALLOWED_IN_LINK.jsValue;
      }
      dataObj.appendChild(
          new ValueProperty(propbitsObjKey, new IntegerLiteral(unk, propBits)));

      List<Expression> litGroups = Lists.newArrayList();
      for (int groupIndex : litPartition.unions[propIndex]) {
        litGroups.add((Expression) QuasiBuilder.substV(
            "L[@i]", "i", new IntegerLiteral(unk, groupIndex)));
      }
      if (!litGroups.isEmpty()) {
        dataObj.appendChild(new ValueProperty(
            litgroupObjKey, new ArrayConstructor(unk, litGroups)));
      }
    }

    ObjectConstructor cssSchema = new ObjectConstructor(unk, cssSchemaProps);

    ParseTreeNode js = QuasiBuilder.substV(
        ""
        + "var cssSchema = (function () {"
        + "  @poolDecls?;"
View Full Code Here

    assertEquals(2, call.children().size());
    Expression testArray = call.children().get(1);
    // testArray is an array like
    // [{ test_name: ..., tests: [] }]
    for (Expression test : ((ArrayConstructor) testArray).children()) {
      ObjectConstructor obj = (ObjectConstructor) test;
      String name = (String)
           ((ValueProperty) obj.propertyWithName("test_name"))
           .getValueExpr().getValue();
      ValueProperty testcases = (ValueProperty) obj.propertyWithName("tests");
      // testcases is an object like
      // [{ cssText: ..., golden: ..., messages: ... }]
      for (Expression testCase
           : ((ArrayConstructor) testcases.getValueExpr()).children()) {
        ObjectConstructor testCaseObj = (ObjectConstructor) testCase;
        String cssText = null;
        String golden = null;
        ArrayConstructor messages = null;
        for (ObjProperty oprop : testCaseObj.children()) {
          ValueProperty prop = (ValueProperty) oprop;
          String pname = prop.getPropertyName();
          try {
            if ("cssText".equals(pname)) {
              cssText = ((StringLiteral) prop.getValueExpr())
                  .getUnquotedValue();
            } else if ("golden".equals(pname)) {
              golden = ((StringLiteral) prop.getValueExpr())
                  .getUnquotedValue();
            } else if ("messages".equals(pname)) {
              messages = (ArrayConstructor) prop.getValueExpr();
            } else if ("altGolden".equals(pname)) {
              // OK.
            } else {
              fail(
                  "Unrecognized testcase property " + pname + " in "
                  + render(testCase) + " at " + testCase.getFilePosition());
            }
          } catch (RuntimeException ex) {
            System.err.println(
                "Type mismatch in " + name
                + " at " + testCase.getFilePosition());
            throw ex;
          }
        }

        String normalizedGolden = "".equals(golden)
            ? "" : render(css(fromString(golden)));

        mq.getMessages().clear();
        try {
          runTest(cssText, normalizedGolden);
          if (messages != null) {
            for (Expression message : messages.children()) {
              ObjectConstructor messageObj = (ObjectConstructor) message;
              String type = ((StringLiteral)
                  ((ValueProperty) messageObj.propertyWithName("type"))
                  .getValueExpr())
                  .getUnquotedValue();
              String level = ((StringLiteral)
                  ((ValueProperty) messageObj.propertyWithName("level"))
                  .getValueExpr())
                  .getUnquotedValue();
              List<String> args = Lists.newArrayList();
              ArrayConstructor argsArray = (ArrayConstructor)
                  ((ValueProperty) messageObj.propertyWithName("args"))
                  .getValueExpr();
              for (Expression argExpr : argsArray.children()) {
                args.add(((StringLiteral) argExpr).getUnquotedValue());
              }
              consumeMessage(message.getFilePosition(), type, level, args);
View Full Code Here

  private boolean discardBoilerPlate(Jobs jobs) {
    for (JobEnvelope env : jobs.getJobsByType(ContentType.JS)) {
      Job job = env.job;
      if (job.getRoot() instanceof CajoledModule) {
        jobs.getJobs().remove(env);
        ObjectConstructor cs = ((CajoledModule) job.getRoot()).getModuleBody();
        FunctionConstructor instantiate = (FunctionConstructor)
            ((ValueProperty) cs.propertyWithName("instantiate")).getValueExpr();
        jobs.getJobs().add(
            JobEnvelope.of(Job.jsJob(instantiate.getBody(), null)));
      }
    }
    return true;
View Full Code Here

TOP

Related Classes of com.google.caja.parser.js.ObjectConstructor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.