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


Java Node.tokenToName方法代码示例

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


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

示例1: getStringValue

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Gets the value of a node as a String, or null if it cannot be converted.
 * When it returns a non-null String, this method effectively emulates the
 * <code>String()</code> JavaScript cast function.
 */
static String getStringValue(Node n) {
  // TODO(user): Convert constant array, object, and regex literals as well.
  switch (n.getType()) {
    case Token.NAME:
    case Token.STRING:
      return n.getString();

    case Token.NUMBER:
      double value = n.getDouble();
      long longValue = (long) value;

      // Return "1" instead of "1.0"
      if (longValue == value) {
        return Long.toString(longValue);
      } else {
        return Double.toString(n.getDouble());
      }

    case Token.FALSE:
    case Token.TRUE:
    case Token.NULL:
      return Node.tokenToName(n.getType());

    case Token.VOID:
      return "undefined";
  }
  return null;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:34,代码来源:NodeUtil.java

示例2: visitNameNode

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Sanity check that our aliases are not already defined by
 * someone else.
 */
private void visitNameNode(Node n) {
  if (isAliasDefinition(n)) {
    throw new IllegalStateException(
        "Existing alias definition for " + Node.tokenToName(n.getType()));
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:11,代码来源:AliasKeywords.java

示例3: precedence

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
static int precedence(int type) {
  switch (type) {
    case Token.COMMA:  return 0;
    case Token.ASSIGN_BITOR:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.ASSIGN_URSH:
    case Token.ASSIGN_ADD:
    case Token.ASSIGN_SUB:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
    case Token.ASSIGN: return 1;
    case Token.HOOK:   return 2;  // ?: operator
    case Token.OR:     return 3;
    case Token.AND:    return 4;
    case Token.BITOR:  return 5;
    case Token.BITXOR: return 6;
    case Token.BITAND: return 7;
    case Token.EQ:
    case Token.NE:
    case Token.SHEQ:
    case Token.SHNE:   return 8;
    case Token.LT:
    case Token.GT:
    case Token.LE:
    case Token.GE:
    case Token.INSTANCEOF:
    case Token.IN:     return 9;
    case Token.LSH:
    case Token.RSH:
    case Token.URSH:   return 10;
    case Token.SUB:
    case Token.ADD:    return 11;
    case Token.MUL:
    case Token.MOD:
    case Token.DIV:    return 12;
    case Token.INC:
    case Token.DEC:
    case Token.NEW:
    case Token.DELPROP:
    case Token.TYPEOF:
    case Token.VOID:
    case Token.NOT:
    case Token.BITNOT:
    case Token.POS:
    case Token.NEG:    return 13;

    case Token.ARRAYLIT:
    case Token.CALL:
    case Token.EMPTY:
    case Token.FALSE:
    case Token.FUNCTION:
    case Token.GETELEM:
    case Token.GETPROP:
    case Token.GET_REF:
    case Token.IF:
    case Token.LP:
    case Token.NAME:
    case Token.NULL:
    case Token.NUMBER:
    case Token.OBJECTLIT:
    case Token.REGEXP:
    case Token.RETURN:
    case Token.STRING:
    case Token.THIS:
    case Token.TRUE:
      return 15;

    default: throw new Error("Unknown precedence for " +
                             Node.tokenToName(type) +
                             " (type " + type + ")");
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:77,代码来源:NodeUtil.java

示例4: tryFoldShift

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Try to fold shift operations
 */
void tryFoldShift(NodeTraversal t, Node n, Node left, Node right,
                  Node parent) {

  if (left.getType() == Token.NUMBER &&
      right.getType() == Token.NUMBER) {

    double result;
    double lval = left.getDouble();
    double rval = right.getDouble();

    // check ranges.  We do not do anything that would clip the double to
    // a 32-bit range, since the user likely does not intend that.
    if (!(lval >= Integer.MIN_VALUE && lval <= Integer.MAX_VALUE)) {
      error(t, BITWISE_OPERAND_OUT_OF_RANGE, left);
      return;
    }

    // only the lower 5 bits are used when shifting, so don't do anything
    // if the shift amount is outside [0,32)
    if (!(rval >= 0 && rval < 32)) {
      error(t, SHIFT_AMOUNT_OUT_OF_BOUNDS, right);
      return;
    }

    // Convert the numbers to ints
    int lvalInt = (int) lval;
    if (lvalInt != lval) {
      error(t, FRACTIONAL_BITWISE_OPERAND, left);
      return;
    }

    int rvalInt = (int) rval;
    if (rvalInt != rval) {
      error(t, FRACTIONAL_BITWISE_OPERAND, right);
      return;
    }

    switch (n.getType()) {
      case Token.LSH:
        result = lvalInt << rvalInt;
        break;
      case Token.RSH:
        result = lvalInt >> rvalInt;
        break;
      case Token.URSH:
        result = lvalInt >>> rvalInt;
        break;
      default:
        throw new AssertionError("Unknown shift operator: " +
            Node.tokenToName(n.getType()));
    }
    parent.replaceChild(n, Node.newNumber(result));
    t.getCompiler().reportCodeChange();
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:59,代码来源:FoldConstants.java


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