use of net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId in project pmd by pmd.
the class CheckResultSetRule method visit.
@Override
public Object visit(ASTLocalVariableDeclaration node, Object data) {
ASTClassOrInterfaceType type = node.getFirstChildOfType(ASTType.class).getFirstDescendantOfType(ASTClassOrInterfaceType.class);
if (type != null && (type.getType() != null && "java.sql.ResultSet".equals(type.getType().getName()) || "ResultSet".equals(type.getImage()))) {
ASTVariableDeclarator declarator = node.getFirstChildOfType(ASTVariableDeclarator.class);
if (declarator != null) {
ASTName name = declarator.getFirstDescendantOfType(ASTName.class);
if (type.getType() != null || name != null && name.getImage().endsWith("executeQuery")) {
ASTVariableDeclaratorId id = declarator.getFirstChildOfType(ASTVariableDeclaratorId.class);
resultSetVariables.put(id.getImage(), node);
}
}
}
return super.visit(node, data);
}
use of net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId in project pmd by pmd.
the class SymbolTableTestRule method visit.
@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;
}
use of net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId in project pmd by pmd.
the class UnsynchronizedStaticDateFormatterRule method visit.
@Override
public Object visit(ASTFieldDeclaration node, Object data) {
if (!node.isStatic()) {
return data;
}
ASTClassOrInterfaceType cit = node.getFirstDescendantOfType(ASTClassOrInterfaceType.class);
if (cit == null || !targets.contains(cit.getImage())) {
return data;
}
ASTVariableDeclaratorId var = node.getFirstDescendantOfType(ASTVariableDeclaratorId.class);
for (NameOccurrence occ : var.getUsages()) {
Node n = occ.getLocation();
if (n.getFirstParentOfType(ASTSynchronizedStatement.class) != null) {
continue;
}
// ignore usages, that don't call a method.
if (!n.getImage().contains(".")) {
continue;
}
ASTMethodDeclaration method = n.getFirstParentOfType(ASTMethodDeclaration.class);
if (method != null && !method.isSynchronized()) {
addViolation(data, n);
}
}
return data;
}
use of net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId in project pmd by pmd.
the class VariableNameDeclaration method isVarargs.
public boolean isVarargs() {
ASTVariableDeclaratorId astVariableDeclaratorId = (ASTVariableDeclaratorId) node;
ASTFormalParameter parameter = astVariableDeclaratorId.getFirstParentOfType(ASTFormalParameter.class);
return parameter != null && parameter.isVarargs();
}
use of net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId in project pmd by pmd.
the class VariableNameDeclaration method getArrayDepth.
public int getArrayDepth() {
ASTVariableDeclaratorId astVariableDeclaratorId = (ASTVariableDeclaratorId) node;
ASTType typeNode = astVariableDeclaratorId.getTypeNode();
if (typeNode != null) {
return ((Dimensionable) typeNode.jjtGetParent()).getArrayDepth();
} else {
return 0;
}
}
Aggregations