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


Java Node.getChildCount方法代码示例

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


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

示例1: updateTypeOfParametersOnClosure

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

示例2: attachJsDoc

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/** Attach JSDocInfo to a node, if we can find one. */
private void attachJsDoc(Comment comment, JSDocInfo info) {
  Collection<NodeWithJsDoc> candidates =
      nodesWithJsDoc.get(comment.getValue());
  if (candidates.isEmpty()) {
    return;
  }

  Iterator<NodeWithJsDoc> candidateIter = candidates.iterator();
  Node node = candidateIter.next().node;
  candidateIter.remove();
  node.setJSDocInfo(info);
  if (info.hasEnumParameterType()) {
    if (node.getType() == Token.NAME) {
      registry.identifyEnumName(node.getString());
    } else if (node.getType() == Token.VAR &&
          node.getChildCount() == 1) {
      registry.identifyEnumName(
          node.getFirstChild().getString());
    } else if (node.getType() == Token.ASSIGN) {
      registry.identifyEnumName(
          node.getFirstChild().getQualifiedName());
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:26,代码来源:IRFactory.java

示例3: identifyTypeDeclarationCall

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

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Removes any optional parameters if no callers specifies it as an argument.
 * @param name The name of the function to optimize. 
 * @param edges All the references to this name.
 */
private void tryEliminateOptionalArgs(Name name,
    List<DiGraphEdge<Name, Reference>> edges) {
  
  // Count the maximum number of arguments passed into this function all
  // all points of the program.
  int maxArgs = -1;

  for (DiGraphEdge<Name, Reference> refEdge : edges) {
    Reference ref = refEdge.getValue();
    Node call = ref.parent;

    if (isCallSite(ref)) {
      int numArgs = call.getChildCount() - 1;
      if (numArgs > maxArgs) {
        maxArgs = numArgs;
      }
    } // else this is a definition or a dereference, ignore it.
  }

  for (Definition definition : name.getDeclarations()) {
    eliminateParamsAfter(definition.getRValue(), maxArgs);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:29,代码来源:OptimizeParameters.java

示例5: consumesDanglingElse

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Does a statement consume a 'dangling else'? A statement consumes
 * a 'dangling else' if an 'else' token following the statement
 * would be considered by the parser to be part of the statement.
 */
private boolean consumesDanglingElse(Node n) {
  while (true) {
    switch (n.getType()) {
      case Token.IF:
        if (n.getChildCount() < 3) return true;
        // This IF node has no else clause.
        n = n.getLastChild();
        continue;
      case Token.WITH:
      case Token.WHILE:
      case Token.FOR:
        n = n.getLastChild();
        continue;
      default:
        return false;
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:24,代码来源:FoldConstants.java

示例6: getPreciserScopeKnowingConditionOutcome

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
@Override
public FlowScope getPreciserScopeKnowingConditionOutcome(Node condition,
    FlowScope blindScope, boolean outcome) {
  if (condition.getType() == CALL && condition.getChildCount() == 2) {
    Node callee = condition.getFirstChild();
    Node param = condition.getLastChild();
    if (callee.getType() == GETPROP && param.isQualifiedName()) {
      JSType paramType =  getTypeIfRefinable(param, blindScope);
      Node left = callee.getFirstChild();
      Node right = callee.getLastChild();
      if (left.getType() == NAME && "goog".equals(left.getString()) &&
          right.getType() == STRING) {
        Function<TypeRestriction, JSType> restricter =
            restricters.get(right.getString());
        if (restricter != null) {
          return restrictParameter(param, paramType, blindScope, restricter,
              outcome);
        }
      }
    }
  }
  return nextPreciserScopeKnowingConditionOutcome(
      condition, blindScope, outcome);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:ClosureReverseAbstractInterpreter.java

示例7: tryFoldFor

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Removes FORs that always evaluate to false.
 */
void tryFoldFor(NodeTraversal t, Node n, Node parent) {
  Preconditions.checkArgument(n.getType() == Token.FOR);
  // This is not a FOR-IN loop
  if (n.getChildCount() != 4) return;
  // There isn't an initializer
  if (n.getFirstChild().getType() != Token.EMPTY) return;

  Node cond = NodeUtil.getConditionExpression(n);
  if (!NodeUtil.isLiteralValue(cond) || NodeUtil.getBooleanValue(cond)) {
    return;
  }
  NodeUtil.redeclareVarsInsideBranch(n);
  NodeUtil.removeChild(parent, n);
  t.getCompiler().reportCodeChange();
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:19,代码来源:FoldConstants.java

示例8: getMaxArguments

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Gets the maximum number of arguments that this function requires,
 * or Integer.MAX_VALUE if this is a variable argument function.
 */
public int getMaxArguments() {
  Node params = getParametersNode();
  if (params != null) {
    Node lastParam = params.getLastChild();
    if (lastParam == null || !lastParam.isVarArgs()) {
      return params.getChildCount();
    }
  }

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

示例9: removeChild

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/** Safely remove children while maintaining a valid node structure. */
static void removeChild(Node parent, Node node) {
  // Node parent = node.getParent();
  if (isStatementBlock(parent)
      || isSwitchCase(node)
      || isTryFinallyNode(parent, node)) {
    // A statement in a block can simply be removed.
    parent.removeChild(node);
  } else if (parent.getType() == Token.VAR) {
    if (parent.hasMoreThanOneChild()) {
      parent.removeChild(node);
    } else {
      // Remove the node from the parent, so it can be reused.
      parent.removeChild(node);
      // This would leave an empty VAR, remove the VAR itself.
      removeChild(parent.getParent(), parent);
    }
  } else if (node.getType() == Token.BLOCK) {
    // Simply empty the block.  This maintains source location and
    // "synthetic"-ness.
    node.detachChildren();
  } else if (parent.getType() == Token.LABEL
      && node == parent.getLastChild()) {
    // Remove the node from the parent, so it can be reused.
    parent.removeChild(node);
    // A LABEL without children can not be referred to, remove it.
    removeChild(parent.getParent(), parent);
  } else if (parent.getType() == Token.FOR
      && parent.getChildCount() == 4) {
    // Only Token.FOR can have an Token.EMPTY other control structure
    // need something for the condition. Others need to be replaced
    // or the structure removed.
    parent.replaceChild(node, new Node(Token.EMPTY));
  } else {
    throw new IllegalStateException("Invalid attempt to remove node: " +
        node.toString() + " of "+ parent.toString());
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:39,代码来源:NodeUtil.java

示例10: visitParameterList

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Visits the parameters of a CALL or a NEW node.
 */
private void visitParameterList(NodeTraversal t, Node call,
    FunctionType functionType) {
  Iterator<Node> arguments = call.children().iterator();
  arguments.next(); // skip the function name

  Iterator<Node> parameters = functionType.getParameters().iterator();
  int ordinal = 0;
  while (arguments.hasNext() && parameters.hasNext()) {
    Node parameter = parameters.next();
    Node argument = arguments.next();
    ordinal++;

    validator.expectArgumentMatchesParameter(t, argument,
        getJSType(argument), getJSType(parameter), call, ordinal);
  }

  int numArgs = call.getChildCount() - 1;
  int minArgs = functionType.getMinArguments();
  int maxArgs = functionType.getMaxArguments();
  if (minArgs > numArgs || maxArgs < numArgs) {
    t.getCompiler().report(
        JSError.make(t, call, WRONG_ARGUMENT_COUNT,
            validator.getReadableJSTypeName(call.getFirstChild(), false),
            String.valueOf(numArgs), String.valueOf(minArgs),
            maxArgs != Integer.MAX_VALUE ?
            " and no more than " + maxArgs + " argument(s)" : ""));
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:32,代码来源:TypeCheck.java

示例11: removeVarDeclaration

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Tries to remove variable declaration if the variable has been coalesced
 * with another variable that has already been declared.
 */
private void removeVarDeclaration(Node name) {
  Node var = name.getParent();
  Node parent = var.getParent();

  // Special case when we are in FOR-IN loop.
  if (NodeUtil.isForIn(parent)) {
    var.removeChild(name);
    parent.replaceChild(var, name);
  } else if (var.getChildCount() == 1) {
    // The removal is easy when there is only one variable in the VAR node.
    if (name.hasChildren()) {
      Node value = name.removeFirstChild();
      var.removeChild(name);
      Node assign = new Node(Token.ASSIGN, name, value);

      // We don't need to wrapped it with EXPR node if it is within a FOR.
      if (parent.getType() != Token.FOR) {
        assign = NodeUtil.newExpr(assign);
      }
      parent.replaceChild(var, assign);

    } else {
      // In a FOR( ; ; ) node, we must replace it with an EMPTY or else it
      // becomes a FOR-IN node.
      NodeUtil.removeChild(parent, var);
    }
  } else {
    if (!name.hasChildren()) {
      var.removeChild(name);
    }
    // We are going to leave duplicated declaration otherwise.
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:38,代码来源:CoalesceVariableNames.java

示例12: 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

示例13: handleContinue

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private void handleContinue(Node node) {
  String label = null;
  if (node.hasChildren()) {
    label = node.getFirstChild().getString();
  }
  Node cur;
  Node lastJump;
  // Similar to handBreak's logic with a few minor variation.
  Node parent = node.getParent();
  for (cur = node, lastJump = node;
      !isContinueTarget(cur, parent, label);
      cur = parent, parent = parent.getParent()) {
    if (cur.getType() == Token.TRY && NodeUtil.hasFinally(cur)) {
      if (lastJump == node) {
        createEdge(lastJump, Branch.UNCOND, cur.getLastChild());
      } else {
        finallyMap.put(lastJump, computeFallThrough(cur.getLastChild()));
      }
      lastJump = cur;
    }
    Preconditions.checkState(parent != null, "Cannot find continue target.");
  }
  Node iter = cur;
  if (cur.getChildCount() == 4) {
    iter = cur.getFirstChild().getNext().getNext();
  }

  if (lastJump == node) {
    createEdge(node, Branch.UNCOND, iter);
  } else {
    finallyMap.put(lastJump, iter);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:34,代码来源:ControlFlowAnalysis.java

示例14: createCallProposals

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private void createCallProposals(Node inspectedNode, Map<Integer, List<Proposal>> proposals, ArrayList<Var> internalVars, ArrayList<Var> externalVars) {
    Node firstChild = inspectedNode.getFirstChild();
    ArrayList<Var> visiableVars = new ArrayList<>();
    internalVars.stream().filter(v->v.getNameNode().getSourceOffset() < inspectedNode.getSourceOffset())
            .forEach(visiableVars::add);
    visiableVars.addAll(externalVars);
    if (firstChild != null && firstChild.getJSType() != null && firstChild.getJSType() instanceof FunctionType) {
        FunctionType ft = (FunctionType)firstChild.getJSType();
        int paramNum = 0;
        for (Node paramterNode : ft.getParameters()) {
            ++paramNum;
            ArrayList<Var> filteredVars = new ArrayList<>();
            JSType parameterNodeType = fixNullType(paramterNode.getJSType());
            visiableVars.stream().filter(v -> noTypeFound(v) || viableAssignment(v.getNameNode().getJSType(), parameterNodeType)).forEach(filteredVars::add);
            Node argumentNode = inspectedNode.getChildCount() > paramNum?inspectedNode.getChildAtIndex(paramNum):null;
            filteredVars.sort(this::compareTypeQuality);
            ArrayList<Proposal> proposalList = new ArrayList<>(filteredVars.stream().map(v -> new Proposal(v.getName())).collect(Collectors.toList()));
            if (parameterNodeType.isFunctionType() && (argumentNode == null || !argumentNode.getJSType().isFunctionType())) {
                String newFunction = createFunctionDeclaration(parameterNodeType.toMaybeFunctionType());
                proposalList.add(0,new Proposal(newFunction));
            }
            if (argumentNode != null) {
                proposals.put(argumentNode.getSourceOffset(), proposalList);
            } else {
                proposals.put(inspectedNode.getSourceOffset()+inspectedNode.getLength()-1, proposalList);
                break;
            }
        }
    } else {
        proposals.put(inspectedNode.getSourceOffset()+1,visiableVars.stream().map(v->new Proposal(v.getName())).collect(Collectors.toList()));
    }
}
 
开发者ID:factoryfx,项目名称:factoryfx,代码行数:33,代码来源:ContentAssist.java

示例15: tryFoldGetProp

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Try to fold array-length. e.g [1, 2, 3].length ==> 3, [x, y].length ==> 2
 */
void tryFoldGetProp(NodeTraversal t, Node n, Node left, Node right,
                    Node parent) {
  if (right.getType() == Token.STRING &&
      right.getString().equals("length")) {
    int knownLength = -1;
    switch (left.getType()) {
      case Token.ARRAYLIT:
        if (NodeUtil.mayHaveSideEffects(left)) {
          // Nope, can't fold this, without handling the side-effects.
          return;
        }
        knownLength = left.getChildCount();
        break;
      case Token.STRING:
        knownLength = left.getString().length();
        break;
      default:
        // Not a foldable case, forget it.
        return;
    }

    Preconditions.checkState(knownLength != -1);
    Node lengthNode = Node.newNumber(knownLength);
    parent.replaceChild(n, lengthNode);
    t.getCompiler().reportCodeChange();
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:31,代码来源:FoldConstants.java


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