Package com.google.caja.parser

Examples of com.google.caja.parser.ParseTreeNode


    // Examine the property signatures and extract a list of keywords
    for (CssPropertyInfo pi : properties.values()) {
      pi.sig.acceptPreOrder(new Visitor() {
        public boolean visit(AncestorChain<?> ancestors) {
          ParseTreeNode n = ancestors.node;
          if (n instanceof CssPropertySignature.LiteralSignature) {
            String kw = ((CssPropertySignature.LiteralSignature) n).value;
            keywords.add(Name.css(kw));
          }
          return true;
        }
      }, null);
    }
    for (SymbolInfo si : symbols.values()) {
      si.sig.acceptPreOrder(new Visitor() {
        public boolean visit(AncestorChain<?> ancestors) {
          ParseTreeNode n = ancestors.node;
          if (n instanceof CssPropertySignature.LiteralSignature) {
            String kw = ((CssPropertySignature.LiteralSignature) n).value;
            keywords.add(Name.css(kw));
          }
          return true;
View Full Code Here


    for (Symbol<S> use : s.uses) { handleUse(use.id, use.useScope); }
    listener.exitScope(scopeImpl);
  }

  private void handleUse(AncestorChain<Identifier> id, ScopeTree<S> s) {
    ParseTreeNode n = id.parent.node;
    if (n instanceof Reference) {
      // Now that we're done with all the declaration in the scope, we can
      // tell whether a use corresponds to a declaration in the scope.
      String symbolName = id.node.getName();
      ScopeTree<S> defSite = definingSite(symbolName, s);
View Full Code Here

  private static String nameAssignedTo(AncestorChain<?> ac) {
    if (ac.parent == null) { return null; }
    if (ac.parent.node instanceof Declaration) {
      return ac.parent.cast(Declaration.class).node.getIdentifierName();
    } else if (Operation.is(ac.parent.node, Operator.ASSIGN)) {
      ParseTreeNode lhs = ac.parent.node.children().get(0);
      return lhs instanceof Reference ?
          ((Reference) lhs).getIdentifierName() : null;
    }
    return null;
  }
View Full Code Here

      boolean childNeedsBlock = (
          n instanceof FunctionConstructor || n instanceof TryStmt
          || n instanceof CatchStmt || n instanceof FinallyStmt
          || n instanceof SwitchCase);
      for (int i = 0; i < nChildren; ++i) {
        ParseTreeNode child = children.get(i);
        ParseTreeNode newChild = optimize(child, childNeedsBlock);
        if (child != newChild) {
          if (newChildren == null) {
            newChildren = Lists.newArrayListWithCapacity(nChildren);
          }
          newChildren.addAll(children.subList(newChildren.size(), i));
View Full Code Here

      List< ? extends Statement> stmts) {
    int nStmts = stmts.size();
    List<Statement> newStmts = null;
    int pos = 0// Position of last stmt processed onto newStmts
    for (int i = 0; i < nStmts; ++i) {
      ParseTreeNode s = stmts.get(i);
      ParseTreeNode optS = optimize(s, false);
      if (s != optS || optS instanceof Noop || optS instanceof Block) {
        if (newStmts == null) {
          newStmts = Lists.newArrayListWithCapacity(nStmts);
        }
        newStmts.addAll(stmts.subList(pos, i));
View Full Code Here

          // We create a fake conditional, and try to optimize it in isolation,
          // which would yield (return baz ? boo() : far()) for the above.
          // This feeds into the tail handling for expression runs below.
          Conditional combined = condAndImplicitElse((Conditional) last, next);
          if (combined != null) {
            ParseTreeNode optCond = optimize(combined, false);
            if (isExpressionListTerminator(optCond)) {
              stmts.subList(i - 1, i + 1).clear();
              stmts.add(i - 1, last = (Statement) optCond);
              --n;
              --i;
View Full Code Here

  private Statement optimizeSwitch(SwitchStmt ss) {
    List<ParseTreeNode> newChildren = Lists.newArrayList(ss.children());
    boolean changed = false;
    for (int i = 0, n = newChildren.size(); i < n; ++i) {
      ParseTreeNode child = newChildren.get(i);
      ParseTreeNode newChild = optimize(child, false);
      if (newChild != child) {
        changed = true;
        newChildren.set(i, newChild);
      }
    }
View Full Code Here

      List<ParseTreeNode> specimens, Map<String, ParseTreeNode> bindings) {
    QuasiNode key = getKey();
    QuasiNode value = getValue();
    Iterator<ParseTreeNode> it = specimens.iterator();
    while (it.hasNext()) {
      ParseTreeNode candidate = it.next();
      if (!(candidate instanceof ValueProperty)) { continue; }
      ValueProperty prop = (ValueProperty) candidate;
      List<ParseTreeNode> keyCandidate = Lists.<ParseTreeNode>newArrayList(
          prop.getPropertyNameNode());
      if (key.consumeSpecimens(keyCandidate, bindings)
View Full Code Here

  @Override
  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;
View Full Code Here

    super.childrenChanged();
    if (children().size() != 1) {
      throw new IllegalStateException(
          "An UncajoledModule may only have one child");
    }
    ParseTreeNode module = children().get(0);
    if (!(module instanceof Block)) {
      throw new ClassCastException("Expected block, not " + module);
    }
  }
View Full Code Here

TOP

Related Classes of com.google.caja.parser.ParseTreeNode

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.