net.sourceforge.pmd.lang.ast.Node.findChildNodesWithXPath()方法的使用及代码示例

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

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

Node.findChildNodesWithXPath介绍

[英]Returns all the nodes matching the xpath expression.
[中]返回与xpath表达式匹配的所有节点。

代码示例

代码示例来源:origin: pmd/pmd

  1. private boolean isEmptyArray(String varName, ASTTypeDeclaration typeDeclaration) {
  2. final List<ASTFieldDeclaration> fds = typeDeclaration.findDescendantsOfType(ASTFieldDeclaration.class);
  3. if (fds != null) {
  4. for (ASTFieldDeclaration fd : fds) {
  5. final ASTVariableDeclaratorId vid = fd.getFirstDescendantOfType(ASTVariableDeclaratorId.class);
  6. if (vid != null && vid.hasImageEqualTo(varName)) {
  7. ASTVariableInitializer initializer = fd.getFirstDescendantOfType(ASTVariableInitializer.class);
  8. if (initializer != null && initializer.jjtGetNumChildren() == 1) {
  9. Node child = initializer.jjtGetChild(0);
  10. if (child instanceof ASTArrayInitializer && child.jjtGetNumChildren() == 0) {
  11. return true;
  12. } else if (child instanceof ASTExpression) {
  13. try {
  14. List<? extends Node> arrayAllocation = child.findChildNodesWithXPath(
  15. "./PrimaryExpression/PrimaryPrefix/AllocationExpression/ArrayDimsAndInits/Expression/PrimaryExpression/PrimaryPrefix/Literal[@IntLiteral=\"true\"][@Image=\"0\"]");
  16. if (arrayAllocation != null && arrayAllocation.size() == 1) {
  17. return true;
  18. }
  19. } catch (JaxenException e) {
  20. return false;
  21. }
  22. }
  23. }
  24. }
  25. }
  26. }
  27. return false;
  28. }
  29. }

代码示例来源:origin: net.sourceforge.pmd/pmd-java

  1. private boolean isEmptyArray(String varName, ASTTypeDeclaration typeDeclaration) {
  2. final List<ASTFieldDeclaration> fds = typeDeclaration.findDescendantsOfType(ASTFieldDeclaration.class);
  3. if (fds != null) {
  4. for (ASTFieldDeclaration fd : fds) {
  5. final ASTVariableDeclaratorId vid = fd.getFirstDescendantOfType(ASTVariableDeclaratorId.class);
  6. if (vid != null && vid.hasImageEqualTo(varName)) {
  7. ASTVariableInitializer initializer = fd.getFirstDescendantOfType(ASTVariableInitializer.class);
  8. if (initializer != null && initializer.jjtGetNumChildren() == 1) {
  9. Node child = initializer.jjtGetChild(0);
  10. if (child instanceof ASTArrayInitializer && child.jjtGetNumChildren() == 0) {
  11. return true;
  12. } else if (child instanceof ASTExpression) {
  13. try {
  14. List<? extends Node> arrayAllocation = child.findChildNodesWithXPath(
  15. "./PrimaryExpression/PrimaryPrefix/AllocationExpression/ArrayDimsAndInits/Expression/PrimaryExpression/PrimaryPrefix/Literal[@IntLiteral=\"true\"][@Image=\"0\"]");
  16. if (arrayAllocation != null && arrayAllocation.size() == 1) {
  17. return true;
  18. }
  19. } catch (JaxenException e) {
  20. return false;
  21. }
  22. }
  23. }
  24. }
  25. }
  26. }
  27. return false;
  28. }
  29. }

代码示例来源:origin: com.alibaba.p3c/p3c-pmd

  1. List<? extends Node> additiveNodes = node.findChildNodesWithXPath(XPATH);
  2. for (Node additiveNode : additiveNodes) {
  3. ASTAdditiveExpression additiveExpression = (ASTAdditiveExpression)additiveNode;

代码示例来源:origin: com.alibaba.p3c/p3c-pmd

  1. List<? extends Node> simpleExpressions = invocation.findChildNodesWithXPath(INVOCATION_PREFIX_XPATH);
  2. if (simpleExpressions == null || simpleExpressions.isEmpty()) {
  3. return super.visit(node, data);

相关文章