• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Token类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: parseResultType

import com.google.javascript.rhino.Token; //导入依赖的package包/类
/**
 * ResultType := <empty> | ':' void | ':' TypeExpression
 */
private Node parseResultType(JsDocToken token) {
  skipEOLs();
  if (!match(JsDocToken.COLON)) {
    return newNode(Token.EMPTY);
  }

  token = next();
  skipEOLs();
  if (match(JsDocToken.STRING) && "void".equals(stream.getString())) {
    next();
    return newNode(Token.VOID);
  } else {
    return parseTypeExpression(next());
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:19,代码来源:JsDocInfoParser.java


示例17: maybeCollectMember

import com.google.javascript.rhino.Token; //导入依赖的package包/类
private void maybeCollectMember(NodeTraversal t,
    Node member, Node nodeWithJsDocInfo) {
  JSDocInfo info = nodeWithJsDocInfo.getJSDocInfo();

  // Do nothing if there is no JSDoc type info, or
  // if the node is not a member expression, or
  // if the member expression is not of the form: this.someProperty.
  if (info == null ||
      member.getType() != Token.GETPROP ||
      member.getFirstChild().getType() != Token.THIS) {
    return;
  }

  member.getFirstChild().setJSType(thisType);
  JSType jsType = getDeclaredTypeInAnnotation(t, member, info);
  Node name = member.getLastChild();
  if (jsType != null &&
      (name.getType() == Token.NAME || name.getType() == Token.STRING)) {
    thisType.defineDeclaredProperty(
        name.getString(),
        jsType,
        false /* functions with implementations are not in externs */);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:TypedScopeCreator.java


示例18: isControlStructure

import com.google.javascript.rhino.Token; //导入依赖的package包/类
/**
 * Determines whether the given node is a FOR, DO, WHILE, WITH, or IF node.
 */
static boolean isControlStructure(Node n) {
  switch (n.getType()) {
    case Token.FOR:
    case Token.DO:
    case Token.WHILE:
    case Token.WITH:
    case Token.IF:
    case Token.LABEL:
    case Token.TRY:
    case Token.CATCH:
    case Token.SWITCH:
    case Token.CASE:
    case Token.DEFAULT:
      return true;
    default:
      return false;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:22,代码来源:NodeUtil.java


示例19: testTypeCheckStandaloneAST

import com.google.javascript.rhino.Token; //导入依赖的package包/类
public void testTypeCheckStandaloneAST() throws Exception {
  Node n = compiler.parseTestCode("function Foo() { }");
  typeCheck(n);
  TypedScopeCreator scopeCreator = new TypedScopeCreator(compiler);
  Scope topScope = scopeCreator.createScope(n, null);

  Node second = compiler.parseTestCode("new Foo");

  Node externs = new Node(Token.BLOCK);
  Node externAndJsRoot = new Node(Token.BLOCK, externs, second);
  externAndJsRoot.setIsSyntheticBlock(true);

  new TypeCheck(
      compiler,
      new SemanticReverseAbstractInterpreter(
          compiler.getCodingConvention(), registry),
      registry, topScope, scopeCreator, CheckLevel.WARNING, CheckLevel.OFF)
      .process(null, second);

  assertEquals(1, compiler.getWarningCount());
  assertEquals("cannot instantiate non-constructor",
      compiler.getWarnings()[0].description);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:24,代码来源:TypeCheckTest.java


示例20: splitVarDeclarations

import com.google.javascript.rhino.Token; //导入依赖的package包/类
/**
 * Split a var node such as:
 *   var a, b;
 * into individual statements:
 *   var a;
 *   var b;
 * @param n The whose children we should inspect.
 */
private void splitVarDeclarations(Node n) {
  for (Node next, c = n.getFirstChild(); c != null; c = next) {
    next = c.getNext();
    if (c.getType() == Token.VAR) {
      if (assertOnChange && !c.hasChildren()) {
        throw new IllegalStateException("Empty VAR node.");
      }

      while (c.getFirstChild() != c.getLastChild()) {
        Node name = c.getFirstChild();
        c.removeChild(name);
        Node newVar = new Node(
            Token.VAR, name, n.getLineno(), n.getCharno());
        n.addChildBefore(newVar, c);
        reportCodeChange("VAR with multiple children");
      }
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:28,代码来源:Normalize.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SoundbankResource类代码示例发布时间:2022-05-21
下一篇:
Java Trash类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap