Package com.google.caja.parser.js

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


   *   a declaration or reference.
   * @return a string literal whose unescaped content is identical to the
   *   identifier's value, and whose file position is that of node.
   */
  protected static final StringLiteral toStringLiteral(ParseTreeNode node) {
    Identifier ident;
    if (node instanceof Reference) {
      ident = ((Reference) node).getIdentifier();
    } else if (node instanceof Declaration) {
      ident = ((Declaration) node).getIdentifier();
    } else {
      ident = (Identifier) node;
    }
    return new StringLiteral(
        ident.getFilePosition(), StringLiteral.toQuotedValue(ident.getName()));
  }
View Full Code Here


      // See the array length case in testSetReadModifyWriteLocalVar.
      String keyText = ((StringLiteral) key).getUnquotedValue();
      if (ParserBase.isJavascriptIdentifier(keyText)
          && Keyword.fromString(keyText) == null) {
        Reference ident = new Reference(
            new Identifier(key.getFilePosition(), keyText));
        propertyAccess = Operation.create(
            FilePosition.span(object.getFilePosition(), key.getFilePosition()),
            Operator.MEMBER_ACCESS, object, ident);
      }
    }
View Full Code Here

  @Override
  protected boolean consumeSpecimens(
      List<ParseTreeNode> specimens, Map<String, ParseTreeNode> bindings) {
    if (specimens.size() > 0 && isCompatibleClass(specimens.get(0))) {
      Identifier specimen = (Identifier) specimens.get(0);
      String value = specimen.getName();
      if (value != null && value.endsWith(trailing)) {
        specimens.remove(0);
        Identifier shortIdentifier = new Identifier(
            specimen.getFilePosition(),
            value.substring(0, value.length() - trailing.length()));
        shortIdentifier.getAttributes().putAll(specimen.getAttributes());
        shortIdentifier.setSynthetic(specimen.isSynthetic());

        return putIfDeepEquals(
            bindings,
            getIdentifier(),
            shortIdentifier);
View Full Code Here

  @Override
  protected boolean createSubstitutes(
      List<ParseTreeNode> substitutes, Map<String, ParseTreeNode> bindings) {
    ParseTreeNode n = bindings.get(getIdentifier());
    if (n == null || !(n instanceof Identifier)) { return false; }
    Identifier withoutSuffix = (Identifier) n;
    Identifier withSuffix = new Identifier(
        withoutSuffix.getFilePosition(), n.getValue() + trailing);
    withSuffix.getAttributes().putAll(withoutSuffix.getAttributes());
    withSuffix.setSynthetic(withoutSuffix.isSynthetic());
    substitutes.add(withSuffix);
    return true;
  }
View Full Code Here

   */
  public Identifier declareStartOfScopeTempVariable() {
    Scope s = getClosestDeclarationContainer();
    // TODO(ihab.awad): Uses private access to 's' which is of same class but distinct
    // instance. Violates capability discipline; kittens unduly sacrificed. Refactor.
    Identifier id = s(new Identifier(
        FilePosition.UNKNOWN, "x" + (s.tempVariableCounter++) + "___"));
    s.addStartOfScopeStatement((Statement) substV(
        "var @id;",
        "id", id));
    return id;
View Full Code Here

              "try { @body*; } catch (/* synthetic */ @ex___) { @handler*; }"),
          substitutes="try { @body*; } catch (@ex___) { @handler*; }")
      public ParseTreeNode fire(ParseTreeNode node, Scope scope) {
        Map<String, ParseTreeNode> bindings = this.match(node);
        if (bindings != null) {
          Identifier ex = (Identifier) bindings.get("ex");
          TryStmt ts = (TryStmt) node;
          CatchStmt cs = ts.getCatchClause();
          if (isSynthetic(ex)) {
            return substV(
                "body", rw.expand(bindings.get("body"), scope),
                "ex", rw.noexpand(ex),
                "handler", rw.expand(
                    bindings.get("handler"), Scope.fromCatchStmt(scope, cs)));
          }
        }
        return NONE;
      }
    },

    new Rule() {
      @Override
      @RuleDescription(
          name="syntheticCatches2",
          synopsis="Pass through synthetic variables which are unmentionable.",
          reason="Catching unmentionable exceptions helps maintain invariants.",
          matches=(
               "try { @body*; } catch (/* synthetic */ @ex___) { @handler*; }"
               + " finally { @cleanup*; }"),
          substitutes=(
               "try { @body*; } catch (/* synthetic */ @ex___) { @handler*; }"
               + " finally { @cleanup*; }"))
      public ParseTreeNode fire(ParseTreeNode node, Scope scope) {
        Map<String, ParseTreeNode> bindings = this.match(node);
        if (bindings != null) {
          TryStmt ts = (TryStmt) node;
          CatchStmt cs = ts.getCatchClause();
          Identifier ex = (Identifier) bindings.get("ex");
          if (isSynthetic(ex)) {
            return substV(
                "body", rw.expand(bindings.get("body"), scope),
                "ex", rw.noexpand(ex),
                "handler", rw.expand(
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

    Statement poolDecls = null;
    if (!stringPool.isEmpty()) {
      poolDecls = joinDeclarations(
          poolDecls,
          new Declaration(unk, new Identifier(unk, "s"),
              new ArrayConstructor(unk, stringPool)));
    }
    if (!regexPool.isEmpty()) {
      poolDecls = joinDeclarations(
          poolDecls,
          new Declaration(unk, new Identifier(unk, "c"),
              new ArrayConstructor(unk, regexPool)));
    }

    // Given keyword sets like
    // [['red','blue','green','transparent','inherit',;none'],
    //  ['red','blue','green'],
    //  ['inherit','none','bold','bolder']]
    // recognize that ['red','blue','green'] probably occurs frequently and
    // create a partition like
    // [['red','blue','green'],['bold','bolder'],['inherit',none'],
    //  ['transparent']]
    // and then store indices into the array of partition elements with
    // CSS property names so they can be unioned as needed.
    List<Set<String>> literalSets = Lists.newArrayList();
    for (Pair<CssSchema.CssPropertyInfo, CssPropertyData> p : propData) {
      literalSets.add(p.b.literals);
    }
    Partitions.Partition<String> litPartition = Partitions.partition(
        literalSets, String.class, null);
    List<ArrayConstructor> literalSetArrs = Lists.newArrayList();
    for (int[] literalIndices : litPartition.partition) {
      List<StringLiteral> literalArr = Lists.newArrayList();
      for (int litIndex : literalIndices) {
        literalArr.add(StringLiteral.valueOf(
            unk, litPartition.universe[litIndex]));
      }
      literalSetArrs.add(new ArrayConstructor(unk, literalArr));
    }
    if (!literalSetArrs.isEmpty()) {
      poolDecls = joinDeclarations(
          poolDecls,
          new Declaration(unk, new Identifier(unk, "L"),
              new ArrayConstructor(unk, literalSetArrs)));
    }

    List<ValueProperty> cssSchemaProps = Lists.newArrayList();
    StringLiteral regexObjKey = new StringLiteral(unk, "cssExtra");
View Full Code Here

    ScopeTree<S> declScope = hoist(id, scope);
    for (ScopeTree<S> s = scope; s != declScope; s = s.outer) {
      if (s.type != ScopeType.CATCH) { continue; }
      AncestorChain<CatchStmt> cs = s.inScope.get(0).cast(CatchStmt.class);
      AncestorChain<Declaration> ex = cs.child(cs.node.getException());
      Identifier exId = ex.node.getIdentifier();
      if (symbolName.equals(exId.getName())) {
        listener.splitInitialization(
            id, declScope.scopeImpl, ex.child(exId), s.scopeImpl);
      }
    }
    ScopeTree<S> maskedScope = definingSite(symbolName, declScope);
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.