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

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

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

Node.findChildrenOfType介绍

[英]Traverses the children to find all the instances of type childType or one of its subclasses.
[中]遍历子类以查找childType类型或其子类之一的所有实例。

代码示例

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

@Override
public List<ASTAnnotation> getDeclaredAnnotations() {
  return this.jjtGetParent().findChildrenOfType(ASTAnnotation.class);
}

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

/**
   * Checks whether the given node contains a qualified name, consisting of
   * one ASTPrimaryPrefix and one or more ASTPrimarySuffix nodes.
   *
   * @param node
   *            the node
   * @return <code>true</code> if it is a qualified name
   */
  private boolean isPartOfQualifiedName(Node node) {
    return node.jjtGetChild(0) instanceof ASTPrimaryPrefix
        && !node.findChildrenOfType(ASTPrimarySuffix.class).isEmpty();
  }
}

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

private Object checkVariableDeclarators(List<String> prefixes, List<String> suffixes, Node root, boolean isStatic,
    boolean isFinal, Object data) {
  for (ASTVariableDeclarator variableDeclarator : root.findChildrenOfType(ASTVariableDeclarator.class)) {
    for (ASTVariableDeclaratorId variableDeclaratorId : variableDeclarator
        .findChildrenOfType(ASTVariableDeclaratorId.class)) {
      checkVariableDeclaratorId(prefixes, suffixes, isStatic, isFinal, variableDeclaratorId, data);
    }
  }
  return data;
}

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

@Override
public Object visit(final ASTElseIfStatement node, final Object data) {
  // verify that this elseif doesn't have any siblings
  if (node.jjtGetParent().findChildrenOfType(ASTElseIfStatement.class).size() == 1) {
    handleIfElseIf(node, data);
  }
  return super.visit(node, data);
}

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

