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

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

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

Node.jjtGetParent介绍

[英]Returns the parent of this node.
[中]返回此节点的父节点。

代码示例

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

private boolean isParent(Node possibleParent, Node node) {
  Node checkNode = node;
  while (checkNode.jjtGetParent() != null) {
    if (checkNode.jjtGetParent().equals(possibleParent)) {
      return true;
    }
    checkNode = checkNode.jjtGetParent();
  }
  return false;
}

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

ASTTreeNode(Node theNode) {
  node = theNode;
  Node parent = node.jjtGetParent();
  if (parent != null) {
    this.parent = new ASTTreeNode(parent);
  }
}

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

/**
 * This method can be called on a prefix
 */
private ASTArguments getSuffixMethodArgs(Node node) {
  Node prefix = node.jjtGetParent();
  if (prefix instanceof ASTPrimaryPrefix
      && prefix.jjtGetParent().jjtGetNumChildren() >= 2) {
    return prefix.jjtGetParent().jjtGetChild(1).getFirstChildOfType(ASTArguments.class);
  }
  return null;
}

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

private boolean insideLoop(ASTSoqlExpression node) {
    Node n = node.jjtGetParent();

    while (n != null) {
      if (n instanceof ASTDoLoopStatement || n instanceof ASTWhileLoopStatement
          || n instanceof ASTForLoopStatement || n instanceof ASTForEachStatement) {
        return true;
      }
      n = n.jjtGetParent();
    }

    return false;
  }
}

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

/**
 * Returns true if this nodes declares an exception parameter in
 * a {@code catch} statement.
 */
public boolean isExceptionBlockParameter() {
  return jjtGetParent().jjtGetParent() instanceof ASTCatchStatement;
}

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

@Override
public Object getParentNode(Object arg0) {
  if (arg0 instanceof Node) {
    return ((Node) arg0).jjtGetParent();
  }
  if (arg0 instanceof Attribute) {
    return ((Attribute) arg0).getParent();
  }
  // can't navigate to parent node...
  return null;
}

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

private boolean insideLoop(ASTSoslExpression node) {
    Node n = node.jjtGetParent();

    while (n != null) {
      if (n instanceof ASTDoLoopStatement || n instanceof ASTWhileLoopStatement
          || n instanceof ASTForLoopStatement || n instanceof ASTForEachStatement) {
        return true;
      }
      n = n.jjtGetParent();
    }

    return false;
  }
}

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

@Override
public <T> List<T> getParentsOfType(Class<T> parentType) {
  List<T> parents = new ArrayList<>();
  Node parentNode = jjtGetParent();
  while (parentNode != null) {
    if (parentType.isInstance(parentNode)) {
      parents.add(parentType.cast(parentNode));
    }
    parentNode = parentNode.jjtGetParent();
  }
  return parents;
}

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

@Override
public Object visit(final ASTConstructorDeclaration node, final Object data) {
  if (node.isPrivate()) {
    final String className = node.jjtGetParent().jjtGetParent().jjtGetParent().getImage();
    if (!privateConstructors.containsKey(className)) {
      privateConstructors.put(className, new ArrayList<ASTConstructorDeclaration>());
    }
    privateConstructors.get(className).add(node);
  }
  return data;
}

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

private void checkDeclarationInInterfaceType(Object data, Node fieldOrMethod, Set<Modifier> unnecessary) {
  // third ancestor could be an AllocationExpression
  // if this is a method in an anonymous inner class
  Node parent = fieldOrMethod.jjtGetParent().jjtGetParent().jjtGetParent();
  if (parent instanceof ASTAnnotationTypeDeclaration
      || parent instanceof ASTClassOrInterfaceDeclaration
      && ((ASTClassOrInterfaceDeclaration) parent).isInterface()) {
    reportUnnecessaryModifiers(data, fieldOrMethod, unnecessary, "the " + getPrintableNodeKind(fieldOrMethod) + " is declared in an " + getPrintableNodeKind(parent) + " type");
  }
}

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

@Override
public Object visit(ASTStatementExpression node, Object data) {
  if (!(node.jjtGetParent().jjtGetParent() instanceof ASTForUpdate)) {
    ((MutableInt) data).increment();
  }
  return data;
}

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

