Package com.google.caja.parser.js

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


  }

  private static Expression withTopRef(Expression e, String lhs) {
    if (e instanceof Reference) {
      return Operation.createInfix(
          Operator.MEMBER_ACCESS, new Reference(new Identifier(UNK, lhs)), e);
    } else {
      Operation op = (Operation) e;
      List<? extends Expression> operands = op.children();
      return Operation.create(
          e.getFilePosition(), op.getOperator(),
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

  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 = new Identifier(
        FilePosition.UNKNOWN, "temp" + (s.tempVariableCounter++) + "_");
    s.addStartOfScopeStatement((Statement) substV(
        "var @id;",
        "id", id));
    return id;
View Full Code Here

            continue;
          }
        }
        QuasiNode keyQuasi = build(
            keyIdent != null
            ? new Reference(new Identifier(FilePosition.UNKNOWN, keyIdent))
            : key);
        propQuasis.add(new SinglePropertyQuasi(keyQuasi, build(value)));
      } else {
        // TODO: support getters and setters in object quasis
        throw new UnsupportedOperationException(prop.getClass().getName());
View Full Code Here

        && Operation.is(parent, Operator.MEMBER_ACCESS)
        && parent.children().get(1) == ref;
  }

  private static void renameOne(MutableParseTreeNode n) {
    Identifier id = (Identifier) n.children().get(0);
    String origName = id.getName();
    ScopeInfo u = n.getAttributes().get(SCOPE);
    Scope s = (n instanceof FunctionConstructor)
        ? u.s :  u.s.thatDefines(origName);
    if (s != null) {  // Will be null for undeclared globals.
      String newName = u.withScope(s).mapping.get(origName);
      if (!newName.equals(origName)) {
        n.replaceChild(new Identifier(id.getFilePosition(), newName), id);
      }
    }
  }
View Full Code Here

    if (!needed.isEmpty()) {
      List<Operation> topAssignments = extractAssignments(
          body, newIdentSet(locals));
      List<Declaration> decls = Lists.newArrayList();
      for (Operation topAssign : topAssignments) {
        Identifier id = ((Reference) topAssign.children().get(0))
            .getIdentifier();
        decls.add(new Declaration(
            topAssign.getFilePosition(), id, topAssign.children().get(1)));
        needed.remove(id);
      }
View Full Code Here

        ParseTreeNode node = chain.node;
        if (node instanceof Declaration
            && !(node instanceof FunctionDeclaration)) {
          if (chain.parent.node instanceof CatchStmt) { return true; }
          Declaration decl = (Declaration) node;
          Identifier id = decl.getIdentifier();
          removedIdents.add(id);
          Expression init = decl.getInitializer();
          Statement replacement;
          if (init != null) {
            replacement = new ExpressionStmt(toAssignment(decl));
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());

        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());
    substitutes.add(withSuffix);
    return true;
  }
View Full Code Here

  private ParseTreeNode getInvoke(JMethod m) {
    List<ParseTreeNode> formals = new ArrayList<ParseTreeNode>();
    List<ParseTreeNode> actuals = new ArrayList<ParseTreeNode>();
    for (int i = 0; i < m.getParameters().length; i++) {
      formals.add(new FormalParam(
          new Identifier(FilePosition.UNKNOWN, makeArgName(i))));
      actuals.add(new Reference(
          new Identifier(FilePosition.UNKNOWN, makeArgName(i))));
    }
    return QuasiBuilder.substV(""
        + "function (@formals*) { return bean.@methodRef(@actuals*); }",
        "methodRef", getMethodAccessor(m),
        "formals", new ParseTreeNodeContainer(formals),
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.