boolean result = false;
Node parent = node.jjtGetParent();
List<ASTAnnotation> annotations = parent.findChildrenOfType(ASTAnnotation.class);
for (ASTAnnotation annotation : annotations) {
  ASTName name = annotation.getFirstDescendantOfType(ASTName.class);

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

@Override
public Object visit(ASTPrimaryPrefix pp, Object ctx) {
  List<ASTPrimarySuffix> primarySuffixes = pp.jjtGetParent().findChildrenOfType(ASTPrimarySuffix.class);
  ASTPrimarySuffix firstSuffix = null;
  if (!primarySuffixes.isEmpty()) {
    firstSuffix = primarySuffixes.get(0);
  }
  if (firstSuffix == null || firstSuffix.getImage() == null || !firstSuffix.getImage().endsWith("finalize")) {
    return super.visit(pp, ctx);
  }
  if (!checkForViolation(pp)) {
    return super.visit(pp, ctx);
  }
  addViolation(ctx, pp);
  return super.visit(pp, ctx);
}

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

List<ASTStatement> allStatements = node.jjtGetParent().findChildrenOfType(ASTStatement.class);
if (LOGGER.isLoggable(Level.FINEST)) {
  LOGGER.finest("ElseClause has " + allStatements.size() + " Statements ");

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

@Override
public Object visit(ASTMethodDeclaration methodDeclaration, Object o) {
  if (junitImported && isAllowedMethod(methodDeclaration)) {
    return super.visit(methodDeclaration, o);
  }
  if (methodDeclaration.getMethodName().startsWith("test")) {
    return super.visit(methodDeclaration, o);
  }
  
  // Ignore overridden methods, the issue should be marked on the method definition
  final List<ASTAnnotation> methodAnnotations = methodDeclaration.jjtGetParent().findChildrenOfType(ASTAnnotation.class);
  for (final ASTAnnotation annotation : methodAnnotations) {
    final ASTName annotationName = annotation.getFirstDescendantOfType(ASTName.class);
    if (annotationName.hasImageEqualTo("Override") || annotationName.hasImageEqualTo("java.lang.Override")) {
      return super.visit(methodDeclaration, o);
    }
  }
  checkExceptions(methodDeclaration, o);
  return super.visit(methodDeclaration, o);
}

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

List<ASTBlockStatement> blocks = parentBlock.jjtGetParent().findChildrenOfType(ASTBlockStatement.class);
int parentBlockIndex = blocks.indexOf(parentBlock);
int tryBlockIndex = blocks.indexOf(tryBlock);

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

@Override
public Object visit(ASTCatchStatement catchStmt, Object data) {
  String target = catchStmt.jjtGetChild(0).findChildrenOfType(ASTVariableDeclaratorId.class).get(0).getImage();

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

/**
   * Checks whether the given node contains a qualified name, consisting of
   * one ASTPrimaryPrefix and one or more ASTPrimarySuffix nodes.
   *
   * @param node
   *            the node
   * @return <code>true</code> if it is a qualified name
   */
  private boolean isPartOfQualifiedName(Node node) {
    return node.jjtGetChild(0) instanceof ASTPrimaryPrefix
        && !node.findChildrenOfType(ASTPrimarySuffix.class).isEmpty();
  }
}

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

@Override
public List<ASTAnnotation> getDeclaredAnnotations() {
  return this.jjtGetParent().findChildrenOfType(ASTAnnotation.class);
}

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

private Object checkVariableDeclarators(List<String> prefixes, List<String> suffixes, Node root, boolean isStatic,
    boolean isFinal, Object data) {
  for (ASTVariableDeclarator variableDeclarator : root.findChildrenOfType(ASTVariableDeclarator.class)) {
    for (ASTVariableDeclaratorId variableDeclaratorId : variableDeclarator
        .findChildrenOfType(ASTVariableDeclaratorId.class)) {
      checkVariableDeclaratorId(prefixes, suffixes, isStatic, isFinal, variableDeclaratorId, data);
    }
  }
  return data;
}

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

boolean result = false;
Node parent = node.jjtGetParent();
List<ASTAnnotation> annotations = parent.findChildrenOfType(ASTAnnotation.class);
for (ASTAnnotation annotation : annotations) {
  ASTName name = annotation.getFirstDescendantOfType(ASTName.class);

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

@Override
public Object visit(ASTPrimaryPrefix pp, Object ctx) {
  List<ASTPrimarySuffix> primarySuffixes = pp.jjtGetParent().findChildrenOfType(ASTPrimarySuffix.class);
  ASTPrimarySuffix firstSuffix = null;
  if (!primarySuffixes.isEmpty()) {
    firstSuffix = primarySuffixes.get(0);
  }
  if (firstSuffix == null || firstSuffix.getImage() == null || !firstSuffix.getImage().endsWith("finalize")) {
    return super.visit(pp, ctx);
  }
  if (!checkForViolation(pp)) {
    return super.visit(pp, ctx);
  }
  addViolation(ctx, pp);
  return super.visit(pp, ctx);
}

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

@Override
public Object visit(ASTMethodDeclaration methodDeclaration, Object o) {
  if (junitImported && isAllowedMethod(methodDeclaration)) {
    return super.visit(methodDeclaration, o);
  }
  if (methodDeclaration.getMethodName().startsWith("test")) {
    return super.visit(methodDeclaration, o);
  }
  
  // Ignore overridden methods, the issue should be marked on the method definition
  final List<ASTAnnotation> methodAnnotations = methodDeclaration.jjtGetParent().findChildrenOfType(ASTAnnotation.class);
  for (final ASTAnnotation annotation : methodAnnotations) {
    final ASTName annotationName = annotation.getFirstDescendantOfType(ASTName.class);
    if (annotationName.hasImageEqualTo("Override") || annotationName.hasImageEqualTo("java.lang.Override")) {
      return super.visit(methodDeclaration, o);
    }
  }
  checkExceptions(methodDeclaration, o);
  return super.visit(methodDeclaration, o);
}

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

List<ASTBlockStatement> blocks = parentBlock.jjtGetParent().findChildrenOfType(ASTBlockStatement.class);
int parentBlockIndex = blocks.indexOf(parentBlock);
int tryBlockIndex = blocks.indexOf(tryBlock);

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

@Override
public Object visit(ASTCatchStatement catchStmt, Object data) {
  String target = catchStmt.jjtGetChild(0).findChildrenOfType(ASTVariableDeclaratorId.class).get(0).getImage();

相关文章