use of net.sourceforge.pmd.lang.java.ast.ASTType 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;
}
}
use of net.sourceforge.pmd.lang.java.ast.ASTType in project pmd by pmd.
the class UselessOperationOnImmutableRule method visit.
@Override
public Object visit(ASTLocalVariableDeclaration node, Object data) {
ASTVariableDeclaratorId var = getDeclaration(node);
if (var == null) {
return super.visit(node, data);
}
String variableName = var.getImage();
for (NameOccurrence no : var.getUsages()) {
// FIXME - getUsages will return everything with the same name as
// the variable,
// see JUnit test, case 6. Changing to Node below, revisit when
// getUsages is fixed
Node sn = no.getLocation();
Node primaryExpression = sn.jjtGetParent().jjtGetParent();
Class<? extends Node> parentClass = primaryExpression.jjtGetParent().getClass();
if (parentClass.equals(ASTStatementExpression.class)) {
String methodCall = sn.getImage().substring(variableName.length());
ASTType nodeType = node.getTypeNode();
if (nodeType != null) {
if (MAP_CLASSES.get(nodeType.getTypeImage()).contains(methodCall)) {
addViolation(data, sn);
}
}
}
}
return super.visit(node, data);
}
use of net.sourceforge.pmd.lang.java.ast.ASTType in project pmd by pmd.
the class ConstructorCallsOverridableMethodRule method getMethodDeclaratorParameterTypes.
private static List<String> getMethodDeclaratorParameterTypes(Node methodOrConstructorDeclarator) {
List<ASTFormalParameter> parameters = methodOrConstructorDeclarator.findDescendantsOfType(ASTFormalParameter.class);
List<String> parameterTypes = new ArrayList<>();
if (parameters != null) {
for (ASTFormalParameter p : parameters) {
ASTType type = p.getFirstChildOfType(ASTType.class);
if (type.jjtGetChild(0) instanceof ASTPrimitiveType) {
parameterTypes.add(type.jjtGetChild(0).getImage());
} else if (type.jjtGetChild(0) instanceof ASTReferenceType) {
parameterTypes.add("ref");
} else {
parameterTypes.add("<unkown>");
}
}
}
return parameterTypes;
}
use of net.sourceforge.pmd.lang.java.ast.ASTType in project pmd by pmd.
the class UnusedFormalParameterRule method isSerializationMethod.
private boolean isSerializationMethod(ASTMethodDeclaration node) {
ASTMethodDeclarator declarator = node.getFirstDescendantOfType(ASTMethodDeclarator.class);
List<ASTFormalParameter> parameters = declarator.findDescendantsOfType(ASTFormalParameter.class);
if (node.isPrivate() && "readObject".equals(node.getMethodName()) && parameters.size() == 1 && throwsOneException(node, InvalidObjectException.class)) {
ASTType type = parameters.get(0).getTypeNode();
if (type.getType() == ObjectInputStream.class || ObjectInputStream.class.getSimpleName().equals(type.getTypeImage()) || ObjectInputStream.class.getName().equals(type.getTypeImage())) {
return true;
}
}
return false;
}
use of net.sourceforge.pmd.lang.java.ast.ASTType in project pmd by pmd.
the class CouplingBetweenObjectsRule method visit.
@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);
}
Aggregations