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


Java Token.FUNCTION属性代码示例

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


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

示例1: updateAssignAllowedStack

/**
 * Determines whether assignment to a define should be allowed
 * in the subtree of the given node, and if not, records that fact.
 *
 * @param n The node whose subtree we're about to enter or exit.
 * @param entering True if we're entering the subtree, false otherwise.
 */
private void updateAssignAllowedStack(Node n, boolean entering) {
  switch (n.getType()) {
    case Token.CASE:
    case Token.FOR:
    case Token.FUNCTION:
    case Token.HOOK:
    case Token.IF:
    case Token.SWITCH:
    case Token.WHILE:
      if (entering) {
        assignAllowed.push(0);
      } else {
        assignAllowed.remove();
      }
      break;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:24,代码来源:ProcessDefines.java

示例2: definitionTypeContainsFunctionType

/**
 * Determines if the type of the value of the rhs expression can
 * be a function node.
 */
private static boolean definitionTypeContainsFunctionType(Definition def) {
  Node rhs = def.getRValue();
  if (rhs == null) {
    return true;
  }

  switch (rhs.getType()) {
    case Token.ASSIGN:
    case Token.AND:
    case Token.CALL:
    case Token.GETPROP:
    case Token.GETELEM:
    case Token.FUNCTION:
    case Token.HOOK:
    case Token.NAME:
    case Token.NEW:
    case Token.OR:
      return true;
    default:
      return false;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:26,代码来源:MarkNoSideEffectCalls.java

示例3: findAnonymousFunctionExpressions

/**
 * Find anonymous functions that are called directly in the form of
 *   (function(a,b,...){...})(a,b,...)
 * or
 *   (function(a,b,...){...}).call(this,a,b, ...)
 */
public void findAnonymousFunctionExpressions(NodeTraversal t, Node n) {
  switch (n.getType()) {
    // Anonymous functions in the form of:
    //   (function(){})();
    case Token.CALL:
      Node fnNode = null;
      if (n.getFirstChild().getType() == Token.FUNCTION) {
        fnNode = n.getFirstChild();
      } else if (NodeUtil.isFunctionObjectCall(n)) {
        Node fnIdentifingNode = n.getFirstChild().getFirstChild();
        if (fnIdentifingNode.getType() == Token.FUNCTION) {
          fnNode = fnIdentifingNode;
        }
      }

      // If a interesting function was discovered, add it.
      if (fnNode != null) {
        Function fn = new AnonymousFunction(fnNode, callsSeen++);
        maybeAddFunction(fn, t.getModule());
        anonFns.put(fnNode, fn.getName());
      }
      break;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:30,代码来源:InlineFunctions.java

示例4: getFunctionValue

/**
 * If the given value is a qualified name which refers
 * a function, the function's node is returned. Otherwise,
 * {@code null} is returned.
 */
protected Node getFunctionValue(Node value) {
  String qualifiedName = value.getQualifiedName();

  if (qualifiedName == null) {
    return null;
  }

  if (!definitionMap.containsKey(qualifiedName)) {
    return null;
  }

  Node definitionParent = definitionMap.get(qualifiedName);
  Node definition = definitionParent.getLastChild();

  if (definition.getType() != Token.FUNCTION) {
    return null;
  }

  return definition;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:ExternExportsPass.java

示例5: createType

/** Returns a concrete type from the JSType of the given variable. */
private ConcreteType createType(Node name, ConcreteScope scope) {
  Preconditions.checkNotNull(name);
  Preconditions.checkArgument(name.getType() == Token.NAME);

  if (name.getJSType() == null) {
    return ConcreteType.ALL;
  }

  if ((name.getFirstChild() != null)
      && (name.getFirstChild().getType() == Token.FUNCTION)) {
    return createConcreteFunction(name.getFirstChild(), scope);
  }

  return createType(name.getJSType());
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:16,代码来源:TightenTypes.java

示例6: visit

@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  if (parent == null) {
    return;
  }
  if (n.getType() == Token.FUNCTION || n.getType() == Token.SCRIPT) {
    return;
  }
  // Removes TRYs that had its CATCH removed and/or empty FINALLY.
  if (n.getType() == Token.TRY) {
    Node body = n.getFirstChild();
    Node catchOrFinallyBlock = body.getNext();
    Node finallyBlock = catchOrFinallyBlock.getNext();

    if (!catchOrFinallyBlock.hasChildren() &&
        (finallyBlock == null || !finallyBlock.hasChildren())) {
      n.removeChild(body);
      parent.replaceChild(n, body);
      compiler.reportCodeChange();
      n = body;
    }
  }
  GraphNode<Node, Branch> gNode = curCfg.getNode(n);
  if (gNode == null) { // Not in CFG.
    return;
  }
  if (gNode.getAnnotation() != GraphReachability.REACHABLE ||
      (removeNoOpStatements && !NodeUtil.mayHaveSideEffects(n))) {
    removeDeadExprStatementSafely(n, parent);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:31,代码来源:UnreachableCodeElimination.java

示例7: visit

public void visit(NodeTraversal t, Node n, Node parent) {
  switch (n.getType()) {
    // Function calls
    case Token.CALL:
      Node child = n.getFirstChild();
      String name = null;
      // NOTE: The normalization pass insures that local names do not
      // collide with global names.
      if (child.getType() == Token.NAME) {
        name = child.getString();
      } else if (child.getType() == Token.FUNCTION) {
        name = anonFunctionMap.get(child);
      } else if (NodeUtil.isFunctionObjectCall(n)) {
        Preconditions.checkState(NodeUtil.isGet(child));
        Node fnIdentifingNode = child.getFirstChild();
        if (fnIdentifingNode.getType() == Token.NAME) {
          name = fnIdentifingNode.getString();
        } else if (fnIdentifingNode.getType() == Token.FUNCTION) {
          name = anonFunctionMap.get(fnIdentifingNode);
        }
      }

      if (name != null) {
        FunctionState fs = functionMap.get(name);
        // Only visit call-sites for functions that can be inlined.
        if (fs != null) {
          callback.visitCallSite(t, n, parent, fs);
        }
      }
      break;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:32,代码来源:InlineFunctions.java

示例8: 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

示例9: isDeclaration

/**
 * Determines if the given name is a declaration, which can be a declaration
 * of a variable, function, or argument.
 */
private static boolean isDeclaration(Node n) {
  switch (n.getParent().getType()) {
    case Token.VAR:
    case Token.FUNCTION:
    case Token.CATCH:
      return true;

    case Token.LP:
      return n.getParent().getParent().getType() == Token.FUNCTION;

    default:
      return false;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:18,代码来源:StrictModeCheck.java

示例10: isInThrowExpression

/**
 * Is the {@link Node} currently within a 'throw' expression?
 */
private static boolean isInThrowExpression(Node n) {
  // Look up the traversal stack to find a THROW node
  for (Node ancestor : n.getAncestors()) {
    switch (ancestor.getType()) {
      case Token.THROW:
        return true;
      case Token.IF:
      case Token.WHILE:
      case Token.DO:
      case Token.FOR:
      case Token.SWITCH:
      case Token.CASE:
      case Token.DEFAULT:
      case Token.BLOCK:
      case Token.SCRIPT:
      case Token.FUNCTION:
      case Token.TRY:
      case Token.CATCH:
      case Token.RETURN:
      case Token.EXPR_RESULT:
        // early exit - these nodes types can't be within a THROW
        return false;
    }
  }
  return false;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:29,代码来源:AliasStrings.java

示例11: getFuncChild

private Node getFuncChild(Node n) {
  for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
    if (c.getType() == Token.FUNCTION) {
      return c;
    }
  }
  return null;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:8,代码来源:NodeUtilTest.java

示例12: isGlobalFunctionDeclaration

/**
 * Determines whether {@code n} is the FUNCTION node in a global function
 * declaration.
 */
private boolean isGlobalFunctionDeclaration(NodeTraversal t,
    Node n, Node parent) {
  return t.inGlobalScope() &&
      (NodeUtil.isFunctionDeclaration(n) ||
       n.getType() == Token.FUNCTION && parent.getType() == Token.NAME);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:10,代码来源:AnalyzePrototypeProperties.java

示例13: shouldTraverse

@Override
public final boolean shouldTraverse(NodeTraversal nodeTraversal, Node n,
    Node parent) {
  if (n.getType() == Token.FUNCTION ||
      n.getType() == Token.SCRIPT) {
    sourceName = (String) n.getProp(Node.SOURCENAME_PROP);
  }

  // We do want to traverse the name of a named function, but we don't
  // want to traverse the arguments or body.
  return parent == null || parent.getType() != Token.FUNCTION ||
      n == parent.getFirstChild() || parent == scope.getRootNode();
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:13,代码来源:TypedScopeCreator.java

示例14: findParentOfFuncDescendant

private Node findParentOfFuncDescendant(Node n) {
  for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
    if (c.getType() == Token.FUNCTION) {
      return n;
    }
    Node result = findParentOfFuncDescendant(c);
    if (result != null) {
      return result;
    }
  }
  return null;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:12,代码来源:NodeUtilTest.java

示例15: visit

/** {@inheritDoc} */
public void visit(NodeTraversal t, Node n, Node parent) {
  switch (n.getType()) {
    case Token.GETPROP:
      Node propNode = n.getFirstChild().getNext();
      if (propNode.getType() == Token.STRING) {
        maybeMarkCandidate(propNode, t);
      }
      break;
    case Token.OBJECTLIT:
      // The children of an OBJECTLIT node are alternating key/value pairs.
      // We skip the values.
      for (Node key = n.getFirstChild(); key != null;
           key = key.getNext().getNext()) {
        // We only want keys that are strings (not numbers), and only keys
        // that were unquoted.
        if (key.getType() == Token.STRING) {
          if (!key.isQuotedString()) {
            maybeMarkCandidate(key, t);
          } else {
            // Ensure that we never rename some other property in a way
            // that could conflict with this quoted key.
            quotedNames.add(key.getString());
          }
        }
      }
      break;
    case Token.GETELEM:
      // If this is a quoted property access (e.g. x['myprop']), we need to
      // ensure that we never rename some other property in a way that
      // could conflict with this quoted name.
      Node child = n.getLastChild();
      if (child != null && child.getType() == Token.STRING) {
        quotedNames.add(child.getString());
      }
      break;
    case Token.CALL:
      // We replace a JSCompiler_renameProperty function call with a string
      // containing the renamed property.
      Node fnName = n.getFirstChild();
      if (fnName.getType() == Token.NAME &&
          RENAME_PROPERTY_FUNCTION_NAME.equals(fnName.getString())) {
        callNodeToParentMap.put(n, parent);
        countCallCandidates(t, n);
      }
      break;
    case Token.FUNCTION:
      // We eliminate any stub implementations of JSCompiler_renameProperty
      // that we encounter.
      if (NodeUtil.isFunctionDeclaration(n)) {
        String name = n.getFirstChild().getString();
        if (RENAME_PROPERTY_FUNCTION_NAME.equals(name)) {
          if (NodeUtil.isExpressionNode(parent)) {
            parent.detachFromParent();
          } else {
            parent.removeChild(n);
          }
          compiler.reportCodeChange();
        }
      } else if (parent.getType() == Token.NAME &&
                 RENAME_PROPERTY_FUNCTION_NAME.equals(parent.getString())) {
        Node varNode = parent.getParent();
        if (varNode.getType() == Token.VAR) {
          varNode.removeChild(parent);
          if (!varNode.hasChildren()) {
            varNode.detachFromParent();
          }
          compiler.reportCodeChange();
        }
      }
      break;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:73,代码来源:RenameProperties.java


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