protected Node getPreviousSibling(Node contextNode) {
  Node parentNode = contextNode.jjtGetParent();
  if (parentNode != null) {
    int prevPosition = contextNode.jjtGetChildIndex() - 1;
    if (prevPosition >= 0) {
      return parentNode.jjtGetChild(prevPosition);
    }
  }
  return null;
}

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

private Node getNextSibling(Node current) {
  if (current.jjtGetParent().jjtGetNumChildren() > current.jjtGetChildIndex() + 1) {
    return current.jjtGetParent().jjtGetChild(current.jjtGetChildIndex() + 1);
  }
  return null;
}

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

public Node getTypeNameNode() {
  if (jjtGetParent() instanceof ASTFormalParameter) {
    return findTypeNameNode(jjtGetParent());
  } else if (jjtGetParent().jjtGetParent() instanceof ASTVariableOrConstantDeclaration
      || jjtGetParent().jjtGetParent() instanceof ASTFieldDeclaration) {
    return findTypeNameNode(jjtGetParent().jjtGetParent());
  }
  throw new RuntimeException(
      "Don't know how to get the type for anything other than ASTLocalVariableDeclaration/ASTFormalParameter/ASTFieldDeclaration");
}

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

protected Node getNextSibling(Node contextNode) {
  Node parentNode = contextNode.jjtGetParent();
  if (parentNode != null) {
    int nextPosition = contextNode.jjtGetChildIndex() + 1;
    if (nextPosition < parentNode.jjtGetNumChildren()) {
      return parentNode.jjtGetChild(nextPosition);
    }
  }
  return null;
}

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

/**
 * Indicate whether this node is allocating a new object.
 *
 * @param n
 *            node that might be allocating a new object
 * @return true if child 0 is an AllocationExpression
 */
private boolean isAllocation(Node n) {
  return n.jjtGetNumChildren() > 0 && n.jjtGetChild(0) instanceof ASTAllocationExpression
      && n.jjtGetParent().jjtGetNumChildren() == 1;
}

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

public ASTDatatype getTypeNode() {
  if (jjtGetParent() instanceof ASTFormalParameter) {
    return ((ASTFormalParameter) jjtGetParent()).getTypeNode();
  } else {
    Node n = jjtGetParent().jjtGetParent();
    if (n instanceof ASTVariableOrConstantDeclaration || n instanceof ASTFieldDeclaration) {
      return n.getFirstChildOfType(ASTDatatype.class);
    }
  }
  throw new RuntimeException(
      "Don't know how to get the type for anything other than ASTLocalVariableDeclaration/ASTFormalParameter/ASTFieldDeclaration");
}

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

public AccessNode getAccessNodeParent() {
  if (node.jjtGetParent() instanceof ASTFormalParameter || node.jjtGetParent() instanceof ASTLambdaExpression) {
    return (AccessNode) node.jjtGetParent();
  }
  return (AccessNode) node.jjtGetParent().jjtGetParent();
}

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

private boolean isStandAlonePostfix(Node primaryExpression) {
  if (!(primaryExpression instanceof ASTPostfixExpression)
      || !(primaryExpression.jjtGetParent() instanceof ASTStatementExpression)) {
    return false;
  }
  ASTPrimaryPrefix pf = (ASTPrimaryPrefix) ((ASTPrimaryExpression) primaryExpression.jjtGetChild(0))
      .jjtGetChild(0);
  if (pf.usesThisModifier()) {
    return true;
  }
  return thirdChildHasDottedName(primaryExpression);
}

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

@Override
public boolean isTargetMethod(JavaNameOccurrence occ) {
  if (occ.getNameForWhichThisIsAQualifier() != null
      && occ.getNameForWhichThisIsAQualifier().getImage().indexOf("trim") != -1) {
    Node pExpression = occ.getLocation().jjtGetParent().jjtGetParent();
    if (pExpression.jjtGetNumChildren() > 2 && "length".equals(pExpression.jjtGetChild(2).getImage())) {
      return true;
    }
  }
  return false;
}

相关文章