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

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

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

Node.getImage介绍

[英]Returns a string token, usually filled-in by the parser, which describes some textual characteristic of this node. This is usually an identifier, but you should check that using the Designer. On most nodes though, this method returns null.
[中]返回一个字符串标记,通常由解析器填写,它描述了这个节点的一些文本特征。这通常是一个标识符,但您应该使用设计器检查它。但在大多数节点上,该方法返回null。

代码示例

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

private static boolean isNotEquals(Node node) {
  // look for "x != y"
  return node instanceof ASTEqualityExpression && "!=".equals(node.getImage());
}

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

private String getLastPartOfName(Node name) {
  String result = "";
  if (name != null) {
    result = name.getImage();
  }
  int dotIndex = result.lastIndexOf('.');
  if (dotIndex > -1 && result.length() > dotIndex + 1) {
    result = result.substring(dotIndex + 1);
  }
  return result;
}

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

private static String[] imagesOf(List<? extends Node> nodes) {
  String[] imageArray = new String[nodes.size()];
  for (int i = 0; i < nodes.size(); i++) {
    imageArray[i] = nodes.get(i).getImage();
  }
  return imageArray;
}

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

/**
 * Returns the name of the annotation as it is used,
 * eg {@code java.lang.Override} or {@code Override}.
 */
public String getAnnotationName() {
  return jjtGetChild(0).getImage();
}

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

/**
 * Returns the full name of the import. For on-demand imports, this is the name without
 * the final dot and asterisk.
 */
public String getImportedName() {
  return jjtGetChild(0).getImage();
}

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

/**
 * Returns the name of the annotation as it is used,
 * eg {@code java.lang.Override} or {@code Override}.
 */
public String getAnnotationName() {
  return jjtGetChild(0).getImage();
}

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

/**
 * Returns the name of the declared variable.
 */
public String getName() {
  // first child will be VariableDeclaratorId
  return jjtGetChild(0).getImage();
}

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

/**
 * Returns the name of the annotation as it is used,
 * eg {@code java.lang.Override} or {@code Override}.
 */
public String getAnnotationName() {
  return jjtGetChild(0).getImage();
}

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

private boolean basicEquivalence(Node node1, Node node2, String varName1, String varName2) {
  // Nodes must have the same type
  if (node1.getClass() != node2.getClass()) {
    return false;
  }
  String image1 = node1.getImage();
  String image2 = node2.getImage();
  // image of nodes must be the same
  return Objects.equals(image1, image2)
      // or must be references to the variable we allow to interchange
      || Objects.equals(image1, varName1) && Objects.equals(image2, varName2)
      // which means we must filter out method references.
      && isNoMethodName(node1) && isNoMethodName(node2);
}

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

@Override
public Object visit(ASTImportDeclaration node, Object data) {
  String img = node.jjtGetChild(0).getImage();
  if (img.startsWith("sun.") && !img.startsWith("sun.misc.Signal")) {
    addViolation(data, node);
  }
  return data;
}

代码示例来源: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

/**
 * Returns the name of the annotation as it is used,
 * eg {@code java.lang.Override} or {@code Override}.
 */
public String getAnnotationName() {
  return jjtGetChild(0).jjtGetChild(0).getImage();
}

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

private void collectNames(String target, List<String> names, Node node) {
  for (int i = 0; i < node.jjtGetNumChildren(); i++) {
    Node child = node.jjtGetChild(i);
    if (child.jjtGetNumChildren() > 0) {
      collectNames(target, names, child);
    } else {
      if (child instanceof ASTName && isQualifiedName(child)
          && target.equals(getVariableName(child.getImage()))) {
        names.add(child.getImage());
      }
    }
  }
}

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

@Override
  public Object visit(ASTFieldDeclaration node, Object data) {
    for (ASTVariableDeclaratorId declaration : node.findDescendantsOfType(ASTVariableDeclaratorId.class)) {
      for (NameOccurrence no : declaration.getUsages()) {
        Node location = no.getLocation();
        System.out.println(declaration.getImage() + " is used here: " + location.getImage());
      }
    }
    return data;
  }
}

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

public String getName() {
  if (node instanceof ASTConstructorDeclaration) {
    return this.getEnclosingScope(ClassScope.class).getClassName();
  }
  return node.jjtGetChild(1).getImage();
}

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

private int checkEachChildOnNextLine(Object data, Node parent, int firstLine, int indentation) {
  int currentLine = firstLine;
  for (int i = 0; i < parent.jjtGetNumChildren(); i++) {
    Node child = parent.jjtGetChild(i);
    if (child.getBeginLine() != currentLine) {
      addViolationWithMessage(data, child, child.getImage() + " should be on line " + currentLine);
    } else if (i > 0 && child.getBeginColumn() != indentation) {
      addViolationWithMessage(data, child, child.getImage() + " should begin at column " + indentation);
    }
    // next entry needs to be on the next line
    currentLine++;
  }
  return currentLine;
}

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

@Override
public Object visit(ASTAllocationExpression node, Object data) {
  if (!inPrimaryExpressionContext || !(node.jjtGetChild(0) instanceof ASTClassOrInterfaceType)) {
    return super.visit(node, data);
  }
  if (!PRIMITIVE_WRAPPERS.contains(node.jjtGetChild(0).getImage())) {
    return super.visit(node, data);
  }
  usingPrimitiveWrapperAllocation = true;
  return super.visit(node, data);
}

代码示例来源: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;
}

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

@Override
public Object visit(ASTFieldDeclaration node, Object data) {
  for (int x = 0; x < node.jjtGetNumChildren(); ++x) {
    Node firstStmt = node.jjtGetChild(x);
    if (firstStmt instanceof ASTType) {
      ASTType tp = (ASTType) firstStmt;
      Node nd = tp.jjtGetChild(0);
      checkVariableType(nd, nd.getImage());
    }
  }
  return super.visit(node, data);
}

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

private boolean hasArraysCopyOf(ASTReturnStatement ret) {
  List<ASTPrimaryExpression> expressions = ret.findDescendantsOfType(ASTPrimaryExpression.class);
  for (ASTPrimaryExpression e : expressions) {
    if (e.jjtGetNumChildren() == 2 && e.jjtGetChild(0) instanceof ASTPrimaryPrefix
        && e.jjtGetChild(0).jjtGetNumChildren() == 1 && e.jjtGetChild(0).jjtGetChild(0) instanceof ASTName
        && e.jjtGetChild(0).jjtGetChild(0).getImage().endsWith("Arrays.copyOf")) {
      return true;
    }
  }
  return false;
}

相关文章