Package com.google.caja.parser.js

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


                + ")"));
  }

  private Reference getGetJsoAccessor() {
    return new Reference(
        new Identifier(
            FilePosition.UNKNOWN,
            "@" + TAMING_INTERFACE + "::"
                + "getJso"
                + "("
                + context.getTypeOracle().findType(FRAME_CLASS)
View Full Code Here


  }

  private Reference getGetBeanAccessor() {
    return new Reference(
        new Identifier(
            FilePosition.UNKNOWN,
            "@" + TAMING_INTERFACE + "::"
                + "getBean"
                + "("
                + context.getTypeOracle().findType(FRAME_CLASS)
View Full Code Here

              ""
              + "var @handlerName = ___./*@synthetic*/markFuncFreeze("
              + "    /*@synthetic*/function ("
              + "        event, " + ReservedNames.THIS_NODE + ") { @body*; });",
              "handlerName", SyntheticNodes.s(
                  new Identifier(FilePosition.UNKNOWN, handlerFnName)),
              "body", new ParseTreeNodeContainer(b.children()));
          handlers.add(new EventHandler(attr.env, handler));
          handlerCache.put(value, handlerFnName);
        }

        FunctionConstructor eventAdapter
            = (FunctionConstructor) QuasiBuilder.substV(
            ""
            + "(/*@synthetic*/ function (event) {"
            + "  return /*@synthetic*/ (___.plugin_dispatchEvent___("
            + "      /*@synthetic*/this, event, "
            + "      ___./*@synthetic*/getId(IMPORTS___), @tail));"
            + "})",
            "tail", new Reference(SyntheticNodes.s(
                new Identifier(pos, handlerFnName))));
        eventAdapter.setFilePosition(pos);
        eventAdapter.getAttributes().set(HANDLER_NAME, handlerFnName);
        dynamicValue = eventAdapter;
        break;
      case STYLE:
        CssTree.DeclarationGroup decls = styleFromAttrib(attr);
        if (decls == null || decls.children().isEmpty()) {
          return noResult(attr);
        }

        // The validator will check that property values are well-formed,
        // marking those that aren't, and identifies all URLs.
        CssValidator v = new CssValidator(cssSchema, htmlSchema, mq)
            .withInvalidNodeMessageLevel(MessageLevel.WARNING);
        v.validateCss(AncestorChain.instance(decls));
        // The rewriter will remove any unsafe constructs.
        // and put URLs in the proper filename namespace
        new CssRewriter(meta.getUriPolicy(), cssSchema, htmlSchema, mq)
            .withInvalidNodeMessageLevel(MessageLevel.WARNING)
            .rewrite(AncestorChain.instance(decls));
        new CssDynamicExpressionRewriter(meta).rewriteCss(decls);
        ArrayConstructor jsValue = CssDynamicExpressionRewriter.cssToJs(decls);

        if (jsValue.children().size() == 0) {
          // No declarations remain after sanitizing
          return noResult(attr);
        } else if (jsValue.children().size() == 1) {
          // Declarations have been reduced to a single, statically known
          // StringLiteral or dynamically computed Expression
          dynamicValue = jsValue.children().get(0);
        } else {
          throw new SomethingWidgyHappenedError(
              "Rewriter thinks STYLE attribute should contain plugin ID");
        }
        break;
      case URI:
        if (attributeContent.containsKey(attr.src)) {  // A javascript: URI
          Block b = this.jsFromAttrib(attr);
          if (b == null || b.children().isEmpty()) { return noResult(attr); }

          String handlerIndexName = meta.generateUniqueName("c");
          Identifier handlerIndex = SyntheticNodes.s(new Identifier(
              FilePosition.UNKNOWN, handlerIndexName));
          Statement handler = (Statement) QuasiBuilder.substV(
              ""
              + "var @handlerIndex = IMPORTS___.handlers___.push("
              + "    ___./*@synthetic*/markFuncFreeze("
 
View Full Code Here

            // Do not recurse into closures.
            if (node instanceof FunctionConstructor) { return false; }
            if (node instanceof Reference) {
              Reference r = (Reference) node;
              if (Keyword.THIS.toString().equals(r.getIdentifierName())) {
                Identifier oldRef = r.getIdentifier();
                Identifier thisNode = new Identifier(
                    oldRef.getFilePosition(), ReservedNames.THIS_NODE);
                r.replaceChild(SyntheticNodes.s(thisNode), oldRef);
              }
              return false;
            }
View Full Code Here

    if (dynamicValue instanceof FunctionConstructor) {
      emitStatement(
          quasiStmt(
              "el___.@name = @eventAdapter;",
              "name", new Reference(
                  SyntheticNodes.s(new Identifier(pos, name))),
              "eventAdapter", dynamicValue),
          source);
    } else {
      emitStatement(
          quasiStmt(
View Full Code Here

      values.add(new IntegerLiteral(unk, valueMaker.apply(e)));
    }
    return new ExpressionStmt(unk,
        (Expression) QuasiBuilder.substV(
            "html4.@i = { @k*: @v* };",
            "i", new Reference(new Identifier(unk, key)),
            "k", new ParseTreeNodeContainer(keys),
            "v", new ParseTreeNodeContainer(values)));
  }
View Full Code Here

    if (scope.hasFreeArguments()) {
      stmts.add(QuasiBuilder.substV(
          "___.deodorize(@ga, -6);" +
          "var @la = ___.args(@ga);",
          "la", s(new Identifier(
              FilePosition.UNKNOWN, ReservedNames.LOCAL_ARGUMENTS)),
          "ga", Rule.newReference(FilePosition.UNKNOWN,
                                  ReservedNames.ARGUMENTS)));
    }
    if (scope.hasFreeThis()) {
View Full Code Here

    root.visitPreOrder(new ParseTreeNodeVisitor() {
      public boolean visit(ParseTreeNode node) {
        if (clazz.isAssignableFrom(node.getClass()) &&
            node.children().size() > 0 &&
            node.children().get(0) instanceof Identifier) {
          Identifier id = (Identifier)node.children().get(0);
          if ((identifierValue == null && id.getValue() == null) ||
              (identifierValue != null && identifierValue.equals(id.getValue()))) {
            assertNull(result.value);
            result.value = (T)node;
            return false;
          }
        }
View Full Code Here

  public final void testIdsWithUnderscores() throws Exception {
    String[] underscoreIds = {"x__", "x\u005f\u005f", "__", "\u005f\u005f" };
    for (String id : underscoreIds) {
      ParseTreeNode specimen = QuasiBuilder.substV(
          "{ var @idWithUnderscore = 1; }",
          "idWithUnderscore", new Identifier(FilePosition.UNKNOWN, id)
      );
      assertTrue("Valid id failed to parse: " + id,
          QuasiBuilder.match("{ var @x__ = 1; }", specimen));
    }
  }
View Full Code Here

      fillOperands(op, operandIdx + 1, operands, out);
    }
  }

  private static Identifier ident(String name) {
    return new Identifier(FilePosition.UNKNOWN, name);
  }
View Full Code Here

TOP

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

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.