com.github.javaparser.ast.Node.getChildNodes()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(194)

本文整理了Java中com.github.javaparser.ast.Node.getChildNodes()方法的一些代码示例,展示了Node.getChildNodes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.getChildNodes()方法的具体详情如下:
包路径:com.github.javaparser.ast.Node
类名称:Node
方法名:getChildNodes

Node.getChildNodes介绍

暂无

代码示例

代码示例来源:origin: javaparser/javasymbolsolver

  1. public static int getParamPos(Parameter parameter) {
  2. int pos = 0;
  3. for (Node node : getParentNode(parameter).getChildNodes()) {
  4. if (node == parameter) {
  5. return pos;
  6. } else if (node instanceof Parameter) {
  7. pos++;
  8. }
  9. }
  10. return pos;
  11. }

代码示例来源:origin: javaparser/javasymbolsolver

  1. private static <N> N findNodeOfGivenClassHelper(Node node, Class<N> clazz) {
  2. if (clazz.isInstance(node)) {
  3. return clazz.cast(node);
  4. }
  5. for (Node child : node.getChildNodes()) {
  6. N resChild = findNodeOfGivenClassHelper(child, clazz);
  7. if (resChild != null) {
  8. return resChild;
  9. }
  10. }
  11. return null;
  12. }

代码示例来源:origin: javaparser/javasymbolsolver

  1. private static <N> void findAllNodesOfGivenClassHelper(Node node, Class<N> clazz, List<N> collector) {
  2. if (clazz.isInstance(node)) {
  3. collector.add(clazz.cast(node));
  4. }
  5. for (Node child : node.getChildNodes()) {
  6. findAllNodesOfGivenClassHelper(child, clazz, collector);
  7. }
  8. }
  9. }

代码示例来源:origin: GumTreeDiff/gumtree

  1. @Override
  2. public void visitPreOrder(Node node) {
  3. process(node);
  4. new ArrayList<>(node.getChildNodes()).forEach(this::visitPreOrder);
  5. if (trees.size() > 0)
  6. trees.pop();
  7. }

代码示例来源:origin: javaparser/javasymbolsolver

  1. private static SwitchStmt findSwitchHelper(Node node) {
  2. if (node instanceof SwitchStmt) {
  3. return (SwitchStmt) node;
  4. }
  5. for (Node child : node.getChildNodes()) {
  6. SwitchStmt resChild = findSwitchHelper(child);
  7. if (resChild != null) {
  8. return resChild;
  9. }
  10. }
  11. return null;
  12. }

代码示例来源:origin: com.github.javaparser/javaparser-symbol-solver-core

  1. public static int getParamPos(Parameter parameter) {
  2. int pos = 0;
  3. for (Node node : requireParentNode(parameter).getChildNodes()) {
  4. if (node == parameter) {
  5. return pos;
  6. } else if (node instanceof Parameter) {
  7. pos++;
  8. }
  9. }
  10. return pos;
  11. }

代码示例来源:origin: com.github.javaparser/java-symbol-solver-core

  1. private static SwitchStmt findSwitchHelper(Node node) {
  2. if (node instanceof SwitchStmt) {
  3. return (SwitchStmt) node;
  4. }
  5. for (Node child : node.getChildNodes()) {
  6. SwitchStmt resChild = findSwitchHelper(child);
  7. if (resChild != null) {
  8. return resChild;
  9. }
  10. }
  11. return null;
  12. }

代码示例来源:origin: com.github.javaparser/java-symbol-solver-core

  1. private static <N> N findNodeOfGivenClassHelper(Node node, Class<N> clazz) {
  2. if (clazz.isInstance(node)) {
  3. return clazz.cast(node);
  4. }
  5. for (Node child : node.getChildNodes()) {
  6. N resChild = findNodeOfGivenClassHelper(child, clazz);
  7. if (resChild != null) {
  8. return resChild;
  9. }
  10. }
  11. return null;
  12. }

代码示例来源:origin: com.github.javaparser/java-symbol-solver-core

  1. public static int getParamPos(Parameter parameter) {
  2. int pos = 0;
  3. for (Node node : getParentNode(parameter).getChildNodes()) {
  4. if (node == parameter) {
  5. return pos;
  6. } else if (node instanceof Parameter) {
  7. pos++;
  8. }
  9. }
  10. return pos;
  11. }

代码示例来源:origin: com.github.javaparser/java-symbol-solver-core

  1. private static <N> void findAllNodesOfGivenClassHelper(Node node, Class<N> clazz, List<N> collector) {
  2. if (clazz.isInstance(node)) {
  3. collector.add(clazz.cast(node));
  4. }
  5. for (Node child : node.getChildNodes()) {
  6. findAllNodesOfGivenClassHelper(child, clazz, collector);
  7. }
  8. }
  9. }

