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


Java TokenStream类代码示例

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


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


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