本文整理了Java中com.github.javaparser.ast.Node.getChildNodes()
方法的一些代码示例,展示了Node.getChildNodes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.getChildNodes()
方法的具体详情如下:
包路径:com.github.javaparser.ast.Node
类名称:Node
方法名:getChildNodes
暂无
代码示例来源:origin: javaparser/javasymbolsolver
public static int getParamPos(Parameter parameter) {
int pos = 0;
for (Node node : getParentNode(parameter).getChildNodes()) {
if (node == parameter) {
return pos;
} else if (node instanceof Parameter) {
pos++;
}
}
return pos;
}
代码示例来源:origin: javaparser/javasymbolsolver
private static <N> N findNodeOfGivenClassHelper(Node node, Class<N> clazz) {
if (clazz.isInstance(node)) {
return clazz.cast(node);
}
for (Node child : node.getChildNodes()) {
N resChild = findNodeOfGivenClassHelper(child, clazz);
if (resChild != null) {
return resChild;
}
}
return null;
}
代码示例来源:origin: javaparser/javasymbolsolver
private static <N> void findAllNodesOfGivenClassHelper(Node node, Class<N> clazz, List<N> collector) {
if (clazz.isInstance(node)) {
collector.add(clazz.cast(node));
}
for (Node child : node.getChildNodes()) {
findAllNodesOfGivenClassHelper(child, clazz, collector);
}
}
}
代码示例来源:origin: GumTreeDiff/gumtree
@Override
public void visitPreOrder(Node node) {
process(node);
new ArrayList<>(node.getChildNodes()).forEach(this::visitPreOrder);
if (trees.size() > 0)
trees.pop();
}
代码示例来源:origin: javaparser/javasymbolsolver
private static SwitchStmt findSwitchHelper(Node node) {
if (node instanceof SwitchStmt) {
return (SwitchStmt) node;
}
for (Node child : node.getChildNodes()) {
SwitchStmt resChild = findSwitchHelper(child);
if (resChild != null) {
return resChild;
}
}
return null;
}
代码示例来源:origin: com.github.javaparser/javaparser-symbol-solver-core
public static int getParamPos(Parameter parameter) {
int pos = 0;
for (Node node : requireParentNode(parameter).getChildNodes()) {
if (node == parameter) {
return pos;
} else if (node instanceof Parameter) {
pos++;
}
}
return pos;
}
代码示例来源:origin: com.github.javaparser/java-symbol-solver-core
private static SwitchStmt findSwitchHelper(Node node) {
if (node instanceof SwitchStmt) {
return (SwitchStmt) node;
}
for (Node child : node.getChildNodes()) {
SwitchStmt resChild = findSwitchHelper(child);
if (resChild != null) {
return resChild;
}
}
return null;
}
代码示例来源:origin: com.github.javaparser/java-symbol-solver-core
private static <N> N findNodeOfGivenClassHelper(Node node, Class<N> clazz) {
if (clazz.isInstance(node)) {
return clazz.cast(node);
}
for (Node child : node.getChildNodes()) {
N resChild = findNodeOfGivenClassHelper(child, clazz);
if (resChild != null) {
return resChild;
}
}
return null;
}
代码示例来源:origin: com.github.javaparser/java-symbol-solver-core
public static int getParamPos(Parameter parameter) {
int pos = 0;
for (Node node : getParentNode(parameter).getChildNodes()) {
if (node == parameter) {
return pos;
} else if (node instanceof Parameter) {
pos++;
}
}
return pos;
}
代码示例来源:origin: com.github.javaparser/java-symbol-solver-core
private static <N> void findAllNodesOfGivenClassHelper(Node node, Class<N> clazz, List<N> collector) {
if (clazz.isInstance(node)) {
collector.add(clazz.cast(node));
}
for (Node child : node.getChildNodes()) {
findAllNodesOfGivenClassHelper(child, clazz, collector);
}
}
}
代码示例来源:origin: javaparser/javasymbolsolver
private void collectAllNodes(Node node, List<Node> nodes) {
nodes.add(node);
node.getChildNodes().forEach(c -> collectAllNodes(c, nodes));
}
代码示例来源:origin: com.github.javaparser/java-symbol-solver-core
private void collectAllNodes(Node node, List<Node> nodes) {
nodes.add(node);
node.getChildNodes().forEach(c -> collectAllNodes(c, nodes));
}
代码示例来源:origin: com.github.javaparser/javaparser-symbol-solver-core
private static Optional<SwitchStmt> findSwitchHelper(Node node) {
// TODO can be replaced by findFirst with the correct algorithm.
if (node instanceof SwitchStmt) {
return Optional.of((SwitchStmt) node);
}
for (Node child : node.getChildNodes()) {
Optional<SwitchStmt> resChild = findSwitchHelper(child);
if (resChild.isPresent()) {
return resChild;
}
}
return Optional.empty();
}
}
代码示例来源:origin: javaparser/javasymbolsolver
private void solveMethodCalls(Node node) {
if (node instanceof MethodCallExpr) {
out.println(" Line " + node.getBegin().get().line + ") " + node + " ==> " + toString((MethodCallExpr) node));
}
for (Node child : node.getChildNodes()) {
solveMethodCalls(child);
}
}
代码示例来源:origin: com.github.javaparser/java-symbol-solver-core
private void solveMethodCalls(Node node) {
if (node instanceof MethodCallExpr) {
out.println(" Line " + node.getBegin().get().line + ") " + node + " ==> " + toString((MethodCallExpr) node));
}
for (Node child : node.getChildNodes()) {
solveMethodCalls(child);
}
}
代码示例来源:origin: ftomassetti/analyze-java-code-examples
public void explore(Node node) {
if (nodeHandler.handle(node)) {
for (Node child : node.getChildNodes()) {
explore(child);
}
}
}
}
代码示例来源:origin: com.github.javaparser/javaparser-symbol-solver-core
private void solveMethodCalls(Node node) {
if (node instanceof MethodCallExpr) {
out.println(" Line " + lineNr(node) + ") " + node + " ==> " + toString((MethodCallExpr) node));
}
for (Node child : node.getChildNodes()) {
solveMethodCalls(child);
}
}
代码示例来源:origin: javaparser/javasymbolsolver
public static SimpleName findSimpleName(Node node, String name) {
if (node instanceof SimpleName) {
SimpleName nameExpr = (SimpleName) node;
if (nameExpr.getId() != null && nameExpr.getId().equals(name)) {
return nameExpr;
}
}
for (Node child : node.getChildNodes()) {
SimpleName res = findSimpleName(child, name);
if (res != null) {
return res;
}
}
return null;
}
代码示例来源:origin: javaparser/javasymbolsolver
public static MethodCallExpr findMethodCall(Node node, String methodName) {
if (node instanceof MethodCallExpr) {
MethodCallExpr methodCallExpr = (MethodCallExpr) node;
if (methodCallExpr.getName().getId().equals(methodName)) {
return methodCallExpr;
}
}
for (Node child : node.getChildNodes()) {
MethodCallExpr res = findMethodCall(child, methodName);
if (res != null) {
return res;
}
}
return null;
}
代码示例来源:origin: javaparser/javasymbolsolver
@Test
public void testFieldAccessThroughClassAndThis() throws ParseException {
CompilationUnit cu = parseSample("Issue156");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Issue156");
List<MethodCallExpr> methods = clazz.getChildNodes().get(2).getChildNodes().get(1).getNodesByType(MethodCallExpr.class);
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
assertEquals("char", javaParserFacade.getType(methods.get(0)).describe());
}
}
内容来源于网络,如有侵权,请联系作者删除!