当前位置: 首页>>代码示例>>Java>>正文


Java Token.SCRIPT属性代码示例

本文整理汇总了Java中com.google.javascript.rhino.Token.SCRIPT属性的典型用法代码示例。如果您正苦于以下问题:Java Token.SCRIPT属性的具体用法?Java Token.SCRIPT怎么用?Java Token.SCRIPT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在com.google.javascript.rhino.Token的用法示例。


在下文中一共展示了Token.SCRIPT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: add

@Override
void add(Node n, Context context) {
  Node parent = n.getParent();
  if (parent.getType() == Token.BLOCK || parent.getType() == Token.SCRIPT) {
    if (n.getType() == Token.FUNCTION) {
      add(getFunctionAnnotation(n));
    } else if (n.getType() == Token.EXPR_RESULT
        && n.getFirstChild().getType() == Token.ASSIGN) {
      Node rhs = n.getFirstChild().getFirstChild();
      add(getTypeAnnotation(rhs));
    } else if (n.getType() == Token.VAR
        && n.getFirstChild().getFirstChild() != null
        && n.getFirstChild().getFirstChild().getType() == Token.FUNCTION) {
      add(getFunctionAnnotation(n.getFirstChild().getFirstChild()));
    }
  }

  super.add(n, context);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:19,代码来源:TypedCodeGenerator.java

示例2: getAddingRoot

/**
 * Gets a Node at the top of the current scope where we can add new var
 * declarations as children.
 */
private static Node getAddingRoot(Node n) {
  Node addingRoot = null;
  Node ancestor = n;
  while (null != (ancestor = ancestor.getParent())) {
    int type = ancestor.getType();
    if (type == Token.SCRIPT) {
      addingRoot = ancestor;
      break;
    } else if (type == Token.FUNCTION) {
      addingRoot = ancestor.getLastChild();
      break;
    }
  }

  // make sure that the adding root looks ok
  Preconditions.checkState(addingRoot.getType() == Token.BLOCK ||
      addingRoot.getType() == Token.SCRIPT);
  Preconditions.checkState(addingRoot.getFirstChild() == null ||
      addingRoot.getFirstChild().getType() != Token.SCRIPT);
  return addingRoot;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:NodeUtil.java

示例3: visit

@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  if (parent == null ||
      parent.getType() != Token.SCRIPT) {
    return;
  }

  if (NodeUtil.isFunctionDeclaration(n)) {
    parent.removeChild(n);
    compiler.reportCodeChange();

    JSModule module = t.getModule();
    List<Node> moduleFunctions = functions.get(module);
    if (moduleFunctions == null) {
      moduleFunctions = Lists.newArrayList();
      functions.put(module, moduleFunctions);
    }
    moduleFunctions.add(n);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:20,代码来源:MoveFunctionDeclarations.java

示例4: computeLiveness

private static LiveVariablesAnalysis computeLiveness(String src) {
  Compiler compiler = new Compiler();
  src = "function _FUNCTION(param1, param2){" + src + "}";
  Node n = compiler.parseTestCode(src).removeFirstChild();
  Node script = new Node(Token.SCRIPT, n);
  assertEquals(0, compiler.getErrorCount());
  Scope scope = new SyntacticScopeCreator(compiler).createScope(
      n, new Scope(script, compiler));
  ControlFlowAnalysis cfa = new ControlFlowAnalysis(compiler, false);
  cfa.process(null, n);
  ControlFlowGraph<Node> cfg = cfa.getCfg();
  LiveVariablesAnalysis analysis =
      new LiveVariablesAnalysis(cfg, scope, compiler);
  analysis.analyze();
  return analysis;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:16,代码来源:LiveVariableAnalysisTest.java

示例5: visit

@Override
public void visit(NodeTraversal t, Node n, Node parent) {

  if (n.getType() != Token.SCRIPT && n.getType() != Token.BLOCK) {
    return;
  }

  if (prototypeAlias == null) {
    // Always in global scope
    prototypeAlias =
      new VariableNameGenerator(t.getScope()).getNameNewName();
  }

  for (Node cur = n.getFirstChild(); cur != null; cur = cur.getNext()) {
    PrototypeMemberDeclaration prototypeMember =
        PrototypeMemberDeclaration.extractDeclaration(cur);
    if (prototypeMember == null) {
      continue;
    }

    // Found a good site here. The constructor will computes the chain of
    // declarations that is qualified for extraction.
    ExtractionInstance instance =
        new ExtractionInstance(prototypeMember, n);
    cur = instance.declarations.getLast().node;

    // Only add it to our work list if the extraction at this instance
    // makes the code smaller.
    if (instance.isFavorable()) {
      instances.add(instance);
      totalDelta += instance.delta;
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:34,代码来源:ExtractPrototypeMemberDeclarations.java

示例6: traverseBranch

/**
 * Traverses a branch.
 */
@SuppressWarnings("fallthrough")
private void traverseBranch(Node n, Node parent) {
  int type = n.getType();
  if (type == Token.SCRIPT) {
    sourceName = getSourceName(n);
  }

  curNode = n;
  if (!callback.shouldTraverse(this, n, parent)) return;

  switch (type) {
    case Token.CATCH:
      Preconditions.checkState(n.getChildCount() == 3);
      Preconditions.checkState(n.getFirstChild().getType() == Token.NAME);
      // the first child is the catch var and the third child
      // is the code block
      traverseBranch(n.getFirstChild(), n);
      traverseBranch(n.getFirstChild().getNext().getNext(), n);
      break;

    case Token.FUNCTION:
      traverseFunction(n, parent);
      break;

    default:
      for (Node child = n.getFirstChild(); child != null; ) {
        // child could be replaced, in which case our child node
        // would no longer point to the true next
        Node next = child.getNext();
        traverseBranch(child, n);
        child = next;
      }
      break;
  }

  curNode = n;
  callback.visit(this, n, parent);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:41,代码来源:NodeTraversal.java

示例7: visit

public void visit(NodeTraversal t, Node n, Node parent) {
  if (n.getType() == Token.SCRIPT) {
    requiresLineNumbers = false;
  } else if (requiresLineNumbers) {
    if (n.getLineno() == -1) {
      // The tree version of the node is really the best diagnostic
      // info we have to offer here.
      compiler.report(
          JSError.make(t, n, MISSING_LINE_INFO,
              n.toStringTree()));
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:13,代码来源:LineNumberCheck.java

示例8: isNodeAttached

private boolean isNodeAttached(Node node) {
  // Make sure the cached var is still attached.
  for (Node current = node;
       current != null; current = current.getParent()) {
    if (current.getType() == Token.SCRIPT) {
      return true;
    }
  }
  return false;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:10,代码来源:SymbolTable.java

示例9: findExpressionRoot

/**
 * @return The statement containing the expression. null if subExpression
 *     is not contain by in by a Node where inlining is known to be possible.
 *     For example, a WHILE node condition expression.
 */
static Node findExpressionRoot(Node subExpression) {
  Node child = subExpression;
  for (Node parent : child.getAncestors()) {
    int parentType = parent.getType();
    switch (parentType) {
      // Supported expression roots:
      // SWITCH and IF can have multiple children, but the CASE, DEFAULT,
      // or BLOCK will be encountered first for any of the children other
      // than the condition.
      case Token.EXPR_RESULT:
      case Token.IF:
      case Token.SWITCH:
      case Token.RETURN:
      case Token.VAR:
        Preconditions.checkState(child == parent.getFirstChild());
        return parent;
      // Any of these indicate an unsupported expression:
      case Token.SCRIPT:
      case Token.BLOCK:
      case Token.LABEL:
      case Token.CASE:
      case Token.DEFAULT:
        return null;
    }
    child = parent;
  }

  throw new IllegalStateException("Unexpected AST structure.");
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:34,代码来源:ExpressionDecomposer.java

示例10: findEnclosingConstructorDeclaration

private Node findEnclosingConstructorDeclaration(Node n) {
  while (n.getParent().getType() != Token.SCRIPT &&
      n.getParent().getType() != Token.BLOCK) {
    n = n.getParent();
  }
  return n;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:7,代码来源:RuntimeTypeCheck.java

示例11: processAstRoot

@Override
Node processAstRoot(AstRoot rootNode) {
  Node node = new ScriptOrFnNode(Token.SCRIPT);
  for (com.google.javascript.jscomp.mozilla.rhino.Node child : rootNode) {
    node.addChildToBack(transform((AstNode)child));
  }
  parseDirectives(node);
  return node;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:9,代码来源:IRFactory.java

示例12: testNewFunctionNode

public void testNewFunctionNode() {
  Node expected = parse("function foo(p1, p2, p3) { throw 2; }");
  Node body = new Node(Token.BLOCK, new Node(Token.THROW, Node.newNumber(2)));
  List<Node> params = Lists.newArrayList(Node.newString(Token.NAME, "p1"),
                                         Node.newString(Token.NAME, "p2"),
                                         Node.newString(Token.NAME, "p3"));
  FunctionNode function = NodeUtil.newFunctionNode(
      "foo", params, body, -1, -1);
  ScriptOrFnNode actual = new ScriptOrFnNode(Token.SCRIPT);
  actual.addChildToFront(function);
  String difference = expected.checkTreeEquals(actual);
  if (difference != null) {
    assertTrue("Nodes do not match:\n" + difference, false);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:15,代码来源:NodeUtilTest.java

示例13: visit

@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  if (n.getType() != Token.VAR) {
    return;
  }

  // It is only safe to collapse anonymous functions that appear
  // at top-level blocks.  In other cases the difference between
  // variable and function declarations can lead to problems or
  // expose subtle bugs in browser implementation as function
  // definitions are added to scopes before the start of execution.

  Node grandparent = parent.getParent();
  if (!(parent.getType() == Token.SCRIPT ||
        grandparent != null &&
        grandparent.getType() == Token.FUNCTION &&
        parent.getType() == Token.BLOCK)) {
    return;
  }

  // Need to store the next name in case the current name is removed from
  // the linked list.
  Preconditions.checkState(n.hasOneChild());
  Node name = n.getFirstChild();
  Node value = name.getFirstChild();
  if (value != null &&
      value.getType() == Token.FUNCTION &&
      !isRecursiveFunction(value)) {
    Node fnName = value.getFirstChild();
    fnName.setString(name.getString());
    NodeUtil.copyNameAnnotations(name, fnName);
    name.removeChild(value);
    parent.replaceChild(n, value);
    compiler.reportCodeChange();
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:36,代码来源:CollapseAnonymousFunctions.java

示例14: isStatementBlock

/**
 * @return Whether the node is of a type that contain other statements.
 */
static boolean isStatementBlock(Node n) {
  return n.getType() == Token.SCRIPT || n.getType() == Token.BLOCK;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:6,代码来源:NodeUtil.java

示例15: isHoistedFunctionDeclaration

/**
 * Is this node a hoisted function declaration? A function declaration in the
 * scope root is hoisted to the top of the scope.
 * See {@link #isFunctionDeclaration}).
 */
static boolean isHoistedFunctionDeclaration(Node n) {
  return NodeUtil.isFunctionDeclaration(n)
      && (n.getParent().getType() == Token.SCRIPT
          || n.getParent().getParent().getType() == Token.FUNCTION);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:10,代码来源:NodeUtil.java


注:本文中的com.google.javascript.rhino.Token.SCRIPT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。