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


Java Node.children方法代码示例

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


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

示例1: addSimplifiedExpression

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private void addSimplifiedExpression(Node n, Node parent) {
  if (parent.getType() == Token.VAR) {
    Node value = n.getFirstChild();
    if (value != null) {
      addSimplifiedChildren(value);
    }
  } else if (n.getType() == Token.ASSIGN &&
      (parent.getType() == Token.EXPR_RESULT ||
       parent.getType() == Token.FOR ||
       parent.getType() == Token.RETURN)) {
    for (Node child : n.children()) {
      addSimplifiedChildren(child);
    }
  } else if (n.getType() == Token.CALL &&
             parent.getType() == Token.EXPR_RESULT) {
    addSimplifiedChildren(n);
  } else {
    addAllChildren(n);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:21,代码来源:NameAnalyzer.java

示例2: declareArguments

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Declares all of a function's arguments.
 */
private void declareArguments(Node functionNode) {
  Node astParameters = functionNode.getFirstChild().getNext();
  Node body = astParameters.getNext();
  FunctionType functionType = (FunctionType) functionNode.getJSType();
  if (functionType != null) {
    Node jsDocParameters = functionType.getParametersNode();
    if (jsDocParameters != null) {
      Node jsDocParameter = jsDocParameters.getFirstChild();
      for (Node astParameter : astParameters.children()) {
        if (jsDocParameter != null) {
          defineSlot(astParameter, functionNode,
              jsDocParameter.getJSType(), true);
          jsDocParameter = jsDocParameter.getNext();
        } else {
          defineSlot(astParameter, functionNode, null, true);
        }
      }
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:24,代码来源:TypedScopeCreator.java

示例3: findModifiedParameters

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Check for uses of the named value that imply a pass-by-value
 * parameter is expected.  This is used to prevent cases like:
 *
 *   function (x) {
 *     x=2;
 *     return x;
 *   }
 *
 * We don't want "undefined" to be substituted for "x", and get
 *   undefined=2
 *
 * @param n The node in question.
 * @param parent The parent of the node.
 * @param names The set of names to check.
 */
private static Set<String> findModifiedParameters(
    Node n, Node parent, Set<String> names, Set<String> unsafe) {
  Preconditions.checkArgument(unsafe != null);
  if (n.getType() == Token.NAME) {
    if (names.contains(n.getString())) {
      if (canNameValueChange(n, parent)) {
        unsafe.add(n.getString());
      }
    }
  }

  for (Node c : n.children()) {
    findModifiedParameters(c, n, names, unsafe);
  }

  return unsafe;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:34,代码来源:FunctionArgumentInjector.java

示例4: replaceReferencesToThis

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Replaces references to "this" with references to name.  Do not
 * traverse function boundaries.
 */
private void replaceReferencesToThis(Node node, String name) {
  if (NodeUtil.isFunction(node)) {
    return;
  }

  for (Node child : node.children()) {
    if (NodeUtil.isThis(child)) {
      Node newName = Node.newString(Token.NAME, name);
      newName.setJSType(child.getJSType());
      node.replaceChild(child, newName);
    } else {
      replaceReferencesToThis(child, name);
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:20,代码来源:DevirtualizePrototypeMethods.java

示例5: findFunction

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private static Node findFunction(Node n, String name) {
  if (n.getType() == Token.FUNCTION) {
    if (n.getFirstChild().getString().equals(name)) {
      return n;
    }
  }

  for (Node c : n.children()) {
    Node result = findFunction(c, name);
    if (result != null) {
      return result;
    }
  }

  return null;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:17,代码来源:FunctionInjectorTest.java

示例6: findNameType

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private JSType findNameType(String name, Scope scope) {
  Node root = scope.getRootNode();
  Deque<Node> queue = Lists.newLinkedList();
  queue.push(root);
  while (!queue.isEmpty()) {
    Node current = queue.pop();
    if (name.equals(current.getQualifiedName()) &&
        current.getJSType() != null) {
      return current.getJSType();
    }

    for (Node child : current.children()) {
      queue.push(child);
    }
  }
  return null;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:18,代码来源:InferJSDocInfoTest.java

示例7: findCall

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private static Node findCall(Node n, String name) {
  if (n.getType() == Token.CALL) {
    Node callee = n.getFirstChild();
    if (callee.getType() == Token.NAME
        && callee.getString().equals(name)) {
      return n;
    }
  }

  for (Node c : n.children()) {
    Node result = findCall(c, name);
    if (result != null) {
      return result;
    }
  }

  return null;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:19,代码来源:ExpresssionDecomposerTest.java

示例8: getParameters

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public Iterable<Node> getParameters() {
  Node n = getParametersNode();
  if (n != null) {
    return n.children();
  } else {
    return Collections.emptySet();
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:9,代码来源:FunctionType.java

示例9: visitVar

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Visits a VAR node.
 *
 * @param t The node traversal object that supplies context, such as the
 * scope chain to use in name lookups as well as error reporting.
 * @param n The node being visited.
 */
private void visitVar(NodeTraversal t, Node n) {
  // TODO(nicksantos): Fix this so that the doc info always shows up
  // on the NAME node. We probably want to wait for the parser
  // merge to fix this.
  JSDocInfo varInfo = n.hasOneChild() ? n.getJSDocInfo() : null;
  for (Node name : n.children()) {
    Node value = name.getFirstChild();
    // A null var would indicate a bug in the scope creation logic.
    Var var = t.getScope().getVar(name.getString());

    if (value != null) {
      JSType valueType = getJSType(value);
      JSType nameType = var.getType();
      nameType = (nameType == null) ? getNativeType(UNKNOWN_TYPE) : nameType;

      JSDocInfo info = name.getJSDocInfo();
      if (info == null) {
        info = varInfo;
      }
      if (info != null && info.hasEnumParameterType()) {
        // var.getType() can never be null, this would indicate a bug in the
        // scope creation logic.
        checkEnumInitializer(
            t, value,  info.getEnumParameterType().evaluate(t.getScope()));
      } else if (var.isTypeInferred()) {
        ensureTyped(t, name, valueType);
      } else {
        validator.expectCanAssignTo(
            t, value, valueType, nameType, "initializing variable");
      }
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:41,代码来源:TypeCheck.java

示例10: containsName

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private boolean containsName(Node n, String name) {
  if (n.getType() == Token.NAME && n.getString().equals(name)) {
    return true;
  }

  for (Node child : n.children()) {
    if (containsName(child, name)) {
      return true;
    }
  }
  return false;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:13,代码来源:CollapseAnonymousFunctions.java

示例11: findCall

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private static Node findCall(Node n, String name) {
  if (n.getType() == Token.CALL) {
    Node callee;
    if (NodeUtil.isGet(n.getFirstChild())) {
      callee = n.getFirstChild().getFirstChild();
      Node prop = callee.getNext();
      // Only "call" is support at this point.
      Preconditions.checkArgument(prop.getType() == Token.STRING &&
          prop.getString().equals("call"));
    } else {
      callee = n.getFirstChild();
    }

    if (callee.getType() == Token.NAME
        && callee.getString().equals(name)) {
      return n;
    }
  }

  for (Node c : n.children()) {
    Node result = findCall(c, name);
    if (result != null) {
      return result;
    }
  }

  return null;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:29,代码来源:FunctionArgumentInjectorTest.java

示例12: gatherFunctions

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
	 * Find all functions in this parse tree by recursively traversing it's children.
	 */
	private void gatherFunctions(Node parent, Set<CFGFunction> gathered) {

		JavaScriptType objectLiteralType = null;
		if(parent.getType() == Token.OBJECTLIT) {
		
			String name = "";

			Node parentParent = parent.getParent();
			if(parentParent != null && parentParent.getType() == Token.ASSIGN) {
				// Was this assigned to a property or a local?
				Node assignee = parentParent.getChildAtIndex(0);
				if(assignee.getType() == Token.GETPROP) {
					Node property = assignee.getLastChild();
					if(property != null && property.getType() == Token.STRING) {
						name = property.getString();							
					}
				}
				else if(assignee.getType() == Token.NAME) {
					name = assignee.getString();
				}
				else if(assignee.getType() == Token.GETELEM) {
				}
				else {
				}
				
			}
			else if(parentParent.getType() == Token.NAME)
				name = parentParent.getString();

			objectLiteralType = new JavaScriptType(name, true);
			objectLiteralTypes.put(parent, objectLiteralType);
			if(!name.equals("")) namedObjectLiteralTypes.put(name, objectLiteralType);			
			
//			Feedlack.out("Found object literal named " + name + " on line " + parent.getLineno());
			
		}
		
		for(Node child : parent.children()) {

//			Feedlack.out("On ");

			if(child instanceof FunctionNode) {
				
				CFGFunction fun = addFunction(parent, (FunctionNode)child);
				gathered.add(fun);
				
				if(objectLiteralType != null) {
					
					objectLiteralType.addFunction(fun);
//					Feedlack.out("Found function " + fun.getFunctionName() + " for type " + objectLiteralType.getName());
					
				}
				
			}

			gatherFunctions(child, gathered);
		}
		
	}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:63,代码来源:Feedlack.java

示例13: inferParameterTypes

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Infer the parameter types from the list of argument names and
 * the doc info.
 */
FunctionTypeBuilder inferParameterTypes(@Nullable Node argsParent,
    @Nullable JSDocInfo info) {
  if (argsParent == null) {
    if (info == null) {
      return this;
    } else {
      return inferParameterTypes(info);
    }
  }

  // arguments
  FunctionParamBuilder builder = new FunctionParamBuilder(typeRegistry);
  boolean warnedAboutArgList = false;
  Set<String> allJsDocParams = (info == null) ?
      Sets.<String>newHashSet() :
      Sets.newHashSet(info.getParameterNames());
  boolean foundTemplateType = false;
  for (Node arg : argsParent.children()) {
    String argumentName = arg.getString();
    allJsDocParams.remove(argumentName);

    // type from JSDocInfo
    JSType parameterType =
        info != null && info.hasParameterType(argumentName) ?
        info.getParameterType(argumentName).evaluate(scope) :
        typeRegistry.getNativeType(UNKNOWN_TYPE);
    if (templateTypeName != null &&
        parameterType.restrictByNotNullOrUndefined().isTemplateType()) {
      if (foundTemplateType) {
        reportError(TEMPLATE_TYPE_DUPLICATED, fnName);
      }
      foundTemplateType = true;
    }
    warnedAboutArgList |= addParameter(
        builder, parameterType, warnedAboutArgList,
        isOptionalParameter(arg, info),
        isVarArgsParameter(arg, info));
  }

  if (templateTypeName != null && !foundTemplateType) {
    reportError(TEMPLATE_TYPE_EXPECTED, fnName);
  }

  for (String inexistentName : allJsDocParams) {
    reportWarning(INEXISTANT_PARAM, inexistentName, fnName);
  }

  parametersNode = builder.build();
  return this;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:55,代码来源:FunctionTypeBuilder.java

示例14: getStatementCount

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private int getStatementCount(Node current, int count) {
	
	if(current.getType() == Token.BLOCK) {
		
		count += current.getChildCount();
		
	}
	for(Node node : current.children()) {
		count = getStatementCount(node, count);
	}
	return count;
	
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:14,代码来源:CFGFunction.java


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