代码示例来源:origin: javaparser/javasymbolsolver

  1. private void collectAllNodes(Node node, List<Node> nodes) {
  2. nodes.add(node);
  3. node.getChildNodes().forEach(c -> collectAllNodes(c, nodes));
  4. }

代码示例来源:origin: com.github.javaparser/java-symbol-solver-core

  1. private void collectAllNodes(Node node, List<Node> nodes) {
  2. nodes.add(node);
  3. node.getChildNodes().forEach(c -> collectAllNodes(c, nodes));
  4. }

代码示例来源:origin: com.github.javaparser/javaparser-symbol-solver-core

  1. private static Optional<SwitchStmt> findSwitchHelper(Node node) {
  2. // TODO can be replaced by findFirst with the correct algorithm.
  3. if (node instanceof SwitchStmt) {
  4. return Optional.of((SwitchStmt) node);
  5. }
  6. for (Node child : node.getChildNodes()) {
  7. Optional<SwitchStmt> resChild = findSwitchHelper(child);
  8. if (resChild.isPresent()) {
  9. return resChild;
  10. }
  11. }
  12. return Optional.empty();
  13. }
  14. }

代码示例来源:origin: javaparser/javasymbolsolver

  1. private void solveMethodCalls(Node node) {
  2. if (node instanceof MethodCallExpr) {
  3. out.println(" Line " + node.getBegin().get().line + ") " + node + " ==> " + toString((MethodCallExpr) node));
  4. }
  5. for (Node child : node.getChildNodes()) {
  6. solveMethodCalls(child);
  7. }
  8. }

代码示例来源:origin: com.github.javaparser/java-symbol-solver-core

  1. private void solveMethodCalls(Node node) {
  2. if (node instanceof MethodCallExpr) {
  3. out.println(" Line " + node.getBegin().get().line + ") " + node + " ==> " + toString((MethodCallExpr) node));
  4. }
  5. for (Node child : node.getChildNodes()) {
  6. solveMethodCalls(child);
  7. }
  8. }

代码示例来源:origin: ftomassetti/analyze-java-code-examples

  1. public void explore(Node node) {
  2. if (nodeHandler.handle(node)) {
  3. for (Node child : node.getChildNodes()) {
  4. explore(child);
  5. }
  6. }
  7. }
  8. }

代码示例来源:origin: com.github.javaparser/javaparser-symbol-solver-core

  1. private void solveMethodCalls(Node node) {
  2. if (node instanceof MethodCallExpr) {
  3. out.println(" Line " + lineNr(node) + ") " + node + " ==> " + toString((MethodCallExpr) node));
  4. }
  5. for (Node child : node.getChildNodes()) {
  6. solveMethodCalls(child);
  7. }
  8. }

代码示例来源:origin: javaparser/javasymbolsolver

  1. public static SimpleName findSimpleName(Node node, String name) {
  2. if (node instanceof SimpleName) {
  3. SimpleName nameExpr = (SimpleName) node;
  4. if (nameExpr.getId() != null && nameExpr.getId().equals(name)) {
  5. return nameExpr;
  6. }
  7. }
  8. for (Node child : node.getChildNodes()) {
  9. SimpleName res = findSimpleName(child, name);
  10. if (res != null) {
  11. return res;
  12. }
  13. }
  14. return null;
  15. }

代码示例来源:origin: javaparser/javasymbolsolver

  1. public static MethodCallExpr findMethodCall(Node node, String methodName) {
  2. if (node instanceof MethodCallExpr) {
  3. MethodCallExpr methodCallExpr = (MethodCallExpr) node;
  4. if (methodCallExpr.getName().getId().equals(methodName)) {
  5. return methodCallExpr;
  6. }
  7. }
  8. for (Node child : node.getChildNodes()) {
  9. MethodCallExpr res = findMethodCall(child, methodName);
  10. if (res != null) {
  11. return res;
  12. }
  13. }
  14. return null;
  15. }

代码示例来源:origin: javaparser/javasymbolsolver

  1. @Test
  2. public void testFieldAccessThroughClassAndThis() throws ParseException {
  3. CompilationUnit cu = parseSample("Issue156");
  4. ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Issue156");
  5. List<MethodCallExpr> methods = clazz.getChildNodes().get(2).getChildNodes().get(1).getNodesByType(MethodCallExpr.class);
  6. TypeSolver typeSolver = new ReflectionTypeSolver();
  7. JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
  8. assertEquals("char", javaParserFacade.getType(methods.get(0)).describe());
  9. }
  10. }

相关文章