本文整理汇总了Java中com.github.javaparser.ast.Node.getChildrenNodes方法的典型用法代码示例。如果您正苦于以下问题:Java Node.getChildrenNodes方法的具体用法?Java Node.getChildrenNodes怎么用?Java Node.getChildrenNodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.javaparser.ast.Node
的用法示例。
在下文中一共展示了Node.getChildrenNodes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitChildren
import com.github.javaparser.ast.Node; //导入方法依赖的package包/类
private void visitChildren(Node node, List<ArrayInitializerExpr> arrayInitializerExprs,
Map<String, String> scanedNames, Set<String> scanedImputs,
Map<String, Pattern> scanedRefeWrap, final String... fileName) {
// int level = 0;
// Node parent = node.getParentNode();
// while (parent != null) {
// parent = parent.getParentNode();
// level++;
// }
// if (level > 0 && fileName.length > 0 && fileName[0].endsWith("TeacherManager.java")) {
// if (node instanceof ClassOrInterfaceDeclaration) {
// ClassOrInterfaceDeclaration real = (ClassOrInterfaceDeclaration) node;
// }
// }
List<Node> children = node.getChildrenNodes();
if (Utils.hasLength(children)) {
//不能使用 for (Node node2 : children)
for (int i = 0; i < children.size(); i++) {
Node child = children.get(i);
visit(child, arrayInitializerExprs, scanedNames, scanedImputs, scanedRefeWrap, false, fileName);
}
}
}
示例2: parseNode
import com.github.javaparser.ast.Node; //导入方法依赖的package包/类
private void parseNode(Node node) {
// Capture all types of Expressions and Statements
if(node instanceof Expression){
incrementDictCount(this.expressions, node.getClass().getSimpleName());
} else if(node instanceof Statement){
incrementDictCount(this.statements, node.getClass().getSimpleName());
}
if(node instanceof ClassOrInterfaceDeclaration){
this.concepts.add("InnerClass");
}
else if(node instanceof MethodDeclaration){
this.concepts.add("InnerMethod");
}
if (node instanceof VariableDeclaratorId){
incrementDictCount(this.variables, ((VariableDeclaratorId) node).getName());
} else if (node instanceof MethodCallExpr) {
this.parseMethodCall((MethodCallExpr) node);
} else if (node instanceof Expression) {
this.parseExpr((Expression) node);
} else if(node instanceof CatchClause){
CatchClause catchClause = (CatchClause) node;
this.exceptions.add(catchClause.getParam().getType().toString());
} else if(node instanceof ThrowStmt){
Expression exp = ((ThrowStmt) node).getExpr();
List<Node> childNodes = exp.getChildrenNodes();
if(childNodes.size() > 1){
this.exceptions.add(childNodes.get(0).toString());
}
}
for(Node childNode : node.getChildrenNodes()){
parseNode(childNode);
}
}
示例3: getNodesByType
import com.github.javaparser.ast.Node; //导入方法依赖的package包/类
public static <N extends Node> List<N> getNodesByType(Node container, Class<N> clazz) {
List<N> nodes = new ArrayList<N>();
for (Node child : container.getChildrenNodes()) {
if (clazz.isInstance(child)) {
nodes.add(clazz.cast(child));
}
nodes.addAll(getNodesByType(child, clazz));
}
return nodes;
}
示例4: visitDepthFirst
import com.github.javaparser.ast.Node; //导入方法依赖的package包/类
/**
* https://en.wikipedia.org/wiki/Depth-first_search
*
* @param node the start node, and the first one that is passed to process(node).
*/
public void visitDepthFirst(Node node) {
process(node);
for (Node child : node.getChildrenNodes()) {
visitDepthFirst(child);
}
}