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


Java Node.getType方法代码示例

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


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

示例1: isSafeReplacement

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Checks name referenced in node to determine if it might have
 * changed.
 * @return Whether the replacement can be made.
 */
private boolean isSafeReplacement(Node node, Node replacement) {
  // No checks are needed for simple names.
  if (node.getType() == Token.NAME) {
    return true;
  }
  Preconditions.checkArgument(node.getType() == Token.GETPROP);

  Node name = node.getFirstChild();
  if (name.getType() == Token.NAME
      && isNameAssignedTo(name.getString(), replacement)) {
    return false;
  }

  return true;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:21,代码来源:CollapseVariableDeclarations.java

示例2: computeFallThrough

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Computes the destination node of n when we want to fallthough into the
 * subtree of n. We don't always create a CFG edge into n itself because of
 * DOs and FORs.
 */
private static Node computeFallThrough(Node n) {
  switch (n.getType()) {
    case Token.DO:
      return computeFallThrough(n.getFirstChild());
    case Token.FOR:
      if (NodeUtil.isForIn(n)) {
        return n;
      }
      return computeFallThrough(n.getFirstChild());
    case Token.LABEL:
      return computeFallThrough(n.getLastChild());
    default:
      return n;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:21,代码来源:ControlFlowAnalysis.java

示例3: eliminateKeysWithStripNamesFromObjLit

import com.google.javascript.rhino.Node; //导入方法依赖的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

示例4: collectAliasCandidates

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * If any of the variables are well-defined and alias other variables,
 * mark them as aliasing candidates.
 */
private void collectAliasCandidates(NodeTraversal t,
    Map<Var, ReferenceCollection> referenceMap) {
  if (mode != Mode.CONSTANTS_ONLY) {
    for (Iterator<Var> it = t.getScope().getVars(); it.hasNext();) {
      Var v = it.next();
      ReferenceCollection referenceInfo = referenceMap.get(v);

      // NOTE(nicksantos): Don't handle variables that are never used.
      // The tests are much easier to write if you don't, and there's
      // another pass that handles unused variables much more elegantly.
      if (referenceInfo != null && referenceInfo.references.size() >= 2 &&
          referenceInfo.isWellDefined() &&
          referenceInfo.isAssignedOnce()) {
        Reference init = referenceInfo.getInitializingReference();
        Node value = init.getAssignedValue();
        if (value != null && value.getType() == Token.NAME) {
          aliasCandidates.put(value, new AliasCandidate(v, referenceInfo));
        }
      }
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:27,代码来源:InlineVariables.java

示例5: allPathsReturn

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * @returns true if all paths from block must exit with an explicit return.
 */
private boolean allPathsReturn(Node block) {
  // Computes the control flow graph.
  ControlFlowAnalysis cfa = new ControlFlowAnalysis(compiler, false);
  cfa.process(null, block);
  ControlFlowGraph<Node> cfg = cfa.getCfg();

  Node returnPathsParent = cfg.getImplicitReturn().getValue();
  for (DiGraphNode<Node, Branch> pred :
    cfg.getDirectedPredNodes(returnPathsParent)) {
    Node n = pred.getValue();
    if (n.getType() != Token.RETURN) {
      return false;
    }
  }
  return true;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:20,代码来源:InstrumentFunctions.java

示例6: mayThrowException

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Determines if the subtree might throw an exception.
 */
private static boolean mayThrowException(Node n) {
  switch (n.getType()) {
    case Token.CALL:
    case Token.GETPROP:
    case Token.GETELEM:
    case Token.THROW:
    case Token.NEW:
    case Token.ASSIGN:
    case Token.INC:
    case Token.DEC:
    case Token.INSTANCEOF:
      return true;
    case Token.FUNCTION:
      return false;
  }
  for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
    if (!ControlFlowGraph.isEnteringNewCfgNode(c) && mayThrowException(c)) {
      return true;
    }
  }
  return false;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:26,代码来源:ControlFlowAnalysis.java

示例7: findNamedFunctions

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void findNamedFunctions(NodeTraversal t, Node n, Node parent) {
  if (!NodeUtil.isStatement(n)) {
    // There aren't any interesting functions here.
    return;
  }

  switch (n.getType()) {
    // Anonymous functions in the form of:
    //   var fooFn = function(x) { return ... }
    case Token.VAR:
      // TODO(johnlenz): Make this a Preconditions check.
      //     Currently this fails for some targets.
      if (n.hasOneChild()) {
        // Only look at declarations in the global scope.
        Node nameNode = n.getFirstChild();
        if (nameNode.getType() == Token.NAME && nameNode.hasChildren()
            && nameNode.getFirstChild().getType() == Token.FUNCTION) {
          maybeAddFunction(new FunctionVar(n), t.getModule());
        }
      }
      break;

    // Named functions
    // function Foo(x) { return ... }
    case Token.FUNCTION:
      Preconditions.checkState(NodeUtil.isStatementBlock(parent)
          || parent.getType() == Token.LABEL);
      Function fn = new NamedFunction(n);
      String name = fn.getName();
      if (!name.isEmpty()) {
        maybeAddFunction(fn, t.getModule());
      }
      break;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:36,代码来源:InlineFunctions.java

示例8: visit

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Delegate the actual processing of the node to visitLabel and
 * visitBreakOrContinue.
 *
 * {@inheritDoc}
 */
public void visit(NodeTraversal nodeTraversal, Node node, Node parent) {
  switch (node.getType()) {
    case Token.LABEL:
      visitLabel(node, parent);
      break;

    case Token.BREAK:
    case Token.CONTINUE:
      visitBreakOrContinue(node);
      break;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:19,代码来源:RenameLabels.java

示例9: defineName

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Defines a variable based on the {@link Token#NAME} node passed.
 * @param name The {@link Token#NAME} node.
 * @param var The parent of the {@code name} node, which must be a
 *     {@link Token#VAR} node.
 * @param parent {@code var}'s parent.
 * @param info the {@link JSDocInfo} information relating to this
 *     {@code name} node.
 */
private void defineName(Node name, Node var, Node parent, JSDocInfo info) {
  Node value = name.getFirstChild();

  if (value != null && value.getType() == Token.FUNCTION) {
    // function
    String functionName = name.getString();
    FunctionType functionType =
        getFunctionType(functionName, value, info, null);
    defineSlot(name, var, functionType);
  } else {
    // variable's type
    JSType type = null;
    if (info == null) {
      // the variable's type will be inferred
      CompilerInput input = compiler.getInput(sourceName);
      Preconditions.checkNotNull(input, sourceName);
      type = input.isExtern() ?
          typeRegistry.getNativeType(UNKNOWN_TYPE) : null;
    } else if (info.hasEnumParameterType()) {
      type = getEnumType(name.getString(), var, value,
          info.getEnumParameterType().evaluate(scope));
    } else if (info.isConstructor()) {
      type = getFunctionType(name.getString(), value, info, name);
    } else {
      type = getDeclaredTypeInAnnotation(sourceName, name, info);
    }

    defineSlot(name, var, type);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:40,代码来源:TypedScopeCreator.java

示例10: maybeRemoveCall

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Removes a method call if {@link #isMethodCallThatTriggersRemoval}
 * indicates that it should be removed.
 *
 * @param t The traversal
 * @param n A CALL node
 * @param parent {@code n}'s parent
 */
void maybeRemoveCall(NodeTraversal t, Node n, Node parent) {
  // CALL
  //   function
  //   arguments
  if (isMethodCallThatTriggersRemoval(t, n, parent)) {
    // Use a while loop to get up out of any nested calls. For example,
    // if we have just detected that we need to remove the a.b() call
    // in a.b().c().d(), we'll have to remove all of the calls, and it
    // will take a few iterations through this loop to get up to d().
    Node ancestor = parent;
    Node ancestorChild = n;
    int ancestorLevel = 1;
    while (true) {
      if (ancestor.getFirstChild() != ancestorChild) {
        replaceWithNull(ancestorChild, ancestor);
        break;
      }
      if (NodeUtil.isExpressionNode(ancestor)) {
        // Remove the entire expression statement.
        Node ancParent = ancestor.getParent();
        replaceWithEmpty(ancestor, ancParent);
        break;
      }
      int type = ancestor.getType();
      if (type != Token.GETPROP &&
          type != Token.GETELEM &&
          type != Token.CALL) {
        replaceWithNull(ancestorChild, ancestor);
        break;
      }
      ancestorChild = ancestor;
      ancestor = ancestor.getParent();
    }
    compiler.reportCodeChange();
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:45,代码来源:StripCode.java

示例11: visit

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void visit(NodeTraversal t, Node n, Node parent) {
  if (n.getType() == Token.NAME) {
    String name = n.getString();
    Scope.Var var = t.getScope().getVar(name);

    // It's ok for var to be null since it won't be in any scope if it's
    // an extern
    if (var != null && var.isLocal()) {
      return;
    }

    Property global = globals.get(name);
    if (global != null) {
      // If a global is being assigned to or otherwise modified, then we
      // don't want to alias it.
      // Using "new" with this global is not a mutator, but it's also
      // something that we want to avoid when aliasing, since we may be
      // dealing with external objects (e.g. ActiveXObject in MSIE)
      if ((NodeUtil.isAssignmentOp(parent) &&
          parent.getFirstChild() == n) ||
          parent.getType() == Token.INC ||
          parent.getType() == Token.DEC ||
          parent.getType() == Token.NEW) {
        global.recordMutator(t);
      } else {
        global.recordAccessor(t);
      }

      globalUses.add(n);
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:33,代码来源:AliasExternals.java

示例12: isGlobalThisObject

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private boolean isGlobalThisObject(NodeTraversal t, Node n) {
  if (n.getType() == Token.THIS) {
    return t.inGlobalScope();
  } else if (n.getType() == Token.NAME && !NodeUtil.isLabelName(n)) {
    String varName = n.getString();
    if (varName.equals(GLOBAL_THIS_NAME)) {
      return true;
    }
  }
  return false;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:12,代码来源:GatherRawExports.java

示例13: visit

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void visit(NodeTraversal t, Node n, Node parent) {
  switch (n.getType()) {

    case Token.NEW:
    case Token.CALL:
      Node fn = n.getFirstChild();
      if (fn.getType() == Token.NAME) {

        String fnName = fn.getString();

        // Lookup the function
        Scope.Var v = t.getScope().getVar(fnName);

        // VarCheck should have caught this undefined function
        if (v == null) {
          return;
        }

        Node fnDef = v.getInitialValue();
        if (fnDef == null ||
            fnDef.getType() != Token.FUNCTION) {
          // It's a variable, can't check this.
          return;
        }

        FunctionInfo f = getFunctionInfo(fnDef, v.getInputName());

        checkCall(n, fnName, Collections.singletonList(f), t, level);
      }
      break;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:33,代码来源:FunctionCheck.java

示例14: getMethodBlock

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Return a BLOCK node if the given FUNCTION node is a valid method
 * definition, null otherwise.
 *
 * Must be private, or moved to NodeUtil.
 */
private static Node getMethodBlock(Node fn) {
  if (fn.getChildCount() != 3) {
    return null;
  }

  Node expectedBlock = fn.getLastChild();
  return  expectedBlock.getType() == Token.BLOCK ?
      expectedBlock : null;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:16,代码来源:InlineGetters.java

示例15: stripPrototype

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Given a qualified name node, strip "prototype" off the end.
 *
 * Examples of this transformation:
 * a.b.c => a.b.c
 * a.b.c.prototype => a.b.c
 */
private Node stripPrototype(Node qualifiedName) {
  if (qualifiedName.getType() == Token.GETPROP &&
      qualifiedName.getLastChild().getString().equals("prototype")) {
    return qualifiedName.getFirstChild();
  }

  return qualifiedName;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:16,代码来源:ClosureCodingConvention.java


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