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


Java Token类代码示例

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


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

示例1: insideAssignmentToIdConstant

import com.google.javascript.rhino.Token; //导入依赖的package包/类
/**
 * Returns whether the node is the right hand side of an assignment or
 * initialization of a variable named *_ID of *_ID_.
 */
private boolean insideAssignmentToIdConstant(Node n, Node parent) {
  if (parent.getType() == Token.ASSIGN) {
    String qname = parent.getFirstChild().getQualifiedName();
    return qname != null && isIdName(qname);
  } else if (parent.getType() == Token.NAME) {
    Node grandParent = parent.getParent();
    if (grandParent != null && grandParent.getType() == Token.VAR) {
      String name = parent.getString();
      return isIdName(name);
    } else {
      return false;
    }
  } else {
    return false;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:21,代码来源:CheckMissingGetCssName.java

示例2: removeDeadExprStatementSafely

import com.google.javascript.rhino.Token; //导入依赖的package包/类
private void removeDeadExprStatementSafely(Node n, Node parent) {
  if (n.getType() == Token.EMPTY ||
      (n.getType() == Token.BLOCK && !n.hasChildren())) {
    // Not always trivial to remove, let FoldContants work its magic later.
    return;
  }
  // Removing an unreachable DO node is messy because it means we still have
  // to execute one iteration. If the DO's body has breaks in the middle, it
  // can get even more trickier and code size might actually increase.
  switch (n.getType()) {
    case Token.DO:
    case Token.TRY:
    case Token.CATCH:
    case Token.FINALLY:
      return;
  }

  NodeUtil.redeclareVarsInsideBranch(n);
  compiler.reportCodeChange();
  if (logger.isLoggable(Level.FINE)) {
    logger.fine("Removing " + n.toString());
  }
  NodeUtil.removeChild(parent, n);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:UnreachableCodeElimination.java

示例3: identifyTypeDeclarationCall

import com.google.javascript.rhino.Token; //导入依赖的package包/类
@Override
public List<String> identifyTypeDeclarationCall(Node n) {
  Node callName = n.getFirstChild();
  if ("goog.addDependency".equals(callName.getQualifiedName()) &&
      n.getChildCount() >= 3) {
    Node typeArray = callName.getNext().getNext();
    if (typeArray.getType() == Token.ARRAYLIT) {
      List<String> typeNames = Lists.newArrayList();
      for (Node name = typeArray.getFirstChild(); name != null;
           name = name.getNext()) {
        if (name.getType() == Token.STRING) {
          typeNames.add(name.getString());
        }
      }
      return typeNames;
    }
  }
  return null;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:20,代码来源:ClosureCodingConvention.java

示例4: getObjectLiteralCast

import com.google.javascript.rhino.Token; //导入依赖的package包/类
@Override
public ObjectLiteralCast getObjectLiteralCast(NodeTraversal t,
    Node callNode) {
  Preconditions.checkArgument(callNode.getType() == Token.CALL);
  Node callName = callNode.getFirstChild();
  if (!"goog.reflect.object".equals(callName.getQualifiedName()) ||
      callName.getChildCount() != 2) {
    return null;
  }

  Node typeNode = callName.getNext();
  if (!typeNode.isQualifiedName()) {
    return null;
  }

  Node objectNode = typeNode.getNext();
  if (objectNode.getType() != Token.OBJECTLIT) {
    t.getCompiler().report(JSError.make(t.getSourceName(), callNode,
                                        OBJECTLIT_EXPECTED));
    return null;
  }

  return new ObjectLiteralCast(typeNode.getQualifiedName(),
                               typeNode.getNext());
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:26,代码来源:ClosureCodingConvention.java

示例5: findAnonymousFunctionExpressions

import com.google.javascript.rhino.Token; //导入依赖的package包/类
/**
 * 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,代码行数:31,代码来源:InlineFunctions.java

示例6: visit

import com.google.javascript.rhino.Token; //导入依赖的package包/类
/** {@inheritDoc} */
public void visit(NodeTraversal t, Node n, Node parent) {
  switch (n.getType()) {
    case Token.GETELEM:
      Node left = n.getFirstChild();
      Node right = left.getNext();
      if (right.getType() == Token.STRING &&
          NodeUtil.isValidPropertyName(right.getString())) {
        n.removeChild(left);
        n.removeChild(right);
        parent.replaceChild(n, new Node(Token.GETPROP, left, right));
        compiler.reportCodeChange();
      }
      break;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:17,代码来源:ConvertToDottedProperties.java

示例7: declarationSnippet

import com.google.javascript.rhino.Token; //导入依赖的package包/类
static String declarationSnippet(Token token) {
    switch (token) {
    case TRUE:
    case FALSE:
        return "Boolean";
    case STRING:
    case STRING_TYPE:
    case STRING_KEY:
        return "String";
    case NUMBER:
        return "Number";
    case ARRAYLIT:
    case ARRAY_PATTERN:
    case ARRAY_TYPE:
        return "Array";
    case OBJECTLIT:
    case OBJECT_PATTERN:
        return "Object";
    default:
        break;
    }
    return null;
}
 
开发者ID:Zir0-93,项目名称:clarpse,代码行数:24,代码来源:JavaScriptListener.java

示例8: normalizeNodeTypes

import com.google.javascript.rhino.Token; //导入依赖的package包/类
/**
 * Covert EXPR_VOID to EXPR_RESULT to simplify the rest of the code.
 */
private void normalizeNodeTypes(Node n) {
  if (n.getType() == Token.EXPR_VOID) {
    n.setType(Token.EXPR_RESULT);
    reportChange();
  }

  // Remove unused properties to minimize differences between ASTs
  // produced by the two parsers.
  if (n.getType() == Token.FUNCTION) {
    Preconditions.checkState(n.getProp(Node.FUNCTION_PROP) == null);
  }

  normalizeBlocks(n);

  for (Node child = n.getFirstChild();
       child != null; child = child.getNext()) {
    // This pass is run during the CompilerTestCase validation, so this
    // parent pointer check serves as a more general check.
    Preconditions.checkState(child.getParent() == n);

    normalizeNodeTypes(child);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:27,代码来源:PrepareAst.java

示例9: updateTypeOfParametersOnClosure

import com.google.javascript.rhino.Token; //导入依赖的package包/类
/**
 * For functions with function parameters, type inference will set the type of
 * a function literal argument from the function parameter type.
 */
private void updateTypeOfParametersOnClosure(Node n, FunctionType fnType) {
  int i = 0;
  for (Node iParameter : fnType.getParameters()) {
    JSType iParameterType = iParameter.getJSType();
    if (iParameterType instanceof FunctionType) {
      FunctionType iParameterFnType = (FunctionType) iParameterType;

      if (i + 1 >= n.getChildCount()) {
        // TypeCheck#visitParametersList will warn so we bail.
        return;
      }
      Node iArgument = n.getChildAtIndex(i + 1);
      JSType iArgumentType = getJSType(iArgument);
      if (iArgument.getType() == Token.FUNCTION &&
          iArgumentType instanceof FunctionType &&
          iArgumentType.getJSDocInfo() == null) {
        iArgument.setJSType(iParameterFnType);
      }
    }
    i++;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:27,代码来源:TypeInference.java

示例10: visit

import com.google.javascript.rhino.Token; //导入依赖的package包/类
/** {@inheritDoc} */
public void visit(NodeTraversal t, Node n, Node parent) {
  switch (n.getType()) {
    case Token.GETPROP:
      Node dest = n.getFirstChild().getNext();
      externedNames.add(dest.getString());
      break;
    case Token.OBJECTLIT:
      for (Node child = n.getFirstChild();
           child != null;
           child = child.getNext().getNext()) {
        if (child.getType() == Token.STRING) {
          externedNames.add(child.getString());
        }
      }
      break;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:19,代码来源:AmbiguateProperties.java

示例11: testSimpleSwitch

import com.google.javascript.rhino.Token; //导入依赖的package包/类
public void testSimpleSwitch() {
  String src = "var x; switch(x){ case(1): x(); case('x'): x(); break" +
      "; default: x();}";
  ControlFlowGraph<Node> cfg = createCfg(src);
  assertCrossEdge(cfg, Token.VAR, Token.SWITCH, Branch.UNCOND);
  assertNoEdge(cfg, Token.SWITCH, Token.NAME);
  // Transfer between cases and default.
  assertDownEdge(cfg, Token.SWITCH, Token.CASE, Branch.UNCOND);
  assertCrossEdge(cfg, Token.CASE, Token.CASE, Branch.ON_FALSE);
  assertCrossEdge(cfg, Token.CASE, Token.DEFAULT, Branch.ON_FALSE);
  // Within each case.
  assertDownEdge(cfg, Token.CASE, Token.BLOCK, Branch.ON_TRUE);
  assertDownEdge(cfg, Token.BLOCK, Token.EXPR_RESULT, Branch.UNCOND);
  assertNoEdge(cfg, Token.EXPR_RESULT, Token.CALL);
  assertNoEdge(cfg, Token.CALL, Token.NAME);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:17,代码来源:ControlFlowAnalysisTest.java

示例12: nodeTypeMayHaveSideEffects

import com.google.javascript.rhino.Token; //导入依赖的package包/类
/**
 * Returns true if the current node's type implies side effects.
 *
 * This is a non-recursive version of the may have side effects
 * check; used to check wherever the current node's type is one of
 * the reason's why a subtree has side effects.
 */
static boolean nodeTypeMayHaveSideEffects(Node n) {
  if (NodeUtil.isAssignmentOp(n)) {
    return true;
  }

  switch(n.getType()) {
    case Token.CALL:
    case Token.DELPROP:
    case Token.NEW:
    case Token.DEC:
    case Token.INC:
    case Token.THROW:
      return true;
    case Token.NAME:
      // A variable definition.
      return n.hasChildren();
    default:
      return false;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:28,代码来源:NodeUtil.java

示例13: getFunctionJsDocInfo

import com.google.javascript.rhino.Token; //导入依赖的package包/类
/**
 * Gets a function's JSDoc information, if it has any. Checks for a few
 * patterns (ellipses show where JSDoc would be):
 * <pre>
 * ... function() {}
 * ... x = function() {};
 * var ... x = function() {};
 * ... var x = function() {};
 * </pre>
 */
private JSDocInfo getFunctionJsDocInfo(Node n) {
  JSDocInfo jsDoc = n.getJSDocInfo();
  Node parent = n.getParent();
  if (jsDoc == null) {
    int parentType = parent.getType();
    if (parentType == Token.NAME || parentType == Token.ASSIGN) {
      jsDoc = parent.getJSDocInfo();
      if (jsDoc == null && parentType == Token.NAME) {
        Node gramps = parent.getParent();
        if (gramps.getType() == Token.VAR) {
          jsDoc = gramps.getJSDocInfo();
        }
      }
    }
  }
  return jsDoc;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:28,代码来源:CheckGlobalThis.java

示例14: eliminateKeysWithStripNamesFromObjLit

import com.google.javascript.rhino.Token; //导入依赖的package包/类
/**
 * Eliminates any object literal keys in an object literal declaration that
 * have strip names.
 *
 * @param t The traversal
 * @param n An OBJLIT node
 */
void eliminateKeysWithStripNamesFromObjLit(NodeTraversal t, Node n) {
  // OBJLIT
  //   key1
  //   value1
  //   ...
  Node key = n.getFirstChild();
  while (key != null) {
    if (key.getType() == Token.STRING &&
        isStripName(key.getString())) {
      Node value = key.getNext();
      Node next = value.getNext();
      n.removeChild(key);
      n.removeChild(value);
      key = next;
      compiler.reportCodeChange();
    } else {
      key = key.getNext().getNext();
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:28,代码来源:StripCode.java

示例15: testConstantAnnotationMismatch

import com.google.javascript.rhino.Token; //导入依赖的package包/类
public void testConstantAnnotationMismatch() throws Exception {
  otherPass = new CompilerPass() {
    @Override public void process(Node externs, Node root) {
      getLastCompiler().reportCodeChange();
      Node name = Node.newString(Token.NAME, "x");
      name.putBooleanProp(Node.IS_CONSTANT_NAME, true);
      root.addChildToBack(new Node(Token.EXPR_RESULT, name));
      getLastCompiler().setNormalized();
    }
  };

  boolean exceptionCaught = false;
  try {
    test("var x;", "var x; x;");
  } catch (RuntimeException e) {
    assertTrue(e.getMessage().contains(
        "The name x is not consistently annotated as constant."));
    exceptionCaught = true;
  }
  assertTrue(exceptionCaught);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:22,代码来源:SanityCheckTest.java


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