Package com.google.caja.parser.js

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


  }

  private Expression getPropertyDescriptorForProperty(
      GwtBeanPropertyDescriptor pd)
      throws UnableToCompleteException {
    Expression get = (pd.readMethod == null) ?
        new Reference(new Identifier(FilePosition.UNKNOWN, UNDEFINED)) :
        (Expression) QuasiBuilder.substV(""
            + "$wnd.caja.makeDefensibleFunction___(function () {"
            + "  return @taming.getJso(frame, bean.@methodRef());"
            + "})",
            "taming", getTamingObject(pd.readMethod.getReturnType()),
            "methodRef", getMethodAccessor(pd.readMethod));
    Expression set = (pd.writeMethod == null) ?
        new Reference(new Identifier(FilePosition.UNKNOWN, UNDEFINED)) :
        (Expression) QuasiBuilder.substV(""
            + "$wnd.caja.makeDefensibleFunction___(function (arg) {"
            + "  bean.@methodRef(@taming.getBean(frame, arg));"
            + "})",
View Full Code Here


  }

  private Expression getPropertyDescriptorForField(
      JField field)
      throws UnableToCompleteException {
    Expression get =
        (Expression) QuasiBuilder.substV(""
            + "$wnd.caja.makeDefensibleFunction___(function () {"
            + "  return @taming.getJso(frame, bean.@fieldRef);"
            + "})",
            "taming", getTamingObject(field.getType()),
            "fieldRef", getFieldAccessor(field));
    Expression set = field.isFinal() ?
        new Reference(new Identifier(FilePosition.UNKNOWN, UNDEFINED)) :
        (Expression) QuasiBuilder.substV(""
            + "$wnd.caja.makeDefensibleFunction___(function (arg) {"
            + "  bean.@fieldRef = @taming.getBean(frame, arg);"
            + "})",
View Full Code Here

      this.result = result;
    }
  }

  public SanitizedAttr sanitizeStringValue(AttrValue attr) {
    Expression dynamicValue = null;
    FilePosition pos = attr.valuePos;
    String value = attr.getPlainValue();
    // There are two cases for name handling.
    // 1. For names that have local scope or names that can't be mangled,
    //    we pass them through unchanged, except we deny the '__' suffix
View Full Code Here

    // a value equal to the empty string, which Domado's rewriteTargetAttribute
    // interprets to mean that the guest code did not supply a value.
    FilePosition pos = attr.valuePos;
    boolean unspecified = null !=
        attr.src.getUserData(TemplateCompiler.ATTRIBUTE_VALUE_WAS_UNSPECIFIED);
    Expression value = unspecified
        ? new NullLiteral(pos)
        : new StringLiteral(pos, attr.src.getValue());
    return (Expression) QuasiBuilder.substV(""
        + "IMPORTS___./*@synthetic*/rewriteTargetAttribute___("
        + "    @value, @tagName, @attribName)",
View Full Code Here

  /** "foo bar baz" -> "foo-suffix___ bar-suffix___ baz-suffix___". */
  private Expression rewriteIdentifiers(FilePosition pos, String names) {
    if ("".equals(names)) { return null; }
    JsConcatenator concat = new JsConcatenator();
    rewriteIdentifiers(pos, names, concat);
    Expression result = concat.toExpression(false);
    ((AbstractExpression) result).setFilePosition(pos);
    return result;
  }
View Full Code Here

    ((AbstractExpression) result).setFilePosition(pos);
    return result;
  }
  private void rewriteIdentifiers(
      FilePosition pos, String names, JsConcatenator concat) {
    Expression idClassExpr;
    String idClass = meta.getIdClass();
    if (idClass != null) {
      idClassExpr = StringLiteral.valueOf(FilePosition.UNKNOWN, idClass);
    } else {
      idClassExpr = (Expression) QuasiBuilder.substV(
View Full Code Here

  private static boolean isCommaOperatorInForLoop(
      AncestorChain<ExpressionStmt> es) {
    if (es.parent == null || !(es.parent.node instanceof ForLoop)) {
      return false;
    }
    Expression e = es.node.getExpression();

    return isCommaOperationNotEvaluatedForValue(e);
  }
View Full Code Here

  private static boolean isCommaOperationNotEvaluatedForValue(Expression e) {
    if (!(e instanceof Operation)) { return false; }
    Operation op = (Operation) e;
    if (op.getOperator() != Operator.COMMA) { return false; }
    Expression left = op.children().get(0), right = op.children().get(1);
    return !shouldBeEvaluatedForValue(right)
        && (!shouldBeEvaluatedForValue(left)
            || isCommaOperationNotEvaluatedForValue(left));
  }
View Full Code Here

    for (Attr a : Nodes.attributesOf(el)) {
      if (!scriptsPerNode.containsKey(a)) { continue; }
      AttribKey attrKey = AttribKey.forAttribute(elKey, a);
      // Keep track of whether there is an ID so that we know whether or
      // not to remove any auto-generated ID later.
      Expression dynamicValue = (Expression) scriptsPerNode.get(a);
      if (ID.ns.uri != attrKey.ns.uri
          || !ID.localName.equals(attrKey.localName)) {
        if (dynamicValue == null
            || dynamicValue instanceof StringLiteral) {
          emitStaticAttr(a, (StringLiteral) dynamicValue, safe);
        } else {
          dynId = makeDynamicId(dynId, pos, bone.source);
          String handlerName = dynamicValue.getAttributes().get(
              HtmlAttributeRewriter.HANDLER_NAME);
          if (handlerName != null
              && handlers.containsKey(handlerName)
              && handlersUsedInModule.add(handlerName)) {
            emitHandler(handlerName);
          }
          emitDynamicAttr(a, dynamicValue, bone.source);
        }
      } else {
        // A previous HTML parsing step should have ensured that each element
        // only has one instance of each attribute.
        assert id == null;
        id = a;
      }
    }
    // Output an ID
    if (id != null) {
      Expression dynamicValue = (Expression) scriptsPerNode.get(id);
      if (dynId == null
          && (dynamicValue == null
              || dynamicValue instanceof StringLiteral)) {
        emitStaticAttr(id, (StringLiteral) dynamicValue, safe);
      } else {
View Full Code Here

      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)) {
        mq.addMessage(
            MessageType.IO_ERROR,
            MessagePart.Factory.valueOf("Invalid JSON in " + f));
View Full Code Here

TOP

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

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.