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


Java Token.VAR属性代码示例

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


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

示例1: addAccessorPropName

/**
 * Adds a string that can be used to reference properties by array []
 * notation.
 *
 * PROP_prototype = 'prototype';
 *
 * @param propName Name of property
 * @param root Root of output tree that function can be added to
 */
private void addAccessorPropName(String propName, Node root) {
  /*
   *  Target:

    var 1
      name PROP_length
          string length
   */
  Node propValue = Node.newString(Token.STRING, propName);
  Node propNameNode =
    Node.newString(Token.NAME, getArrayNotationNameFor(propName));
  propNameNode.addChildToFront(propValue);
  Node var = new Node(Token.VAR, propNameNode);
  root.addChildToFront(var);

  compiler.reportCodeChange();
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:26,代码来源:AliasExternals.java

示例2: getInfoForNameNode

/**
 * @param nameNode A name node
 * @return The JSDocInfo for the name node
 */
static JSDocInfo getInfoForNameNode(Node nameNode) {
  JSDocInfo info = null;
  Node parent = null;
  if (nameNode != null) {
    info = nameNode.getJSDocInfo();
    parent = nameNode.getParent();
  }

  if (info == null && parent != null &&
      ((parent.getType() == Token.VAR && parent.hasOneChild()) ||
        parent.getType() == Token.FUNCTION)) {
    info = parent.getJSDocInfo();
  }
  return info;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:19,代码来源:NodeUtil.java

示例3: isConstructorOrEnumDeclaration

/**
 * Determines whether a set operation is a constructor or enumeration
 * declaration. The set operation may either be an assignment to a name,
 * a variable declaration, or an object literal key mapping.
 *
 * @param n The node that represents the name being set
 * @param parent Parent node of {@code n} (an ASSIGN, VAR, or OBJLIT node)
 * @return Whether the set operation is either a constructor or enum
 *     declaration
 */
private boolean isConstructorOrEnumDeclaration(Node n, Node parent) {
  JSDocInfo info;
  int valueNodeType;
  switch (parent.getType()) {
    case Token.ASSIGN:
      info = parent.getJSDocInfo();
      valueNodeType = n.getNext().getType();
      break;
    case Token.VAR:
      info = n.getJSDocInfo();
      if (info == null) {
        info = parent.getJSDocInfo();
      }
      Node valueNode = n.getFirstChild();
      valueNodeType = valueNode != null ? valueNode.getType() : Token.VOID;
      break;
    default:
      return false;
  }
  // Heed the annotations only if they're sensibly used.
  return info != null &&
         (info.isConstructor() && valueNodeType == Token.FUNCTION ||
          info.hasEnumParameterType() && valueNodeType == Token.OBJECTLIT);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:34,代码来源:GlobalNamespace.java

示例4: getFunctionJsDocInfo

/**
 * 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,代码行数:27,代码来源:CheckGlobalThis.java

示例5: checkNameDeprecation

/**
 * Checks the given NAME node to ensure that access restrictions are obeyed.
 */
private void checkNameDeprecation(NodeTraversal t, Node n, Node parent) {
  // Don't bother checking definitions or constructors.
  if (parent.getType() == Token.FUNCTION || parent.getType() == Token.VAR ||
      parent.getType() == Token.NEW) {
    return;
  }

  Scope.Var var = t.getScope().getVar(n.getString());
  JSDocInfo docInfo = var == null ? null : var.getJSDocInfo();

  if (docInfo != null && docInfo.isDeprecated() &&
      shouldEmitDeprecationWarning(t, n, parent)) {

    if (docInfo.getDeprecationReason() != null) {
      compiler.report(
          JSError.make(t, n, DEPRECATED_NAME_REASON, n.getString(),
                       docInfo.getDeprecationReason()));
    } else {
      compiler.report(
          JSError.make(t, n, DEPRECATED_NAME, n.getString()));
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:26,代码来源:CheckAccessControls.java

示例6: addGlobalAliasNode

/**
 * Adds an alias variable for the global:
 *
 * var GLOBAL_window = window;
 *
 * @param globalName Name of global
 * @param root Root of output tree that function can be added to
 */
private void addGlobalAliasNode(String globalName, Node root) {
  /*
   *  Target:

    var 1
      name GLOBAL_window
          name window
   */
  Node globalValue = Node.newString(Token.NAME, globalName);
  Node globalNameNode =
    Node.newString(Token.NAME, "GLOBAL_" + globalName);
  globalNameNode.addChildToFront(globalValue);
  Node var = new Node(Token.VAR, globalNameNode);
  root.addChildToFront(var);

  compiler.reportCodeChange();
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:AliasExternals.java

示例7: handleCandidateProvideDefinition

/**
 * Handles a candidate definition for a goog.provided name.
 */
private void handleCandidateProvideDefinition(
    NodeTraversal t, Node n, Node parent) {
  if (t.inGlobalScope()) {
    String name = null;
    if (n.getType() == Token.NAME && parent.getType() == Token.VAR) {
      name = n.getString();
    } else if (n.getType() == Token.ASSIGN &&
        parent.getType() == Token.EXPR_RESULT) {
      name = n.getFirstChild().getQualifiedName();
    }

    if (name != null) {
      if (parent.getBooleanProp(Node.IS_NAMESPACE)) {
        processProvideFromPreviousPass(t, name, parent);
      } else {
        ProvidedName pn = providedNames.get(name);
        if (pn != null) {
          pn.addDefinition(parent, t.getModule());
        }
      }
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:26,代码来源:ProcessClosurePrimitives.java

示例8: doExtraction

/**
 * Declares the temp variable to point to prototype objects and iterates
 * through all ExtractInstance and performs extraction there.
 */
private void doExtraction(GatherExtractionInfo info) {
  // First declare the temp variable.
  Node var = new Node(Token.VAR, Node.newString(Token.NAME, prototypeAlias));
  compiler.getNodeForCodeInsertion(null).addChildrenToFront(var);

  // Go through all extraction instances and extract each of them.
  for (ExtractionInstance instance : info.instances) {
    extractInstance(instance);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:14,代码来源:ExtractPrototypeMemberDeclarations.java

示例9: visit

public void visit(Node n) {
  if (n.getType() == Token.NAME) {
    Node parent = n.getParent();
    if (parent != null && parent.getType() == Token.VAR) {
      String name = n.getString();
      if (!vars.containsKey(name)) {
        vars.put(name, n);
      }
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:11,代码来源:NodeUtil.java

示例10: findExpressionRoot

/**
 * @return The statement containing the expression. null if subExpression
 *     is not contain by in by a Node where inlining is known to be possible.
 *     For example, a WHILE node condition expression.
 */
static Node findExpressionRoot(Node subExpression) {
  Node child = subExpression;
  for (Node parent : child.getAncestors()) {
    int parentType = parent.getType();
    switch (parentType) {
      // Supported expression roots:
      // SWITCH and IF can have multiple children, but the CASE, DEFAULT,
      // or BLOCK will be encountered first for any of the children other
      // than the condition.
      case Token.EXPR_RESULT:
      case Token.IF:
      case Token.SWITCH:
      case Token.RETURN:
      case Token.VAR:
        Preconditions.checkState(child == parent.getFirstChild());
        return parent;
      // Any of these indicate an unsupported expression:
      case Token.SCRIPT:
      case Token.BLOCK:
      case Token.LABEL:
      case Token.CASE:
      case Token.DEFAULT:
        return null;
    }
    child = parent;
  }

  throw new IllegalStateException("Unexpected AST structure.");
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:34,代码来源:ExpressionDecomposer.java

示例11: visit

@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  JSDocInfo docInfo = n.getJSDocInfo();
  if (docInfo != null && docInfo.isExport()) {
    String export = null;
    GenerateNodeContext context = null;

    switch (n.getType()) {
      case Token.FUNCTION:
        if (parent.getType() == Token.SCRIPT) {
          export = NodeUtil.getFunctionName(n, parent);
          context = new GenerateNodeContext(n, parent, n);
        }
        break;
      case Token.ASSIGN:
        Node grandparent = parent.getParent();
        if (grandparent != null && grandparent.getType() == Token.SCRIPT &&
            parent.getType() == Token.EXPR_RESULT &&
            n.getLastChild().getType() != Token.ASSIGN) {
          export = n.getFirstChild().getQualifiedName();
          context = new GenerateNodeContext(n, grandparent, parent);
        }
        break;
      case Token.VAR:
        if (parent.getType() == Token.SCRIPT) {
          if (n.getFirstChild().hasChildren() &&
              n.getFirstChild().getFirstChild().getType() != Token.ASSIGN) {
            export = n.getFirstChild().getString();
            context = new GenerateNodeContext(n, parent, n);
          }
        }
    }

    if (export != null) {
      exports.put(export, context);
    } else {
      compiler.report(JSError.make(t, n, NON_GLOBAL_ERROR));
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:40,代码来源:FindExportableNodes.java

示例12: visit

public void visit(NodeTraversal t, Node n, Node parent) {
  if (n.getType() == Token.NAME) {
    switch (parent.getType()) {
      case Token.VAR:
      case Token.FUNCTION:
      case Token.GETPROP:
      case Token.LP:
        // These are okay.
        break;
      default:
        t.report(n, NAME_REFERENCE_IN_EXTERNS_ERROR, n.getString());
        break;
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:15,代码来源:VarCheck.java

示例13: isMethodCallThatTriggersRemoval

/**
 * Gets whether a CALL node triggers statement removal, based on the name
 * of the object whose method is being called, or the name of the method.
 * Checks whether the name begins with a strip type, ends with a field name
 * that's a strip name, or belongs to the set of global class-defining
 * functions (e.g. goog.inherits).
 *
 * @param t The traversal
 * @param n A CALL node
 * @return Whether the node triggers statement removal
 */
boolean isMethodCallThatTriggersRemoval(NodeTraversal t, Node n,
                                        Node parent) {
  // CALL
  //   GETPROP (function)         <-- we're interested in this, the function
  //     GETPROP (callee object)  <-- or the object on which it is called
  //       ...
  //       STRING (field name)
  //     STRING (method name)
  //   ... (arguments)

  Node function = n.getFirstChild();
  if (function == null || function.getType() != Token.GETPROP) {
    // We are only interested in calls on object references that are
    // properties. We don't need to eliminate method calls on variables
    // that are getting removed, since that's already done by the code
    // that removes all references to those variables.
    return false;
  }

  if (parent != null && parent.getType() == Token.NAME) {
    Node gramps = parent.getParent();
    if (gramps != null && gramps.getType() == Token.VAR) {
      // The call's return value is being used to initialize a newly
      // declared variable. We should leave the call intact for now.
      // That way, when the traversal reaches the variable declaration,
      // we'll recognize that the variable and all references to it need
      // to be eliminated.
      return false;
    }
  }

  Node callee = function.getFirstChild();
  return nameEndsWithFieldNameToStrip(callee) ||
      nameEndsWithFieldNameToStrip(function) ||
      qualifiedNameBeginsWithStripType(callee) ||
      actsOnStripType(t, n);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:48,代码来源:StripCode.java

示例14: isInitializingDeclaration

/**
 * Determines whether the variable is initialized at the declaration.
 */
boolean isInitializingDeclaration() {
  // VAR is the only type of variable declaration that may not initialize
  // its variable. Catch blocks, named functions, and parameters all do.
  return isDeclaration() &&
      (parent.getType() != Token.VAR || nameNode.getFirstChild() != null);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:9,代码来源:ReferenceCollectingCallback.java

示例15: onRedeclaration

/**
 * Remove duplicate VAR declarations encountered discovered during
 * scope creation.
 */
@Override
public void onRedeclaration(
    Scope s, String name, Node n, Node parent, Node gramps,
    Node nodeWithLineNumber) {
  Preconditions.checkState(n.getType() == Token.NAME);
  if (parent.getType() == Token.VAR) {
    Preconditions.checkState(parent.hasOneChild());

    //
    // Remove the parent VAR. There are three cases that need to be handled:
    //  1) "var a = b;" which is replaced with "a = b"
    //  2) "label:var a;" which is replaced with "label:;".  Ideally, the
    //     label itself would be removed but that is not possible in the
    //     context in which "onRedeclaration" is called.
    //  3) "for (var a in b) ..." which is replaced with "for (a in b)..."
    // Cases we don't need to handle are VARs with multiple children,
    // which have already been split into separate declarations, so there
    // is no need to handle that here, and "for (var a;;);", which has
    // been moved out of the loop.
    //
    // The result of this is that in each case the parent node is replaced
    // which is generally dangerous in a traversal but is fine here with
    // the scope creator, as the next node of interest is the parent's
    // next sibling.
    //
    if (n.hasChildren()) {
      // The var is being initialize, preserve the new value.
      parent.removeChild(n);
      // Convert "var name = value" to "name = value"
      Node value = n.getFirstChild();
      n.removeChild(value);
      Node replacement = new Node(Token.ASSIGN, n, value);
      gramps.replaceChild(parent, new Node(Token.EXPR_RESULT, replacement));
    } else {
      // It is an empty reference remove it.
      if (NodeUtil.isStatementBlock(gramps)) {
        gramps.removeChild(parent);
      } else if (gramps.getType() == Token.FOR) {
        // This is the "for (var a in b)..." case.  We don't need to worry
        // about initializers in "for (var a;;)..." as those are moved out
        // as part of the other normalizations.
        parent.removeChild(n);
        gramps.replaceChild(parent, n);
      } else {
        Preconditions.checkState(gramps.getType() == Token.LABEL);
        gramps.replaceChild(parent, new Node(Token.EMPTY));
      }
    }
    reportCodeChange("Duplicate VAR declaration");
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:55,代码来源:Normalize.java


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