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

Java TokenStream类代码示例

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

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



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

示例1: countCallCandidates

import com.google.javascript.rhino.TokenStream; //导入依赖的package包/类
/**
 * Counts references to property names that occur in a special function
 * call.
 *
 * @param callNode The CALL node for a property
 * @param t The traversal
 */
private void countCallCandidates(NodeTraversal t, Node callNode) {
  Node firstArg = callNode.getFirstChild().getNext();
  if (firstArg.getType() != Token.STRING) {
    t.report(callNode, BAD_CALL);
    return;
  }

  for (String name : firstArg.getString().split("[.]")) {
    if (!TokenStream.isJSIdentifier(name)) {
      t.report(callNode, BAD_ARG, name);
      continue;
    }
    if (!externedNames.contains(name)) {
      countPropertyOccurrence(name, t);
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:RenameProperties.java


示例2: handleScopeVar

import com.google.javascript.rhino.TokenStream; //导入依赖的package包/类
/**
 * For the Var declared in the current scope determine if it is possible
 * to revert the name to its orginal form without conflicting with other
 * values.
 */
void handleScopeVar(Var v) {
  String name  = v.getName();
  if (containsSeparator(name)) {
    String newName = getOrginalName(name);
    // Check if the new name is valid and if it would cause conflicts.
    if (TokenStream.isJSIdentifier(newName) &&
        !referencedNames.contains(newName) && 
        !newName.equals(ARGUMENTS)) {
      referencedNames.remove(name);
      // Adding a reference to the new name to prevent either the parent
      // scopes or the current scope renaming another var to this new name.
      referencedNames.add(newName);
      List<Node> references = nameMap.get(name);
      Preconditions.checkState(references != null);
      for (Node n : references) {
        Preconditions.checkState(n.getType() == Token.NAME);
        n.setString(newName);
      }
      compiler.reportCodeChange();
    }
    nameMap.remove(name);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:29,代码来源:MakeDeclaredNamesUnique.java


示例3: countCallCandidates

import com.google.javascript.rhino.TokenStream; //导入依赖的package包/类
/**
 * Counts references to property names that occur in a special function
 * call.
 *
 * @param callNode The CALL node for a property
 * @param t The traversal
 */
private void countCallCandidates(NodeTraversal t, Node callNode) {
  Node firstArg = callNode.getFirstChild().getNext();
  if (!firstArg.isString()) {
    t.report(callNode, BAD_CALL);
    return;
  }

  for (String name : firstArg.getString().split("[.]")) {
    if (!TokenStream.isJSIdentifier(name)) {
      t.report(callNode, BAD_ARG, name);
      continue;
    }
    if (!externedNames.contains(name)) {
      countPropertyOccurrence(name);
    }
  }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:25,代码来源:RenameProperties.java


示例4: countCallCandidates

import com.google.javascript.rhino.TokenStream; //导入依赖的package包/类
/**
 * Counts references to property names that occur in a special function
 * call.
 *
 * @param callNode The CALL node for a property
 * @param t The traversal
 */
private void countCallCandidates(NodeTraversal t, Node callNode) {
  String fnName = callNode.getFirstChild().getOriginalName();
  if (fnName == null) {
    fnName = callNode.getFirstChild().getString();
  }
  Node firstArg = callNode.getSecondChild();
  if (!firstArg.isString()) {
    t.report(callNode, BAD_CALL, fnName);
    return;
  }

  for (String name : DOT_SPLITTER.split(firstArg.getString())) {
    if (!TokenStream.isJSIdentifier(name)) {
      t.report(callNode, BAD_ARG, fnName);
      continue;
    }
    if (!externedNames.contains(name)) {
      countPropertyOccurrence(name);
    }
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:29,代码来源:RenameProperties.java


示例5: maybeWarnReservedKeyword

import com.google.javascript.rhino.TokenStream; //导入依赖的package包/类
private void maybeWarnReservedKeyword(IdentifierToken token) {
  String identifier = token.value;
  boolean isIdentifier = false;
  if (TokenStream.isKeyword(identifier)) {
    features = features.with(Feature.ES3_KEYWORDS_AS_IDENTIFIERS);
    isIdentifier = config.languageMode() == LanguageMode.ECMASCRIPT3;
  }
  if (reservedKeywords != null && reservedKeywords.contains(identifier)) {
    features = features.with(Feature.KEYWORDS_AS_PROPERTIES);
    isIdentifier = config.languageMode() == LanguageMode.ECMASCRIPT3;
  }
  if (isIdentifier) {
    errorReporter.error(
        "identifier is a reserved word",
        sourceName,
        lineno(token.location.start),
        charno(token.location.start));
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:20,代码来源:IRFactory.java


示例6: isValidPropertyName

import com.google.javascript.rhino.TokenStream; //导入依赖的package包/类
/**
 * Determines whether the given name can appear on the right side of
 * the dot operator. Many properties (like reserved words) cannot.
 */
static boolean isValidPropertyName(String name) {
  return TokenStream.isJSIdentifier(name) &&
      !TokenStream.isKeyword(name) &&
      // no Unicode escaped characters - some browsers are less tolerant
      // of Unicode characters that might be valid according to the
      // language spec.
      // Note that by this point, unicode escapes have been converted
      // to UTF-16 characters, so we're only searching for character
      // values, not escapes.
      NodeUtil.isLatin(name);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:16,代码来源:NodeUtil.java


示例7: isValidPropertyName

import com.google.javascript.rhino.TokenStream; //导入依赖的package包/类
/**
 * Determines whether the given name can appear on the right side of
 * the dot operator. Many properties (like reserved words) cannot.
 */
static boolean isValidPropertyName(String name) {
  return TokenStream.isJSIdentifier(name) &&
      !TokenStream.isKeyword(name) &&
      // no Unicode escaped characters - some browsers are less tolerant
      // of Unicode characters that might be valid according to the
      // language spec.
      // Note that by this point, unicode escapes have been converted
      // to UTF-16 characters, so we're only searching for character
      // values, not escapes.
      isLatin(name);
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:16,代码来源:NodeUtil.java


示例8: isValidName

import com.google.javascript.rhino.TokenStream; //导入依赖的package包/类
/**
 * @return Whether the name is valid to use in the local scope.
 */
private boolean isValidName(String name) {
  if (TokenStream.isJSIdentifier(name) &&
      !referencedNames.contains(name) &&
      !name.equals(ARGUMENTS)) {
    return true;
  }
  return false;
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:12,代码来源:MakeDeclaredNamesUnique.java


示例9: isValidSimpleName

import com.google.javascript.rhino.TokenStream; //导入依赖的package包/类
/**
 * Determines whether the given name is a valid variable name.
 */
static boolean isValidSimpleName(String name) {
  return TokenStream.isJSIdentifier(name) &&
      !TokenStream.isKeyword(name) &&
      // no Unicode escaped characters - some browsers are less tolerant
      // of Unicode characters that might be valid according to the
      // language spec.
      // Note that by this point, Unicode escapes have been converted
      // to UTF-16 characters, so we're only searching for character
      // values, not escapes.
      isLatin(name);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:15,代码来源:NodeUtil.java


示例10: visit

import com.google.javascript.rhino.TokenStream; //导入依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  switch (n.getType()) {
    case Token.GETPROP:
    case Token.GETELEM:
      Node dest = n.getFirstChild().getNext();
      if (dest.isString()) {
        String s = dest.getString();
        if (s.equals("prototype")) {
          processPrototypeParent(parent, t.getInput());
        } else {
          markPropertyAccessCandidate(dest, t.getInput());
        }
      }
      break;
    case Token.OBJECTLIT:
      if (!prototypeObjLits.contains(n)) {
        // Object literals have their property name/value pairs as a flat
        // list as their children. We want every other node in order to get
        // only the property names.
        for (Node child = n.getFirstChild();
             child != null;
             child = child.getNext()) {

          if (TokenStream.isJSIdentifier(child.getString())) {
            markObjLitPropertyCandidate(child, t.getInput());
          }
        }
      }
      break;
  }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:33,代码来源:RenamePrototypes.java


示例11: processPrototypeParent

import com.google.javascript.rhino.TokenStream; //导入依赖的package包/类
/**
 * Processes the parent of a GETPROP prototype, which can either be
 * another GETPROP (in the case of Foo.prototype.bar), or can be
 * an assignment (in the case of Foo.prototype = ...).
 */
private void processPrototypeParent(Node n, CompilerInput input) {
  switch (n.getType()) {
    // Foo.prototype.getBar = function() { ... }
    case Token.GETPROP:
    case Token.GETELEM:
      Node dest = n.getFirstChild().getNext();
      if (dest.isString()) {
        markPrototypePropertyCandidate(dest, input);
      }
      break;

    // Foo.prototype = { "getBar" : function() { ... } }
    case Token.ASSIGN:
    case Token.CALL:
      Node map;
      if (n.isAssign()) {
        map = n.getFirstChild().getNext();
      } else {
        map = n.getLastChild();
      }
      if (map.isObjectLit()) {
        // Remember this node so that we can avoid processing it again when
        // the traversal reaches it.
        prototypeObjLits.add(map);

        for (Node key = map.getFirstChild();
             key != null; key = key.getNext()) {
          if (TokenStream.isJSIdentifier(key.getString())) {
           // May be STRING, GET, or SET
            markPrototypePropertyCandidate(key, input);
          }
        }
      }
      break;
  }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:42,代码来源:RenamePrototypes.java


示例12: checkModuleName

import com.google.javascript.rhino.TokenStream; //导入依赖的package包/类
/**
 * Validates the module name. Can be overridden by subclasses.
 * @param name The module name
 * @throws FlagUsageException if the validation fails
 */
protected void checkModuleName(String name)
    throws FlagUsageException {
  if (!TokenStream.isJSIdentifier(name)) {
    throw new FlagUsageException("Invalid module name: '" + name + "'");
  }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:12,代码来源:AbstractCommandLineRunner.java


示例13: isValidSimpleName

import com.google.javascript.rhino.TokenStream; //导入依赖的package包/类
/**
 * Determines whether the given name is a valid variable name.
 */
static boolean isValidSimpleName(String name) {
  return TokenStream.isJSIdentifier(name)
      && !TokenStream.isKeyword(name)
      // no Unicode escaped characters - some browsers are less tolerant
      // of Unicode characters that might be valid according to the
      // language spec.
      // Note that by this point, Unicode escapes have been converted
      // to UTF-16 characters, so we're only searching for character
      // values, not escapes.
      && isLatin(name);
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:15,代码来源:NodeUtil.java


示例14: isValidPropertyName

import com.google.javascript.rhino.TokenStream; //导入依赖的package包/类
/**
 * Determines whether the given name can appear on the right side of the dot operator. Many
 * properties (like reserved words) cannot, in ES3.
 */
static boolean isValidPropertyName(FeatureSet mode, String name) {
  if (isValidSimpleName(name)) {
    return true;
  } else {
    return mode.has(Feature.KEYWORDS_AS_PROPERTIES) && TokenStream.isKeyword(name);
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:12,代码来源:NodeUtil.java


示例15: checkModuleName

import com.google.javascript.rhino.TokenStream; //导入依赖的package包/类
@Override
protected void checkModuleName(String name) {
  if (!TokenStream.isJSIdentifier(
      extraModuleNameChars.matcher(name).replaceAll("_"))) {
    throw new FlagUsageException("Invalid module name: '" + name + "'");
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:8,代码来源:CommandLineRunner.java


示例16: getTempParameterName

import com.google.javascript.rhino.TokenStream; //导入依赖的package包/类
/**
 * Find or create the best name to use for a parameter we need to rewrite.
 *
 * <ol>
 * <li> Use the JS Doc function parameter name at the given index, if possible.
 * <li> Otherwise, build one of our own.
 * </ol>
 * @param function
 * @param parameterIndex
 * @return name to use for the given parameter
 */
private String getTempParameterName(Node function, int parameterIndex) {
  String tempVarName;
  JSDocInfo fnJSDoc = NodeUtil.getBestJSDocInfo(function);
  if (fnJSDoc != null && fnJSDoc.getParameterNameAt(parameterIndex) != null) {
    tempVarName = fnJSDoc.getParameterNameAt(parameterIndex);
  } else {
    tempVarName = DESTRUCTURING_TEMP_VAR + (destructuringVarCounter++);
  }
  checkState(TokenStream.isJSIdentifier(tempVarName));
  return tempVarName;
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:23,代码来源:Es6RewriteDestructuring.java


示例17: generateNextName

import com.google.javascript.rhino.TokenStream; //导入依赖的package包/类
/**
 * Generates the next short name.
 *
 * <p>This generates names of increasing length. To minimize output size,
 * therefore, it's good to call it for the most used symbols first.
 */
@Override
public String generateNextName() {
  while (true) {
    String name = prefix + generateSuffix(prefix.length(), nameCount++);

    // Make sure it's not a JS keyword or reserved name.
    if (TokenStream.isKeyword(name) || reservedNames.contains(name)) {
      continue;
    }

    return name;
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:20,代码来源:RandomNameGenerator.java


示例18: maybeWarnKeywordProperty

import com.google.javascript.rhino.TokenStream; //导入依赖的package包/类
private void maybeWarnKeywordProperty(Node node) {
  if (TokenStream.isKeyword(node.getString())) {
    features = features.with(Feature.KEYWORDS_AS_PROPERTIES);
    if (config.languageMode() == LanguageMode.ECMASCRIPT3) {
      errorReporter.warning(INVALID_ES3_PROP_NAME, sourceName,
          node.getLineno(), node.getCharno());
    }
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:10,代码来源:IRFactory.java


示例19: addStringKey

import com.google.javascript.rhino.TokenStream; //导入依赖的package包/类
void addStringKey(Node n) {
  String key = n.getString();
  // Object literal property names don't have to be quoted if they are not JavaScript keywords.
  boolean mustBeQuoted =
      n.isQuotedString()
      || (quoteKeywordProperties && TokenStream.isKeyword(key))
      || !TokenStream.isJSIdentifier(key)
      // do not encode literally any non-literal characters that were Unicode escaped.
      || !NodeUtil.isLatin(key);
  if (!mustBeQuoted) {
    // Check if the property is eligible to be printed as shorthand.
    if (n.isShorthandProperty()) {
      Node child = n.getFirstChild();
      if (child.matchesQualifiedName(key)
          || (child.isDefaultValue() && child.getFirstChild().matchesQualifiedName(key))) {
        add(child);
        return;
      }
    }
    add(key);
  } else {
    // Determine if the string is a simple number.
    double d = getSimpleNumber(key);
    if (!Double.isNaN(d)) {
      cc.addNumber(d, n);
    } else {
      addJsString(n);
    }
  }
  if (n.hasChildren()) {
    // NOTE: the only time a STRING_KEY node does *not* have children is when it's
    // inside a TypeScript enum.  We should change these to their own ENUM_KEY token
    // so that the bifurcating logic can be removed from STRING_KEY.
    add(":");
    addExpr(n.getFirstChild(), 1, Context.OTHER);
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:38,代码来源:CodeGenerator.java


示例20: getName

import com.google.javascript.rhino.TokenStream; //导入依赖的package包/类
/**
 * Returns a qualified name of the specified node. Dots and brackets
 * are changed to the delimiter passed in when constructing the
 * NodeNameExtractor object.  We also replace ".prototype" with the
 * delimiter to keep names short, while still differentiating them
 * from static properties.  (Prototype properties will end up
 * looking like "a$b$$c" if this.delimiter = '$'.)
 */
String getName(Node node) {
  switch (node.getType()) {
    case Token.FUNCTION:
      Node functionNameNode = node.getFirstChild();
      return functionNameNode.getString();
    case Token.GETPROP:
      Node lhsOfDot = node.getFirstChild();
      Node rhsOfDot = lhsOfDot.getNext();
      String lhsOfDotName = getName(lhsOfDot);
      String rhsOfDotName = getName(rhsOfDot);
      if ("prototype".equals(rhsOfDotName)) {
        return lhsOfDotName + delimiter;
      } else {
        return lhsOfDotName + delimiter + rhsOfDotName;
      }
    case Token.GETELEM:
      Node outsideBrackets = node.getFirstChild();
      Node insideBrackets = outsideBrackets.getNext();
      String nameOutsideBrackets = getName(outsideBrackets);
      String nameInsideBrackets = getName(insideBrackets);
      if ("prototype".equals(nameInsideBrackets)) {
        return nameOutsideBrackets + delimiter;
      } else {
        return nameOutsideBrackets + delimiter + nameInsideBrackets;
      }
    case Token.NAME:
      return node.getString();
    case Token.STRING:
      return TokenStream.isJSIdentifier(node.getString()) ?
          node.getString() : ("__" + nextUniqueInt++);
    case Token.NUMBER:
      return NodeUtil.getStringValue(node);
    case Token.THIS:
      return "this";
    case Token.CALL:
      return getName(node.getFirstChild());
    default:
      StringBuilder sb = new StringBuilder();
      for (Node child = node.getFirstChild(); child != null;
           child = child.getNext()) {
        if (sb.length() > 0) {
          sb.append(delimiter);
        }
        sb.append(getName(child));
      }
      return sb.toString();
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:57,代码来源:NodeNameExtractor.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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